Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use random_itensor, random_mps, etc. #183

Merged
merged 2 commits into from
May 17, 2024
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
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ITensorNetworks"
uuid = "2919e153-833c-4bdc-8836-1ea460a35fc7"
authors = ["Matthew Fishman <[email protected]>, Joseph Tindall <[email protected]> and contributors"]
version = "0.11.8"
version = "0.11.9"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down Expand Up @@ -58,8 +58,8 @@ DocStringExtensions = "0.9"
EinExprs = "0.6.4"
Graphs = "1.8"
GraphsFlows = "0.1.1"
ITensorMPS = "0.1"
ITensors = "0.4, 0.5, 0.6"
ITensorMPS = "0.2.2"
ITensors = "0.6.8"
IsApprox = "0.1"
IterTools = "1.4.0"
KrylovKit = "0.6, 0.7"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Returns a [`NestedEinsum`](@ref) instance.
```jldoctest
julia> using ITensors, ITensorContractionOrders
julia> i, j, k, l = Index(4), Index(5), Index(6), Index(7);
julia> x, y, z = randomITensor(i, j), randomITensor(j, k), randomITensor(k, l);
julia> x, y, z = random_itensor(i, j), random_itensor(j, k), random_itensor(k, l);
julia> net = optimize_contraction([x, y, z]; optimizer=TreeSA());
```
"""
Expand Down
4 changes: 2 additions & 2 deletions src/lib/ModelNetworks/src/ModelNetworks.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ModelNetworks
using Graphs: degree, dst, edges, src
using ..ITensorNetworks: IndsNetwork, delta_network, insert_linkinds, itensor
using ITensors: commoninds, diagITensor, inds, noprime
using ITensors: commoninds, diag_itensor, inds, noprime
using LinearAlgebra: Diagonal, eigen
using NamedGraphs: NamedGraph

Expand All @@ -21,7 +21,7 @@ function ising_network(
tn = delta_network(eltype, s)
if (szverts != nothing)
for v in szverts
tn[v] = diagITensor(eltype[1, -1], inds(tn[v]))
tn[v] = diag_itensor(eltype[1, -1], inds(tn[v]))
end
end
for edge in edges(tn)
Expand Down
4 changes: 2 additions & 2 deletions src/mpo_mps_compatibility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ function ITensorMPS.MPO(opsum_sum::Sum{<:OpSum}, s::IndsNetwork)
return ITensorMPS.MPO(sum(Ops.terms(opsum_sum)), s)
end

function ITensorMPS.randomMPS(s::IndsNetwork, args...; kwargs...)
function ITensorMPS.random_mps(s::IndsNetwork, args...; kwargs...)
s_linear = [only(s[v]) for v in 1:nv(s)]
return ITensorMPS.randomMPS(s_linear, args...; kwargs...)
return ITensorMPS.random_mps(s_linear, args...; kwargs...)
end

function ITensorMPS.MPS(s::IndsNetwork, args...; kwargs...)
Expand Down
4 changes: 2 additions & 2 deletions test/test_belief_propagation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ using ITensorNetworks:
update,
update_factor,
update_message
using ITensors: ITensors, ITensor, combiner, dag, inds, inner, op, prime, randomITensor
using ITensors: ITensors, ITensor, combiner, dag, inds, inner, op, prime, random_itensor
using ITensorNetworks.ModelNetworks: ModelNetworks
using ITensors.NDTensors: array
using LinearAlgebra: eigvals, tr
Expand Down Expand Up @@ -55,7 +55,7 @@ using Test: @test, @testset

#Test updating the underlying tensornetwork in the cache
v = first(vertices(ψψ))
new_tensor = randomITensor(inds(ψψ[v]))
new_tensor = random_itensor(inds(ψψ[v]))
bpc_updated = update_factor(bpc, v, new_tensor)
ψψ_updated = tensornetwork(bpc_updated)
@test ψψ_updated[v] == new_tensor
Expand Down
10 changes: 5 additions & 5 deletions test/test_binary_tree_partition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using DataGraphs: DataGraph, underlying_graph, vertex_data
using Graphs: add_vertex!, vertices
# Trigger package extension.
using GraphsFlows: GraphsFlows
using ITensors: Index, ITensor, contract, noncommoninds, randomITensor
using ITensors: Index, ITensor, contract, noncommoninds, random_itensor
using ITensorMPS: MPS
using ITensorNetworks:
_DensityMartrixAlgGraph,
Expand Down Expand Up @@ -35,7 +35,7 @@ using Test: @test, @testset
o = Index(2, "o")
p = Index(2, "p")

T = randomITensor(i, j, k, l, m, n, o, p)
T = random_itensor(i, j, k, l, m, n, o, p)
M = MPS(T, (i, j, k, l, m, n, o, p); cutoff=1e-5, maxdim=500)
tn = ITensorNetwork(M[:])
for out in [binary_tree_structure(tn), path_graph_structure(tn)]
Expand Down Expand Up @@ -75,7 +75,7 @@ end

@testset "test partition with mincut_recursive_bisection alg of disconnected tn" begin
inds = [Index(2, "$i") for i in 1:5]
tn = ITensorNetwork([randomITensor(i) for i in inds])
tn = ITensorNetwork([random_itensor(i) for i in inds])
par = _partition(tn, binary_tree_structure(tn); alg="mincut_recursive_bisection")
network = mapreduce(v -> collect(eachtensor(par[v])), vcat, vertices(par))
@test isapprox(contract(tn), contract(network))
Expand All @@ -88,7 +88,7 @@ end
l = Index(2, "l")
m = Index(2, "m")
for dtype in (Float64, Complex{Float64})
T = randomITensor(dtype, i, j, k, l, m)
T = random_itensor(dtype, i, j, k, l, m)
M = MPS(T, (i, j, k, l, m); cutoff=1e-5, maxdim=5)
network = M[:]
out1 = contract(network...)
Expand Down Expand Up @@ -126,7 +126,7 @@ end
k = Index(2, "k")
l = Index(2, "l")
m = Index(2, "m")
T = randomITensor(i, j, k, l, m)
T = random_itensor(i, j, k, l, m)
M = MPS(T, (i, j, k, l, m); cutoff=1e-5, maxdim=5)
tn = ITensorNetwork(M[:])
out_tree = path_graph_structure(tn)
Expand Down
4 changes: 2 additions & 2 deletions test/test_contract_deltas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Graphs: dfs_tree, nv, vertices
# Trigger package extension.
using GraphsFlows: GraphsFlows
using ITensors: Index, ITensor, delta, noncommoninds, randomITensor
using ITensors: Index, ITensor, delta, noncommoninds, random_itensor
using ITensorNetworks:
IndsNetwork,
ITensorNetwork,
Expand All @@ -21,7 +21,7 @@ using Test: @test, @testset

@testset "test _contract_deltas with no deltas" begin
i = Index(2, "i")
t = randomITensor(i)
t = random_itensor(i)
tn = _contract_deltas(ITensorNetwork([t]))
@test tn[1] == t
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_forms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ using ITensorNetworks:
tensornetwork,
union_all_inds,
update
using ITensors: contract, dag, inds, prime, randomITensor
using ITensors: contract, dag, inds, prime, random_itensor
using LinearAlgebra: norm
using Test: @test, @testset
using Random: Random
Expand Down Expand Up @@ -52,7 +52,7 @@ using Random: Random
@test isempty(flatten_siteinds(qf))

v = (1, 1)
new_tensor = randomITensor(inds(ψket[v]))
new_tensor = random_itensor(inds(ψket[v]))
qf_updated = update(qf, v, copy(new_tensor))

@test tensornetwork(qf_updated)[bra_vertex(qf_updated, v)] ≈
Expand Down
4 changes: 2 additions & 2 deletions test/test_gauging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using ITensorNetworks:
random_tensornetwork,
siteinds,
update
using ITensors: diagITensor, inds, inner
using ITensors: diag_itensor, inds, inner
using ITensors.NDTensors: vector
using LinearAlgebra: diag
using NamedGraphs.NamedGraphGenerators: named_grid
Expand Down Expand Up @@ -43,7 +43,7 @@ using Test: @test, @testset
#Test all message tensors are approximately diagonal even when we keep running BP
bp_cache = update(bp_cache; maxiter=10)
for m_e in values(messages(bp_cache))
@test diagITensor(vector(diag(only(m_e))), inds(only(m_e))) ≈ only(m_e) atol = 1e-8
@test diag_itensor(vector(diag(only(m_e))), inds(only(m_e))) ≈ only(m_e) atol = 1e-8
end
end
end
2 changes: 1 addition & 1 deletion test/test_itensornetwork.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ using ITensors:
itensor,
onehot,
order,
randomITensor,
random_itensor,
scalartype,
sim,
uniqueinds
Expand Down
4 changes: 2 additions & 2 deletions test/test_itensorsextensions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using ITensors:
noprime,
op,
prime,
randomITensor,
random_itensor,
replaceind,
replaceinds,
sim
Expand Down Expand Up @@ -53,7 +53,7 @@ Random.seed!(1234)
n in (2, 3, 5, 10)

i, j = Index.(([QN() => n], [QN() => n]))
A = randomITensor(elt, i, j)
A = random_itensor(elt, i, j)
P = A * prime(dag(A), i)
sqrtP = map_eigvals(sqrt, P, i, i'; ishermitian=true)
inv_P = dag(map_eigvals(inv, P, i, i'; ishermitian=true))
Expand Down
6 changes: 3 additions & 3 deletions test/test_treetensornetworks/test_solvers/test_contract.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ end
nbit = 3
sites = siteinds("Qubit", nbit)

# randomMPO does not support linkdims keyword.
# random_mpo does not support linkdims keyword.
M1 = replaceprime(
ITensorMPS.randomMPO(sites) + ITensorMPS.randomMPO(sites), 1 => 2, 0 => 1
ITensorMPS.random_mpo(sites) + ITensorMPS.random_mpo(sites), 1 => 2, 0 => 1
)
M2 = ITensorMPS.randomMPO(sites) + ITensorMPS.randomMPO(sites)
M2 = ITensorMPS.random_mpo(sites) + ITensorMPS.random_mpo(sites)
M12_ref = contract(M1, M2; alg="naive")
t12_ref = ttn([M12_ref[v] for v in eachindex(M12_ref)])

Expand Down
6 changes: 3 additions & 3 deletions test/test_treetensornetworks/test_solvers/test_dmrg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ end
vmap = Dictionary(collect(vertices(s))[linear_order], 1:length(linear_order))
sline = only.(collect(vertex_data(s)))[linear_order]
Hline = ITensorMPS.MPO(replace_vertices(v -> vmap[v], os), sline)
psiline = ITensorMPS.randomMPS(sline, i -> isodd(i) ? "Up" : "Dn"; linkdims=20)
psiline = ITensorMPS.random_mps(sline, i -> isodd(i) ? "Up" : "Dn"; linkdims=20)
e2, psi2 = dmrg(Hline, psiline; nsweeps, maxdim, cutoff, outputlevel=0)

@test inner(psi', H, psi) ≈ inner(psi2', Hline, psi2) atol = 1e-5
Expand Down Expand Up @@ -242,7 +242,7 @@ end
# get MPS / MPO with JW string result
ITensors.disable_auto_fermion()
Hline = ITensorMPS.MPO(replace_vertices(v -> vmap[v], os), sline)
psiline = ITensorMPS.randomMPS(sline, i -> isodd(i) ? "Up" : "Dn"; linkdims=20)
psiline = ITensorMPS.random_mps(sline, i -> isodd(i) ? "Up" : "Dn"; linkdims=20)
e_jw, psi_jw = dmrg(Hline, psiline; nsweeps, maxdim, cutoff, outputlevel=0)
ITensors.enable_auto_fermion()

Expand All @@ -261,7 +261,7 @@ end

# Compare to `ITensors.MPO` version of `dmrg`
Hline = ITensorMPS.MPO(replace_vertices(v -> vmap[v], os), sline)
psiline = ITensorMPS.randomMPS(sline, i -> isodd(i) ? "Up" : "Dn"; linkdims=20)
psiline = ITensorMPS.random_mps(sline, i -> isodd(i) ? "Up" : "Dn"; linkdims=20)
e2, psi2 = dmrg(Hline, psiline; nsweeps, maxdim, cutoff, outputlevel=0)

@test inner(psi', H, psi) ≈ inner(psi2', Hline, psi2) atol = 1e-5
Expand Down
4 changes: 2 additions & 2 deletions test/test_ttno.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@eval module $(gensym())
using Graphs: vertices
using ITensorNetworks: ttn, contract, ortho_region, siteinds, union_all_inds
using ITensors: @disable_warn_order, prime, randomITensor
using ITensors: @disable_warn_order, prime, random_itensor
using LinearAlgebra: norm
using NamedGraphs.NamedGraphGenerators: named_comb_tree
using Random: shuffle
Expand All @@ -24,7 +24,7 @@ using Test: @test, @testset
cutoff = 1e-10
sites_o = [is_isp[v] for v in vertex_order]
# create random ITensor with these indices
O = randomITensor(sites_o...)
O = random_itensor(sites_o...)
# dense TTN constructor from IndsNetwork
@disable_warn_order o1 = ttn(O, is_isp; cutoff)
root_vertex = only(ortho_region(o1))
Expand Down
4 changes: 2 additions & 2 deletions test/test_ttns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using DataGraphs: vertex_data
using Graphs: vertices
using ITensorNetworks: ttn, contract, ortho_region, siteinds
using ITensors: @disable_warn_order, randomITensor
using ITensors: @disable_warn_order, random_itensor
using LinearAlgebra: norm
using NamedGraphs.NamedGraphGenerators: named_comb_tree
using Random: shuffle
Expand All @@ -22,7 +22,7 @@ using Test: @test, @testset
@testset "Construct TTN from ITensor or Array" begin
cutoff = 1e-10
# create random ITensor with these indices
S = randomITensor(vertex_data(is)...)
S = random_itensor(vertex_data(is)...)
# dense TTN constructor from IndsNetwork
@disable_warn_order s1 = ttn(S, is; cutoff)
root_vertex = only(ortho_region(s1))
Expand Down
Loading