MatchCake

matchcake.operations.single_particle_transition_matrices package

Submodules

matchcake.operations.single_particle_transition_matrices.single_particle_transition_matrix module

class matchcake.operations.single_particle_transition_matrices.single_particle_transition_matrix.SingleParticleTransitionMatrixOperation(matrix, wires: Sequence[int] | Wires | None = None, *, id=None, clip_angles: bool = True, check_angles: bool = False, check_matrix: bool = False, normalize: bool = False, **kwargs)

Bases: _SingleParticleTransitionMatrix, Operation

ALLOWED_ANGLES = None
DEFAULT_CHECK_ANGLES = False
DEFAULT_CHECK_MATRIX = False
DEFAULT_CLIP_ANGLES = True
DEFAULT_NORMALIZE = False
EQUAL_ALLOWED_ANGLES = None
__init__(matrix, wires: Sequence[int] | Wires | None = None, *, id=None, clip_angles: bool = True, check_angles: bool = False, check_matrix: bool = False, normalize: bool = False, **kwargs)
adjoint() SingleParticleTransitionMatrixOperation

Create an operation that is the adjoint of this one.

Adjointed operations are the conjugated and transposed version of the original operation. Adjointed ops are equivalent to the inverted operation for unitary gates.

Returns:

The adjointed operation.

casting_priorities: List[Literal['numpy', 'autograd', 'jax', 'tf', 'torch']] = ['numpy', 'autograd', 'jax', 'tf', 'torch']
classmethod check_angles(angles)

If the ALLOWED_ANGLES is not none, check if the angles are in the allowed range.

check_is_in_so4(atol=1e-06, rtol=1e-06)
check_is_unitary(atol=1e-06, rtol=1e-06)
classmethod clip_angles(angles)

If the ALLOWED_ANGLES is not none, set the angles to the closest allowed angle. If all the angles are equal in the last dimension, the EQUAL_ALLOWED_ANGLES is used instead.

classmethod clip_to_allowed_angles(angles, allowed_angles: Sequence[float] | None = None)

If the ALLOWED_ANGLES is not none, set the angles to the closest allowed angle.

property cs_wires
classmethod from_operation(op: Any | SingleParticleTransitionMatrixOperation, **kwargs) SingleParticleTransitionMatrixOperation
classmethod from_operations(ops: Iterable[Any | SingleParticleTransitionMatrixOperation], **kwargs) SingleParticleTransitionMatrixOperation

This method will contract multiple SingleParticleTransitionMatrixOperations into a single one. Each operation must act on a different set of wires.

Parameters:
  • ops – The operations to contract.

  • kwargs – Additional keyword arguments.

Returns:

The contracted SingleParticleTransitionMatrixOperation.

Return type:

SingleParticleTransitionMatrixOperation

generator = None
grad_method = 'A'
grad_recipe = None

Gradient recipe for the parameter-shift method.

This is a tuple with one nested list per operation parameter. For parameter \(\phi_k\), the nested list contains elements of the form \([c_i, a_i, s_i]\) where \(i\) is the index of the term, resulting in a gradient recipe of

\[\frac{\partial}{\partial\phi_k}f = \sum_{i} c_i f(a_i \phi_k + s_i).\]

If None, the default gradient recipe containing the two terms \([c_0, a_0, s_0]=[1/2, 1, \pi/2]\) and \([c_1, a_1, s_1]=[-1/2, 1, -\pi/2]\) is assumed for every parameter.

Type:

tuple(Union(list[list[float]], None)) or None

matrix(wire_order=None) TensorLike

Representation of the operator as a matrix in the computational basis.

If wire_order is provided, the numerical representation considers the position of the operator’s wires in the global wire order. Otherwise, the wire order defaults to the operator’s wires.

If the matrix depends on trainable parameters, the result will be cast in the same autodifferentiation framework as the parameters.

A MatrixUndefinedError is raised if the matrix representation has not been defined.

See also

