netket.experimental.logging.HDF5Log

netket.experimental.logging.HDF5Log#

class netket.experimental.logging.HDF5Log[source]#

Bases: AbstractLog

HDF5 Logger, that can be passed with keyword argument logger to Monte Carlo drivers in order to serialize the output data of the simulation.

The logger has support for scalar numbers, NumPy/JAX arrays, and netket.stats.Stats objects. These are stored as individual groups within a HDF5 file, under the main group data/:

  • scalars are stored as a group with one dataset values of shape (n_steps,) containing the logged values,

  • arrays are stored in the same way, but with values having shape (n_steps, *array_shape),

  • netket.stats.Stats are stored as a group containing each field (Mean, Variance, etc...) as a separate dataset.

Importantly, each group has a dataset iters, which tracks the iteration number of the logged quantity.

If the model state is serialized, then it is serialized as a dataset in the group variational_state/. The target of the serialization is the parameters PyTree of the variational state (stored in the group variational_state/parameters), and the rest of the variational state variables (stored in the group variational_state/model_state)

Data can be deserialized by calling f = h5py.File(filename, 'r') and inspecting the datasets as a dictionary, i.e. f['data/energy/Mean']

Note

The API of this logger is covered by our Semantic Versioning API guarantees. However, the structure of the logged files is not, and might change in the future while we iterate on this logger. If you think that we could improve the output format of this logger, please open an issue on the NetKet repository and let us know.

Inheritance
Inheritance diagram of netket.experimental.logging.HDF5Log
__init__(path, mode='write', save_params=True, save_params_every=1)[source]#

Construct a HDF5 Logger.

Parameters:
  • path (str) – the name of the output files before the extension

  • mode (str) – Specify the behaviour in case the file already exists at this path. Options are - [w]rite: (default) overwrites file if it already exists; - [x] or fail: fails if file already exists;

  • save_params (bool) – bool flag indicating whether variables of the variational state should be serialized at some interval

  • save_params_every (int) – every how many iterations should machine parameters be flushed to file

Methods
__call__(step, log_data, variational_state)[source]#

Logs at a given integer step a dictionary of data, optionally specifying a variational state to encode additional data.

Parameters:
  • step – monotonically increasing integer representing the row in the database corresponding to this log entry;

  • item – Any dictionary of data to be logged;

  • variational_state – optional variational state from which additional data might be extracted.

flush(variational_state=None)[source]#

Writes to file the content of this logger.

Parameters:

variational_state – optionally also writes the parameters of the machine.