netket.utils.history.HistoryDict#

class netket.utils.history.HistoryDict[source]#

Bases: object

A class that behaves like a dictionary, mapping strings to History instances or nested HistoryDict instances.

This class behaves to all effects as a dictionary at runtime, but it allows us to specify custom serialization and deserialization routines, which are used to save and load the data.

Note

This class can be used to deserialize a dictionary of histories, such as the standard log files obtained from RuntimeLog and JsonLog.

Warning

This class should not be constructed directly. Instead, use accum_histories_in_tree() to build complex nested history structures, or create instances through RuntimeLog for logging purposes.

Inheritance
Inheritance diagram of netket.utils.history.HistoryDict
__init__(*args, **kwargs)[source]#

Create a new HistoryDict instance from a dictionary of histories.

Methods
classmethod from_file(fname)[source]#

Create an HistoryDict from a text-file containing its serialization.

Parameters:

fname (str) – The name of the file to read.

Return type:

Self

get(key, default=None)[source]#

Get a value from the dictionary, with a default value if the key is not present.

If the value is a dictionary, it is wrapped in a HistoryDict instance.

Parameters:
  • key (str) – The key to retrieve.

  • default – The default value to return if the key is not present.

items()[source]#
keys()[source]#
push(value, step=None)[source]#

Accumulate a new data point into this HistoryDict.

Updates the history by appending the values in value at the given step. Keys present in value but not yet in this HistoryDict are added automatically; keys present in this HistoryDict but absent from value are left unchanged (sparse logging is supported).

Parameters:
  • value – A (nested) dictionary whose leaves are the new scalar or array values to record.

  • step (int | None) – The iteration index associated with this data point. If None (the default), it is set to one past the last step recorded in any leaf history (0 for an empty HistoryDict), yielding an auto-incrementing index 0, 1, 2, ... that also resumes correctly after an explicit step.

Return type:

HistoryDict

Returns:

An updated HistoryDict with the new data appended.

to_dict()[source]#

Convert the HistoryDict to normal dictionary, with all nested HistoryDict instances.

Return type:

dict[str, dict | ndarray]

values()[source]#