From 8eb3adaf62bcf9505070e9434b2f2a14fae35741 Mon Sep 17 00:00:00 2001 From: Satoshi Terasaki Date: Sat, 16 Nov 2024 10:07:19 +0900 Subject: [PATCH 1/4] Drop support for old ITensors --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 6be4564..5dc3184 100644 --- a/Project.toml +++ b/Project.toml @@ -8,7 +8,7 @@ ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5" TensorCrossInterpolation = "b261b2ec-6378-4871-b32e-9173bb050604" [compat] -ITensors = "0.3, 0.4, 0.5, 0.6" +ITensors = "0.7" TensorCrossInterpolation = "0.8, 0.9" julia = "1.6" From 1901d9017f595650a52194f413772428df7a8c7c Mon Sep 17 00:00:00 2001 From: Satoshi Terasaki Date: Sat, 16 Nov 2024 10:07:51 +0900 Subject: [PATCH 2/4] Use Reexport macro --- Project.toml | 2 ++ src/TCIITensorConversion.jl | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Project.toml b/Project.toml index 5dc3184..5b97d6b 100644 --- a/Project.toml +++ b/Project.toml @@ -5,10 +5,12 @@ version = "0.1.4" [deps] ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5" +Reexport = "189a3867-3050-52da-a836-e630ba90ab69" TensorCrossInterpolation = "b261b2ec-6378-4871-b32e-9173bb050604" [compat] ITensors = "0.7" +Reexport = "1.2.2" TensorCrossInterpolation = "0.8, 0.9" julia = "1.6" diff --git a/src/TCIITensorConversion.jl b/src/TCIITensorConversion.jl index e293456..73cb4ae 100644 --- a/src/TCIITensorConversion.jl +++ b/src/TCIITensorConversion.jl @@ -2,6 +2,8 @@ module TCIITensorConversion import TensorCrossInterpolation as TCI using ITensors +using Reexport: @reexport +@reexport using ITensorMPS: MPS export MPS export evaluate_mps From af554329a6a617ca5fc708643eea40a35ec5c9f0 Mon Sep 17 00:00:00 2001 From: Satoshi Terasaki Date: Sat, 16 Nov 2024 10:08:12 +0900 Subject: [PATCH 3/4] Use ITensorMPS package --- Project.toml | 4 +++- src/TCIITensorConversion.jl | 2 +- src/mpsutil.jl | 18 +++++++++--------- src/ttmpsconversion.jl | 32 ++++++++++++++++---------------- test/runtests.jl | 2 ++ test/test_ttmpsconversion.jl | 4 ++-- 6 files changed, 33 insertions(+), 29 deletions(-) diff --git a/Project.toml b/Project.toml index 5b97d6b..32d37d1 100644 --- a/Project.toml +++ b/Project.toml @@ -4,15 +4,17 @@ authors = ["Ritter.Marc and contributors"] version = "0.1.4" [deps] +ITensorMPS = "0d1a4710-d33b-49a5-8f18-73bdf49b47e2" ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" TensorCrossInterpolation = "b261b2ec-6378-4871-b32e-9173bb050604" [compat] +ITensorMPS = "0.3.2" ITensors = "0.7" Reexport = "1.2.2" TensorCrossInterpolation = "0.8, 0.9" -julia = "1.6" +julia = "1.10" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/src/TCIITensorConversion.jl b/src/TCIITensorConversion.jl index 73cb4ae..670deab 100644 --- a/src/TCIITensorConversion.jl +++ b/src/TCIITensorConversion.jl @@ -3,9 +3,9 @@ module TCIITensorConversion import TensorCrossInterpolation as TCI using ITensors using Reexport: @reexport +import ITensorMPS @reexport using ITensorMPS: MPS -export MPS export evaluate_mps include("ttmpsconversion.jl") diff --git a/src/mpsutil.jl b/src/mpsutil.jl index 02ac81d..740e7ee 100644 --- a/src/mpsutil.jl +++ b/src/mpsutil.jl @@ -1,17 +1,17 @@ @doc raw""" function evaluate_mps( - mps::Union{ITensors.MPS,ITensors.MPO}, - indexspecs::Vararg{AbstractVector{<:Tuple{ITensors.Index,Int}}} + mps::Union{ITensorMPS.MPS,ITensorMPS.MPO}, + indexspecs::Vararg{AbstractVector{<:Tuple{ITensorMPS.Index,Int}}} ) Evaluates an MPS or MPO for a given set of index values. -- `indexspec` is a list of tuples, where each tuple contains an `Itensors.Index` object specifying an index, and an `Int` corresponding to the value of the specified index. +- `indexspec` is a list of tuples, where each tuple contains an `ITensorMPS.Index` object specifying an index, and an `Int` corresponding to the value of the specified index. If many evaluations are necessary, it may be advantageous to convert your MPS to a `TensorCrossInterpolation.TTCache` object first. """ function evaluate_mps( - mps::Union{ITensors.MPS,ITensors.MPO}, + mps::Union{ITensorMPS.MPS,ITensorMPS.MPO}, indexspecs::Vararg{AbstractVector{<:Tuple{ITensors.Index,Int}}} ) if isempty(indexspecs) @@ -22,27 +22,27 @@ function evaluate_mps( V = ITensor(1.0) for j in eachindex(indexspecs[1]) - states = prod(state(spec[j]...) for spec in indexspecs) + states = prod(ITensorMPS.state(spec[j]...) for spec in indexspecs) V *= mps[j] * states end return scalar(V) end @doc raw""" function evaluate_mps( - mps::Union{ITensors.MPS,ITensors.MPO}, - indices::AbstractVector{<:ITensors.Index}, + mps::Union{ITensorMPS.MPS,ITensorMPS.MPO}, + indices::AbstractVector{<:ITensorMPS.Index}, indexvalues::AbstractVector{Int} ) Evaluates an MPS or MPO for a given set of index values. -- `indices` is a list of `ITensors.Index` objects that specifies the order in which indices are given. +- `indices` is a list of `ITensorMPS.Index` objects that specifies the order in which indices are given. - `indexvalues` is a list of integer values in the same order as `indices`. If many evaluations are necessary, it may be advantageous to convert your MPS to a `TensorCrossInterpolation.TTCache` object first. """ function evaluate_mps( - mps::Union{ITensors.MPS,ITensors.MPO}, + mps::Union{ITensorMPS.MPS,ITensorMPS.MPO}, indices::AbstractVector{<:ITensors.Index}, indexvalues::AbstractVector{Int} ) diff --git a/src/ttmpsconversion.jl b/src/ttmpsconversion.jl index 7b39175..44985f4 100644 --- a/src/ttmpsconversion.jl +++ b/src/ttmpsconversion.jl @@ -9,7 +9,7 @@ Convert a tensor train to an ITensor MPS If `siteindices` is left empty, a default set of indices will be used. """ -function ITensors.MPS(tt::TCI.TensorTrain{T}; sites=nothing)::MPS where {T} +function ITensorMPS.MPS(tt::TCI.TensorTrain{T}; sites=nothing)::MPS where {T} N = length(tt) localdims = [size(t, 2) for t in tt] @@ -30,11 +30,11 @@ function ITensors.MPS(tt::TCI.TensorTrain{T}; sites=nothing)::MPS where {T} return MPS(tensors_) end -function ITensors.MPS(tci::TCI.AbstractTensorTrain{T}; sites=nothing)::MPS where {T} +function ITensorMPS.MPS(tci::TCI.AbstractTensorTrain{T}; sites=nothing)::MPS where {T} return MPS(TCI.tensortrain(tci), sites=sites) end -function ITensors.MPO(tt::TCI.TensorTrain{T}; sites=nothing)::MPO where {T} +function ITensorMPS.MPO(tt::TCI.TensorTrain{T}; sites=nothing)::ITensorMPS.MPO where {T} N = length(tt) localdims = TCI.sitedims(tt) @@ -57,22 +57,22 @@ function ITensors.MPO(tt::TCI.TensorTrain{T}; sites=nothing)::MPO where {T} tensors_[1] *= onehot(links[1] => 1) tensors_[end] *= onehot(links[end] => 1) - return MPO(tensors_) + return ITensorMPS.MPO(tensors_) end -function ITensors.MPO(tci::TCI.AbstractTensorTrain{T}; sites=nothing)::MPO where {T} - return MPO(TCI.tensortrain(tci), sites=sites) +function ITensorMPS.MPO(tci::TCI.AbstractTensorTrain{T}; sites=nothing)::ITensorMPS.MPO where {T} + return ITensorMPS.MPO(TCI.tensortrain(tci), sites=sites) end """ - function TCI.TensorTrain(mps::ITensors.MPS) + function TCI.TensorTrain(mps::ITensorMPS.MPS) -Converts an ITensor MPS object into a TensorTrain. Note that this only works if the MPS has a single leg per site! Otherwise, use [`TCI.TensorTrain(mps::ITensors.MPO)`](@ref). +Converts an ITensor MPS object into a TensorTrain. Note that this only works if the MPS has a single leg per site! Otherwise, use [`TCI.TensorTrain(mps::ITensorMPS.MPO)`](@ref). """ -function TCI.TensorTrain(mps::ITensors.MPS) - links = linkinds(mps) - sites = siteinds(mps) +function TCI.TensorTrain(mps::ITensorMPS.MPS) + links = ITensorMPS.linkinds(mps) + sites = ITensors.SiteTypes.siteinds(mps) Tfirst = zeros(ComplexF64, 1, dim(sites[1]), dim(links[1])) Tfirst[1, :, :] = Array(mps[1], sites[1], links[1]) Tlast = zeros(ComplexF64, dim(links[end]), dim(sites[end]), 1) @@ -87,15 +87,15 @@ function TCI.TensorTrain(mps::ITensors.MPS) end """ - function TCI.TensorTrain(mps::ITensors.MPO) + function TCI.TensorTrain(mps::ITensorMPS.MPO) Convertes an ITensor MPO object into a TensorTrain. """ -function TCI.TensorTrain{V, N}(mpo::ITensors.MPO; sites=nothing) where {N, V} - links = linkinds(mpo) +function TCI.TensorTrain{V, N}(mpo::ITensorMPS.MPO; sites=nothing) where {N, V} + links = ITensorMPS.linkinds(mpo) if sites === nothing - sites = siteinds(mpo) - elseif !all(issetequal.(siteinds(mpo), sites)) + sites = ITensors.SiteTypes.siteinds(mpo) + elseif !all(issetequal.(ITensors.SiteTypes.siteinds(mpo), sites)) error("Site indices do not correspond to the site indices of the MPO.") end diff --git a/test/runtests.jl b/test/runtests.jl index 6590a06..27cc215 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,6 @@ using ITensors +using ITensors.SiteTypes: siteinds +using ITensorMPS import TensorCrossInterpolation as TCI using TCIITensorConversion using Test diff --git a/test/test_ttmpsconversion.jl b/test/test_ttmpsconversion.jl index 33fd678..6df73fe 100644 --- a/test/test_ttmpsconversion.jl +++ b/test/test_ttmpsconversion.jl @@ -2,13 +2,13 @@ @testset "TCIITensorConversion.jl" begin @testset "TT to MPS conversion" begin tt = TCI.TensorTrain([rand(1, 4, 4), rand(4, 4, 2), rand(2, 4, 7), rand(7, 4, 1)]) - mps = ITensors.MPS(tt) + mps = ITensorMPS.MPS(tt) @test linkdims(mps) == [4, 2, 7] end @testset "TT to MPO conversion and back" begin tt = TCI.TensorTrain([rand(1, 4, 3, 4), rand(4, 2, 4, 2), rand(2, 5, 1, 7), rand(7, 9, 4, 1)]) - mpo = ITensors.MPO(tt) + mpo = ITensorMPS.MPO(tt) @test linkdims(mpo) == [4, 2, 7] @test dim.(siteinds(mpo)[1]) == [4, 3] @test dim.(siteinds(mpo)[2]) == [2, 4] From 8cf416676be72cd6549af6ce865697e252e3f862 Mon Sep 17 00:00:00 2001 From: Satoshi Terasaki Date: Sat, 16 Nov 2024 10:11:19 +0900 Subject: [PATCH 4/4] Fix CI --- .github/workflows/CI.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 9f9d79d..6c6a8b8 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -11,6 +11,11 @@ concurrency: # Cancel intermediate builds: only if it is a pull request build. group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} + +permissions: + actions: write + contents: read + jobs: test: name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} @@ -19,7 +24,7 @@ jobs: fail-fast: false matrix: version: - - '1.9' + - 'lts' - '1' os: - ubuntu-latest @@ -33,7 +38,7 @@ jobs: with: version: ${{ matrix.version }} arch: ${{ matrix.arch }} - - uses: julia-actions/cache@v1 + - uses: julia-actions/cache@v2 - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 continue-on-error: ${{ matrix.version == 'nightly' }}