MatchCake

matchcake.matchgate_parameter_sets package

Submodules

matchcake.matchgate_parameter_sets.matchgate_composed_hamiltonian_params module

class matchcake.matchgate_parameter_sets.matchgate_composed_hamiltonian_params.MatchgateComposedHamiltonianParams(*args, **kwargs)

Bases: MatchgateParams

ALLOW_COMPLEX_PARAMS = False
ATTRS = ['n_x', 'n_y', 'n_z', 'm_x', 'm_y', 'm_z', 'epsilon']
DEFAULT_PARAMS_TYPE

alias of float

DEFAULT_RANGE_OF_PARAMS = (-1.0, 1.0)
N_PARAMS = 7
__init__(*args, **kwargs)
property epsilon: float
property m_x: float
property m_y: float
property m_z: float
property n_x: float
property n_y: float
property n_z: float
classmethod to_sympy()

matchcake.matchgate_parameter_sets.matchgate_hamiltonian_coefficients_params module

class matchcake.matchgate_parameter_sets.matchgate_hamiltonian_coefficients_params.MatchgateHamiltonianCoefficientsParams(*args, **kwargs)

Bases: MatchgateParams

The hamiltionian of a system of non-interacting fermions can be written as:

\[H = -i\sum_{\mu\nu}h_{\mu\nu}c_{\mu}c_{\nu} + \epsilon\mathbb{I}\]

where \(c_{\mu}\) and \(c_{\nu}\) are the fermionic majorana operators, \(\epsilon\) is the energy offset, \(\mathbb{I}\) is the identity matrix, and \(h_{\mu\nu}\) are the hamiltonian coefficients that can be expressed in terms of a skew-symmetric matrix \(h\) as:

\[\begin{split}h = \begin{pmatrix} 0 & h_{0} & h_{1} & h_{2} \\ -h_{0} & 0 & h_{3} & h_{4} \\ -h_{1} & -h_{3} & 0 & h_{5} \\ -h_{2} & -h_{4} & -h_{5} & 0 \end{pmatrix}\end{split}\]

where \(h_{0}, h_{1}, h_{2}, h_{3}, h_{4}, h_{5}\) are the hamiltonian coefficients.

ALLOW_COMPLEX_PARAMS = False
ATTRS = ['h0', 'h1', 'h2', 'h3', 'h4', 'h5', 'epsilon']
DEFAULT_PARAMS_TYPE

alias of float

DEFAULT_RANGE_OF_PARAMS = (-1000000.0, 1000000.0)
N_PARAMS = 7
__init__(*args, **kwargs)
compute_hamiltonian()
property epsilon: float
property epsilon_op
property h0: float
property h0_op
property h1: float
property h1_op
property h2: float
property h2_op
property h3: float
property h3_op
property h4: float
property h4_op
property h5: float
property h5_op
to_matrix(add_epsilon: bool = True)
classmethod to_sympy()

matchcake.matchgate_parameter_sets.matchgate_params module

class matchcake.matchgate_parameter_sets.matchgate_params.MatchgateParams(*args, **kwargs)

Bases: object

A matchgate can be represented by several set of parameters and there exists a mapping between them.

ALLOW_COMPLEX_PARAMS = True
ATTRS = []
ATTRS_DEFAULT_VALUES = {}
DEFAULT_ARRAY_DTYPE

alias of complex

DEFAULT_PARAMS_TYPE

alias of float

DEFAULT_RANGE_OF_PARAMS = (-1000000000000.0, 1000000000000.0)
DIVISION_EPSILON = 1e-12
ELEMENTS_INDEXES = None
EQUALITY_ABSOLUTE_TOLERANCE = 0.0001
EQUALITY_RELATIVE_TOLERANCE = 0.0001
FORCE_CAST_PARAMS_TO_REAL = True
N_PARAMS = None
PARAMS_TYPES = None
RAISE_ERROR_IF_INVALID_PARAMS = True
RANGE_OF_PARAMS = None
UNPICKEABLE_ATTRS = []
__init__(*args, **kwargs)
adjoint()
property batch_size: int | None
classmethod from_matrix(matrix: TensorLike, **kwargs) MatchgateParams

Parse the input matrix to a MatchgateParams object. The input is a matchgate in his matrix form of shape (4, 4) or (batch_size, 4, 4).

Parameters:
  • matrix – The matrix representation of the matchgate.

  • kwargs – Additional arguments.

