netket.utils#

Generic functions#

Utility functions and classes.

is_probably_holomorphic

Check if a function \(\psi\) is likely to be holomorphic almost everywhere.

Dataclass and PyTree utilities#

struct.Pytree

Astract Base class for jaw-aware PyTree classes.

struct.field

Mark a field of a dataclass or PyTree to be:

struct.ShardedFieldSpec

Specification of a sharded field.

Utils#

Utility functions and classes.

HashableArray

This class wraps a numpy or jax array in order to make it hashable and equality comparable (which is necessary since a well-defined hashable object needs to satisfy obj1 == obj2 whenever hash(obj1) == hash(obj2).

StaticRange

An object representing a range similar to python's range, but that works with jax.jit.

numbers.StaticZero

A static representation of 0, which can be used in Jax and attempts to behave like a normal jax array.

Tree traversal helpers#

NetKet logging backends share a path-aware tree walker implemented in netket.utils.tree_walk.walk_tree_with_path.

walk_tree_with_path

Traverse a nested tree while threading a path to each leaf.

It traverses nested dict, list, tuple, namedtuple, to_dict(), and to_compound() structures while threading a path accumulator down to each leaf. This helper is used internally by the HDF5 and TensorBoard loggers to keep their tree traversal logic consistent without duplicating the walk itself.

The function docstring includes a minimal example showing how to define visit_leaf, enter_node, and expand_node callbacks.

Symmetry Group Manipulation#

The group-manipulation API is documented under netket.symmetry. The legacy netket.utils.group namespace re-exports the same public objects, including Permutation, PermutationGroup, FiniteGroup, and PointGroup.

History and time-series data#

Utilities for storing and managing time-series data, particularly useful for tracking optimization progress and simulation results.

history.History

A class to store a time-series of arbitrary data.

history.HistoryDict

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

history.accum_histories_in_tree

Accumulate history data in nested tree structures.

Timing utils#

Use those utilities to coarsely profile some netket functions or scopes. The timer here can be nested and can be used in low-level library functions.

timing.Timer

Measures how much time was spent in a timer, with possible sub-timers.

timing.timed_scope

Context manager used to mark a scope to be timed individually by NetKet timers.

timing.timed

Marks the decorated function to be timed individually in NetKet timing scopes.