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
36 changes: 0 additions & 36 deletions .github/workflows/format_check.yml

This file was deleted.

14 changes: 11 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name = "ITensorNumericalAnalysis"
uuid = "666f501e-685d-4e36-ab44-ece85df6022b"
version = "0.3.0"
authors = ["Joseph Tindall <jtindall@flatironinstitute.org>", "Ryan Levy <rlevy@flatironinstitute.org>"]
version = "0.2.1"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Dictionaries = "85a47980-9c8c-11e8-2b9f-f7ca1fa99fb4"
Glob = "c27321d9-0574-5035-807b-f59d2c89b15c"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
Expand All @@ -12,7 +13,10 @@ ITensorNetworks = "2919e153-833c-4bdc-8836-1ea460a35fc7"
ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5"
NamedGraphs = "678767b0-92e7-4007-89e4-4527a8725b19"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
SplitApplyCombine = "03a91e81-4c3e-53e1-a0a4-9c0c8f19dd66"
TensorNetworkQuantumSimulator = "4de3b72a-362e-43dd-83ff-3f381eda9f9c"
TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[weakdeps]
Expand All @@ -22,16 +26,20 @@ ITensorTCI = "23d98011-b9e5-4fd0-831d-c25c73611ef5"
ITensorNumericalAnalysisTCIExt = "ITensorTCI"

[compat]
Adapt = "4.4.0"
Dictionaries = "0.4.2"
Glob = "1.3.1"
Graphs = "1.9"
ITensorMPS = "0.3.17"
ITensorNetworks = "0.13"
ITensorNetworks = "0.15.2"
ITensorTCI = "0.0.1"
ITensors = "0.9"
NamedGraphs = "0.6"
NamedGraphs = "0.7.0"
Random = "1.8"
Revise = "3.12.1"
SplitApplyCombine = "1.2.3"
TensorNetworkQuantumSimulator = "0.2.7"
TensorOperations = "5.3.1"
julia = "1.10"

[extras]
Expand Down
67 changes: 0 additions & 67 deletions examples/2d_laplace_solver.jl

This file was deleted.

66 changes: 0 additions & 66 deletions examples/boundary_conditions.jl

This file was deleted.

19 changes: 10 additions & 9 deletions examples/construct_multi_dimensional_function.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,33 @@ using Graphs: SimpleGraph, uniform_tree
using NamedGraphs: NamedGraph
using NamedGraphs.NamedGraphGenerators: named_comb_tree
using ITensors: siteinds, inds
using ITensorNetworks: maxlinkdim
using TensorNetworkQuantumSimulator
using Random: Random

L = 4
println(
"Constructing the 3D complex function f(z1,z2,z3) = z1³(z2 + z2²) + cosh(πz3)^2 as a tensor network on a comb tree with $L vertices",
"Constructing the 3D complex function f(z1,z2,z3) = z1³(z2 + z2²) + cosh(πz3)^2 as a tensor network on a comb tree with $L vertices",
)
Random.seed!(1234)
g = named_comb_tree((3, L))
real_dim_vertices = [[(j, i) for i in 1:L] for j in 1:3]
imag_dim_vertices = [[(j, i) for i in L:-1:1] for j in 3:-1:1]
s = complex_continuous_siteinds(g, real_dim_vertices, imag_dim_vertices)
ψ_fz1 = poly_itn(s, [0.0, 0.0, 0.0, 1.0]; dim=1)
ψ_fz2 = poly_itn(s, [0.0, 1.0, 1.0]; dim=2)
ψ_fz3 = cosh_itn(s; k=Number(pi), dim=3)
ψ_fz1 = poly_tnf(g, s, [0.0, 0.0, 0.0, 1.0]; dim = 1)
ψ_fz2 = poly_tnf(g, s, [0.0, 1.0, 1.0]; dim = 2)
ψ_fz3 = cosh_tnf(g, s; k = Number(pi), dim = 3)
ψ_z = ψ_fz1 * ψ_fz2 + ψ_fz3 * ψ_fz3

ψ_z = truncate(ψ_z; cutoff=1e-12)
println("Maximum bond dimension of the network is $(maxlinkdim(ψ_z))")
#TODO: Get working
#ψ_z = truncate(ψ_z; cutoff=1e-12)
println("Maximum bond dimension of the network is $(maxvirtualdim(ψ_z))")

