Parameters

Parameter

Superclass for Constant and Variable.

Constant

A parameter with a constant, immutable value.

Variable

A parameter whose value can change.

Inheritance Diagram

Inheritance diagram of Constant, Parameter, Variable

Parameter

class mrmustard.parameters.parameters.Parameter(value=None, name=None, dtype=None, *, update_fn='update_euclidean')[source]

Superclass for Constant and Variable.

Parameters:
  • value (ArrayLike | Parameter | None)

  • name (str | None)

  • dtype (str | None)

  • update_fn (UpdateFn)

property value: Tensor

Returns the value of the parameter.

property dtype: DTypeLike

Returns the dtype of the parameter.

property shape: tuple[int, ...]

Returns the shape of the parameter.

classmethod orthogonal(name='orthogonal', N=1, seed=None, batch_shape=())[source]

Initializes a parameter in O(N) with update_fn for orthogonal optimization.

Parameters:
  • name (str) – The name of the returned parameter.

  • N (int) – The dimension of the random orthogonal matrix.

  • seed (int | None) – The seed for the random number generator.

  • batch_shape (tuple[int, ...]) – The batch shape for generating multiple random matrices.

Returns:

A variable with update_fn for orthogonal optimization or a constant.

Return type:

Parameter

classmethod symplectic(name='symplectic', N=1, max_r=1.0, seed=None, batch_shape=())[source]

Initializes a parameter in SP(2N, R) with update_fn for symplectic optimization.

Parameters:
  • name (str) – The name of the returned parameter.

  • N (int) – (half) the dimension of the random symplectic matrix.

  • max_r (float) – The maximum squeezing value sampled uniformly.

  • seed (int | None) – The seed for the random number generator.

  • batch_shape (tuple[int, ...]) – The batch shape for generating multiple random matrices.

Returns:

A variable with update_fn for symplectic optimization or a constant.

Return type:

Parameter

classmethod unitary(name='unitary', N=1, seed=None, batch_shape=())[source]

Initializes a parameter in U(N) with update_fn for unitary optimization.

Parameters:
  • name (str) – The name of the returned parameter.

  • N (int) – The dimension of the random unitary matrix.

  • seed (int | None) – The seed for the random number generator.

  • batch_shape (tuple[int, ...]) – The batch shape for generating multiple random matrices.

Returns:

A variable with update_fn for unitary optimization or a constant.

Return type:

Parameter

classmethod siegel(name='siegel', n=1, max_r=0.9, seed=None, batch_shape=())[source]

Initializes a parameter in the open Siegel disk \(\mathcal{D}_n = \{Z \in \mathbb{C}^{n\times n} : Z = Z^T,\ I - Z^* Z \succ 0\}\) with update_fn for Siegel-disk Riemannian optimization (Bergman metric).

The matrix is sampled with Haar-random unitary eigenbasis and Takagi values drawn uniformly in \([0, \mathtt{max\_r})\), ensuring \(\|Z\|_\mathrm{op} < 1\). All eigenvalues of \(Z\) lie in the open unit disk.

Parameters:
  • name (str) – The name of the returned parameter.

  • n (int) – The dimension of the matrix.

  • max_r (float) – The maximum Takagi value of the initial matrix. Must satisfy 0 <= max_r < 1 to start strictly inside the disk.

  • seed (int | None) – The seed for the random number generator.

  • batch_shape (tuple[int, ...]) – The batch shape for generating multiple random matrices.

Returns:

A variable with update_fn for Siegel-disk optimization or a constant.

Return type:

Parameter

classmethod complex_normal(name='complex', variance=1.0, mean=0j, seed=None, batch_shape=())[source]

Initializes a parameter with a circular complex normal distribution.

This samples complex numbers where the real and imaginary parts are independent Gaussian random variables, each with variance variance/2. This ensures the total variance of |z|² is variance, which is the standard convention for complex normal distributions.

