Skip to content

Commit

Permalink
Fix renaming to tdvp_sweep and kwarg handling in updaters.
Browse files Browse the repository at this point in the history
  • Loading branch information
b-kloss committed Jan 20, 2024
1 parent e08ba96 commit 30455a4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
10 changes: 7 additions & 3 deletions src/solvers/eigsolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function eigsolve_updater(
projected_operator!,
outputlevel,
which_sweep,
region_updates,
sweep_plan,
which_region_update,
region_kwargs,
updater_kwargs,
Expand All @@ -20,13 +20,17 @@ function eigsolve_updater(
)
updater_kwargs = merge(default_updater_kwargs, updater_kwargs) #last collection has precedence
howmany = 1
which = updater_kwargs.which_eigenvalue
which, updater_kwargs = _pop_which_eigenvalue(;updater_kwargs...)

Check warning on line 23 in src/solvers/eigsolve.jl

View workflow job for this annotation

GitHub Actions / format

[JuliaFormatter] reported by reviewdog 🐶 Raw Output: src/solvers/eigsolve.jl:23:- which, updater_kwargs = _pop_which_eigenvalue(;updater_kwargs...) src/solvers/eigsolve.jl:23:+ which, updater_kwargs = _pop_which_eigenvalue(; updater_kwargs...)
vals, vecs, info = eigsolve(
projected_operator![],
init,
howmany,
which;
updater_kwargs... # leaves it to the user to supply only supported kwargs
updater_kwargs... #this leaves it

Check warning on line 29 in src/solvers/eigsolve.jl

View workflow job for this annotation

GitHub Actions / format

[JuliaFormatter] reported by reviewdog 🐶 Raw Output: src/solvers/eigsolve.jl:29:- updater_kwargs... #this leaves it src/solvers/eigsolve.jl:29:+ updater_kwargs..., #this leaves it
)
return vecs[1], (; info, eigvals=vals)
end

function _pop_which_eigenvalue(;which_eigenvalue, kwargs...)

Check warning on line 34 in src/solvers/eigsolve.jl

View workflow job for this annotation

GitHub Actions / format

[JuliaFormatter] reported by reviewdog 🐶 Raw Output: src/solvers/eigsolve.jl:34:-function _pop_which_eigenvalue(;which_eigenvalue, kwargs...) src/solvers/eigsolve.jl:34:+function _pop_which_eigenvalue(; which_eigenvalue, kwargs...)
return which_eigenvalue, NamedTuple(kwargs)
end

Check warning on line 36 in src/solvers/eigsolve.jl

View workflow job for this annotation

GitHub Actions / format

[JuliaFormatter] reported by reviewdog 🐶 Raw Output: src/solvers/eigsolve.jl:36:-end src/solvers/eigsolve.jl:36:+end
7 changes: 4 additions & 3 deletions src/solvers/exponentiate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@ function exponentiate_updater(
projected_operator!,
outputlevel,
which_sweep,
region_updates,
sweep_plan,
which_region_update,
region_kwargs,
updater_kwargs,
)
default_updater_kwargs = (;
krylovdim=30, #from here only solver kwargs
krylovdim=30,
maxiter=100,
verbosity=0,
tol=1E-12,
ishermitian=true,
issymmetric=true,
eager=true,
)

Check warning on line 21 in src/solvers/exponentiate.jl

View workflow job for this annotation

GitHub Actions / format

[JuliaFormatter] reported by reviewdog 🐶 Raw Output: src/solvers/exponentiate.jl:21:- src/solvers/exponentiate.jl:21:+
updater_kwargs = merge(default_updater_kwargs, updater_kwargs) #last collection has precedence
result, exp_info = exponentiate(
projected_operator![],

Check warning on line 24 in src/solvers/exponentiate.jl

View workflow job for this annotation

GitHub Actions / format

[JuliaFormatter] reported by reviewdog 🐶 Raw Output: src/solvers/exponentiate.jl:24:- projected_operator![], src/solvers/exponentiate.jl:25:- region_kwargs.time_step, src/solvers/exponentiate.jl:26:- init; src/solvers/exponentiate.jl:27:- updater_kwargs... src/solvers/exponentiate.jl:24:+ projected_operator![], region_kwargs.time_step, init; updater_kwargs...
time_step,
region_kwargs.time_step,
init;
updater_kwargs...
)
Expand Down
20 changes: 10 additions & 10 deletions src/treetensornetworks/solvers/update_step.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ function default_sweep_regions(nsites, graph::AbstractGraph; kwargs...) ###move
end

function region_update_printer(;
cutoff, maxdim, mindim, outputlevel::Int=0, state, region_updates, spec, which_region_update, which_sweep,kwargs...
cutoff, maxdim, mindim, outputlevel::Int=0, state, sweep_plan, spec, which_region_update, which_sweep,kwargs...
)
if outputlevel >= 2
region=first(region_updates[which_region_update])
region=first(sweep_plan[which_region_update])
@printf("Sweep %d, region=%s \n", which_sweep, region)
print(" Truncated using")
@printf(" cutoff=%.1E", cutoff)
Expand Down Expand Up @@ -53,7 +53,7 @@ function sweep_update(

# Append empty namedtuple to each element if not already present
# (Needed to handle user-provided region_updates)
region_updates = append_missing_namedtuple.(to_tuple.(region_updates))
sweep_plan = append_missing_namedtuple.(to_tuple.(sweep_plan))

if nv(state) == 1
error(
Expand All @@ -71,7 +71,7 @@ function sweep_update(
normalize,
outputlevel,
which_sweep,
region_updates,
sweep_plan,
which_region_update,
region_kwargs,
region_observer!,
Expand Down Expand Up @@ -167,15 +167,15 @@ function region_update(
normalize,
outputlevel,
which_sweep,
region_updates,
sweep_plan,
which_region_update,
region_kwargs,
region_observer!,
#insertion_kwargs, #ToDo: later
#extraction_kwargs, #ToDo: implement later with possibility to pass custom extraction/insertion func (or code into func)
updater_kwargs
)
region=first(region_updates[which_region_update])
region=first(sweep_plan[which_region_update])
state = orthogonalize(state, current_ortho(region))
state, phi = extract_local_tensor(state, region;)
nsites = (region isa AbstractEdge) ? 0 : length(region) #ToDo move into separate funtion
Expand All @@ -189,7 +189,7 @@ function region_update(
projected_operator!,
outputlevel,
which_sweep,
region_updates,
sweep_plan,
which_region_update,
region_kwargs,
updater_kwargs
Expand Down Expand Up @@ -222,9 +222,9 @@ function region_update(
maxdim,
mindim,
which_region_update,
region_updates,
total_sweep_steps=length(region_updates),
end_of_sweep=(which_region_update == length(region_updates)),
sweep_plan,
total_sweep_steps=length(sweep_plan),
end_of_sweep=(which_region_update == length(sweep_plan)),
state,
region,
which_sweep,
Expand Down
4 changes: 2 additions & 2 deletions test/test_treetensornetworks/test_solvers/test_dmrg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ end
sweep(; which_sweep, kw...) = which_sweep
sweep_observer! = observer(sweep)

region(; which_region_update, region_updates, kw...) =
first(region_updates[which_region_update])
region(; which_region_update, sweep_plan, kw...) =
first(sweep_plan[which_region_update])
energy(; eigvals, kw...) = eigvals[1]
region_observer! = observer(region, sweep, energy)

Expand Down
3 changes: 2 additions & 1 deletion test/test_treetensornetworks/test_solvers/test_tdvp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,8 @@ end
# Should rotate back to original state:
@test abs(inner(ψ0, ψ2)) > 0.99
end
#=
# ToDo: Discuss whether the test commented out here is necessary given the new design?
#=
@testset "Custom updater in TDVP" begin
cutoff = 1e-12
Expand Down

0 comments on commit 30455a4

Please sign in to comment.