Returns:

The parsed parameters.

classmethod from_numpy(params: ndarray) MatchgateParams
classmethod from_tensor(params: TensorLike) MatchgateParams

Parse the input tensor to a MatchgateParams object. The input is a matchgate in his vector form i.e. the non-zero elements of the matchgate matrix. The input tensor has the shape (N_PARAMS,) or (batch_size, N_PARAMS).

Parameters:

params – The tensor representation of the matchgate.

Returns:

The parsed parameters.

classmethod from_vector(params: TensorLike) MatchgateParams

Parse the input vector to a MatchgateParams object. The input is a matchgate in his vector form i.e. the elements in ELEMENTS_INDEXES order. The input vector has the shape (N_PARAMS,) or (batch_size, N_PARAMS).

Parameters:

params – The vector representation of the matchgate.

Returns:

The parsed parameters.

classmethod get_short_name()

Remove the “Matchgate” prefix from the class name and the “Params” suffix.

Returns:

The short name of the class.

property grad
property is_batched
property is_cuda
static load_backend_lib(backend)
classmethod parse_from_any(params: Any) MatchgateParams

Try to parse the input parameters to a MatchgateParams object.

Parameters:

params (Any) – The input parameters.

Returns:

The parsed parameters.

Return type:

MatchgateParams

classmethod parse_from_params(params: MatchgateParams, **kwargs) MatchgateParams
classmethod random(*args, **kwargs)
classmethod random_batch_numpy(batch_size: int = 1, seed: int | None = None, **kwargs)
classmethod random_numpy(*args, **kwargs)
property requires_grad
requires_grad_(requires_grad: bool = True)
to_interface(interface: Literal['numpy', 'torch'], dtype=None) MatchgateParams
to_matrix() TensorLike
to_numpy(dtype=None)
to_string()
classmethod to_sympy()
to_tensor(dtype=None)

Return the parameters as a tensor of shape (N_PARAMS,) or (batch_size, N_PARAMS) and as a torch tensor. See also to_vector.

Parameters:

dtype – The data type of the tensor. Default is None (torch.cfloat).

Returns:

The parameters as a tensor.

to_vector()

Return the parameters as a vector of shape (N_PARAMS,) or (batch_size, N_PARAMS). The vector is the elements in ELEMENTS_INDEXES order.

Returns:

The parameters as a vector.

classmethod zeros_numpy(batch_size: int | None = None) ndarray

matchcake.matchgate_parameter_sets.matchgate_polar_params module

class matchcake.matchgate_parameter_sets.matchgate_polar_params.MatchgatePolarParams(*args, **kwargs)

Bases: MatchgateParams

Matchgate polar parameters.

They are the parameters of a Matchgate operation in the standard form which is a 4x4 matrix

\[ \begin{align}\begin{aligned}\begin{split} \begin{bmatrix} r_0 e^{i\theta_0} & 0 & 0 & (\sqrt{1 - r_0^2}) e^{-i(\theta_1+\pi)} \\ 0 & r_1 e^{i\theta_2} & (\sqrt{1 - r_1^2}) e^{-i(\theta_3+\pi)} & 0 \\ 0 & (\sqrt{1 - r_1^2}) e^{i\theta_3} & r_1 e^{-i\theta_2} & 0 \\ (\sqrt{1 - r_0^2}) e^{i\theta_1} & 0 & 0 & r_0 e^{-i\theta_0} \end{bmatrix}\end{split}\\where :math:`r_0, r_1, \theta_0, \theta_1, \theta_2, \theta_3, \theta_4` are the parameters.\end{aligned}\end{align} \]
ALLOW_COMPLEX_PARAMS = False
ATTRS = ['r0', 'r1', 'theta0', 'theta1', 'theta2', 'theta3', 'theta4']
N_PARAMS = 7
RANGE_OF_PARAMS = [(0.0, 1.0), (0.0, 1.0), (0, 6.283185307179586), (0, 6.283185307179586), (0, 6.283185307179586), (0, 6.283185307179586), (0, 6.283185307179586)]
__init__(*args, **kwargs)
adjoint()
classmethod compute_r_tilde(r, backend='pennylane.math') complex
property r0: float
property r0_tilde: complex

Return \(\Tilde{r}_0 = \sqrt{1 - r_0^2}\)

Returns:

\(\Tilde{r}_0\)

property r1: float
property r1_tilde: complex