z1, z2, z3 = 0.125 + 0.5 * im, 0.625 + 0.875 * im, 0.5
z = [z1, z2, z3]
f_at_z = evaluate(ψ_z, z)
println(
"Tensor network evaluates the function as $f_at_z at the co-ordinate: (z1,z2,z3) = ($z1, $z2, $z3)",
"Tensor network evaluates the function as $f_at_z at the co-ordinate: (z1,z2,z3) = ($z1, $z2, $z3)",
)
println(
"Actual value of the function is $(z1^3 * (z2 + z2^2) + cosh(pi * z3)^2) at the co-ordinate: (z1,z2,z3) =($z1, $z2, $z3)",
"Actual value of the function is $(z1^3 * (z2 + z2^2) + cosh(pi * z3)^2) at the co-ordinate: (z1,z2,z3) =($z1, $z2, $z3)",
)
105 changes: 54 additions & 51 deletions examples/fredholm_solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,73 @@ using Graphs: SimpleGraph, uniform_tree
using NamedGraphs: NamedGraph, NamedEdge, rename_vertices, edges, vertices
using NamedGraphs.NamedGraphGenerators: named_grid, named_comb_tree
using ITensors:
ITensors,
ITensor,
Index,
siteinds,
dim,
tags,
replaceprime!,
MPO,
MPS,
inner,
Op,
@OpName_str,
@SiteType_str,
op
using ITensorNetworks: ITensorNetwork, dmrg, ttn, maxlinkdim, siteinds, union_all_inds
using Dictionaries: Dictionary
ITensors,
ITensor,
Index,
dim,
tags,
replaceprime!,
inner,
Op,
op
using Dictionaries: Dictionary, set!
using Random: seed!
using TensorNetworkQuantumSimulator: setindex_preserve!, siteinds, tensors, tensornetwork, TensorNetwork, insert_virtualinds!

using ITensorNumericalAnalysis: partial_integrate, reduced_indsnetworkmap
function main()

seed!(1234)
L = 100
g = named_comb_tree((2, L ÷ 2))
seed!(1234)
L = 100
g = named_comb_tree((2, L ÷ 2))

println(
"########## Iteratively solve a inhomogeneous Fredholm equation of the second kind ##########",
)
println("solve f(x) = eˣ + ∫₀¹ (xy) f(y) dy")
# solution: f(x) = 3x/2 + eˣ
println(
"########## Iteratively solve a inhomogeneous Fredholm equation of the second kind ##########",
)
println("solve f(x) = eˣ + ∫₀¹ (xy) f(y) dy")
# solution: f(x) = 3x/2 + eˣ

# start f(x) = f(x)⊗1_y
# 1. make g(x,y)
# 2. f*g
# 3. apply operator I or |x>
# 4. apply shift if any
# start f(x) = f(x)⊗1_y
# 1. make g(x,y)
# 2. f*g
# 3. apply operator I or |x>
# 4. apply shift if any

s = continuous_siteinds(g, [[(i, j) for j in 1:(L ÷ 2)] for i in 1:2])
dim_ψ = 2
s1, s2 = reduced_indsnetworkmap(s, 1), reduced_indsnetworkmap(s, 2)
s = continuous_siteinds(g, [[(i, j) for j in 1:(L ÷ 2)] for i in 1:2])
dim_ψ = 2
s1, s2 = reduced_indexmap(s, 1), reduced_indexmap(s, 2)

ψ = const_itn(s2) # f(x) = 1_x⊗1_y
ψ = const_tnf(g, s) # f(x) = 1_x⊗1_y

# make g(x,y) = x*y
g = poly_itn(s1, [0, 1]; dim=1) * poly_itn(s2, [0, 1]; dim=2)
# make g(x,y) = x*y
gxy = poly_tnf(g, s, [0, 1]; dim = 1) * poly_tnf(g, s, [0, 1]; dim = 2)

c1, c2 = exp_itn(s1; dim=1), exp_itn(s2; dim=2)
c1, c2 = exp_tnf(g, s; dim = 1), exp_tnf(g, s; dim = 2)

niter = 100
for iter in 1:niter
global ψ = ψ * g
niter = 20
for iter in 1:niter
ψ = ψ * gxy

global ψ = partial_integrate(ψ, [dim_ψ])
ψ = partial_integrate(ψ, [dim_ψ])

global dim_ψ = dim_ψ == 1 ? 2 : 1
new_tensors = Dictionary(dimension_vertices(s, dim_ψ), [ITensors.ITensor([1, 1], only(siteinds(s)[v])) for v in dimension_vertices(s, dim_ψ)])
ψ = TensorNetwork(merge(new_tensors, tensors(tensornetwork(ψ))), g)
ψ = TensorNetworkFunction(ψ, s)
insert_virtualinds!(ψ)

local c = dim_ψ == 1 ? c1 : c2
dim_ψ = dim_ψ == 1 ? 2 : 1

global ψ = ψ + c
end
c = dim_ψ == 1 ? c1 : c2

ψ = ψ + c
end

n_grid = 100
x_vals = grid_points(s, n_grid, 1)
ψ_vals = [real(evaluate(ψ, x)) for x in x_vals]
correct_vals = (3 / 2) * x_vals + exp.(x_vals)
n_grid = 100
x_vals = grid_points(s, n_grid, 1)
ψ_vals = dim_ψ == 1 ? [real(evaluate(ψ, [x, 0.5])) for x in x_vals] : [real(evaluate(ψ, [0.5, x])) for x in x_vals]
correct_vals = (3 / 2) * x_vals + exp.(x_vals)

avg_err = sum(abs.(correct_vals - ψ_vals)) / n_grid
return @show avg_err
end

avg_err = sum(abs.(correct_vals - ψ_vals)) / n_grid
@show avg_err
main()
Loading
Loading