Skip to content

Commit 3a0ad7c

Browse files
Merge pull request #6 from tensor4all/terasaki/issue-5
Issue 5
2 parents c1ec1a5 + 8cf4166 commit 3a0ad7c

File tree

7 files changed

+45
-32
lines changed

7 files changed

+45
-32
lines changed

.github/workflows/CI.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ concurrency:
1111
# Cancel intermediate builds: only if it is a pull request build.
1212
group: ${{ github.workflow }}-${{ github.ref }}
1313
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
14+
15+
permissions:
16+
actions: write
17+
contents: read
18+
1419
jobs:
1520
test:
1621
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
@@ -19,7 +24,7 @@ jobs:
1924
fail-fast: false
2025
matrix:
2126
version:
22-
- '1.9'
27+
- 'lts'
2328
- '1'
2429
os:
2530
- ubuntu-latest
@@ -33,7 +38,7 @@ jobs:
3338
with:
3439
version: ${{ matrix.version }}
3540
arch: ${{ matrix.arch }}
36-
- uses: julia-actions/cache@v1
41+
- uses: julia-actions/cache@v2
3742
- uses: julia-actions/julia-buildpkg@v1
3843
- uses: julia-actions/julia-runtest@v1
3944
continue-on-error: ${{ matrix.version == 'nightly' }}

Project.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ authors = ["Ritter.Marc <[email protected]> and contributors"]
44
version = "0.1.4"
55

66
[deps]
7+
ITensorMPS = "0d1a4710-d33b-49a5-8f18-73bdf49b47e2"
78
ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5"
9+
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
810
TensorCrossInterpolation = "b261b2ec-6378-4871-b32e-9173bb050604"
911

1012
[compat]
11-
ITensors = "0.3, 0.4, 0.5, 0.6"
13+
ITensorMPS = "0.3.2"
14+
ITensors = "0.7"
15+
Reexport = "1.2.2"
1216
TensorCrossInterpolation = "0.8, 0.9"
13-
julia = "1.6"
17+
julia = "1.10"
1418

1519
[extras]
1620
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

src/TCIITensorConversion.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ module TCIITensorConversion
22

33
import TensorCrossInterpolation as TCI
44
using ITensors
5+
using Reexport: @reexport
6+
import ITensorMPS
7+
@reexport using ITensorMPS: MPS
58

6-
export MPS
79
export evaluate_mps
810

911
include("ttmpsconversion.jl")