compute_matrix()

Parameters:

wire_order (Iterable) – global wire order, must contain all wire labels from the operator’s wires

Returns:

matrix representation

Return type:

tensor_like

num_params = 1
num_wires: int | WiresEnum = -1

Number of wires the operator acts on.

pad(wires: Wires)
par_domain = 'A'
classmethod random(wires: Wires, batch_size=None, **kwargs)
classmethod random_params(batch_size=None, **kwargs)
real()
property sorted_wires
to_cuda()
to_torch()

matchcake.operations.single_particle_transition_matrices.sptm_angle_embedding module

class matchcake.operations.single_particle_transition_matrices.sptm_angle_embedding.SptmAngleEmbedding(features, wires, rotations='X', id=None, **kwargs)

Bases: Operation

__init__(features, wires, rotations='X', id=None, **kwargs)

Construct a new Matchgate AngleEmbedding operation.

Note:

It is better to have one more wire than the number of features because every gate acts on two wires.

Parameters:
  • features – The features to embed.

  • wires – The wires to embed the features on.

  • id – The id of the operation.

Keyword Arguments:

contract_rots – If True, contract the rotations. Default is False.

static compute_decomposition(*params, wires=None, **hyperparameters)

Representation of the operator as a product of other operators (static method).

\[O = O_1 O_2 \dots O_n.\]

Note

Operations making up the decomposition should be queued within the compute_decomposition method.

See also

decomposition().

Parameters:
  • *params (list) – trainable parameters of the operator, as stored in the parameters attribute

  • wires (Iterable[Any], Wires) – wires that the operator acts on

  • **hyperparams (dict) – non-trainable hyperparameters of the operator, as stored in the hyperparameters attribute

Returns:

decomposition of the operator

Return type:

list[Operator]

grad_method = None
property ndim_params

Number of dimensions per trainable parameter of the operator.

By default, this property returns the numbers of dimensions of the parameters used for the operator creation. If the parameter sizes for an operator subclass are fixed, this property can be overwritten to return the fixed value.

Returns:

Number of dimensions for each trainable parameter.

Return type:

tuple

property num_params

Number of trainable parameters that the operator depends on.

By default, this property returns as many parameters as were used for the operator creation. If the number of parameters for an operator subclass is fixed, this property can be overwritten to return the fixed value.

Returns:

number of parameters

Return type:

int

num_wires: int | WiresEnum = -1

Number of wires the operator acts on.

static pad_params(params)

If the number of parameters is odd, pad the parameters with zero to make it even.

Parameters:

params – The parameters to pad.

Returns:

The padded parameters.

matchcake.operations.single_particle_transition_matrices.sptm_block_diag_angle_embedding module

class matchcake.operations.single_particle_transition_matrices.sptm_block_diag_angle_embedding.SptmBlockDiagAngleEmbedding(params, wires=None, id=None)

Bases: SingleParticleTransitionMatrixOperation

Embedding operation for the block diagonal angle single-particle transition matrix. The input features will be embedded into the block diagonal of the single-particle transition matrix of size \(2N \times 2N\), where \(N\) is the number of qubits. This operation can then encode \(N\) features into the diagonal of the single-particle transition matrix. Here is the formula for the block diagonal angle embedding:

\[\begin{split}\begin{align} R = \begin{bmatrix} \cos(f_0) & -\sin(f_0) & 0 & 0 & \cdots & 0 \\ \sin(f_0) & \cos(f_0) & 0 & 0 & \cdots & 0 \\ 0 & 0 & \cos(f_1) & -\sin(f_1) & \cdots & 0 \\ 0 & 0 & \sin(f_1) & \cos(f_1) & \cdots & 0 \\ \vdots & \vdots & \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & 0 & 0 & \cdots & \cos(f_{N-1}) & -\sin(f_{N-1}) \\ 0 & 0 & 0 & 0 & \cdots & \sin(f_{N-1}) & \cos(f_{N-1}) \end{bmatrix}\end{split}\]
Parameters:

