mm.physics.ansatze.PolyExpAnsatz

class mrmustard.physics.ansatze.PolyExpAnsatz(A=None, b=None, c=1.0, name='')[source]

Bases: PolyExpBase

The ansatz of the Fock-Bargmann representation.

Represents the ansatz function:

\(F(z) = \sum_i \textrm{poly}_i(z) \textrm{exp}(z^T A_i z / 2 + z^T b_i)\)

where each \(poly_i\) is a polynomial in z that can be expressed as

\(\textrm{poly}_i(z) = \sum_k c^(i)_k z^k\),

with k being a multi-index. The matrices \(A_i\) and vectors \(b_i\) are parameters of the exponential terms in the ansatz, and \(z\) is a vector of variables.

>>> from mrmustard.physics.ansatze import PolyExpAnsatz

>>> A = np.array([[1.0, 0.0], [0.0, 1.0]])
>>> b = np.array([1.0, 1.0])
>>> c = np.array(1.0)

>>> F = PolyExpAnsatz(A, b, c)
>>> z = np.array([1.0, 2.0])

>>> # calculate the value of the function at ``z``
>>> val = F(z)
Parameters:
  • A (Optional[Batch[ndarray[Tuple[int, int], Union[TypeVar(R, float16, float32, float64), TypeVar(C, complex64, complex128), TypeVar(Z, int16, int32, int64), TypeVar(N, uint16, uint32, uint64)]]]]) – The list of square matrices \(A_i\)

  • b (Optional[Batch[ndarray[Tuple[int], Union[TypeVar(R, float16, float32, float64), TypeVar(C, complex64, complex128), TypeVar(Z, int16, int32, int64), TypeVar(N, uint16, uint32, uint64)]]]]) – The list of vectors \(b_i\)

  • c (Batch[Union[ndarray[Tuple[int, ...], Union[TypeVar(R, float16, float32, float64), TypeVar(C, complex64, complex128), TypeVar(Z, int16, int32, int64), TypeVar(N, uint16, uint32, uint64)]], TypeVar(R, float16, float32, float64), TypeVar(C, complex64, complex128), TypeVar(Z, int16, int32, int64), TypeVar(N, uint16, uint32, uint64)]]) – The array of coefficients for the polynomial terms in the ansatz.

A

The list of square matrices \(A_i\).

b

The list of vectors \(b_i\).

c

The array of coefficients for the polynomial terms in the ansatz.

degree

The degree of this ansatz.

A

The list of square matrices \(A_i\).

b

The list of vectors \(b_i\).

c

The array of coefficients for the polynomial terms in the ansatz.

degree

The degree of this ansatz.

__call__(z)

Value of this ansatz at z.

simplify()

Simplifies the representation by combining together terms that have the same exponential part, i.e. two terms along the batch are considered equal if their matrix and vector are equal.

simplify_v2()

A different implementation of simplify that orders the batch dimension first.

__call__(z)[source]

Value of this ansatz at z.

Parameters:

z (Batch[ndarray[Tuple[int], Union[TypeVar(R, float16, float32, float64), TypeVar(C, complex64, complex128), TypeVar(Z, int16, int32, int64), TypeVar(N, uint16, uint32, uint64)]]]) – point in C^n where the function is evaluated

Return type:

Union[TypeVar(R, float16, float32, float64), TypeVar(C, complex64, complex128), TypeVar(Z, int16, int32, int64), TypeVar(N, uint16, uint32, uint64)]

Returns:

The value of the function.

simplify()

Simplifies the representation by combining together terms that have the same exponential part, i.e. two terms along the batch are considered equal if their matrix and vector are equal. In this case only one is kept and the arrays are added.

Does not run if the representation has already been simplified, so it is safe to call.

Return type:

None

simplify_v2()

A different implementation of simplify that orders the batch dimension first.

Return type:

None