Custom operators and observables#
NetKet exposes several extension paths for custom observables and operators.
They differ in how much you implement yourself, whether gradients come for free,
and whether expect_to_precision() works automatically.
All three rely on NetKet’s multiple-dispatch extension mechanism; if you need
the background first, start with Overriding defaults in NetKet and in particular
NetKet Architecture: Multiple Dispatch.
Use the table below as the entry point, then jump to the tutorial section that matches the interface you want to implement.
Path |
What you implement |
Best when |
Start here |
|||
|---|---|---|---|---|---|---|
Scalar operator kernel interface |
Subclass |
Automatic |
Automatic |
Automatic for scalar local estimators |
The observable is a standard operator whose expectation is the mean of one local-estimator channel. |
|
Explicit |
Register |
Automatic |
No |
Automatic |
You need multi-channel local estimators, delta-method error propagation,
or |
|
Explicit observable dispatch |
Register |
Yes |
Only if you define it |
No |
You want full control over the computation, or the observable does not fit NetKet’s local-estimator interfaces. |
Recommended starting points
If you need gradients and your observable is a standard scalar operator, start with Example: the lean operator-kernel interface.
If you do not need gradients and you want
expect_to_precision(), start with Example: V-score custom operator.If neither interface fits, fall back to Example: explicit observable dispatch and implement the exact expectation logic yourself.