Skip to content

Use Observer for output #93

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

Merged
merged 18 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fixes mostly related to return values of solvers
  • Loading branch information
emstoudenmire committed Jun 23, 2023
commit 41cc5d1a9e2edbf8abb67684cf4f76d45b2d87d7
2 changes: 1 addition & 1 deletion src/treetensornetworks/solvers/contract.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function contract_solver(PH, psi; kwargs...)
v *= PH.psi0[j]
end
Hpsi0 = contract(PH, v)
return Hpsi0, nothing
return Hpsi0, NamedTuple()
end

function contract(
Expand Down
3 changes: 2 additions & 1 deletion src/treetensornetworks/solvers/dmrg_x.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ function dmrg_x_solver(PH, init; kwargs...)
u = uniqueind(U, H)
max_overlap, max_ind = findmax(abs, array(dag(init) * U))
U_max = U * dag(onehot(u => max_ind))
return U_max, (;)
# TODO: improve this to return the energy estimate too
return U_max, NamedTuple()
end

function dmrg_x(PH, init::AbstractTTN; kwargs...)
Expand Down
2 changes: 1 addition & 1 deletion src/treetensornetworks/solvers/linsolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function linsolve(
)
b = dag(only(proj_mps(P)))
x, info = KrylovKit.linsolve(P, b, x₀, a₀, a₁; solver_kwargs...)
return x, nothing
return x, NamedTuple()
end

error("`linsolve` for TTN not yet implemented.")
Expand Down
4 changes: 4 additions & 0 deletions src/treetensornetworks/solvers/update_step.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ function local_update(
PH = position(PH, psi, region)

phi, info = solver(PH, phi; normalize, region, step_kwargs..., kwargs...)
if !(phi isa ITensor && info isa NamedTuple)
println("Solver returned the following types: $(typeof(phi)), $(typeof(info))")
error("In alternating_update, solver must return an ITensor and a NamedTuple")
end
normalize && (phi /= norm(phi))

drho = nothing
Expand Down
2 changes: 1 addition & 1 deletion test/test_treetensornetworks/test_solvers/test_dmrg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ end
# Test out certain values
#
@test step_observer![9, :region] == [2, 1]
@test step_observer![30, :energy] < -4.258
@test step_observer![30, :energy] < -4.25
end

@testset "Regression test: Arrays of Parameters" begin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,24 @@ ode_kwargs = (; reltol=1e-8, abstol=1e-8)
f⃗ = [t -> cos(ω * t) for ω in ω⃗]

function tdvp_ode_solver(H⃗₀, ψ₀; time_step, kwargs...)
return ode_solver(
psi_t, info = ode_solver(
-im * TimeDependentSum(f⃗, H⃗₀), time_step, ψ₀; solver_alg=ode_alg, ode_kwargs...
)
return psi_t, (; info)
end

krylov_kwargs = (; tol=1e-8, eager=true)

function krylov_solver(H⃗₀, ψ₀; time_step, ishermitian=false, issymmetric=false, kwargs...)
return krylov_solver(
psi_t, info = krylov_solver(
-im * TimeDependentSum(f⃗, H⃗₀),
time_step,
ψ₀;
krylov_kwargs...,
ishermitian,
issymmetric,
)
return psi_t, (; info)
end

@testset "MPS: Time dependent Hamiltonian" begin
Expand Down