Return \(\Tilde{r}_1 = \sqrt{1 - r_1^2}\)

Returns:

\(\Tilde{r}_1\)

property theta0: float
property theta1: float
property theta2: float
property theta3: float
property theta4: float
property theta4_is_relevant: bool
classmethod to_sympy()

matchcake.matchgate_parameter_sets.matchgate_standard_hamiltonian_params module

class matchcake.matchgate_parameter_sets.matchgate_standard_hamiltonian_params.MatchgateStandardHamiltonianParams(*args, **kwargs)

Bases: MatchgateParams

The hamiltonian in the standard form is given by:

\[\begin{split}H = \begin{pmatrix} u_0 & 0 & 0 & u_1 \\ 0 & u_2 & u_3 & 0 \\ 0 & u_4 & u_5 & 0 \\ u_6 & 0 & 0 & u_7 \end{pmatrix}\end{split}\]

where the \(u_i\) are the parameters and \(H\) is the hamiltonian matrix of shape \(2^n \times 2^n\) where \(n\) is the number of particles in the system. In our case, \(n=2\).

ALLOW_COMPLEX_PARAMS = True
ATTRS = ['u0', 'u1', 'u2', 'u3', 'u4', 'u5', 'u6', 'u7']
DEFAULT_RANGE_OF_PARAMS = (-1000000000000.0, 1000000000000.0)
ELEMENTS_INDEXES = [(0, 0), (0, 3), (1, 1), (1, 2), (2, 1), (2, 2), (3, 0), (3, 3)]
N_PARAMS = 8
PARAMS_TYPES = [<class 'float'>, <class 'complex'>, <class 'float'>, <class 'complex'>, <class 'complex'>, <class 'float'>, <class 'complex'>, <class 'float'>]
ZEROS_INDEXES = [(0, 1), (0, 2), (1, 0), (1, 3), (2, 0), (2, 3), (3, 1), (3, 2)]
__init__(*args, **kwargs)
adjoint()

Return the adjoint version of the parameters.

Returns:

The adjoint parameters.

classmethod to_sympy()
property u0: float | complex
property u1: float | complex
property u2: float | complex
property u3: float | complex
property u4: float | complex
property u5: float | complex
property u6: float | complex
property u7: float | complex

matchcake.matchgate_parameter_sets.matchgate_standard_params module

class matchcake.matchgate_parameter_sets.matchgate_standard_params.MatchgateStandardParams(*args, **kwargs)

Bases: MatchgateParams

Matchgate standard parameters.

They are the parameters of a Matchgate operation in the standard form which is a 4x4 matrix

\[ \begin{align}\begin{aligned}\begin{split} \begin{bmatrix} a & 0 & 0 & b \\ 0 & w & x & 0 \\ 0 & y & z & 0 \\ c & 0 & 0 & d \end{bmatrix}\end{split}\\where :math:`a, b, c, d, w, x, y, z` are the parameters.\end{aligned}\end{align} \]
ALLOW_COMPLEX_PARAMS = True
ATTRS = ['a', 'b', 'c', 'd', 'w', 'x', 'y', 'z']
DEFAULT_PARAMS_TYPE

alias of complex

DEFAULT_RANGE_OF_PARAMS = (-1000000000000.0, 1000000000000.0)
ELEMENTS_INDEXES = [(0, 0), (0, 3), (3, 0), (3, 3), (1, 1), (1, 2), (2, 1), (2, 2)]
N_PARAMS = 8
ZEROS_INDEXES = [(0, 1), (0, 2), (1, 0), (1, 3), (2, 0), (2, 3), (3, 1), (3, 2)]
__init__(*args, **kwargs)
property a: float | complex
adjoint()

Return the adjoint version of the parameters.

Returns:

The adjoint parameters.

property b: float | complex
property c: float | complex
property d: float | complex
classmethod from_sub_matrices(outer_matrix: ndarray, inner_matrix: ndarray)
to_inner_matrix()
to_outer_matrix()
classmethod to_sympy()
property w: float | complex
property x: float | complex
property y: float | complex
property z: float | complex

matchcake.matchgate_parameter_sets.transfer_functions module

matchcake.matchgate_parameter_sets.transfer_functions.composed_hamiltonian_to_hamiltonian_coefficients(params: MatchgateComposedHamiltonianParams, **kwargs) MatchgateHamiltonianCoefficientsParams

