# netket.vqs.MCMixedState¶

class netket.vqs.MCMixedState(sampler, model=None, *, sampler_diag=None, n_samples_diag=None, n_samples_per_rank_diag=None, n_discard_per_chain_diag=None, n_discard_diag=None, seed=None, sampler_seed=None, variables=None, **kwargs)[source]

Bases: netket.vqs.base.VariationalMixedState, netket.vqs.mc_state.MCState

Variational State for a Mixed Variational Neural Quantum State.

The state is sampled according to the provided sampler, and it’s diagonal is sampled according to another sampler.

__init__(sampler, model=None, *, sampler_diag=None, n_samples_diag=None, n_samples_per_rank_diag=None, n_discard_per_chain_diag=None, n_discard_diag=None, seed=None, sampler_seed=None, variables=None, **kwargs)[source]

Constructs the MCMixedState. Arguments are the same as MCState.

Parameters
• sampler – The sampler

• model – (Optional) The model. If not provided, you must provide init_fun and apply_fun.

• n_samples – the total number of samples across chains and processes when sampling (default=1000).

• n_samples_per_rank – the total number of samples across chains on one process when sampling. Cannot be specified together with n_samples (default=None).

• n_discard_per_chain – number of discarded samples at the beginning of each monte-carlo chain (default=n_samples/10).

• n_samples_diag (Optional[int]) – the total number of samples across chains and processes when sampling the diagonal of the density matrix (default=1000).

• n_samples_per_rank_diag (Optional[int]) – the total number of samples across chains on one process when sampling the diagonal. Cannot be specified together with n_samples_diag (default=None).

• n_discard_per_chain_diag (Optional[int]) – number of discarded samples at the beginning of each monte-carlo chain used when sampling the diagonal of the density matrix for observables (default=n_samples_diag/10).

• parameters – Optional PyTree of weights from which to start.

• seed – rng seed used to generate a set of parameters (only if parameters is not passed). Defaults to a random one.

• sampler_seed (Optional[int]) – rng seed used to initialise the sampler. Defaults to a random one.

• mutable – Dict specifing mutable arguments. Use it to specify if the model has a state that can change during evaluation, but that should not be optimised. See also flax.linen.module.apply documentation (default=False)

• init_fun – Function of the signature f(model, shape, rng_key, dtype) -> Optional_state, parameters used to initialise the parameters. Defaults to the standard flax initialiser. Only specify if your network has a non-standard init method.

• apply_fun – Function of the signature f(model, variables, σ) that should evaluate the model. Defafults to model.apply(variables, σ). specify only if your network has a non-standard apply method.

• training_kwargs – a dict containing the optionaal keyword arguments to be passed to the apply_fun during training. Useful for example when you have a batchnorm layer that constructs the average/mean only during training.

• sampler_diag (Optional[netket.sampler.base.Sampler]) –

• n_discard_diag (Optional[int]) –

Attributes
chain_length

Length of the markov chain used for sampling configurations.

If running under MPI, the total samples will be n_nodes * chain_length * n_batches.

Return type

int

chain_length_diag

Length of the markov chain used for sampling the diagonal configurations.

If running under MPI, the total samples will be n_nodes * chain_length * n_batches.

Return type

int

diagonal
hilbert

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

Return type

AbstractHilbert

hilbert_physical
Return type

AbstractHilbert

model_state: Optional[Any]

An Optional PyTree encoding a mutable state of the model that is not trained.

Return type
n_discard

Use n_discard_per_chain instead.

Number of discarded samples at the beginning of the markov chain.

Type

DEPRECATED

Return type

int

n_discard_diag

Use n_discard_per_chain_diag instead.

Number of discarded samples at the beginning of the markov chain.

Type

DEPRECATED

Return type

int

n_discard_per_chain

Number of discarded samples at the beginning of the markov chain.

Return type

int

n_discard_per_chain_diag

Number of discarded samples at the beginning of the markov chain used to sample the diagonal of this mixed state.

Return type

int

n_parameters

The total number of parameters in the model.

Return type

int

n_samples

The total number of samples generated at every sampling step.

Return type

int

n_samples_diag

The total number of samples generated at every sampling step when sampling the diagonal of this mixed state.

Return type

int

n_samples_per_rank

The number of samples generated on one MPI rank at every sampling step.

Return type

int

parameters

The pytree of the parameters of the model.

Return type

Any

sampler

The Monte Carlo sampler used by this Monte Carlo variational state.

Return type

Sampler

sampler_diag

The Monte Carlo sampler used by this Monte Carlo variational state to sample the diagonal.

Return type

Sampler

samples

Returns the set of cached samples.

The samples returnede are guaranteed valid for the current state of the variational state. If no cached parameters are available, then they are sampled first and then cached.

To obtain a new set of samples either use reset or sample.

Return type

ndarray

variables

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

Return type

Any

Methods
evaluate(σ)

DEPRECATED: use log_value instead.

Return type

ndarray

Parameters

σ (jax._src.numpy.lax_numpy.ndarray) –

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.

• Ô (netket.operator._abstract_operator.AbstractOperator) –

Return type

Stats

Returns

An estimation of the quantum expectation value <O>.

expect_and_grad(Ô, mutable=None, is_hermitian=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 it’s gradient

• mutable (Optional[bool]) – 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).

• is_hermitian (Optional[bool]) – optional override for whever to use or not the hermitian logic. By default it’s automatically detected.

• Ô (netket.operator._abstract_operator.AbstractOperator) –

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>.

expect_and_grad_operator(Ô, is_hermitian=None)[source]
Return type

Tuple[Stats, Any]

Parameters

Ô (netket.operator._abstract_operator.AbstractOperator) –

expect_operator(Ô)[source]
Return type

Stats

Parameters

Ô (netket.operator._abstract_operator.AbstractOperator) –

grad(Ô, *, is_hermitian=None, mutable=None)

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

Parameters
Returns

An estimation of the average gradient of the quantum expectation value <O>.

Return type

array

grad_operator(Ô)
Return type

Stats

Parameters

Ô (netket.operator._abstract_operator.AbstractOperator) –

init(seed=None, dtype=None)

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(σ)

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

σ (jax._src.numpy.lax_numpy.ndarray) –

quantum_geometric_tensor(qgt_T=QGTAuto())

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 internal cache of th variational state. Called automatically when the parameters/state is updated.

sample(*, chain_length=None, n_samples=None, n_discard_per_chain=None)

Sample a certain number of configurations.

If one among chain_leength or n_samples is defined, that number of samples are gen erated. Otherwise the value set internally is used.

Parameters
Return type

ndarray

to_array(normalize=True)

Returns the dense-vector representation of this state.

Parameters

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

Return type

ndarray

Returns

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

to_matrix(normalize=True)[source]

Returns the dense-matrix representation of this operator.

Parameters

normalize (bool) – If True, the matrix is normalized to have trace 1.

Return type

ndarray

Returns

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