# netket.vqs.ExactState¶

class netket.vqs.ExactState(hilbert, model=None, *, variables=None, init_fun=None, apply_fun=None, seed=None, mutable=False, training_kwargs={}, dtype=<class 'float'>)

Variational State for a variational quantum state computed on the whole Hilbert space without Monte Carlo sampling.

Expectation values and gradients are deterministic. The only non-deterministic part is due to the initialization seed used to generate the parameters.

Inheritance
__init__(hilbert, model=None, *, variables=None, init_fun=None, apply_fun=None, seed=None, mutable=False, training_kwargs={}, dtype=<class 'float'>)[source]

Constructs the ExactState.

Parameters
Attributes
hilbert

The descriptor of the Hilbert space on which this variational state is defined.

Return type

AbstractHilbert

model

Returns the model definition of this variational state.

This field is optional, and is set to None if the variational state has been initialized using a custom function.

Return type
model_state: Optional[Any]

The optional pytree with the mutable state of the model.

Return type
n_parameters

The total number of parameters in the model.

Return type

int

parameters

The pytree of the parameters of the model.

Return type

Any

variables

The PyTreee containing the paramters and state of the model, used when evaluating it.

Return type

Any

Methods
expect(Ô)
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)

Estimates both the gradient of the quantum expectation value of a given operator O.

Parameters
• – the operator Ô 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

Tuple[Stats, Any]

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)

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(seed=None, dtype=None)[source]

Initialises the variational parameters of the variational state.

init_parameters(init_fun=None, *, seed=None)

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
log_value(σ)[source]

Evaluate the variational state for a batch of states and returns the logarithm of the amplitude of the quantum state. For pure states, this is $$log(<σ|ψ>)$$, whereas for mixed states this is $$log(<σr|ρ|σc>)$$, where ψ and ρ are respectively a pure state (wavefunction) and a mixed state (density matrix). For the density matrix, the left and right-acting states (row and column) are obtained as σr=σ[::,0:N] and σc=σ[::,N:].

Given a batch of inputs (Nb, N), returns a batch of outputs (Nb,).

Return type

ndarray

Parameters
probability_distribution()[source]
quantum_geometric_tensor(qgt_T=QGTAuto())[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_T (LinearOperator) – the optional type of the quantum geometric tensor. By default it’s automatically selected.

Returns

A linear operator representing the quantum geometric tensor.

Return type

nk.optimizer.LinearOperator

reset()[source]

Resets the sampled states. This method is called automatically every time that the parameters/state is updated.

to_array(normalize=True, allgather=True)[source]

Returns the dense-vector representation of this state.

Parameters
• normalize (bool) – If True, the vector is normalized to have L2-norm 1.

• allgather (bool) –

Return type

ndarray

Returns

An exponentially large vector representing the state in the computational basis.

to_qobj()

Convert the variational state to a qutip’s ket Qobj.

Returns

A qutip.Qobj object.