Skip to content

Commit

Permalink
Merge pull request #17 from tensor4all/16-support-zip-up-algorithm
Browse files Browse the repository at this point in the history
Implement interface for zipup
  • Loading branch information
shinaoka authored Jan 23, 2025
2 parents 313c75f + f97bb7e commit b596f95
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/contractMPO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ function contract_mpo_mpo(M1::MPO, M2::MPO; alg::String = "densitymatrix", kwarg
return contract_densitymatrix(M1, M2; kwargs...)
elseif alg == "fit"
return contract_fit(M1, M2; kwargs...)
elseif alg == "zipup"
return ITensors.contract(M1, M2; alg = "zipup", kwargs...)
elseif alg == "naive"
return ITensors.contract(M1, M2; alg = "naive", kwargs...)
else
Expand Down
19 changes: 11 additions & 8 deletions test/densitymatrix.jl → test/contractMPO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ using Test

import FastMPOContractions as FMPOC
using ITensors
using Random

algs = ["densitymatrix", "fit", "zipup"]

@testset "MPO-MPO contraction (x-y-z)" for alg in algs
Random.seed!(1234)

@testset "densitymatrix (x-y-z)" begin
R = 3
sitesx = [Index(2, "Qubit,x=$n") for n = 1:R]
sitesy = [Index(2, "Qubit,y=$n") for n = 1:R]
Expand All @@ -16,11 +19,11 @@ using ITensors
a = _random_mpo(sitesa)
b = _random_mpo(sitesb)
ab_ref = contract(a, b; alg = "naive")
ab = FMPOC.contract_densitymatrix(a, b)
ab = FMPOC.contract_mpo_mpo(a, b; alg=alg)
@test ab_ref ab
end

@testset "densitymatrix (xk-y-z)" begin
@testset "MPO-MPO contraction (xk-y-z)" for alg in algs
R = 3
sitesx = [Index(2, "Qubit,x=$n") for n = 1:R]
sitesk = [Index(2, "Qubit,k=$n") for n = 1:R]
Expand All @@ -32,11 +35,11 @@ end
a = _random_mpo(sitesa)
b = _random_mpo(sitesb)
ab_ref = contract(a, b; alg = "naive")
ab = FMPOC.contract_densitymatrix(a, b)
ab = FMPOC.contract_mpo_mpo(a, b; alg=alg)
@test ab_ref ab
end

@testset "densitymatrix (xk-y-zl)" begin
@testset "MPO-MPO contraction (xk-y-zl)" for alg in algs
R = 3
sitesx = [Index(2, "Qubit,x=$n") for n = 1:R]
sitesk = [Index(2, "Qubit,k=$n") for n = 1:R]
Expand All @@ -49,11 +52,11 @@ end
a = _random_mpo(sitesa)
b = _random_mpo(sitesb)
ab_ref = contract(a, b; alg = "naive")
ab = FMPOC.contract_densitymatrix(a, b)
ab = FMPOC.contract_mpo_mpo(a, b; alg=alg)
@test ab_ref ab
end

@testset "densitymatrix (xk-ym-zl)" begin
@testset "MPO-MPO contraction (xk-ym-zl)" for alg in algs
R = 3
sitesx = [Index(2, "Qubit,x=$n") for n = 1:R]
sitesk = [Index(2, "Qubit,k=$n") for n = 1:R]
Expand All @@ -67,6 +70,6 @@ end
a = _random_mpo(sitesa)
b = _random_mpo(sitesb)
ab_ref = contract(a, b; alg = "naive")
ab = FMPOC.contract_densitymatrix(a, b)
ab = FMPOC.contract_mpo_mpo(a, b; alg=alg)
@test ab_ref ab
end
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ include("test_with_jet.jl")

include("_util.jl")

include("densitymatrix.jl")
include("contractMPO.jl")
include("fitalgorithm.jl")
include("util.jl")
include("fitalgorithm_sum.jl")
Expand Down

0 comments on commit b596f95

Please sign in to comment.