Convert from composed hamiltonian to hamiltonian coefficients parameterization. The conversion is given by

\[\begin{split}\begin{align} h_0 &= n_z + m_z \\ h_1 &= n_y + m_y \\ h_2 &= n_x - m_x \\ h_3 &= n_x + m_x \\ h_4 &= n_y - m_y \\ h_5 &= n_z - m_z \end{align}\end{split}\]
Parameters:
Returns:

The hamiltonian coefficients parameters

Return type:

MatchgateHamiltonianCoefficientsParams

matchcake.matchgate_parameter_sets.transfer_functions.composed_hamiltonian_to_polar(params: MatchgateComposedHamiltonianParams, **kwargs) MatchgatePolarParams
matchcake.matchgate_parameter_sets.transfer_functions.composed_hamiltonian_to_standard(params: MatchgateComposedHamiltonianParams, **kwargs) MatchgateStandardParams
matchcake.matchgate_parameter_sets.transfer_functions.composed_hamiltonian_to_standard_hamiltonian(params: MatchgateComposedHamiltonianParams, **kwargs) MatchgateStandardHamiltonianParams
matchcake.matchgate_parameter_sets.transfer_functions.get_closest_cls(cls_list: List[Type[MatchgateParams]], target_cls: Type[MatchgateParams], **kwargs)
matchcake.matchgate_parameter_sets.transfer_functions.hamiltonian_coefficients_to_composed_hamiltonian(params: MatchgateHamiltonianCoefficientsParams, **kwargs) MatchgateComposedHamiltonianParams

Convert from hamiltonian coefficients to composed hamiltonian parameterization. The conversion is given by

\[\begin{split}\begin{align} n_x &= \frac{1}{2} (h_2 + h_3), \\ n_y &= \frac{1}{2} (h_1 + h_4), \\ n_z &= \frac{1}{2} (h_0 + h_5), \\ m_x &= \frac{1}{2} (h_3 - h_2), \\ m_y &= \frac{1}{2} (h_1 - h_4), \\ m_z &= \frac{1}{2} (h_0 - h_5). \end{align}\end{split}\]
Parameters:
Returns:

The composed hamiltonian parameters

Return type:

MatchgateComposedHamiltonianParams

matchcake.matchgate_parameter_sets.transfer_functions.hamiltonian_coefficients_to_polar(params: MatchgateHamiltonianCoefficientsParams, **kwargs) MatchgatePolarParams
matchcake.matchgate_parameter_sets.transfer_functions.hamiltonian_coefficients_to_standard(params: MatchgateHamiltonianCoefficientsParams, **kwargs) MatchgateStandardParams
matchcake.matchgate_parameter_sets.transfer_functions.hamiltonian_coefficients_to_standard_hamiltonian(params: MatchgateHamiltonianCoefficientsParams, **kwargs) MatchgateStandardHamiltonianParams

Convert from hamiltonian coefficients to standard hamiltonian parameterization. The conversion is given by

\[\begin{split}\begin{align} \hat{h}_0 &= 2i (h_0 + h_5) + \epsilon \\ \hat{h}_1 &= 2(h_4 - h_1) + 2i(h_2 + h_3) \\ \hat{h}_2 &= 2i(h_0 - h_5) + \epsilon \\ \hat{h}_3 &= 2i(h_3 - h_2) - 2(h_1 + h_4) \\ \hat{h}_4 &= 2(h_1 + h_4) + 2i(h_3 - h_2) \\ \hat{h}_5 &= 2i (h_5 - h_0) + \epsilon \\ \hat{h}_6 &= 2(h_1 - h_4) + 2i(h_2 + h_3) \\ \hat{h}_7 &= -2i (h_0 + h_5) + \epsilon \end{align}\end{split}\]
Parameters:
Returns:

The standard hamiltonian parameters

Return type:

MatchgateStandardHamiltonianParams

matchcake.matchgate_parameter_sets.transfer_functions.identity_transfer(params: MatchgateParams, **kwargs) MatchgateParams
matchcake.matchgate_parameter_sets.transfer_functions.infer_transfer_func(from_cls: Type[MatchgateParams], to_cls: Type[MatchgateParams]) Callable
matchcake.matchgate_parameter_sets.transfer_functions.params_to(params, __cls: Type[MatchgateParams], **kwargs) MatchgateParams
matchcake.matchgate_parameter_sets.transfer_functions.polar_to_composed_hamiltonian(params: MatchgatePolarParams, **kwargs) MatchgateComposedHamiltonianParams
matchcake.matchgate_parameter_sets.transfer_functions.polar_to_hamiltonian_coefficients(params: MatchgatePolarParams, **kwargs) MatchgateHamiltonianCoefficientsParams
matchcake.matchgate_parameter_sets.transfer_functions.polar_to_standard(params: MatchgatePolarParams, **kwargs) MatchgateStandardParams

