matchcake.operations package¶
Subpackages¶
- matchcake.operations.single_particle_transition_matrices package
- Submodules
- matchcake.operations.single_particle_transition_matrices.single_particle_transition_matrix module
SingleParticleTransitionMatrixOperation
SingleParticleTransitionMatrixOperation.ALLOWED_ANGLES
SingleParticleTransitionMatrixOperation.DEFAULT_CHECK_ANGLES
SingleParticleTransitionMatrixOperation.DEFAULT_CHECK_MATRIX
SingleParticleTransitionMatrixOperation.DEFAULT_CLIP_ANGLES
SingleParticleTransitionMatrixOperation.DEFAULT_NORMALIZE
SingleParticleTransitionMatrixOperation.EQUAL_ALLOWED_ANGLES
SingleParticleTransitionMatrixOperation.__init__()
SingleParticleTransitionMatrixOperation.adjoint()
SingleParticleTransitionMatrixOperation.casting_priorities
SingleParticleTransitionMatrixOperation.check_angles()
SingleParticleTransitionMatrixOperation.check_is_in_so4()
SingleParticleTransitionMatrixOperation.check_is_unitary()
SingleParticleTransitionMatrixOperation.clip_angles()
SingleParticleTransitionMatrixOperation.clip_to_allowed_angles()
SingleParticleTransitionMatrixOperation.cs_wires
SingleParticleTransitionMatrixOperation.from_operation()
SingleParticleTransitionMatrixOperation.from_operations()
SingleParticleTransitionMatrixOperation.generator
SingleParticleTransitionMatrixOperation.grad_method
SingleParticleTransitionMatrixOperation.grad_recipe
SingleParticleTransitionMatrixOperation.matrix()
SingleParticleTransitionMatrixOperation.num_params
SingleParticleTransitionMatrixOperation.num_wires
SingleParticleTransitionMatrixOperation.pad()
SingleParticleTransitionMatrixOperation.par_domain
SingleParticleTransitionMatrixOperation.random()
SingleParticleTransitionMatrixOperation.random_params()
SingleParticleTransitionMatrixOperation.real()
SingleParticleTransitionMatrixOperation.sorted_wires
SingleParticleTransitionMatrixOperation.to_cuda()
SingleParticleTransitionMatrixOperation.to_torch()
- matchcake.operations.single_particle_transition_matrices.sptm_angle_embedding module
- matchcake.operations.single_particle_transition_matrices.sptm_block_diag_angle_embedding module
- matchcake.operations.single_particle_transition_matrices.sptm_diag_embedding module
- matchcake.operations.single_particle_transition_matrices.sptm_f_rxrx module
- matchcake.operations.single_particle_transition_matrices.sptm_fermionic_superposition module
- matchcake.operations.single_particle_transition_matrices.sptm_fhh module
- matchcake.operations.single_particle_transition_matrices.sptm_fswap module
- matchcake.operations.single_particle_transition_matrices.sptm_fswap_hh module
- matchcake.operations.single_particle_transition_matrices.sptm_fswap_rzrz module
- matchcake.operations.single_particle_transition_matrices.sptm_identity module
- matchcake.operations.single_particle_transition_matrices.sptm_ryry module
- matchcake.operations.single_particle_transition_matrices.sptm_rzrz module
- Module contents
Submodules¶
matchcake.operations.angle_embedding module¶
- class matchcake.operations.angle_embedding.MAngleEmbedding(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
attributewires (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.
- simplify() Operation ¶
Reduce the depth of nested operators to the minimum.
- Returns:
simplified operator
- Return type:
.Operator
- class matchcake.operations.angle_embedding.MAngleEmbeddings(features, wires, rotations='X', id=None)¶
Bases:
Operation
- __init__(features, wires, rotations='X', id=None)¶
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.
- 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
attributewires (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.fermionic_controlled_z module¶
- matchcake.operations.fermionic_controlled_z.FermionicControlledZ¶
alias of
FermionicControlledZ
- class matchcake.operations.fermionic_controlled_z.fCZ(*params: TensorLike, wires: Wires | Iterable[Hashable] | Hashable | None = None, id: str | None = None)¶
Bases:
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
attributewires (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]
- label(decimals=None, base_label=None, cache=None)¶
A customizable string representation of the operator.
- Parameters:
decimals=None (int) – If
None
, no parameters are included. Else, specifies how to round the parameters.base_label=None (str) – overwrite the non-parameter component of the label
cache=None (dict) – dictionary that carries information between label calls in the same drawing
- Returns:
label to use in drawings
- Return type:
str
Example:
>>> op = qml.RX(1.23456, wires=0) >>> op.label() "RX" >>> op.label(base_label="my_label") "my_label" >>> op = qml.RX(1.23456, wires=0, id="test_data") >>> op.label() "RX("test_data")" >>> op.label(decimals=2) "RX\n(1.23,"test_data")" >>> op.label(base_label="my_label") "my_label("test_data")" >>> op.label(decimals=2, base_label="my_label") "my_label\n(1.23,"test_data")"
If the operation has a matrix-valued parameter and a cache dictionary is provided, unique matrices will be cached in the
'matrices'
key list. The label will contain the index of the matrix in the'matrices'
list.>>> op2 = qml.QubitUnitary(np.eye(2), wires=0) >>> cache = {'matrices': []} >>> op2.label(cache=cache) 'U(M0)' >>> cache['matrices'] [tensor([[1., 0.], [0., 1.]], requires_grad=True)] >>> op3 = qml.QubitUnitary(np.eye(4), wires=(0,1)) >>> op3.label(cache=cache) 'U(M1)' >>> cache['matrices'] [tensor([[1., 0.], [0., 1.]], requires_grad=True), tensor([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]], requires_grad=True)]
- num_params = 0¶
- num_wires: int | WiresEnum = 2¶
Number of wires the operator acts on.
matchcake.operations.fermionic_hadamard module¶
- matchcake.operations.fermionic_hadamard.FermionicHadamard¶
alias of
FermionicHadamard
- class matchcake.operations.fermionic_hadamard.fH(wires=None, id=None, **kwargs)¶
Bases:
MatchgateOperation
- __init__(wires=None, id=None, **kwargs)¶
Construct a Matchgate from the parameters. The parameters can be a MatchgateParams object, a list, a tuple or a numpy array. If the parameters are a list, tuple or numpy array, the parameters will be interpreted as the keyword argument default_given_params_cls.
If the parameters are a MatchgateParams object, the parameters will be interpreted as the type of the object.
- Parameters:
params (Union[mps.MatchgateParams, np.ndarray, list, tuple]) – The parameters of the Matchgate.
backend (str) – The backend to use for the computations. Can be ‘numpy’, ‘sympy’ or ‘torch’.
- label(decimals=None, base_label=None, cache=None)¶
A customizable string representation of the operator.
- Parameters:
decimals=None (int) – If
None
, no parameters are included. Else, specifies how to round the parameters.base_label=None (str) – overwrite the non-parameter component of the label
cache=None (dict) – dictionary that carries information between label calls in the same drawing
- Returns:
label to use in drawings
- Return type:
str
Example:
>>> op = qml.RX(1.23456, wires=0) >>> op.label() "RX" >>> op.label(base_label="my_label") "my_label" >>> op = qml.RX(1.23456, wires=0, id="test_data") >>> op.label() "RX("test_data")" >>> op.label(decimals=2) "RX\n(1.23,"test_data")" >>> op.label(base_label="my_label") "my_label("test_data")" >>> op.label(decimals=2, base_label="my_label") "my_label\n(1.23,"test_data")"
If the operation has a matrix-valued parameter and a cache dictionary is provided, unique matrices will be cached in the
'matrices'
key list. The label will contain the index of the matrix in the'matrices'
list.>>> op2 = qml.QubitUnitary(np.eye(2), wires=0) >>> cache = {'matrices': []} >>> op2.label(cache=cache) 'U(M0)' >>> cache['matrices'] [tensor([[1., 0.], [0., 1.]], requires_grad=True)] >>> op3 = qml.QubitUnitary(np.eye(4), wires=(0,1)) >>> op3.label(cache=cache) 'U(M1)' >>> cache['matrices'] [tensor([[1., 0.], [0., 1.]], requires_grad=True), tensor([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]], requires_grad=True)]
- num_params = 0¶
- num_wires: int | WiresEnum = 2¶
Number of wires the operator acts on.
- classmethod random(wires: Wires, batch_size=None, **kwargs)¶
Construct a random Matchgate.
- Returns:
A random Matchgate.
- Rtype Matchgate:
matchcake.operations.fermionic_paulis module¶
- class matchcake.operations.fermionic_paulis.FermionicPauli(wires=None, paulis='XX', id=None, *, backend=<module 'pennylane.numpy' from '/home/runner/work/MatchCake/MatchCake/venv/lib/python3.10/site-packages/pennylane/numpy/__init__.py'>, **kwargs)¶
Bases:
MatchgateOperation
- __init__(wires=None, paulis='XX', id=None, *, backend=<module 'pennylane.numpy' from '/home/runner/work/MatchCake/MatchCake/venv/lib/python3.10/site-packages/pennylane/numpy/__init__.py'>, **kwargs)¶
Construct a Matchgate from the parameters. The parameters can be a MatchgateParams object, a list, a tuple or a numpy array. If the parameters are a list, tuple or numpy array, the parameters will be interpreted as the keyword argument default_given_params_cls.
If the parameters are a MatchgateParams object, the parameters will be interpreted as the type of the object.
- Parameters:
params (Union[mps.MatchgateParams, np.ndarray, list, tuple]) – The parameters of the Matchgate.
backend (str) – The backend to use for the computations. Can be ‘numpy’, ‘sympy’ or ‘torch’.
- get_implicit_parameters()¶
- label(decimals=None, base_label=None, cache=None)¶
A customizable string representation of the operator.
- Parameters:
decimals=None (int) – If
None
, no parameters are included. Else, specifies how to round the parameters.base_label=None (str) – overwrite the non-parameter component of the label
cache=None (dict) – dictionary that carries information between label calls in the same drawing
- Returns:
label to use in drawings
- Return type:
str
Example:
>>> op = qml.RX(1.23456, wires=0) >>> op.label() "RX" >>> op.label(base_label="my_label") "my_label" >>> op = qml.RX(1.23456, wires=0, id="test_data") >>> op.label() "RX("test_data")" >>> op.label(decimals=2) "RX\n(1.23,"test_data")" >>> op.label(base_label="my_label") "my_label("test_data")" >>> op.label(decimals=2, base_label="my_label") "my_label\n(1.23,"test_data")"
If the operation has a matrix-valued parameter and a cache dictionary is provided, unique matrices will be cached in the
'matrices'
key list. The label will contain the index of the matrix in the'matrices'
list.>>> op2 = qml.QubitUnitary(np.eye(2), wires=0) >>> cache = {'matrices': []} >>> op2.label(cache=cache) 'U(M0)' >>> cache['matrices'] [tensor([[1., 0.], [0., 1.]], requires_grad=True)] >>> op3 = qml.QubitUnitary(np.eye(4), wires=(0,1)) >>> op3.label(cache=cache) 'U(M1)' >>> cache['matrices'] [tensor([[1., 0.], [0., 1.]], requires_grad=True), tensor([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]], requires_grad=True)]
- num_params = 0¶
- num_wires: int | WiresEnum = 2¶
Number of wires the operator acts on.
- classmethod random(wires: Wires, batch_size=None, **kwargs)¶
Construct a random Matchgate.
- Returns:
A random Matchgate.
- Rtype Matchgate:
- matchcake.operations.fermionic_paulis.FermionicXX¶
alias of
FermionicXX
- matchcake.operations.fermionic_paulis.FermionicYY¶
alias of
FermionicYY
- matchcake.operations.fermionic_paulis.FermionicZZ¶
alias of
FermionicZZ
- class matchcake.operations.fermionic_paulis.fXX(wires=None, id=None, *, backend=<module 'pennylane.numpy' from '/home/runner/work/MatchCake/MatchCake/venv/lib/python3.10/site-packages/pennylane/numpy/__init__.py'>, **kwargs)¶
Bases:
FermionicPauli
- __init__(wires=None, id=None, *, backend=<module 'pennylane.numpy' from '/home/runner/work/MatchCake/MatchCake/venv/lib/python3.10/site-packages/pennylane/numpy/__init__.py'>, **kwargs)¶
Construct a Matchgate from the parameters. The parameters can be a MatchgateParams object, a list, a tuple or a numpy array. If the parameters are a list, tuple or numpy array, the parameters will be interpreted as the keyword argument default_given_params_cls.
If the parameters are a MatchgateParams object, the parameters will be interpreted as the type of the object.
- Parameters:
params (Union[mps.MatchgateParams, np.ndarray, list, tuple]) – The parameters of the Matchgate.
backend (str) – The backend to use for the computations. Can be ‘numpy’, ‘sympy’ or ‘torch’.
- class matchcake.operations.fermionic_paulis.fYY(wires=None, id=None, *, backend=<module 'pennylane.numpy' from '/home/runner/work/MatchCake/MatchCake/venv/lib/python3.10/site-packages/pennylane/numpy/__init__.py'>, **kwargs)¶
Bases:
FermionicPauli
- __init__(wires=None, id=None, *, backend=<module 'pennylane.numpy' from '/home/runner/work/MatchCake/MatchCake/venv/lib/python3.10/site-packages/pennylane/numpy/__init__.py'>, **kwargs)¶
Construct a Matchgate from the parameters. The parameters can be a MatchgateParams object, a list, a tuple or a numpy array. If the parameters are a list, tuple or numpy array, the parameters will be interpreted as the keyword argument default_given_params_cls.
If the parameters are a MatchgateParams object, the parameters will be interpreted as the type of the object.
- Parameters:
params (Union[mps.MatchgateParams, np.ndarray, list, tuple]) – The parameters of the Matchgate.
backend (str) – The backend to use for the computations. Can be ‘numpy’, ‘sympy’ or ‘torch’.
- class matchcake.operations.fermionic_paulis.fZZ(wires=None, id=None, *, backend=<module 'pennylane.numpy' from '/home/runner/work/MatchCake/MatchCake/venv/lib/python3.10/site-packages/pennylane/numpy/__init__.py'>, **kwargs)¶
Bases:
FermionicPauli
- __init__(wires=None, id=None, *, backend=<module 'pennylane.numpy' from '/home/runner/work/MatchCake/MatchCake/venv/lib/python3.10/site-packages/pennylane/numpy/__init__.py'>, **kwargs)¶
Construct a Matchgate from the parameters. The parameters can be a MatchgateParams object, a list, a tuple or a numpy array. If the parameters are a list, tuple or numpy array, the parameters will be interpreted as the keyword argument default_given_params_cls.
If the parameters are a MatchgateParams object, the parameters will be interpreted as the type of the object.
- Parameters:
params (Union[mps.MatchgateParams, np.ndarray, list, tuple]) – The parameters of the Matchgate.
backend (str) – The backend to use for the computations. Can be ‘numpy’, ‘sympy’ or ‘torch’.
matchcake.operations.fermionic_rotations module¶
- class matchcake.operations.fermionic_rotations.FermionicRotation(params: ~numpy.ndarray | list | tuple, wires=None, directions='XX', id=None, *, backend=<module 'pennylane.numpy' from '/home/runner/work/MatchCake/MatchCake/venv/lib/python3.10/site-packages/pennylane/numpy/__init__.py'>, **kwargs)¶
Bases:
MatchgateOperation
- TAYLOR_SERIES_TERMS = 10¶
- USE_EXP_TAYLOR_SERIES = False¶
- __init__(params: ~numpy.ndarray | list | tuple, wires=None, directions='XX', id=None, *, backend=<module 'pennylane.numpy' from '/home/runner/work/MatchCake/MatchCake/venv/lib/python3.10/site-packages/pennylane/numpy/__init__.py'>, **kwargs)¶
Construct a Matchgate from the parameters. The parameters can be a MatchgateParams object, a list, a tuple or a numpy array. If the parameters are a list, tuple or numpy array, the parameters will be interpreted as the keyword argument default_given_params_cls.
If the parameters are a MatchgateParams object, the parameters will be interpreted as the type of the object.
- Parameters:
params (Union[mps.MatchgateParams, np.ndarray, list, tuple]) – The parameters of the Matchgate.
backend (str) – The backend to use for the computations. Can be ‘numpy’, ‘sympy’ or ‘torch’.
- get_implicit_parameters()¶
- label(decimals=None, base_label=None, cache=None)¶
A customizable string representation of the operator.
- Parameters:
decimals=None (int) – If
None
, no parameters are included. Else, specifies how to round the parameters.base_label=None (str) – overwrite the non-parameter component of the label
cache=None (dict) – dictionary that carries information between label calls in the same drawing
- Returns:
label to use in drawings
- Return type:
str
Example:
>>> op = qml.RX(1.23456, wires=0) >>> op.label() "RX" >>> op.label(decimals=2) "RX\n(1.23)" >>> op.label(base_label="my_label") "my_label" >>> op.label(decimals=2, base_label="my_label") "my_label\n(1.23)"
If the operation has a matrix-valued parameter and a cache dictionary is provided, unique matrices will be cached in the
'matrices'
key list. The label will contain the index of the matrix in the'matrices'
list.>>> op2 = qml.QubitUnitary(np.eye(2), wires=0) >>> cache = {'matrices': []} >>> op2.label(cache=cache) 'U(M0)' >>> cache['matrices'] [tensor([[1., 0.], [0., 1.]], requires_grad=True)] >>> op3 = qml.QubitUnitary(np.eye(4), wires=(0,1)) >>> op3.label(cache=cache) 'U(M1)' >>> cache['matrices'] [tensor([[1., 0.], [0., 1.]], requires_grad=True), tensor([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]], requires_grad=True)]
- num_params = 2¶
- num_wires: int | WiresEnum = 2¶
Number of wires the operator acts on.
- classmethod random_params(batch_size=None, **kwargs)¶
- matchcake.operations.fermionic_rotations.FermionicRotationXX¶
alias of
FermionicRotationXX
- matchcake.operations.fermionic_rotations.FermionicRotationYY¶
alias of
FermionicRotationYY
- matchcake.operations.fermionic_rotations.FermionicRotationZZ¶
alias of
FermionicRotationZZ
- class matchcake.operations.fermionic_rotations.fRXX(params: ~numpy.ndarray | list | tuple, wires=None, id=None, *, backend=<module 'pennylane.numpy' from '/home/runner/work/MatchCake/MatchCake/venv/lib/python3.10/site-packages/pennylane/numpy/__init__.py'>, **kwargs)¶
Bases:
FermionicRotation
- __init__(params: ~numpy.ndarray | list | tuple, wires=None, id=None, *, backend=<module 'pennylane.numpy' from '/home/runner/work/MatchCake/MatchCake/venv/lib/python3.10/site-packages/pennylane/numpy/__init__.py'>, **kwargs)¶
Construct a Matchgate from the parameters. The parameters can be a MatchgateParams object, a list, a tuple or a numpy array. If the parameters are a list, tuple or numpy array, the parameters will be interpreted as the keyword argument default_given_params_cls.
If the parameters are a MatchgateParams object, the parameters will be interpreted as the type of the object.
- Parameters:
params (Union[mps.MatchgateParams, np.ndarray, list, tuple]) – The parameters of the Matchgate.
backend (str) – The backend to use for the computations. Can be ‘numpy’, ‘sympy’ or ‘torch’.
- class matchcake.operations.fermionic_rotations.fRYY(params: ~numpy.ndarray | list | tuple, wires=None, id=None, *, backend=<module 'pennylane.numpy' from '/home/runner/work/MatchCake/MatchCake/venv/lib/python3.10/site-packages/pennylane/numpy/__init__.py'>, **kwargs)¶
Bases:
FermionicRotation
- __init__(params: ~numpy.ndarray | list | tuple, wires=None, id=None, *, backend=<module 'pennylane.numpy' from '/home/runner/work/MatchCake/MatchCake/venv/lib/python3.10/site-packages/pennylane/numpy/__init__.py'>, **kwargs)¶
Construct a Matchgate from the parameters. The parameters can be a MatchgateParams object, a list, a tuple or a numpy array. If the parameters are a list, tuple or numpy array, the parameters will be interpreted as the keyword argument default_given_params_cls.
If the parameters are a MatchgateParams object, the parameters will be interpreted as the type of the object.
- Parameters:
params (Union[mps.MatchgateParams, np.ndarray, list, tuple]) – The parameters of the Matchgate.
backend (str) – The backend to use for the computations. Can be ‘numpy’, ‘sympy’ or ‘torch’.
- adjoint()¶
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.
- class matchcake.operations.fermionic_rotations.fRZZ(params: ~numpy.ndarray | list | tuple, wires=None, id=None, *, backend=<module 'pennylane.numpy' from '/home/runner/work/MatchCake/MatchCake/venv/lib/python3.10/site-packages/pennylane/numpy/__init__.py'>, **kwargs)¶
Bases:
FermionicRotation
- __init__(params: ~numpy.ndarray | list | tuple, wires=None, id=None, *, backend=<module 'pennylane.numpy' from '/home/runner/work/MatchCake/MatchCake/venv/lib/python3.10/site-packages/pennylane/numpy/__init__.py'>, **kwargs)¶
Construct a Matchgate from the parameters. The parameters can be a MatchgateParams object, a list, a tuple or a numpy array. If the parameters are a list, tuple or numpy array, the parameters will be interpreted as the keyword argument default_given_params_cls.
If the parameters are a MatchgateParams object, the parameters will be interpreted as the type of the object.
- Parameters:
params (Union[mps.MatchgateParams, np.ndarray, list, tuple]) – The parameters of the Matchgate.
backend (str) – The backend to use for the computations. Can be ‘numpy’, ‘sympy’ or ‘torch’.
matchcake.operations.fermionic_superposition module¶
- class matchcake.operations.fermionic_superposition.FermionicSuperposition(wires, id=None, **kwargs)¶
Bases:
Operation
- __init__(wires, id=None, **kwargs)¶
Construct a new Matchgate Superposition operation. After applying this operation on the vacuum state each even modes will be in equal superposition.
- Note:
The number of wires must be even.
- Parameters:
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
attributewires (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 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.
- classmethod random(wires: Wires, batch_size=None, **kwargs)¶
- to_sptm_operation()¶
matchcake.operations.fermionic_swap module¶
- matchcake.operations.fermionic_swap.FermionicSWAP¶
alias of
FermionicSWAP
- class matchcake.operations.fermionic_swap.fSWAP(wires=None, id=None, *, backend=<module 'pennylane.numpy' from '/home/runner/work/MatchCake/MatchCake/venv/lib/python3.10/site-packages/pennylane/numpy/__init__.py'>, **kwargs)¶
Bases:
MatchgateOperation
- __init__(wires=None, id=None, *, backend=<module 'pennylane.numpy' from '/home/runner/work/MatchCake/MatchCake/venv/lib/python3.10/site-packages/pennylane/numpy/__init__.py'>, **kwargs)¶
Construct a Matchgate from the parameters. The parameters can be a MatchgateParams object, a list, a tuple or a numpy array. If the parameters are a list, tuple or numpy array, the parameters will be interpreted as the keyword argument default_given_params_cls.
If the parameters are a MatchgateParams object, the parameters will be interpreted as the type of the object.
- Parameters:
params (Union[mps.MatchgateParams, np.ndarray, list, tuple]) – The parameters of the Matchgate.
backend (str) – The backend to use for the computations. Can be ‘numpy’, ‘sympy’ or ‘torch’.
- num_params = 0¶
- num_wires: int | WiresEnum = 2¶
Number of wires the operator acts on.
- classmethod random(wires: Wires, batch_size=None, **kwargs)¶
Construct a random Matchgate.
- Returns:
A random Matchgate.
- Rtype Matchgate:
- matchcake.operations.fermionic_swap.fswap_chain(wires, **kwargs)¶
- matchcake.operations.fermionic_swap.fswap_chain_gen(wires, **kwargs)¶
matchcake.operations.matchgate_operation module¶
- class matchcake.operations.matchgate_operation.MatchgateOperation(params: MatchgateParams | ndarray | list | tuple, wires=None, id=None, **kwargs)¶
Bases:
Matchgate
,Operation
- __init__(params: MatchgateParams | ndarray | list | tuple, wires=None, id=None, **kwargs)¶
Construct a Matchgate from the parameters. The parameters can be a MatchgateParams object, a list, a tuple or a numpy array. If the parameters are a list, tuple or numpy array, the parameters will be interpreted as the keyword argument default_given_params_cls.
If the parameters are a MatchgateParams object, the parameters will be interpreted as the type of the object.
- Parameters:
params (Union[mps.MatchgateParams, np.ndarray, list, tuple]) – The parameters of the Matchgate.
backend (str) – The backend to use for the computations. Can be ‘numpy’, ‘sympy’ or ‘torch’.
- adjoint()¶
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.
- property batch_size¶
Batch size of the operator if it is used with broadcasted parameters.
The
batch_size
is determined based onndim_params
and the provided parameters for the operator. If (some of) the latter have an additional dimension, and this dimension has the same size for all parameters, its size is the batch size of the operator. If no parameter has an additional dimension, the batch size isNone
.- Returns:
Size of the parameter broadcasting dimension if present, else
None
.- Return type:
int or None
- casting_priorities = ['numpy', 'autograd', 'jax', 'tf', 'torch']¶
- static compute_decomposition(*params: functools.partial(<function do at 0x7f68f15370a0>, 'TensorLike'), wires: ~pennylane.wires.Wires | ~collections.abc.Iterable[~collections.abc.Hashable] | ~collections.abc.Hashable | None = None, **hyperparameters: dict[str, typing.Any])¶
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
attributewires (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]
- static compute_matrix(*params, **hyperparams)¶
Representation of the operator as a canonical matrix in the computational basis (static method).
The canonical matrix is the textbook matrix representation that does not consider wires. Implicitly, this assumes that the wires of the operator correspond to the global wire order.
See also
Operator.matrix()
andqml.matrix()
- Parameters:
*params (list) – trainable parameters of the operator, as stored in the
parameters
attribute**hyperparams (dict) – non-trainable hyperparameters of the operator, as stored in the
hyperparameters
attribute
- Returns:
matrix representation
- Return type:
tensor_like
- property cs_wires¶
- generator = None¶
- get_padded_single_particle_transition_matrix(wires=None)¶
Return the padded single particle transition matrix in order to have the block diagonal form where the block is the single particle transition matrix at the corresponding wires.
- Parameters:
wires – The wires of the whole system.
- Returns:
padded single particle transition matrix
- 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
- label(decimals=None, base_label=None, cache=None)¶
A customizable string representation of the operator.
- Parameters:
decimals=None (int) – If
None
, no parameters are included. Else, specifies how to round the parameters.base_label=None (str) – overwrite the non-parameter component of the label
cache=None (dict) – dictionary that carries information between label calls in the same drawing
- Returns:
label to use in drawings
- Return type:
str
Example:
>>> op = qml.RX(1.23456, wires=0) >>> op.label() "RX" >>> op.label(base_label="my_label") "my_label" >>> op = qml.RX(1.23456, wires=0, id="test_data") >>> op.label() "RX("test_data")" >>> op.label(decimals=2) "RX\n(1.23,"test_data")" >>> op.label(base_label="my_label") "my_label("test_data")" >>> op.label(decimals=2, base_label="my_label") "my_label\n(1.23,"test_data")"
If the operation has a matrix-valued parameter and a cache dictionary is provided, unique matrices will be cached in the
'matrices'
key list. The label will contain the index of the matrix in the'matrices'
list.>>> op2 = qml.QubitUnitary(np.eye(2), wires=0) >>> cache = {'matrices': []} >>> op2.label(cache=cache) 'U(M0)' >>> cache['matrices'] [tensor([[1., 0.], [0., 1.]], requires_grad=True)] >>> op3 = qml.QubitUnitary(np.eye(4), wires=(0,1)) >>> op3.label(cache=cache) 'U(M1)' >>> cache['matrices'] [tensor([[1., 0.], [0., 1.]], requires_grad=True), tensor([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]], requires_grad=True)]
- num_params = 7¶
- num_wires: int | WiresEnum = 2¶
Number of wires the operator acts on.
- par_domain = 'A'¶
- classmethod random(wires: Wires, batch_size=None, **kwargs) MatchgateOperation ¶
Construct a random Matchgate.
- Returns:
A random Matchgate.
- Rtype Matchgate:
- classmethod random_params(batch_size=None, **kwargs)¶
- property sorted_wires¶
- to_sptm_operation()¶
matchcake.operations.rxx module¶
- class matchcake.operations.rxx.Rxx(params: ndarray | list | tuple, wires=None, id=None, **kwargs)¶
Bases:
MatchgateOperation
This operation implements the following as a MatchgateOperation:
\[\begin{split}U = e^{-i\theta X_{j} \otimes X_{j+1}} \\ = \begin{bmatrix} \cos(\theta) & 0 & 0 & -i\sin(\theta) \\ 0 & \cos(\theta) & -i\sin(\theta) & 0 \\ 0 & -i\sin(\theta) & \cos(\theta) & 0 \\ -i\sin(\theta) & 0 & 0 & \cos(\theta) \end{bmatrix}\end{split}\]where \(\theta\) is a parameter, \(X_{j}\) is the Pauli-X operator applied on the wire \(j\), and \(i\) is the imaginary unit.
- __init__(params: ndarray | list | tuple, wires=None, id=None, **kwargs)¶
Construct a Matchgate from the parameters. The parameters can be a MatchgateParams object, a list, a tuple or a numpy array. If the parameters are a list, tuple or numpy array, the parameters will be interpreted as the keyword argument default_given_params_cls.
If the parameters are a MatchgateParams object, the parameters will be interpreted as the type of the object.
- Parameters:
params (Union[mps.MatchgateParams, np.ndarray, list, tuple]) – The parameters of the Matchgate.
backend (str) – The backend to use for the computations. Can be ‘numpy’, ‘sympy’ or ‘torch’.
- num_params = 1¶
- num_wires: int | WiresEnum = 2¶
Number of wires the operator acts on.
matchcake.operations.rzz module¶
- class matchcake.operations.rzz.Rzz(params: ndarray | list | tuple, wires=None, id=None, **kwargs)¶
Bases:
MatchgateOperation
This operation implements the following as a MatchgateOperation:
\[\begin{split}U = e^{-i\theta Z_{j} \otimes Z_{j+1}} \\ = \begin{bmatrix} e^{-i\theta} & 0 & 0 & 0 \\ 0 & e^{i\theta} & 0 & 0 \\ 0 & 0 & e^{i\theta} & 0 \\ 0 & 0 & 0 & e^{-i\theta} \end{bmatrix}\end{split}\]where \(\theta\) is a parameter, \(Z_{j}\) is the Pauli-Z operator applied on the wire \(j\), and \(i\) is the imaginary unit.
- __init__(params: ndarray | list | tuple, wires=None, id=None, **kwargs)¶
Construct a Matchgate from the parameters. The parameters can be a MatchgateParams object, a list, a tuple or a numpy array. If the parameters are a list, tuple or numpy array, the parameters will be interpreted as the keyword argument default_given_params_cls.
If the parameters are a MatchgateParams object, the parameters will be interpreted as the type of the object.
- Parameters:
params (Union[mps.MatchgateParams, np.ndarray, list, tuple]) – The parameters of the Matchgate.
backend (str) – The backend to use for the computations. Can be ‘numpy’, ‘sympy’ or ‘torch’.
- num_params = 1¶
- num_wires: int | WiresEnum = 2¶
Number of wires the operator acts on.
Module contents¶
- class matchcake.operations.IZ(wires)¶
Bases:
MatchgateOperation
- __init__(wires)¶
Construct a Matchgate from the parameters. The parameters can be a MatchgateParams object, a list, a tuple or a numpy array. If the parameters are a list, tuple or numpy array, the parameters will be interpreted as the keyword argument default_given_params_cls.
If the parameters are a MatchgateParams object, the parameters will be interpreted as the type of the object.
- Parameters:
params (Union[mps.MatchgateParams, np.ndarray, list, tuple]) – The parameters of the Matchgate.
backend (str) – The backend to use for the computations. Can be ‘numpy’, ‘sympy’ or ‘torch’.
- num_params = 0¶
- num_wires: int | WiresEnum = 2¶
Number of wires the operator acts on.
- class matchcake.operations.ZI(wires)¶
Bases:
MatchgateOperation
- __init__(wires)¶
Construct a Matchgate from the parameters. The parameters can be a MatchgateParams object, a list, a tuple or a numpy array. If the parameters are a list, tuple or numpy array, the parameters will be interpreted as the keyword argument default_given_params_cls.
If the parameters are a MatchgateParams object, the parameters will be interpreted as the type of the object.
- Parameters:
params (Union[mps.MatchgateParams, np.ndarray, list, tuple]) – The parameters of the Matchgate.
backend (str) – The backend to use for the computations. Can be ‘numpy’, ‘sympy’ or ‘torch’.
- num_params = 0¶
- num_wires: int | WiresEnum = 2¶
Number of wires the operator acts on.