Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,33 @@ authors = ["Hiroshi Shinaoka <[email protected]> and contributors"]
version = "0.5.4"

[deps]
Coverage = "a2441757-f6aa-5fb2-8edb-039e3f45d037"
CoverageTools = "c36e975a-824b-4404-a568-ef97ca766997"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
EllipsisNotation = "da5c29d0-fa7d-589e-88eb-ea29b0a81949"
FastMPOContractions = "f6e391d2-8ffa-4d7a-98cd-7e70024481ca"
ITensorMPS = "0d1a4710-d33b-49a5-8f18-73bdf49b47e2"
ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LocalCoverage = "5f6e1e16-694c-5876-87ef-16b5274f298e"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"

[sources]
TCIAlgorithms = {url = "https://github.com/tensor4all/TCIAlgorithms.jl.git"}

[compat]
Coverage = "1"
CoverageTools = "1"
Distributed = "1"
EllipsisNotation = "1"
FastMPOContractions = "0.2.5"
FastMPOContractions = "0.2.8"
ITensorMPS = "0.3.2"
ITensors = "0.7"
LocalCoverage = "0.8"
OrderedCollections = "1.6.3"
julia = "1.6"

[extras]
QuanticsGrids = "634c7f73-3e90-4749-a1bd-001b8efc642d"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
TCIAlgorithms = "baf62351-2e82-41dd-9129-4f5768a618e1"
TCIITensorConversion = "9f0aa9f4-9415-4e6a-8795-331ebf40aa04"
TensorCrossInterpolation = "b261b2ec-6378-4871-b32e-9173bb050604"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Quantics = "87f76fb3-a40a-40c9-a63c-29fcfe7b7547"

[targets]
test = ["Test", "Random", "Quantics"]
test = ["Test", "Random", "TCIAlgorithms", "TensorCrossInterpolation", "TCIITensorConversion", "QuanticsGrids"]
89 changes: 89 additions & 0 deletions benchmark/distributecontract.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using Distributed
using BenchmarkTools
using Random

nworkers = 2

if nworkers > nprocs() - 1
addprocs(nworkers)
end

library_dir = normpath(joinpath(dirname(pathof(PartitionedMPSs))))

@everywhere begin
using Pkg
Pkg.activate(library_dir)
Pkg.instantiate()
Pkg.precompile()
end

@everywhere begin
import PartitionedMPSs:
PartitionedMPSs,
contract,
PartitionedMPS,
SubDomainMPS,
Projector,
project,
_add,
projcontract
end

using ITensors, ITensorMPS

random_mpo_file = normpath(joinpath(dirname(pathof(PartitionedMPSs)), "../test/_util.jl"))

Random.seed!(1234)
R = 10
d = 2
L = 5

sites_x = [Index(d, "Qubit,x=$x") for x in 1:R]
sites_y = [Index(d, "Qubit,y=$y") for y in 1:R]
sites_s = [Index(d, "Qubit,s=$s") for s in 1:R]

sites_xs = collect(collect.(zip(sites_x, sites_s)))
sites_sy = collect(collect.(zip(sites_s, sites_y)))

sites_xs_flat = collect(Iterators.flatten(sites_xs))
sites_sy_flat = collect(Iterators.flatten(sites_sy))

Ψ_l = ITensorMPS.convert(MPS, _random_mpo(sites_xs; linkdims=L))
Ψ_r = ITensorMPS.convert(MPS, _random_mpo(sites_sy; linkdims=L))

proj_lev_l = 4
proj_l = vec([
Dict(zip(sites_xs_flat, combo)) for
combo in Iterators.product((1:d for _ in 1:proj_lev_l)...)
])

proj_lev_r = 6
proj_r = vec([
Dict(zip(sites_sy_flat, combo)) for
combo in Iterators.product((1:d for _ in 1:proj_lev_r)...)
])

partΨ_l = PartitionedMPS(project.(Ref(Ψ_l), proj_l))
partΨ_r = PartitionedMPS(project.(Ref(Ψ_r), proj_r))

# ------------------------------------------------------------------
# Warm‑up (compile both code paths) --------------------------------
# ------------------------------------------------------------------
println("warming up …")
serial_warm = contract(partΨ_l, partΨ_r; parallel=:serial)
dist_warm = contract(partΨ_l, partΨ_r; parallel=:distributed)
@assert MPS(serial_warm) ≈ MPS(dist_warm) # sanity check

# ------------------------------------------------------------------
# Benchmark --------------------------------------------------------
# ------------------------------------------------------------------
println("\nbenchmarking …")
serial_time = @belapsed contract($partΨ_l, $partΨ_r; parallel=:serial)
dist_time = @belapsed contract($partΨ_l, $partΨ_r; parallel=:distributed)

println("\n---------------- results ----------------")
println("workers : $(nprocs() - 1)")
println("serial time : $(round(serial_time; digits = 4)) s")
println("distributed time : $(round(dist_time; digits = 4)) s")
println("speed‑up : $(round(serial_time / dist_time; digits = 2))×")
println("-----------------------------------------")
Loading
Loading