netket.vqs.VariationalState¶
-
class
netket.vqs.
VariationalState
(hilbert)¶ Bases:
abc.ABC
Abstract class for variational states representing either pure states or mixed quantum states.
A variational state is a quantum state depending on a set of parameters, and that supports operations such as computing quantum expectation values and their gradients.
A Variational stat can be serialized using flax’s msgpack machinery. See their docs.
- Inheritance
-
__init__
(hilbert)[source]¶ Initialize the Abstract base class of a Variational State defined on an hilbert space.
- Parameters
hilbert (
AbstractHilbert
) – The hilbert space upon which this state is defined.
- Attributes
-
hilbert
¶ The descriptor of the Hilbert space on which this variational state is defined.
- Return type
-
- Methods
-
expect
(Ô)[source]¶ - Estimates the quantum expectation value for a given operator O.
In the case of a pure state $psi$, this is $<O>= <Psi|O|Psi>/<Psi|Psi>$ otherwise for a mixed state $rho$, this is $<O> = Tr[rho hat{O}/Tr[rho]$.
- Parameters
Ô – the operator O.
- Return type
Stats
- Returns
An estimation of the quantum expectation value <O>.
-
expect_and_grad
(Ô, *, mutable=None, use_covariance=None)[source]¶ Estimates both the gradient of the quantum expectation value of a given operator O.
- Parameters
Ô – the operator Ô for which we compute the expectation value and its gradient
mutable (
Optional
[Any
]) – Can be bool, str, or list. Specifies which collections in the model_state should be treated as mutable: bool: all/no collections are mutable. str: The name of a single mutable collection. list: A list of names of mutable collections. This is used to mutate the state of the model while you train it (for example to implement BatchNorm. Consult Flax’s Module.apply documentation for a more in-depth exaplanation).use_covariance (
Optional
[bool
]) – whever to use the covariance formula, usually reserved for hermitian operators, ⟨∂logψ Oˡᵒᶜ⟩ - ⟨∂logψ⟩⟨Oˡᵒᶜ⟩
- Return type
- Returns
An estimation of the quantum expectation value <O>. An estimation of the average gradient of the quantum expectation value <O>.
-
grad
(Ô, *, use_covariance=None, mutable=None)[source]¶ Estimates the gradient of the quantum expectation value of a given operator O.
- Parameters
op (
netket.operator.AbstractOperator
) – the operator O.is_hermitian – optional override for whever to use or not the hermitian logic. By default it’s automatically detected.
use_covariance (Optional[bool]) –
mutable (Optional[Any]) –
- Returns
An estimation of the average gradient of the quantum expectation value <O>.
- Return type
array
-
init_parameters
(init_fun=None, *, seed=None)[source]¶ Re-initializes all the parameters with the provided initialization function, defaulting to the normal distribution of standard deviation 0.01.
Warning
The init function will not change the dtype of the parameters, which is determined by the model. DO NOT SPECIFY IT INSIDE THE INIT FUNCTION
- Parameters
init_fun (
Optional
[Callable
[[Any
,Sequence
[int
],Any
],Union
[ndarray
,DeviceArray
,Tracer
]]]) – a jax initializer such as jax.nn.initializers.normal. Must be a Callable taking 3 inputs, the jax PRNG key, the shape and the dtype, and outputting an array with the valid dtype and shape. If left unspecified, defaults tojax.nn.initializers.normal(stddev=0.01)
seed (
Optional
[Any
]) – Optional seed to be used. The seed is synced across all MPI processes. If unspecified, uses a random seed.
-
quantum_geometric_tensor
(qgt_type)[source]¶ Computes an estimate of the quantum geometric tensor G_ij.
This function returns a linear operator that can be used to apply G_ij to a given vector or can be converted to a full matrix.
- Parameters
qgt_type – the optional type of the quantum geometric tensor. By default it is automatically selected.
- Returns
- A linear operator representing the quantum
geometric tensor.
- Return type
nk.optimizer.LinearOperator
-
reset
()[source]¶ Resets the internal cache of th variational state. Called automatically when the parameters/state is updated.
-