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' }} diff --git a/Project.toml b/Project.toml index 6be4564..32d37d1 100644 --- a/Project.toml +++ b/Project.toml @@ -4,13 +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] -ITensors = "0.3, 0.4, 0.5, 0.6" +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 e293456..670deab 100644 --- a/src/TCIITensorConversion.jl +++ b/src/TCIITensorConversion.jl @@ -2,8 +2,10 @@ 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]