Skip to content

Commit ba6f367

Browse files
DMRG Callback (#304)
Co-authored-by: Matt Fishman <mtfishman@users.noreply.github.com>
1 parent 7e4c461 commit ba6f367

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ITensorNetworks"
22
uuid = "2919e153-833c-4bdc-8836-1ea460a35fc7"
3-
version = "0.15.25"
3+
version = "0.15.26"
44
authors = ["Matthew Fishman <mfishman@flatironinstitute.org>, Joseph Tindall <jtindall@flatironinstitute.org> and contributors"]
55

66
[workspace]

src/solvers/eigsolve.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ energy, psi = eigsolve(H, psi0;
9797
See also: [`dmrg`](@ref), [`time_evolve`](@ref).
9898
"""
9999
function eigsolve(
100-
operator, init_state; nsweeps, nsites = 1, factorize_kwargs, sweep_kwargs...
100+
operator, init_state; nsweeps, nsites = 1, factorize_kwargs,
101+
sweep_callback = default_sweep_callback, sweep_kwargs...
101102
)
102103
init_prob = EigsolveProblem(;
103104
state = align_indices(init_state), operator = ProjTTN(align_indices(operator))
@@ -110,7 +111,7 @@ function eigsolve(
110111
subspace_expand!_kwargs = (; eigen_kwargs = factorize_kwargs),
111112
sweep_kwargs...
112113
)
113-
prob = problem(sweep_solve!(sweep_iter))
114+
prob = problem(sweep_solve!(sweep_callback, sweep_iter))
114115
return eigenvalue(prob), state(prob)
115116
end
116117

test/solvers/test_eigsolve.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Graphs: dst, edges, src, vertices
22
using ITensorMPS: OpSum
3-
using ITensorNetworks: dmrg, siteinds, ttn
3+
using ITensorNetworks: SweepIterator, dmrg, siteinds, ttn
44
using ITensors
55
using Suppressor: @capture_out
66
using TensorOperations: TensorOperations
@@ -73,6 +73,17 @@ include("utilities/tree_graphs.jl")
7373
(outputlevel >= 1) && println("2-site DMRG energy = ", E)
7474
@test E Ex atol = 1.0e-5
7575

76+
#
77+
# Test ability to pass custom sweep_callback
78+
# (Regression test for PR #304)
79+
#
80+
sweep_count = 0
81+
function sweep_callback(sweep_iter::SweepIterator; kws...)
82+
return sweep_count += 1
83+
end
84+
dmrg(H, psi0; factorize_kwargs, nsweeps, outputlevel, sweep_callback)
85+
@test sweep_count == nsweeps
86+
7687
#
7788
# Test that outputlevel > 0 generates output
7889
# and outputlevel == 0 generates no output

0 commit comments

Comments
 (0)