netket.errors.ForwardAndBackwardDeprecationWarning

netket.errors.ForwardAndBackwardDeprecationWarning#

exception netket.errors.ForwardAndBackwardDeprecationWarning[source]#

Warning issued when a driver subclass overrides the deprecated _forward_and_backward method instead of the renamed compute_loss_and_update.

The method _forward_and_backward has been renamed to compute_loss_and_update in the new driver base class. The two methods differ in their return value: the old one returned only the gradient (setting self._loss_stats as a side-effect), while the new one must return a (loss_stats, gradient) tuple.

NetKet will automatically wrap your old implementation so that it is compatible with the new interface, but you should update your code to silence this warning.

Examples

Instead of:

class MyDriver(nk.driver.AbstractOptimizationDriver):
    def _forward_and_backward(self):
        # ... compute loss and gradient ...
        self._loss_stats = loss
        return gradient

Use:

class MyDriver(nk.driver.AbstractOptimizationDriver):
    def compute_loss_and_update(self):
        # ... compute loss and gradient ...
        return loss, gradient