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

Renaming Changes #36

Merged
merged 5 commits into from
May 31, 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
4 changes: 2 additions & 2 deletions examples/2d_laplace_solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ x_vals, y_vals = grid_points(s, n_grid, 1), grid_points(s, n_grid, 2)
vals = zeros((length(x_vals), length(y_vals)))
for (i, x) in enumerate(x_vals)
for (j, y) in enumerate(y_vals)
vals[i, j] = real(calculate_fxyz(ϕ_fxy, [x, y]))
vals[i, j] = real(evaluate(ϕ_fxy, [x, y]))
end
end

Expand All @@ -60,7 +60,7 @@ x_vals = grid_points(s, n_grid, 1)
y = 0.5
vals = zeros(length(x_vals))
for (i, x) in enumerate(x_vals)
vals[i] = real(calculate_fxyz(ϕ_fxy, [x, y]))
vals[i] = real(evaluate(ϕ_fxy, [x, y]))
end

println("Here is a cut of the function at y = $y")
Expand Down
6 changes: 3 additions & 3 deletions examples/boundary_conditions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ end
vals = zeros((length(x_vals), length(y_vals)))
for (i, x) in enumerate(x_vals)
for (j, y) in enumerate(y_vals)
vals[i, j] = real(calculate_fxyz(ϕ_fxy, [x, y]; alg="exact"))
vals[i, j] = real(evaluate(ϕ_fxy, [x, y]; alg="exact"))
end
end

