qml.labs.resource_estimation.ResourceSWAP¶
- class ResourceSWAP(*args, wires=None, **kwargs)[source]¶
Bases:
ResourceOperator
Resource class for the SWAP gate.
- Parameters:
wires (Sequence[int], optional) – the wires the operation acts on
- Resources:
The resources come from the following identity expressing SWAP as the product of three
CNOT
gates:\[\begin{split}SWAP = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 1\\ 0 & 0 & 1 & 0 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1\\ 0 & 0 & 1 & 0\\ 0 & 1 & 0 & 0 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 1\\ 0 & 0 & 1 & 0 \end{bmatrix}.\end{split}\]
See also
Example
The resources for this operation are computed using:
>>> plre.ResourceSWAP.resource_decomp() [(3 x CNOT)]
Attributes
Returns a dictionary containing the minimal information needed to compute the resources.
- num_wires = 2¶
- resource_keys = {}¶
- resource_params¶
Returns a dictionary containing the minimal information needed to compute the resources.
- Returns:
Empty dictionary. The resources of this operation don’t depend on any additional parameters.
- Return type:
dict
Methods
adjoint_resource_decomp
(*args, **kwargs)Returns a list of actions that define the resources of the operator.
Returns a list representing the resources for a controlled version of the operator.
Returns a list representing the resources for the adjoint of the operator.
Returns a list representing the resources for a controlled version of the operator.
default_pow_resource_decomp
(pow_z)Returns a list representing the resources for an operator raised to a power.
default_resource_decomp
(**kwargs)Returns a list representing the resources of the operator.
dequeue
(op_to_remove[, context])Remove the given resource operator(s) from the Operator queue.
pow_resource_decomp
(pow_z, *args, **kwargs)Returns a list representing the resources for an operator raised to a power.
queue
([context])Append the operator to the Operator queue.
resource_decomp
(*args, **kwargs)Returns a list of actions that define the resources of the operator.
Returns a compressed representation containing only the parameters of the Operator that are needed to compute a resource estimation.
Returns a compressed representation directly from the operator
set_resources
(new_func[, override_type])Set a custom function to override the default resource decomposition.
tracking_name
(*args, **kwargs)Returns a name used to track the operator during resource estimation.
Returns the tracking name built with the operator's parameters.
- classmethod adjoint_resource_decomp(*args, **kwargs)¶
Returns a list of actions that define the resources of the operator.
- classmethod controlled_resource_decomp(ctrl_num_ctrl_wires, ctrl_num_ctrl_values, *args, **kwargs)¶
Returns a list representing the resources for a controlled version of the operator.
- Parameters:
ctrl_num_ctrl_wires (int) – the number of qubits the operation is controlled on
ctrl_num_ctrl_values (int) – the number of control qubits, that are controlled when in the \(|0\rangle\) state
- classmethod default_adjoint_resource_decomp()[source]¶
Returns a list representing the resources for the adjoint of the operator.
- Resources:
This operation is self-adjoint, so the resources of the adjoint operation results in the original operation.
- Returns:
A list of GateCount objects, where each object represents a specific quantum gate and the number of times it appears in the decomposition.
- Return type:
list[GateCount]
- classmethod default_controlled_resource_decomp(ctrl_num_ctrl_wires, ctrl_num_ctrl_values)[source]¶
Returns a list representing the resources for a controlled version of the operator.
- Parameters:
ctrl_num_ctrl_wires (int) – the number of qubits the operation is controlled on
ctrl_num_ctrl_values (int) – the number of control qubits, that are controlled when in the \(|0\rangle\) state
- Resources:
For a single control wire, the cost is a single instance of
ResourceCSWAP
. Two additionalResourceX
gates are used to flip the control qubit if it is zero-controlled.In the case where multiple controlled wires are provided, the resources are given by two
ResourceCNOT
gates and oneResourceMultiControlledX
gate. This is because of the symmetric resource decomposition of the SWAP gate. By controlling on the middle CNOT gate, we obtain the required controlled operation.
- Returns:
A list of GateCount objects, where each object represents a specific quantum gate and the number of times it appears in the decomposition.
- Return type:
list[GateCount]
- classmethod default_pow_resource_decomp(pow_z)[source]¶
Returns a list representing the resources for an operator raised to a power.
- Parameters:
pow_z (int) – the power that the operator is being raised to
- Resources:
The SWAP gate raised to even powers produces identity and raised to odd powers it produces itself.
- Returns:
A list of GateCount objects, where each object represents a specific quantum gate and the number of times it appears in the decomposition.
- Return type:
list[GateCount]
- classmethod default_resource_decomp(**kwargs)[source]¶
Returns a list representing the resources of the operator. Each object represents a quantum gate and the number of times it occurs in the decomposition.
- Resources:
The resources come from the following identity expressing SWAP as the product of three CNOT gates:
\[\begin{split}SWAP = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 1\\ 0 & 0 & 1 & 0 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1\\ 0 & 0 & 1 & 0\\ 0 & 1 & 0 & 0 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 1\\ 0 & 0 & 1 & 0 \end{bmatrix}.\end{split}\]
- static dequeue(op_to_remove, context=<class 'pennylane.queuing.QueuingManager'>)¶
Remove the given resource operator(s) from the Operator queue.
- classmethod pow_resource_decomp(pow_z, *args, **kwargs)¶
Returns a list representing the resources for an operator raised to a power.
- Parameters:
pow_z (int) – exponent that the operator is being raised to
- queue(context=<class 'pennylane.queuing.QueuingManager'>)¶
Append the operator to the Operator queue.
- classmethod resource_decomp(*args, **kwargs)¶
Returns a list of actions that define the resources of the operator.
- classmethod resource_rep()[source]¶
Returns a compressed representation containing only the parameters of the Operator that are needed to compute a resource estimation.
- resource_rep_from_op()¶
Returns a compressed representation directly from the operator
- classmethod set_resources(new_func, override_type='base')¶
Set a custom function to override the default resource decomposition.
This method allows users to replace any of the resource_decomp, adjoint_resource_decomp, ctrl_resource_decomp, or pow_resource_decomp methods globally for every instance of the class.
- classmethod tracking_name(*args, **kwargs)¶
Returns a name used to track the operator during resource estimation.
- tracking_name_from_op()¶
Returns the tracking name built with the operator’s parameters.