Skip to content

Commit

Permalink
core: dmrg callback
Browse files Browse the repository at this point in the history
  • Loading branch information
hczhai committed Aug 9, 2024
1 parent a86cc30 commit febe6fc
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pyblock2/driver/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4311,6 +4311,19 @@ def orbital_reordering_interaction_matrix(self, imat, method="fiedler", **kwargs

return np.array(idx, dtype=int)

def make_callback(self, kernel=None):
CK = self.bw.b.CallbackKernel

class Kernel(CK):
def __init__(self, kernel):
CK.__init__(self)
self.kernel = kernel

def compute(self, p, i):
self.kernel(p, i)

return Kernel(kernel)

def make_kernel(self, kernel=None):
EK = self.bw.bx.EffectiveKernel

Expand All @@ -4324,6 +4337,17 @@ def compute(self, beta, f, a, b, xs):

return Kernel(kernel)

def set_callback(self, f):
"""
Set a callback function which will be invoked before the iteration at each DMRG site.
Args:
f : Callable[[str, int], None]
A function with inputs: stage name and DMRG verbosity.
"""
self.callback_f = self.make_callback(kernel=f)
self.bw.b.set_callback(self.callback_f)

def dmrg(
self,
mpo,
Expand Down

0 comments on commit febe6fc

Please sign in to comment.