netket.driver.VMC#

class netket.driver.VMC[source]#

Bases: netket.driver.abstract_variational_driver.AbstractVariationalDriver

Energy minimization using Variational Monte Carlo (VMC).

Inheritance
Inheritance diagram of netket.driver.VMC
__init__(hamiltonian, optimizer, *args, variational_state=None, preconditioner=None, sr=None, sr_restart=None, **kwargs)[source]#

Initializes the driver class.

Parameters
  • hamiltonian (AbstractOperator) – The Hamiltonian of the system.

  • optimizer – Determines how optimization steps are performed given the bare energy gradient.

  • preconditioner (Optional[Callable[[VariationalState, Any], Any]]) – Determines which preconditioner to use for the loss gradient. This must be a tuple of (object, solver) as documented in the section preconditioners in the documentation. The standard preconditioner included with NetKet is Stochastic Reconfiguration. By default, no preconditioner is used and the bare gradient is passed to the optimizer.

  • sr (Optional[Callable[[netket.vqs.VariationalState, Any], Any]]) –

  • sr_restart (Optional[bool]) –

Attributes
energy#

Return MCMC statistics for the expectation value of observables in the current state of the driver.

Return type

Stats

optimizer#

The optimizer used to update the parameters at every iteration.

state#

Returns the machine that is optimized by this driver.

step_count#

Returns a monotonic integer labelling all the steps performed by this driver. This can be used, for example, to identify the line in a log file.

Methods
advance(steps=1)#

Performs steps optimization steps.

steps: (Default=1) number of steps

Parameters

steps (int) –

estimate(observables)#

Return MCMC statistics for the expectation value of observables in the current state of the driver.

Parameters

observables – A pytree of operators for which statistics should be computed.

Returns

A pytree of the same structure as the input, containing MCMC statistics for the corresponding operators as leaves.

info(depth=0)[source]#

Returns an info string used to print information to screen about this driver.

iter(n_steps, step=1)#

Returns a generator which advances the VMC optimization, yielding after every step_size steps.

Parameters
  • n_iter – The total number of steps to perform.

  • step_size – The number of internal steps the simulation is advanced every turn.

  • n_steps (int) –

  • step (int) –

Yields

int – The current step.

reset()#

Resets the driver. Concrete drivers should also call super().reset() to ensure that the step count is set to 0.

run(n_iter, out=None, obs=None, show_progress=True, save_params_every=50, write_every=50, step_size=1, callback=<function AbstractVariationalDriver.<lambda>>)#

Executes the Monte Carlo Variational optimization, updating the weights of the network stored in this driver for n_iter steps and dumping values of the observables obs in the output logger. If no logger is specified, creates a json file at out, overwriting files with the same prefix.

By default uses nk.logging.JsonLog. To know about the output format check it’s documentation. The logger object is also returned at the end of this function so that you can inspect the results without reading the json output.

Parameters
  • n_iter – the total number of iterations

  • out – A logger object, or an iterable of loggers, to be used to store simulation log and data. If this argument is a string, it will be used as output prefix for the standard JSON logger.

  • obs – An iterable containing all observables that should be computed

  • save_params_every – Every how many steps the parameters of the network should be serialized to disk (ignored if logger is provided)

  • write_every – Every how many steps the json data should be flushed to disk (ignored if logger is provided)

  • step_size – Every how many steps should observables be logged to disk (default=1)

  • show_progress – If true displays a progress bar (default=True)

  • callback – Callable or list of callable callback functions to stop training given a condition

update_parameters(dp)#

Updates the parameters of the machine using the optimizer in this driver

Parameters

dp – the pytree containing the updates to the parameters