params – The parameters of the operation

__init__(params, wires=None, id=None)
num_wires: int | WiresEnum = -1

Number of wires the operator acts on.

matchcake.operations.single_particle_transition_matrices.sptm_diag_embedding module

class matchcake.operations.single_particle_transition_matrices.sptm_diag_embedding.SptmDiagEmbedding(params, wires=None, id=None)

Bases: SingleParticleTransitionMatrixOperation

Embedding operation for the diagonal single-particle transition matrix. The input features will be embedded into the diagonal of the single-particle transition matrix of size \(2N \times 2N\), where \(N\) is the number of qubits. This operation can then encode \(2N\) features into the diagonal of the single-particle transition matrix.

Parameters:

params – The parameters of the operation

__init__(params, wires=None, id=None)
classmethod get_n_required_wires(params)
num_wires: int | WiresEnum = -1

Number of wires the operator acts on.

matchcake.operations.single_particle_transition_matrices.sptm_f_rxrx module

class matchcake.operations.single_particle_transition_matrices.sptm_f_rxrx.SptmfRxRx(params, wires=None, id=None, **kwargs)

Bases: SingleParticleTransitionMatrixOperation

This class represents the single-particle transition matrix for the fermionic RxRx rotation gate.

This matrix is defined as

\[\begin{split}\begin{align} M(Rx(2\theta), Rx(2\phi)) = U(2\theta, 2\phi) = \begin{pmatrix} \cos(\phi - \theta) & 0 & 0 & -\sin(\phi - \theta) \\ 0 & \cos(\phi + \theta) & \sin(\phi + \theta) & 0 \\ 0 & -\sin(\phi + \theta) & \cos(\phi + \theta) & 0 \\ \sin(\phi - \theta) & 0 & 0 & \cos(\phi - \theta) \end{pmatrix}. \end{align}\end{split}\]
Note:

In general, the ‘f’ in the name of the class stands for fermionic, which means that the gate is defined

directly as a matchgate in the form M(A, W) where A is the outer matrix and W is the inner matrix. This is in contrast to a gate defined as AW where A and W are two gates that are tensor-multiplied together.

__init__(params, wires=None, id=None, **kwargs)
classmethod random_params(batch_size=None, **kwargs)

matchcake.operations.single_particle_transition_matrices.sptm_fermionic_superposition module

class matchcake.operations.single_particle_transition_matrices.sptm_fermionic_superposition.SptmFermionicSuperposition(wires=None, id=None, **kwargs)

Bases: SingleParticleTransitionMatrixOperation

__init__(wires=None, id=None, **kwargs)
adjoint() SingleParticleTransitionMatrixOperation

Create an operation that is the adjoint of this one.

Adjointed operations are the conjugated and transposed version of the original operation. Adjointed ops are equivalent to the inverted operation for unitary gates.

Returns:

The adjointed operation.

static compute_decomposition(*params, wires=None, **hyperparameters)

Representation of the operator as a product of other operators (static method).

\[O = O_1 O_2 \dots O_n.\]

Note

Operations making up the decomposition should be queued within the compute_decomposition method.

See also

decomposition().

Parameters:
  • *params (list) – trainable parameters of the operator, as stored in the parameters attribute

  • wires (Iterable[Any], Wires) – wires that the operator acts on

  • **hyperparams (dict) – non-trainable hyperparameters of the operator, as stored in the hyperparameters attribute

Returns:

decomposition of the operator

Return type:

list[Operator]

classmethod random(wires: Wires, batch_size=None, **kwargs)

matchcake.operations.single_particle_transition_matrices.sptm_fhh module

class matchcake.operations.single_particle_transition_matrices.sptm_fhh.SptmFHH(wires=None, id=None, **kwargs)

Bases: SingleParticleTransitionMatrixOperation

__init__(wires=None, id=None, **kwargs)
adjoint() SingleParticleTransitionMatrixOperation

