diff --git a/.github/workflows/Format.yml b/.github/workflows/Format.yml index e1a731d..6682f79 100644 --- a/.github/workflows/Format.yml +++ b/.github/workflows/Format.yml @@ -10,5 +10,5 @@ jobs: steps: - uses: julia-actions/julia-format@v3 with: - version: '1' # Set `version` to '1.0.54' if you need to use JuliaFormatter.jl v1.0.54 (default: '1') + version: '2' suggestion-label: 'format-suggest' # leave this unset or empty to show suggestions for all PRs diff --git a/Project.toml b/Project.toml index d73b9b9..d7089a2 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "TCIAlgorithms" uuid = "baf62351-2e82-41dd-9129-4f5768a618e1" -authors = ["Hiroshi Shinaoka and contributors"] version = "0.5.0" +authors = ["Hiroshi Shinaoka and contributors"] [deps] Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b" @@ -12,7 +12,6 @@ ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" Quantics = "87f76fb3-a40a-40c9-a63c-29fcfe7b7547" -TCIITensorConversion = "9f0aa9f4-9415-4e6a-8795-331ebf40aa04" TensorCrossInterpolation = "b261b2ec-6378-4871-b32e-9173bb050604" [compat] @@ -22,13 +21,11 @@ FastMPOContractions = "0.2.2" HubbardAtoms = "0.1.0" ITensorMPS = "0.3.2" ITensors = "0.7" -JET = "0.9.12" OrderedCollections = "1" -Quantics = "0.4" -QuanticsGrids = "0.3.2" +Quantics = "0.4.7" +QuanticsGrids = "0.6" SparseIR = "1.0.19" -TCIITensorConversion = "0.2" -TensorCrossInterpolation = "0.9.7" +TensorCrossInterpolation = "0.9" julia = "1.10" [extras] diff --git a/src/TCIAlgorithms.jl b/src/TCIAlgorithms.jl index fa9fbd1..bcb108d 100644 --- a/src/TCIAlgorithms.jl +++ b/src/TCIAlgorithms.jl @@ -4,7 +4,6 @@ import TensorCrossInterpolation as TCI import TensorCrossInterpolation: TensorTrain, evaluate, TTCache, MultiIndex, LocalIndex, TensorCI2 -using TCIITensorConversion using ITensors using ITensorMPS: ITensorMPS using ITensorMPS: MPO, MPS, linkdims, linkinds @@ -17,7 +16,6 @@ using EllipsisNotation import TensorCrossInterpolation as TCI import TensorCrossInterpolation: TensorTrain, evaluate, TTCache, MultiIndex, LocalIndex, TensorCI2 -using TCIITensorConversion import LinearAlgebra as LA import FastMPOContractions as FMPOC @@ -38,7 +36,4 @@ include("patching.jl") include("crossinterpolate.jl") include("adaptivematmul.jl") -# ITensor interface -include("itensor.jl") - end diff --git a/src/crossinterpolate.jl b/src/crossinterpolate.jl index 3c4f578..67f69bf 100644 --- a/src/crossinterpolate.jl +++ b/src/crossinterpolate.jl @@ -1,5 +1,6 @@ """ # For TCI2 + `f` is a function that can be evaluated at full-length indices (including projected and non-projected indices). The wrapped function can be evaluated only on unprojected indices. """ struct _FuncAdapterTCI2Subset{T} <: TCI.BatchEvaluator{T} diff --git a/src/itensor.jl b/src/itensor.jl deleted file mode 100644 index 9bcd49c..0000000 --- a/src/itensor.jl +++ /dev/null @@ -1,339 +0,0 @@ -# Struct Definitions -struct ProjMPS - data::MPS - sites::Vector{Vector{Index}} - projector::Projector - - function ProjMPS( - data::MPS, sites::AbstractVector{<:AbstractVector}, projector::Projector - ) - _check_projector_compatibility(projector, data, sites) || error( - "Incompatible projector and data. Even small numerical noise can cause this error.", - ) - return new(permutesiteinds(data, sites), sites, projector) - end -end - -struct ProjMPSContainer - data::Vector{ProjMPS} - sites::Vector{Vector{Index}} - projector::Projector - - function ProjMPSContainer(data::AbstractVector{ProjMPS}) - for n in 2:length(data) - data[n].sites == data[1].sites || - error("Sitedims mismatch $(data[n].sites) != $(data[1].sites)") - end - projector = reduce(|, x.projector for x in data) - return new(data, data[1].sites, projector) - end -end - -# Constructor Functions -function ProjMPS(Ψ::MPS, sites::AbstractVector{<:AbstractVector}) - sitedims = [collect(dim.(s)) for s in sites] - globalprojector = Projector([fill(0, length(s)) for s in sitedims], sitedims) - return ProjMPS(Ψ, sites, globalprojector) -end - -function ProjMPSContainer(::Type{T}, projttcont::ProjTTContainer{T}, sites) where {T} - return ProjMPSContainer([ProjMPS(T, patch, sites) for patch in projttcont.data]) -end - -# Conversion Functions -ITensorMPS.MPS(projΨ::ProjMPS) = projΨ.data - -function ProjTensorTrain{T}(projΨ::ProjMPS) where {T} - return ProjTensorTrain{T}( - asTT3(T, projΨ.data, projΨ.sites; permdims=false), projΨ.projector - ) -end - -function ProjMPS(::Type{T}, projtt::ProjTensorTrain{T}, sites) where {T} - links = [Index(ld, "Link,l=$l") for (l, ld) in enumerate(TCI.linkdims(projtt.data))] - - tensors = ITensor[] - sitedims = [collect(dim.(s)) for s in sites] - linkdims = dim.(links) - - push!( - tensors, - ITensor( - reshape(projtt.data[1], 1, prod(sitedims[1]), linkdims[1]), - sites[1]..., - links[1], - ), - ) - - for n in 2:(length(projtt.data) - 1) - push!( - tensors, - ITensor( - reshape(projtt.data[n], linkdims[n - 1], prod(sitedims[n]), linkdims[n]), - links[n - 1], - sites[n]..., - links[n], - ), - ) - end - - push!( - tensors, - ITensor( - reshape(projtt.data[end], linkdims[end], prod(sitedims[end])), - links[end], - sites[end]..., - ), - ) - - return ProjMPS(MPS(tensors), sites, projtt.projector) -end - -function ProjTTContainer{T}(projmpss::ProjMPSContainer) where {T} - return ProjTTContainer([ProjTensorTrain{T}(projmps) for projmps in projmpss.data]) -end - -# Utility Functions -function permutesiteinds(Ψ::MPS, sites::AbstractVector{<:AbstractVector}) - links = linkinds(Ψ) - tensors = Vector{ITensor}(undef, length(Ψ)) - tensors[1] = permute(Ψ[1], vcat(sites[1], links[1])) - for n in 2:(length(Ψ) - 1) - tensors[n] = permute(Ψ[n], vcat(links[n - 1], sites[n], links[n])) - end - tensors[end] = permute(Ψ[end], vcat(links[end], sites[end])) - return MPS(tensors) -end - -function project(tensor::ITensor, projsiteinds::Dict{K,Int}) where {K} - slice = Union{Int,Colon}[ - idx ∈ keys(projsiteinds) ? projsiteinds[idx] : Colon() for idx in inds(tensor) - ] - data_org = Array(tensor, inds(tensor)...) - data_trim = zero(data_org) - data_trim[slice...] .= data_org[slice...] - return ITensor(data_trim, inds(tensor)...) -end - -function project(oldprojector::Projector, sites, projsiteinds::Dict{Index{T},Int}) where {T} - newprojdata = deepcopy(oldprojector.data) - for (siteind, projind) in projsiteinds - pos = find_nested_index(sites, siteind) - if pos === nothing - error("Site index not found: $siteind") - end - newprojdata[pos[1]][pos[2]] = projind - end - return Projector(newprojdata, oldprojector.sitedims) -end - -function project(projΨ::ProjMPS, projsiteinds::Dict{Index{T},Int}) where {T} - return ProjMPS( - MPS([project(projΨ.data[n], projsiteinds) for n in 1:length(projΨ.data)]), - projΨ.sites, - project(projΨ.projector, projΨ.sites, projsiteinds), - ) -end - -function asTT3(::Type{T}, Ψ::MPS, sites; permdims=true)::TensorTrain{T,3} where {T} - Ψ2 = permdims ? _permdims(Ψ, sites) : Ψ - tensors = Array{T,3}[] - links = linkinds(Ψ2) - push!(tensors, reshape(Array(Ψ2[1], sites[1]..., links[1]), 1, :, dim(links[1]))) - for n in 2:(length(Ψ2) - 1) - push!( - tensors, - reshape( - Array(Ψ2[n], links[n - 1], sites[n]..., links[n]), - dim(links[n - 1]), - :, - dim(links[n]), - ), - ) - end - push!( - tensors, reshape(Array(Ψ2[end], links[end], sites[end]...), dim(links[end]), :, 1) - ) - return TensorTrain{T,3}(tensors) -end - -function _check_projector_compatibility( - projector::Projector, Ψ::MPS, sites::AbstractVector{<:AbstractVector} -) - links = linkinds(Ψ) - sitedims = [collect(dim.(s)) for s in sites] - - sitetensors = [] - push!( - sitetensors, - reshape( - Array(Ψ[1], [sites[1]..., links[1]]), [1, prod(sitedims[1]), dim(links[1])]... - ), - ) - for n in 2:(length(Ψ) - 1) - push!( - sitetensors, - reshape( - Array(Ψ[n], [links[n - 1], sites[n]..., links[n]]), - dim(links[n - 1]), - prod(sitedims[n]), - dim(links[n]), - ), - ) - end - push!( - sitetensors, - reshape( - Array(Ψ[end], [links[end], sites[end]...]), - dim(links[end]), - prod(sitedims[end]), - 1, - ), - ) - - return reduce( - &, - _check_projector_compatibility(projector[n], sitedims[n], sitetensors[n]) for - n in 1:length(Ψ) - ) -end - -function find_nested_index(data::Vector{Vector{T}}, target::T) where {T} - for (i, subvector) in enumerate(data) - j = findfirst(x -> x == target, subvector) - if j !== nothing - return (i, j) - end - end - return nothing # Not found -end - -# Quantics Functions -function Quantics.makesitediagonal(projmps::ProjMPS, site::Index) - mps_diagonal = Quantics.makesitediagonal(MPS(projmps), site) - sites_diagonal = ITensors.SiteTypes.siteinds(all, mps_diagonal) - projmps_diagonal = ProjMPS(mps_diagonal, sites_diagonal) - - prjsiteinds = Dict{Index{Int},Int}() - for (p, s) in zip(projmps.projector, projmps.sites) - for (p_, s_) in zip(p, s) - iszero(p_) && continue - prjsiteinds[s_] = p_ - if s_ == site - prjsiteinds[s_'] = p_ - end - end - end - - return project(projmps_diagonal, prjsiteinds) -end - -function Quantics.makesitediagonal(projmps::ProjMPS, tag::String) - mps_diagonal = Quantics.makesitediagonal(MPS(projmps), tag) - sites_diagonal = ITensors.SiteTypes.siteinds(all, mps_diagonal) - projmps_diagonal = ProjMPS(mps_diagonal, sites_diagonal) - - target_positions = Quantics.findallsiteinds_by_tag( - ITensors.SiteTypes.siteinds(MPS(projmps)); tag=tag - ) - prjsiteinds = Dict{Index{Int},Int}() - for (p, s) in zip(projmps.projector, projmps.sites) - for (p_, s_) in zip(p, s) - iszero(p_) && continue - prjsiteinds[s_] = p_ - if s_ ∈ target_positions - prjsiteinds[s_'] = p_ - end - end - end - - return project(projmps_diagonal, prjsiteinds) -end - -function Quantics.makesitediagonal(projmpss::ProjMPSContainer, sites) - return ProjMPSContainer([ - Quantics.makesitediagonal(projmps, sites) for projmps in projmpss.data - ]) -end - -function Quantics.extractdiagonal(projmps::ProjMPS, tag::String) - mps_diagonal = Quantics.extractdiagonal(MPS(projmps), tag) - sites_diagonal = ITensors.SiteTypes.siteinds(all, mps_diagonal) - projmps_diagonal = ProjMPS(mps_diagonal, sites_diagonal) - sites_diagonal_set = Set(Iterators.flatten(sites_diagonal)) - - prjsiteinds = Dict{Index{Int},Int}() - for (p, s) in zip(projmps.projector, projmps.sites) - for (p_, s_) in zip(p, s) - !iszero(p_) || continue - s_ ∈ sites_diagonal_set || continue - prjsiteinds[s_] = p_ - end - end - - return project(projmps_diagonal, prjsiteinds) -end - -function Quantics.extractdiagonal(projmpss::ProjMPSContainer, sites) - return ProjMPSContainer([ - Quantics.extractdiagonal(projmps, sites) for projmps in projmpss.data - ]) -end - -function Quantics.rearrange_siteinds(projmps::ProjMPS, sites) - mps_rearranged = Quantics.rearrange_siteinds(MPS(projmps), sites) - projmps_rearranged = ProjMPS(mps_rearranged, sites) - prjsiteinds = Dict{Index{Int},Int}() - for (p, s) in zip(projmps.projector, projmps.sites) - for (p_, s_) in zip(p, s) - if p_ != 0 - prjsiteinds[s_] = p_ - end - end - end - return project(projmps_rearranged, prjsiteinds) -end - -function Quantics.rearrange_siteinds(projmpss::ProjMPSContainer, sites) - return ProjMPSContainer([ - Quantics.rearrange_siteinds(projmps, sites) for projmps in projmpss.data - ]) -end - -# Miscellaneous Functions -function Base.show(io::IO, obj::ProjMPS) - return print(io, "ProjMPS projected on $(obj.projector.data)") -end - -function ITensors.prime(Ψ::ProjMPS, args...; kwargs...) - return ProjMPS( - prime(MPS(Ψ), args...; kwargs...), prime.(Ψ.sites, args...; kwargs...), Ψ.projector - ) -end - -function ITensors.prime(Ψ::ProjMPSContainer, args...; kwargs...) - return ProjMPSContainer([prime(projmps, args...; kwargs...) for projmps in Ψ.data]) -end - -Base.isapprox(x::ProjMPS, y::ProjMPS; kwargs...) = Base.isapprox(x.data, y.data, kwargs...) - -# Random MPO Functions (commented out) -#== -function _random_mpo( - rng::AbstractRNG, sites::AbstractVector{<:AbstractVector{Index{T}}}; m::Int=1 -) where {T} - sites_ = collect(Iterators.flatten(sites)) - Ψ = random_mps(rng, sites_, m) - tensors = ITensor[] - pos = 1 - for i in 1:length(sites) - push!(tensors, prod(Ψ[pos:(pos + length(sites[i]) - 1)])) - pos += length(sites[i]) - end - return MPS(tensors) -end - -function _random_mpo(sites::AbstractVector{<:AbstractVector{Index{T}}}; m::Int=1) where {T} - return _random_mpo(Random.default_rng(), sites; m=m) -end -==# diff --git a/src/projectable_evaluator.jl b/src/projectable_evaluator.jl index d3082ca..7f92446 100644 --- a/src/projectable_evaluator.jl +++ b/src/projectable_evaluator.jl @@ -2,8 +2,9 @@ Represents an object that can be projected on a subset of indices Attributes: -- projector: Projector object -- sitedims: Vector{Vector{Int}} of the dimensions of the local indices + + - projector: Projector object + - sitedims: Vector{Vector{Int}} of the dimensions of the local indices """ abstract type ProjectableEvaluator{T} <: TCI.BatchEvaluator{T} end @@ -41,7 +42,7 @@ end Compute a tensor train approximation of the object. The computation should be quick because the result will be used as initial guesses for the optimization. Override this function - """ +""" function approxtt( obj::ProjectableEvaluator{T}; maxbonddim=typemax(Int), tolerance=1e-14, kwargs... )::ProjTensorTrain{T} where {T} diff --git a/src/projtensortrain.jl b/src/projtensortrain.jl index 5134608..5fbe22b 100644 --- a/src/projtensortrain.jl +++ b/src/projtensortrain.jl @@ -2,9 +2,10 @@ Represents a TensorTrain object which can be projected on a subset of indices Compared to TCI.TensorTrain, this object has additional functionalities: -* Projection -* Multi site indices per tensor are supported. -* Fast evaluation by caching intermediate objects of contraction + + - Projection + - Multi site indices per tensor are supported. + - Fast evaluation by caching intermediate objects of contraction """ mutable struct ProjTensorTrain{T} <: ProjectableEvaluator{T} data::TensorTrain{T} diff --git a/test/adaptivematmul_tests.jl b/test/adaptivematmul_tests.jl index 128b6ea..48c62fc 100644 --- a/test/adaptivematmul_tests.jl +++ b/test/adaptivematmul_tests.jl @@ -129,8 +129,9 @@ import TCIAlgorithms: _random_tt() = TCI.TensorTrain([ rand(bonddims[n], sitedims[n]..., bonddims[n + 1]) for n in 1:N ]) - _random_tt(bs::BlockStructure) = - [project(ProjTensorTrain(_random_tt()), p) for p in bs] + _random_tt(bs::BlockStructure) = [ + project(ProjTensorTrain(_random_tt()), p) for p in bs + ] bs = TCIA.BlockStructure( vec([TCIA.Projector([[i, j], [0, 0], [0, 0]], sitedims) for i in 1:2, j in 1:2]) @@ -172,8 +173,8 @@ import TCIAlgorithms: product = TCIA.adaptivematmul(expttpatches, expttpatches, pordering; maxbonddim=50) nested_quantics(x, y) = [ - collect(p) for p in - zip(QG.origcoord_to_quantics(grid1, x), QG.origcoord_to_quantics(grid1, y)) + collect(p) for + p in zip(QG.origcoord_to_quantics(grid1, x), QG.origcoord_to_quantics(grid1, y)) ] points = [(rand() * 10 - 5, rand() * 10 - 5) for i in 1:100] @@ -241,8 +242,8 @@ import TCIAlgorithms: ) nested_quantics(x, y) = [ - collect(p) for p in - zip(QG.origcoord_to_quantics(grid1, x), QG.origcoord_to_quantics(grid1, y)) + collect(p) for + p in zip(QG.origcoord_to_quantics(grid1, x), QG.origcoord_to_quantics(grid1, y)) ] points = [(rand(), rand()) for i in 1:100] @@ -319,18 +320,18 @@ import TCIAlgorithms: ) nested_quantics(x, y) = [ - collect(p) for p in - zip(QG.origcoord_to_quantics(grid1, x), QG.origcoord_to_quantics(grid1, y)) + collect(p) for + p in zip(QG.origcoord_to_quantics(grid1, x), QG.origcoord_to_quantics(grid1, y)) ] C = zeros(2^R, 2^R) .+ 0.0 - for i in 0:(2^R - 1) + for i in 0:(2 ^ R - 1) C[i + 1, i + 1] = i^5 end product_matrix = zeros(2^R, 2^R) .+ 0.0 product_matrix_without_patches = zeros(2^R, 2^R) .+ 0.0 - for i in 0:(2^R - 1), j in 0:(2^R - 1) + for i in 0:(2 ^ R - 1), j in 0:(2 ^ R - 1) product_matrix[i + 1, j + 1] = product(nested_quantics(i, j)) product_matrix_without_patches[i + 1, j + 1] = product_without_patches( nested_quantics(i, j) @@ -370,19 +371,19 @@ import TCIAlgorithms: return 1 / beta^2 * chi0(ch, model, (FermionicFreq(2x + 1), FermionicFreq(2y + 1), m)) end - fI_chi0 = QG.quanticsfunction(ComplexF64, grid, fq_chi0) + fI_chi0 = x -> fq_chi0(quantics_to_origcoord(grid, x)...) function fq_full(x, y) return full_vertex( ch, model, (FermionicFreq(2x + 1), FermionicFreq(2y + 1), m) ) end - fI_full = QG.quanticsfunction(ComplexF64, grid, fq_full) + fI_full = x -> fq_full(quantics_to_origcoord(grid, x)...) function fq_gamma(x, y) return gamma(ch, model, (FermionicFreq(2x + 1), FermionicFreq(2y + 1), m)) end - fI_gamma = QG.quanticsfunction(ComplexF64, grid, fq_gamma) + fI_gamma = x -> fq_gamma(quantics_to_origcoord(grid, x)...) ######################################################################### initialpivots = [QG.origcoord_to_quantics(grid, (0, 0))] # approx center of grid diff --git a/test/bse3d_tests.jl b/test/bse3d_tests.jl index d5c5f34..9073e7c 100644 --- a/test/bse3d_tests.jl +++ b/test/bse3d_tests.jl @@ -28,19 +28,19 @@ using ITensors ch, model, (FermionicFreq(x), FermionicFreq(y), BosonicFreq(z)) ) end - fI_full = QG.quanticsfunction(ComplexF64, grid, fq_full) + fI_full = x -> fq_full(quantics_to_origcoord(grid, x)...) # we absorb 1/β^2 into the chi0 function function fq_chi0(x, y, z) return 1 / beta^2 * chi0(ch, model, (FermionicFreq(x), FermionicFreq(y), BosonicFreq(z))) end - fI_chi0 = QG.quanticsfunction(ComplexF64, grid, fq_chi0) + fI_chi0 = x -> fq_chi0(quantics_to_origcoord(grid, x)...) function fq_gamma(x, y, z) return gamma(ch, model, (FermionicFreq(x), FermionicFreq(y), BosonicFreq(z))) end - fI_gamma = QG.quanticsfunction(ComplexF64, grid, fq_gamma) + fI_gamma = x -> fq_gamma(quantics_to_origcoord(grid, x)...) return fq_full, fq_chi0, fq_gamma, fI_full, fI_chi0, fI_gamma end @@ -129,7 +129,8 @@ using ITensors # normal multiplication for comparison box = [ (x, y, z) for x in range(-N + 1; step=2, length=N), - y in range(-N + 1; step=2, length=N), z in range(-N; step=2, length=N) + y in range(-N + 1; step=2, length=N), + z in range(-N; step=2, length=N) ] chi0_exact = map(splat(fq_chi0), box) full_exact = map(splat(fq_full), box) diff --git a/test/codequality_tests.jl b/test/codequality_tests.jl index 58dd01a..6c2b0e0 100644 --- a/test/codequality_tests.jl +++ b/test/codequality_tests.jl @@ -7,8 +7,8 @@ using TCIAlgorithms Aqua.test_all(TCIAlgorithms; deps_compat=false) end -#= -@testset "JET.jl" begin - JET.test_package(TCIAlgorithms; target_defined_modules=true) +@testset "JET" begin + if VERSION ≥ v"1.10" + JET.test_package(TCIAlgorithms; target_defined_modules=true) + end end -=# diff --git a/test/itensor_tests.jl b/test/itensor_tests.jl deleted file mode 100644 index 9dc2901..0000000 --- a/test/itensor_tests.jl +++ /dev/null @@ -1,118 +0,0 @@ -using Test -import TensorCrossInterpolation as TCI -import TCIAlgorithms as TCIA -using Quantics - -import TCIAlgorithms: Projector, project, ProjTensorTrain, LazyMatrixMul, makeprojectable - -using ITensors -using ITensorMPS - -@testset "itensor" begin - @testset "ProjMPS" begin - N = 3 - sitesx = [Index(2, "x=$n") for n in 1:N] - sitesy = [Index(2, "y=$n") for n in 1:N] - sites = collect(collect.(zip(sitesx, sitesy))) - Ψ = MPS(collect(_random_mpo(sites))) - prjΨ = TCIA.ProjMPS(Ψ, sites) - - prjΨ1 = project(prjΨ, Dict(sitesx[1] => 1)) - prjΨ2 = project(prjΨ, Dict(sitesx[1] => 2)) - - Ψreconst = MPS(prjΨ1) + MPS(prjΨ2) - - @test Ψreconst ≈ Ψ - end - - @testset "conversion" begin - N = 2 - sitesx = [Index(2, "x=$n") for n in 1:N] - sitesy = [Index(2, "y=$n") for n in 1:N] - sites = collect(collect.(zip(sitesx, sitesy))) - sitedims = [dim.(s) for s in sites] - Ψ = MPS(collect(_random_mpo(sites))) - prjΨ = TCIA.ProjMPS(Ψ, sites) - prjΨ1 = project(prjΨ, Dict(sitesx[1] => 1)) - - prjtt1 = TCIA.ProjTensorTrain{Float64}(prjΨ1) - @test prjtt1.projector == Projector([[1, 0], [0, 0]], sitedims) - - prjΨ1_reconst = TCIA.ProjMPS(Float64, prjtt1, sites) - - @test prjΨ1 ≈ prjΨ1_reconst - end - - @testset "rearrange_siteinds" begin - N = 3 - sitesx = [Index(2, "x=$n") for n in 1:N] - sitesy = [Index(2, "y=$n") for n in 1:N] - sitesz = [Index(2, "z=$n") for n in 1:N] - sites = collect(collect.(zip(sitesx, sitesy, sitesz))) - - Ψ = MPS(collect(_random_mpo(sites))) - - prjΨ = TCIA.ProjMPS(Ψ, sites) - prjΨ1 = project(prjΨ, Dict(sitesx[1] => 1)) - - sitesxy = collect(collect.(zip(sitesx, sitesy))) - sites_rearranged = Vector{Index{Int}}[] - for i in 1:N - push!(sites_rearranged, sitesxy[i]) - push!(sites_rearranged, [sitesz[i]]) - end - prjΨ1_rearranged = Quantics.rearrange_siteinds(prjΨ1, sites_rearranged) - - @test reduce(*, MPS(prjΨ1)) ≈ reduce(*, MPS(prjΨ1_rearranged)) - @test prjΨ1_rearranged.sites == sites_rearranged - end - - @testset "makesitediagonal and extractdiagonal" begin - N = 3 - sitesx = [Index(2, "x=$n") for n in 1:N] - sitesy = [Index(2, "y=$n") for n in 1:N] - sitesz = [Index(2, "z=$n") for n in 1:N] - - sitesxy_vec = [[x, y] for (x, y) in zip(sitesx, sitesy)] - sitesz_vec = [[z] for z in sitesz] - sites = [x for pair in zip(sitesxy_vec, sitesz_vec) for x in pair] - - Ψ = MPS(collect(_random_mpo(sites))) - - prjΨ = TCIA.ProjMPS(Ψ, sites) - prjΨ1 = project(prjΨ, Dict(sitesx[1] => 1)) - - prjΨ1_diagonalz = Quantics.makesitediagonal(prjΨ1, "y") - sites_diagonalz = Iterators.flatten(prjΨ1_diagonalz.sites) - - psi_diag = prod(prjΨ1_diagonalz.data) - psi = prod(prjΨ1.data) - - @test Quantics.extractdiagonal(prjΨ1_diagonalz, "y") ≈ prjΨ1 - - for indval in eachindval(sites_diagonalz...) - ind = first.(indval) - val = last.(indval) - - index_dict = Dict{Index{Int},Vector{Int}}() - for (i, el) in enumerate(ind) - baseind = noprime(el) - if haskey(index_dict, baseind) - push!(index_dict[baseind], i) - else - index_dict[baseind] = [i] - end - end - repeated_indices = [is for is in values(index_dict) if length(is) > 1] - - isdiagonalelement = all(allequal(val[i] for i in is) for is in repeated_indices) - - if isdiagonalelement - nondiaginds = unique(noprime(i) => v for (i, v) in indval) - @test psi_diag[indval...] == psi[nondiaginds...] - else - @test iszero(psi_diag[indval...]) - end - end - end -end diff --git a/test/runtests.jl b/test/runtests.jl index 6341d15..0cafd9a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -28,8 +28,5 @@ include("patching_tests.jl") include("crossinterpolate_tests.jl") include("tree_tests.jl") include("adaptivematmul_tests.jl") - -include("itensor_tests.jl") -include("bse3d_tests.jl") - -#include("crossinterpolate_lazyeval_tests.jl") +# include("bse3d_tests.jl") +include("crossinterpolate_lazyeval_tests.jl")