src/mpsutil.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
@doc raw"""
22
function evaluate_mps(
3-
mps::Union{ITensors.MPS,ITensors.MPO},
4-
indexspecs::Vararg{AbstractVector{<:Tuple{ITensors.Index,Int}}}
3+
mps::Union{ITensorMPS.MPS,ITensorMPS.MPO},
4+
indexspecs::Vararg{AbstractVector{<:Tuple{ITensorMPS.Index,Int}}}
55
)
66
77
Evaluates an MPS or MPO for a given set of index values.
88
9-
- `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.
9+
- `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.
1010
1111
If many evaluations are necessary, it may be advantageous to convert your MPS to a `TensorCrossInterpolation.TTCache` object first.
1212
"""
1313
function evaluate_mps(
14-
mps::Union{ITensors.MPS,ITensors.MPO},
14+
mps::Union{ITensorMPS.MPS,ITensorMPS.MPO},
1515
indexspecs::Vararg{AbstractVector{<:Tuple{ITensors.Index,Int}}}
1616
)
1717
if isempty(indexspecs)
@@ -22,27 +22,27 @@ function evaluate_mps(
2222

2323
V = ITensor(1.0)
2424
for j in eachindex(indexspecs[1])
25-
states = prod(state(spec[j]...) for spec in indexspecs)
25+
states = prod(ITensorMPS.state(spec[j]...) for spec in indexspecs)
2626
V *= mps[j] * states
2727
end
2828
return scalar(V)
2929
end
3030
@doc raw"""
3131
function evaluate_mps(
32-
mps::Union{ITensors.MPS,ITensors.MPO},
33-
indices::AbstractVector{<:ITensors.Index},
32+
mps::Union{ITensorMPS.MPS,ITensorMPS.MPO},
33+
indices::AbstractVector{<:ITensorMPS.Index},
3434
indexvalues::AbstractVector{Int}
3535
)
3636
3737
Evaluates an MPS or MPO for a given set of index values.
3838
39-
- `indices` is a list of `ITensors.Index` objects that specifies the order in which indices are given.
39+
- `indices` is a list of `ITensorMPS.Index` objects that specifies the order in which indices are given.
4040
- `indexvalues` is a list of integer values in the same order as `indices`.
4141
4242
If many evaluations are necessary, it may be advantageous to convert your MPS to a `TensorCrossInterpolation.TTCache` object first.
4343
"""
4444
function evaluate_mps(
45-
mps::Union{ITensors.MPS,ITensors.MPO},
45+
mps::Union{ITensorMPS.MPS,ITensorMPS.MPO},
4646
indices::AbstractVector{<:ITensors.Index},
4747
indexvalues::AbstractVector{Int}
4848
)

src/ttmpsconversion.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Convert a tensor train to an ITensor MPS
99
1010
If `siteindices` is left empty, a default set of indices will be used.
1111
"""
12-
function ITensors.MPS(tt::TCI.TensorTrain{T}; sites=nothing)::MPS where {T}
12+
function ITensorMPS.MPS(tt::TCI.TensorTrain{T}; sites=nothing)::MPS where {T}
1313
N = length(tt)
1414
localdims = [size(t, 2) for t in tt]
1515

@@ -30,11 +30,11 @@ function ITensors.MPS(tt::TCI.TensorTrain{T}; sites=nothing)::MPS where {T}
3030
return MPS(tensors_)
3131
end
3232

33-
function ITensors.MPS(tci::TCI.AbstractTensorTrain{T}; sites=nothing)::MPS where {T}
33+
function ITensorMPS.MPS(tci::TCI.AbstractTensorTrain{T}; sites=nothing)::MPS where {T}
3434
return MPS(TCI.tensortrain(tci), sites=sites)
3535
end
3636

37-
function ITensors.MPO(tt::TCI.TensorTrain{T}; sites=nothing)::MPO where {T}
37+
function ITensorMPS.MPO(tt::TCI.TensorTrain{T}; sites=nothing)::ITensorMPS.MPO where {T}
3838
N = length(tt)
3939
localdims = TCI.sitedims(tt)
4040

@@ -57,22 +57,22 @@ function ITensors.MPO(tt::TCI.TensorTrain{T}; sites=nothing)::MPO where {T}
5757
tensors_[1] *= onehot(links[1] => 1)
5858
tensors_[end] *= onehot(links[end] => 1)
5959

60-
return MPO(tensors_)
60+
return ITensorMPS.MPO(tensors_)
6161
end
6262

63-
function ITensors.MPO(tci::TCI.AbstractTensorTrain{T}; sites=nothing)::MPO where {T}
64-
return MPO(TCI.tensortrain(tci), sites=sites)
63+
function ITensorMPS.MPO(tci::TCI.AbstractTensorTrain{T}; sites=nothing)::ITensorMPS.MPO where {T}
64+
return ITensorMPS.MPO(TCI.tensortrain(tci), sites=sites)
6565
end
6666

6767

6868
"""
69-
function TCI.TensorTrain(mps::ITensors.MPS)
69+
function TCI.TensorTrain(mps::ITensorMPS.MPS)
7070
71-
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).
71+
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).
7272
"""
73-
function TCI.TensorTrain(mps::ITensors.MPS)
74-
links = linkinds(mps)
75-
sites = siteinds(mps)
73+
function TCI.TensorTrain(mps::ITensorMPS.MPS)
74+
links = ITensorMPS.linkinds(mps)
75+
sites = ITensors.SiteTypes.siteinds(mps)
7676
Tfirst = zeros(ComplexF64, 1, dim(sites[1]), dim(links[1]))
7777
Tfirst[1, :, :] = Array(mps[1], sites[1], links[1])
7878
Tlast = zeros(ComplexF64, dim(links[end]), dim(sites[end]), 1)
@@ -87,15 +87,15 @@ function TCI.TensorTrain(mps::ITensors.MPS)
8787
end
8888

8989
"""
90-
function TCI.TensorTrain(mps::ITensors.MPO)
90+
function TCI.TensorTrain(mps::ITensorMPS.MPO)
9191
9292
Convertes an ITensor MPO object into a TensorTrain.
9393
"""
94-
function TCI.TensorTrain{V, N}(mpo::ITensors.MPO; sites=nothing) where {N, V}
95-
links = linkinds(mpo)
94+
function TCI.TensorTrain{V, N}(mpo::ITensorMPS.MPO; sites=nothing) where {N, V}
95+
links = ITensorMPS.linkinds(mpo)
9696
if sites === nothing
97-
sites = siteinds(mpo)
98-
elseif !all(issetequal.(siteinds(mpo), sites))
97+
sites = ITensors.SiteTypes.siteinds(mpo)
98+
elseif !all(issetequal.(ITensors.SiteTypes.siteinds(mpo), sites))
9999
error("Site indices do not correspond to the site indices of the MPO.")
100100
end
101101

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using ITensors
2+
using ITensors.SiteTypes: siteinds
3+
using ITensorMPS
24
import TensorCrossInterpolation as TCI
35
using TCIITensorConversion
46
using Test

test/test_ttmpsconversion.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
@testset "TCIITensorConversion.jl" begin
33
@testset "TT to MPS conversion" begin
44
tt = TCI.TensorTrain([rand(1, 4, 4), rand(4, 4, 2), rand(2, 4, 7), rand(7, 4, 1)])
5-
mps = ITensors.MPS(tt)
5+
mps = ITensorMPS.MPS(tt)
66
@test linkdims(mps) == [4, 2, 7]
77
end
88

99
@testset "TT to MPO conversion and back" begin
1010
tt = TCI.TensorTrain([rand(1, 4, 3, 4), rand(4, 2, 4, 2), rand(2, 5, 1, 7), rand(7, 9, 4, 1)])
11-
mpo = ITensors.MPO(tt)
11+
mpo = ITensorMPS.MPO(tt)
1212
@test linkdims(mpo) == [4, 2, 7]
1313
@test dim.(siteinds(mpo)[1]) == [4, 3]
1414
@test dim.(siteinds(mpo)[2]) == [2, 4]

0 commit comments

Comments
 (0)