Parameters:
  • name (str) – The name of the returned parameter.

  • variance (float | RealTensor | Parameter) – The variance of the complex distribution. The real and imaginary parts each have variance variance/2. Can be a scalar or array for element-wise variance.

  • mean (complex | Tensor | Parameter) – The mean of the complex normal distribution. Can be a scalar or array.

  • seed (int | None) – The seed for the random number generator.

  • batch_shape (tuple[int, ...]) – The batch shape for generating multiple random values.

Returns:

A parameter with complex normal distribution.

Return type:

Parameter

classmethod complex_uniform(name='complex', max_r=1.0, min_r=0.0, seed=None, batch_shape=())[source]

Initializes a parameter with a complex uniform distribution in the unit disk, i.e. a complex number with radius between min_r and max_r and angle between 0 and 2*pi.

Parameters:
  • name (str) – The name of the returned parameter.

  • max_r (float) – The maximum radius of the complex uniform distribution.

  • min_r (float) – The minimum radius of the complex uniform distribution.

  • seed (int | None) – The seed for the random number generator.

  • batch_shape (tuple[int, ...]) – The batch shape for generating multiple random matrices.

Returns:

A variable with update_fn for complex uniform optimization or a constant.

Return type:

Parameter

classmethod real_normal(name='real', variance=1.0, mean=0.0, seed=None, batch_shape=())[source]

Initializes a parameter with a real normal distribution, i.e. a real number drawn from a normal distribution with mean mean and variance variance.

Parameters:
  • name (str) – The name of the returned parameter.

  • variance (float) – The variance of the real normal distribution.

  • mean (float) – The mean of the real normal distribution.

  • seed (int | None) – The seed for the random number generator.

  • batch_shape (tuple[int, ...]) – The batch shape for generating multiple random matrices.

Return type:

Parameter

classmethod real_uniform(name='real', low=0.0, high=1.0, seed=None, batch_shape=())[source]

Initializes a parameter with a real uniform distribution, i.e. a real number drawn from a uniform distribution over the half-open interval [min_r, max_r).

Parameters:
  • name (str) – The name of the returned parameter.

  • low (float) – The minimum of the real uniform distribution.

  • high (float) – The maximum of the real uniform distribution.

  • seed (int | None) – The seed for the random number generator.

  • batch_shape (tuple[int, ...]) – The batch shape for generating multiple random matrices.

Return type:

Parameter

classmethod from_cc_init(value, expected_dtype, name)[source]

Raise error if Parameter has wrong dtype, or simply cast to expected dtype if not a Parameter.

Parameters:
  • value (ArrayLike | Parameter) – The input value. Can be an array, a scalar, a Parameter, or a nested list or tuple.

  • expected_dtype (str) – The expected dtype string (e.g. “float64”, “complex128”).

  • name (str) – The name of the parameter for error messages.

Returns:

A Constant object with the value cast to the expected dtype (if raw value), or the original Parameter (if dtype matches).

Raises:

ValueError – If a Parameter object has the wrong dtype.

Return type:

Constant | Variable

Constant

class mrmustard.parameters.parameters.Constant(value=None, name=None, dtype=None, *, update_fn='update_euclidean')[source]

Bases: Parameter

A parameter with a constant, immutable value.

Parameters:
  • value (ArrayLike | Parameter | None) – The value of this constant.

  • name (str | None) – The name of this constant.

  • dtype (str | None) – The dtype of this constant.

  • update_fn (UpdateFn)

Example

my_const = Constant(1, "my_const")
property value: Tensor

Returns the value of the parameter.

Variable

class mrmustard.parameters.parameters.Variable(value=None, name=None, dtype=None, update_fn='update_euclidean')[source]

Bases: Parameter

A parameter whose value can change.

Parameters:
  • value (Tensor | Parameter | None) – The value of this variable.

  • name (str) – The name of this variable.

  • dtype (str | None) – The dtype of this variable.

  • update_fn (UpdateFn) – The name of the function used to update this variable during training.

Example

my_var = Variable(1, "my_var")
property update_fn: Literal['update_euclidean', 'update_orthogonal', 'update_siegel', 'update_symplectic', 'update_unitary']

The name of the function used to update this variable during training.