netket.logging.WandbLog#
- class netket.logging.WandbLog[source]#
Bases:
AbstractCallbackLogger that streams metrics and optional model checkpoints to Weights & Biases.
On the first call the logger lazily starts a wandb run so that constructing the logger does not create a run if it is never used.
The
wandbpackage must be installed (pip install wandb).Nested metric keys (e.g.
Energy/Mean) are logged with/preserved, which wandbβs UI renders as collapsible groups. Complex-valued scalars are split into separate<key>/reand<key>/imentries.NetKet loggers can be called more than once with the same
step(for different keys), while wandb expects a single, monotonically increasing global step. For this reason, every top-level namespace (the first path segment of a key, e.g.Energy) gets its own hidden<namespace>/stepmetric, declared withwandb.define_metric(), and its metrics are plotted against it.This class is a full
AbstractCallbackand can be passed either asout=loggeror ascallback=logger. When used as a callback the logger automatically captures the variational state snapshot taken just before the parameter update.- Parameters:
project (
str|None) β Name of the wandb project. IfNonewandb uses its own default (theWANDB_PROJECTenvironment variable, or"uncategorized").entity (
str|None) β wandb entity (user or team) that owns the run.run_name (
str|None) β Human-readable label attached to the new run.run_id (
str|None) β If provided, the run with this id is resumed if it exists, or created with this id otherwise. Useful to resume an interrupted job in place.group (
str|None) β Group name used to cluster related runs in the wandb UI.job_type (
str|None) β Free-form job type of the run (e.g."vmc"), useful to filter the runs of a group.tags (
Collection[str] |None) β Optional collection of string tags to attach to the run.mode (
str|None) β wandb mode, one of"online","offline"or"disabled". IfNone, wandbβs default is used (which can be set with theWANDB_MODEenvironment variable).save_params (
bool) β IfTrue, periodically serialize model parameters as a versioned wandb artifact (MessagePack binary, same format asJsonLog).save_params_every (
int) β Save parameters every this many optimisation steps. Only relevant whensave_params=True.save_final_state (
bool) β IfTrue, the variational state at the end of the run is uploaded as a separate artifact.log_histograms (
bool) β IfTrue, log a histogram of every parameter every time the parameters are saved.metadata (
dict|None) β Optional dict of hyper-parameters stored in the wandbconfigof the run.ignore (
Collection[str] |None) β Optional collection of top-level log-dict keys to skip entirely. Useful for suppressing entries that cannot be serialised as wandb metrics (e.g. large arrays or custom objects).
Tip
Use
metadatato attach a dict of hyper-parameters (learning rate, system size, model type, β¦) to the run. They are stored in the wandb config of the run, making it easy to filter and compare runs in the wandb UI without external bookkeeping.Examples
Log an optimisation run to wandb.
>>> import pytest; pytest.skip("skip automated test of this docstring") >>> >>> import netket as nk >>> logger = nk.logging.WandbLog( ... project="Ising1d", ... run_name="RBM_alpha1", ... tags=["RBM"], ... metadata={"learning_rate": 0.01, "alpha": 1, "L": 20}, ... ) >>> gs.run(n_iter=500, out=logger)
Log offline, to synchronise later with
wandb sync.>>> import pytest; pytest.skip("skip automated test of this docstring") >>> >>> import netket as nk >>> logger = nk.logging.WandbLog(project="Ising1d", mode="offline") >>> gs.run(n_iter=500, out=logger)
Resume a previous run.
>>> import pytest; pytest.skip("skip automated test of this docstring") >>> >>> import netket as nk >>> logger = nk.logging.WandbLog(project="Ising1d", run_id="<run-id>") >>> gs.run(n_iter=500, out=logger)
Using the logger as a callback.
>>> import pytest; pytest.skip("skip automated test of this docstring") >>> >>> import netket as nk >>> logger = nk.logging.WandbLog(project="Ising1d") >>> gs.run(n_iter=500, callback=logger)
- Inheritance

- Attributes
- callback_order#
- Methods
- __call__(step, item, variational_state=None)[source]#
Call self as a function.
- Parameters:
step (int)
variational_state (VariationalState | None)
- before_parameter_update(step, log_data, driver)[source]#
Called after all update logic has been computed and the step has been accepted, but before the driver applies the parameter update.
At this point:
The loss and its gradient have been computed by
compute_loss_and_update().The step has been accepted (not rejected by
on_compute_update_end()).driver.step_countstill refers to the current step β it has not yet been incremented.The variational state parameters have not yet changed.
This is the right place to estimate additional observables, add data to
log_data, or take a snapshot of the state for logging. Callbacks with a lowercallback_orderrun first, so observables callbacks (order 0) are guaranteed to populatelog_databefore logger callbacks (order 10) read it.
- flush(variational_state=None)[source]#
Flushes pending data and optionally saves model parameters.
- Parameters:
variational_state (
VariationalState|None) β if provided andsave_params=True, the current model parameters are uploaded as an artifact.
- on_compute_update_end(step, log_data, driver)[source]#
Callback called at the end of the compute update phase, after computing the loss and its gradient.
This is called before the parameters are updated, so it can be used to implement custom logic for rejecting a step based on the computed loss or gradient.
- Return type:
- Returns:
A boolean indicating whether to reject the step (i.e. repeat it with the same parameters). If it returns None, it is treated as False.