Convert from polar to standard parameterization. The conversion is given by

\[\begin{split}\begin{align} a &= r_0 e^{i\theta_0} \\ b &= (\sqrt{1 - r_0^2}) e^{i(\theta_2+\theta_4-(\theta_1+\pi))} \\ c &= (\sqrt{1 - r_0^2}) e^{i\theta_1} \\ d &= r_0 e^{i(\theta_2+\theta_4-\theta_0)} \\ w &= r_1 e^{i\theta_2} \\ x &= (\sqrt{1 - r_1^2}) e^{i(\theta_2+\theta_4-(\theta_3+\pi))} \\ y &= (\sqrt{1 - r_1^2}) e^{i\theta_3} \\ z &= r_1 e^{i\theta_4} \end{align}\end{split}\]
Parameters:
Keyword Arguments:

backend – The backend to use for the computation

Returns:

The standard parameters

Return type:

MatchgateStandardParams

matchcake.matchgate_parameter_sets.transfer_functions.polar_to_standard_hamiltonian(params: MatchgatePolarParams, **kwargs) MatchgateStandardHamiltonianParams
matchcake.matchgate_parameter_sets.transfer_functions.shortest_transfer_to(params_list: List[MatchgateParams], __cls: Type[MatchgateParams], **kwargs)
matchcake.matchgate_parameter_sets.transfer_functions.standard_hamiltonian_to_composed_hamiltonian(params: MatchgateStandardHamiltonianParams, **kwargs) MatchgateComposedHamiltonianParams
matchcake.matchgate_parameter_sets.transfer_functions.standard_hamiltonian_to_hamiltonian_coefficients(params: MatchgateStandardHamiltonianParams, **kwargs) MatchgateHamiltonianCoefficientsParams

Convert from standard hamiltonian to hamiltonian coefficients parameterization. The conversion is given by

\[\begin{split}\begin{align} h_0 &= -\frac{i}{2} (\hat{h}_0 + \hat{h}_2), \\ h_1 &= \frac{1}{4} (\hat{h}_6 - \hat{h}_1 + \hat{h}_4 - \hat{h}_3), \\ h_2 &= \frac{i}{4} (\hat{h}_3 + \hat{h}_4 - \hat{h}_1 - \hat{h}_6), \\ h_3 &= -\frac{i}{4} (\hat{h}_3 + \hat{h}_4 + \hat{h}_1 + \hat{h}_6), \\ h_4 &= \frac{1}{4} (\hat{h}_1 - \hat{h}_6 + \hat{h}_4 - \hat{h}_3), \\ h_5 &= \frac{i}{2} (\hat{h}_2 - \hat{h}_0). \end{align}\end{split}\]
Parameters:
Returns:

The hamiltonian coefficients parameters

Return type:

MatchgateHamiltonianCoefficientsParams

matchcake.matchgate_parameter_sets.transfer_functions.standard_hamiltonian_to_polar(params: MatchgateStandardHamiltonianParams, **kwargs) MatchgatePolarParams
matchcake.matchgate_parameter_sets.transfer_functions.standard_hamiltonian_to_standard(params: MatchgateStandardHamiltonianParams, **kwargs) MatchgateStandardParams
matchcake.matchgate_parameter_sets.transfer_functions.standard_to_composed_hamiltonian(params: MatchgateStandardParams, **kwargs) MatchgateComposedHamiltonianParams
matchcake.matchgate_parameter_sets.transfer_functions.standard_to_hamiltonian_coefficients(params: MatchgateStandardParams, **kwargs) MatchgateHamiltonianCoefficientsParams
matchcake.matchgate_parameter_sets.transfer_functions.standard_to_polar(params: MatchgateStandardParams, **kwargs) MatchgatePolarParams
matchcake.matchgate_parameter_sets.transfer_functions.standard_to_standard_hamiltonian(params: MatchgateStandardParams, **kwargs) MatchgateStandardHamiltonianParams

Module contents