Create an operation that is the adjoint of this one.

Adjointed operations are the conjugated and transposed version of the original operation. Adjointed ops are equivalent to the inverted operation for unitary gates.

Returns:

The adjointed operation.

classmethod random(wires: Wires, batch_size=None, **kwargs)

matchcake.operations.single_particle_transition_matrices.sptm_fswap module

class matchcake.operations.single_particle_transition_matrices.sptm_fswap.SptmFSwap(wires=None, id=None, **kwargs)

Bases: SingleParticleTransitionMatrixOperation

__init__(wires=None, id=None, **kwargs)
adjoint() SingleParticleTransitionMatrixOperation

Create an operation that is the adjoint of this one.

Adjointed operations are the conjugated and transposed version of the original operation. Adjointed ops are equivalent to the inverted operation for unitary gates.

Returns:

The adjointed operation.

classmethod random(wires: Wires, batch_size=None, **kwargs)

matchcake.operations.single_particle_transition_matrices.sptm_fswap_hh module

class matchcake.operations.single_particle_transition_matrices.sptm_fswap_hh.SptmFSwapHH(wires=None, id=None, **kwargs)

Bases: SingleParticleTransitionMatrixOperation

__init__(wires=None, id=None, **kwargs)
adjoint() SingleParticleTransitionMatrixOperation

Create an operation that is the adjoint of this one.

Adjointed operations are the conjugated and transposed version of the original operation. Adjointed ops are equivalent to the inverted operation for unitary gates.

Returns:

The adjointed operation.

classmethod random(wires: Wires, batch_size=None, **kwargs)

matchcake.operations.single_particle_transition_matrices.sptm_fswap_rzrz module

class matchcake.operations.single_particle_transition_matrices.sptm_fswap_rzrz.SptmFSwapRzRz(params, wires=None, *, id=None, **kwargs)

Bases: SingleParticleTransitionMatrixOperation

ALLOWED_ANGLES = [-3.141592653589793, 3.141592653589793]
__init__(params, wires=None, *, id=None, **kwargs)
classmethod random_params(batch_size=None, **kwargs)

matchcake.operations.single_particle_transition_matrices.sptm_identity module

class matchcake.operations.single_particle_transition_matrices.sptm_identity.SptmIdentity(wires, id=None, **kwargs)

Bases: SingleParticleTransitionMatrixOperation

__init__(wires, id=None, **kwargs)
adjoint() SingleParticleTransitionMatrixOperation

Create an operation that is the adjoint of this one.

Adjointed operations are the conjugated and transposed version of the original operation. Adjointed ops are equivalent to the inverted operation for unitary gates.

Returns:

The adjointed operation.

classmethod random(wires: Wires, batch_size=None, **kwargs)

matchcake.operations.single_particle_transition_matrices.sptm_ryry module

class matchcake.operations.single_particle_transition_matrices.sptm_ryry.SptmRyRy(params, wires=None, *, id=None, **kwargs)

Bases: SingleParticleTransitionMatrixOperation

ALLOWED_ANGLES = [3.141592653589793, 9.42477796076938]
EQUAL_ALLOWED_ANGLES = [0, 3.141592653589793, 6.283185307179586, 9.42477796076938]
__init__(params, wires=None, *, id=None, **kwargs)
classmethod random_params(batch_size=None, **kwargs)

matchcake.operations.single_particle_transition_matrices.sptm_rzrz module

class matchcake.operations.single_particle_transition_matrices.sptm_rzrz.SptmRzRz(params, wires=None, *, id=None, **kwargs)

Bases: SingleParticleTransitionMatrixOperation

ALLOWED_ANGLES = [3.141592653589793, 9.42477796076938]
EQUAL_ALLOWED_ANGLES = [0, 3.141592653589793, 6.283185307179586, 9.42477796076938]
__init__(params, wires=None, *, id=None, **kwargs)
classmethod random_params(batch_size=None, **kwargs)

Module contents