Parameters¶
Superclass for Constant and Variable. |
|
A parameter with a constant, immutable value. |
|
A parameter whose value can change. |
Inheritance Diagram¶

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 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_fnfor 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_fnfor orthogonal optimization or a constant.- Return type:
- classmethod symplectic(name='symplectic', N=1, max_r=1.0, seed=None, batch_shape=())[source]¶
Initializes a parameter in SP(2N, R) with
update_fnfor 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_fnfor symplectic optimization or a constant.- Return type:
- classmethod unitary(name='unitary', N=1, seed=None, batch_shape=())[source]¶
Initializes a parameter in U(N) with
update_fnfor 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_fnfor unitary optimization or a constant.- Return type:
- 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_fnfor 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 < 1to 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_fnfor Siegel-disk optimization or a constant.- Return type:
- 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|²isvariance, 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:
- 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_randmax_rand 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_fnfor complex uniform optimization or a constant.- Return type:
- 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
meanand variancevariance.- 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:
- 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:
- 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¶
- class mrmustard.parameters.parameters.Constant(value=None, name=None, dtype=None, *, update_fn='update_euclidean')[source]¶
Bases:
ParameterA 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")
Variable¶
- class mrmustard.parameters.parameters.Variable(value=None, name=None, dtype=None, update_fn='update_euclidean')[source]¶
Bases:
ParameterA parameter whose value can change.
- Parameters:
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.