Expand All @@ -49,15 +49,15 @@ display(heatmap(vals; xfact=1 / 32, yfact=1 / 32, xoffset=0, yoffset=0, colormap
y = 0.5
vals2 = zeros(length(x_vals))
for (i, x) in enumerate(x_vals)
vals2[i] = real(calculate_fxyz(ϕ_fxy, [x, y]; alg="exact"))
vals2[i] = real(evaluate(ϕ_fxy, [x, y]; alg="exact"))
end

lp = lineplot(x_vals, vals2; name="cut y=$y")

x = 0.5
vals3 = zeros(length(y_vals))
for (i, y) in enumerate(y_vals)
vals3[i] = real(calculate_fxyz(ϕ_fxy, [x, y]; alg="exact"))
vals3[i] = real(evaluate(ϕ_fxy, [x, y]; alg="exact"))
end

println("Here is a cut of the function at x = $x or y = $y")
Expand Down
8 changes: 4 additions & 4 deletions examples/construct_multi_dimensional_function.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ s = continuous_siteinds(g; map_dimension=3)
println(
"Constructing the 3D function f(x,y,z) = x³(y + y²) + cosh(πz) as a tensor network on a randomly chosen tree with $L vertices",
)
ψ_fx = poly_itn(s, [0.0, 0.0, 0.0, 1.0]; dimension=1)
ψ_fy = poly_itn(s, [0.0, 1.0, 1.0, 0.0]; dimension=2)
ψ_fz = cosh_itn(s; k=Number(pi), dimension=3)
ψ_fx = poly_itn(s, [0.0, 0.0, 0.0, 1.0]; dim=1)
ψ_fy = poly_itn(s, [0.0, 1.0, 1.0, 0.0]; dim=2)
ψ_fz = cosh_itn(s; k=Number(pi), dim=3)
ψxyz = ψ_fx * ψ_fy + ψ_fz

ψxyz = truncate(ψxyz; cutoff=1e-12)
println("Maximum bond dimension of the network is $(maxlinkdim(ψxyz))")

x, y, z = 0.125, 0.625, 0.5
fxyz_xyz = calculate_fxyz(ψxyz, [x, y, z])
fxyz_xyz = evaluate(ψxyz, [x, y, z])
println(
"Tensor network evaluates the function as $fxyz_xyz at the co-ordinate: (x,y,z) = ($x, $y, $z)",
)
Expand Down
8 changes: 4 additions & 4 deletions examples/fredholm_solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ println("solve f(x) = eˣ + ∫₀¹ (xy) f(y) dy")
s = continuous_siteinds(g; map_dimension=2)
ψ = const_itn(s) # f(x) = 1_x⊗1_y
# make g(x,y) = x*y
g = poly_itn(s, [0, 1]; dimension=1) * poly_itn(s, [0, 1]; dimension=2)
g = poly_itn(s, [0, 1]; dim=1) * poly_itn(s, [0, 1]; dim=2)

sU = union_all_inds(s.indsnetwork, s.indsnetwork')
∫_odd = ITensorNetwork(v -> v ∈ dimension_vertices(s, 1) ? Op("I") : Op("HalfInt"), sU)
∫_even = ITensorNetwork(v -> v ∈ dimension_vertices(s, 1) ? Op("HalfInt") : Op("I"), sU)
const_exp_odd = exp_itn(s; dimension=1)
const_exp_even = exp_itn(s; dimension=2)
const_exp_odd = exp_itn(s; dim=1)
const_exp_even = exp_itn(s; dim=2)

niter = 20
for iter in 1:niter
Expand All @@ -71,7 +71,7 @@ x_vals = grid_points(s, n_grid, 1)
y = 0.5 # arbitrary
cutvals = zeros(length(x_vals))
for (i, x) in enumerate(x_vals)
cutvals[i] = real(calculate_fxyz(ψ, [x, y]; alg="bp")) # alg="exact" if you encounter NaNs
cutvals[i] = real(evaluate(ψ, [x, y]; alg="bp")) # alg="exact" if you encounter NaNs
end

correct = (3 / 2 * x_vals) .+ exp.(x_vals)
Expand Down
8 changes: 3 additions & 5 deletions src/ITensorNumericalAnalysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ export ITensorNetworkFunction, itensornetwork, dimension_vertices
export IndexMap,
default_dimension_map,
dimension_inds,
calculate_xyz,
calculate_x,
calculate_p,
calculate_ind_values,
dimension,
dimensions,
Expand Down Expand Up @@ -44,14 +43,13 @@ export const_itensornetwork,
third_derivative_operator,
fourth_derivative_operator,
identity_operator,
delta_x,
delta_xyz,
delta_p,
map_to_zero_operator,
map_to_zeros,
const_plane_op
export const_itn,
poly_itn, cosh_itn, sinh_itn, tanh_itn, exp_itn, sin_itn, cos_itn, rand_itn
export calculate_fx, calculate_fxyz
export evaluate
export operate, operator_proj, multiply

end
58 changes: 29 additions & 29 deletions src/elementary_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ function exp_itensornetwork(
k=default_k_value(),
a=default_a_value(),
c=default_c_value(),
dimension::Int=default_dimension(),
dim::Int=default_dimension(),
)
ψ = const_itensornetwork(s)
Lx = length(dimension_vertices(ψ, dimension))
for v in dimension_vertices(ψ, dimension)
Lx = length(dimension_vertices(ψ, dim))
for v in dimension_vertices(ψ, dim)
sind = only(inds(s, v))
ψ[v] = ITensor(exp(a / Lx) * exp.(k * index_values_to_scalars(s, sind)), inds(ψ[v]))
end

ψ[first(dimension_vertices(ψ, dimension))] *= c
ψ[first(dimension_vertices(ψ, dim))] *= c

return ψ
end
Expand All @@ -53,10 +53,10 @@ function cosh_itensornetwork(
k=default_k_value(),
a=default_a_value(),
c=default_c_value(),
dimension::Int=default_dimension(),
dim::Int=default_dimension(),
)
ψ1 = exp_itensornetwork(s; a, k, c=0.5 * c, dimension)
ψ2 = exp_itensornetwork(s; a=-a, k=-k, c=0.5 * c, dimension)
ψ1 = exp_itensornetwork(s; a, k, c=0.5 * c, dim)
ψ2 = exp_itensornetwork(s; a=-a, k=-k, c=0.5 * c, dim)

return ψ1 + ψ2
end
Expand All @@ -68,10 +68,10 @@ function sinh_itensornetwork(
k=default_k_value(),
a=default_a_value(),
c=default_c_value(),
dimension::Int=default_dimension(),
dim::Int=default_dimension(),
)
ψ1 = exp_itensornetwork(s; a, k, c=0.5 * c, dimension)
ψ2 = exp_itensornetwork(s; a=-a, k=-k, c=-0.5 * c, dimension)
ψ1 = exp_itensornetwork(s; a, k, c=0.5 * c, dim)
ψ2 = exp_itensornetwork(s; a=-a, k=-k, c=-0.5 * c, dim)

return ψ1 + ψ2
end
Expand All @@ -84,16 +84,16 @@ function tanh_itensornetwork(
a=default_a_value(),
c=default_c_value(),
nterms::Int=default_nterms(),
dimension::Int=default_dimension(),
dim::Int=default_dimension(),
)
ψ = const_itensornetwork(s)
for n in 1:nterms
ψt = exp_itensornetwork(s; a=-2 * n * a, k=-2 * k * n, dimension)
ψt[first(dimension_vertices(ψ, dimension))] *= 2 * ((-1)^n)
ψt = exp_itensornetwork(s; a=-2 * n * a, k=-2 * k * n, dim)
ψt[first(dimension_vertices(ψ, dim))] *= 2 * ((-1)^n)
ψ = ψ + ψt
end

ψ[first(dimension_vertices(ψ, dimension))] *= c
ψ[first(dimension_vertices(ψ, dim))] *= c

return ψ
end
Expand All @@ -105,10 +105,10 @@ function cos_itensornetwork(
k=default_k_value(),
a=default_a_value(),
c=default_c_value(),
dimension::Int=default_dimension(),
dim::Int=default_dimension(),
)
ψ1 = exp_itensornetwork(s; a=a * im, k=k * im, c=0.5 * c, dimension)
ψ2 = exp_itensornetwork(s; a=-a * im, k=-k * im, c=0.5 * c, dimension)
ψ1 = exp_itensornetwork(s; a=a * im, k=k * im, c=0.5 * c, dim)
ψ2 = exp_itensornetwork(s; a=-a * im, k=-k * im, c=0.5 * c, dim)

return ψ1 + ψ2
end
Expand All @@ -120,10 +120,10 @@ function sin_itensornetwork(
k=default_k_value(),
a=default_a_value(),
c=default_c_value(),
dimension::Int=default_dimension(),
dim::Int=default_dimension(),
)
ψ1 = exp_itensornetwork(s; a=a * im, k=k * im, c=-0.5 * im * c, dimension)
ψ2 = exp_itensornetwork(s; a=-a * im, k=-k * im, c=0.5 * im * c, dimension)
ψ1 = exp_itensornetwork(s; a=a * im, k=k * im, c=-0.5 * im * c, dim)
ψ2 = exp_itensornetwork(s; a=-a * im, k=-k * im, c=0.5 * im * c, dim)

return ψ1 + ψ2
end
Expand All @@ -133,7 +133,7 @@ by indsnetwork"""
function polynomial_itensornetwork(
s::IndsNetworkMap,
coeffs::Vector;
dimension::Int=default_dimension(),
dim::Int=default_dimension(),
k=default_k_value(),
c=default_c_value(),
)
Expand All @@ -147,7 +147,7 @@ function polynomial_itensornetwork(
s_tree = IndsNetworkMap(s_tree, indexmap(s))

ψ = const_itensornetwork(s_tree; linkdim=n)
dim_vertices = dimension_vertices(ψ, dimension)
dim_vertices = dimension_vertices(ψ, dim)
source_vertex = first(dim_vertices)

for v in dim_vertices
Expand Down Expand Up @@ -207,7 +207,7 @@ function random_itensornetwork(s::IndsNetworkMap; kwargs...)
end

"Create a product state of a given bit configuration. Will make planes if all dims not specificed"
function delta_xyz(
function delta_p(
s::IndsNetworkMap,
xs::Vector{<:Number},
dims::Vector{Int}=[i for i in 1:length(xs)];
Expand All @@ -222,12 +222,12 @@ function delta_xyz(
end

"Create a product state of a given bit configuration of a 1D function"
function delta_x(s::IndsNetworkMap, x::Number, kwargs...)
function delta_p(s::IndsNetworkMap, x::Number, kwargs...)
@assert dimension(s) == 1
return delta_xyz(s, [x], [1]; kwargs...)
return delta_p(s, [x], [1]; kwargs...)
end

function delta_xyz(
function delta_p(
s::IndsNetworkMap,
points::Vector{<:Vector},
points_dims::Vector{<:Vector}=[[i for i in 1:length(xs)] for xs in points];
Expand All @@ -236,7 +236,7 @@ function delta_xyz(
@assert length(points) != 0
@assert length(points) == length(points_dims)
ψ = reduce(
+, [delta_xyz(s, xs, dims; kwargs...) for (xs, dims) in zip(points, points_dims)]
+, [delta_p(s, xs, dims; kwargs...) for (xs, dims) in zip(points, points_dims)]
)
return ψ
end
Expand All @@ -251,7 +251,7 @@ function delta_kernel(
include_identity=true,
truncate_kwargs...,
)
ψ = coeff * delta_xyz(s, points, points_dims; truncate_kwargs...)
ψ = coeff * delta_p(s, points, points_dims; truncate_kwargs...)

if include_identity
ψ = const_itn(s) + ψ
Expand Down Expand Up @@ -297,7 +297,7 @@ function delta_kernel(
end
end
if length(overlap_points) != 0
ψ = ψ + -coeff * delta_xyz(s, overlap_points, overlap_dims; truncate_kwargs...)
ψ = ψ + -coeff * delta_p(s, overlap_points, overlap_dims; truncate_kwargs...)
end
end

Expand Down
Loading
Loading