qml.estimator.templates.Reflection

class Reflection(num_wires=None, U=None, alpha=3.141592653589793, wires=None)[source]

Bases: ResourceOperator

Resource class for the Reflection operator. Apply a reflection about a state \(|\Psi\rangle\).

This operator works by providing an operation, \(U\), that prepares the desired state, \(\vert \Psi \rangle\), that we want to reflect about. We can also provide a reflection angle \(\alpha\) to define the operation in a more generic form:

\[R(U, \alpha) = -I + (1 - e^{i\alpha}) |\Psi\rangle \langle \Psi|\]
Parameters:
  • num_wires (int | None) – The number of wires the operator acts on. If None is provided, the number of wires are inferred from the U operator.

  • U (ResourceOperator | None) – the operator that prepares the state \(|\Psi\rangle\)

  • alpha (float | None) – the angle of the operator, should be between \([0, 2\pi]\). Default is \(\pi\).

  • wires (WiresLike | None) – The wires the operation acts on.

Resources:

The resources are derived from the decomposition \(R(U, \alpha) = U R(\alpha) U^\dagger\). The center block \(R(\alpha) = -I + (1 - e^{i\alpha})|0\rangle\langle 0|\) is implemented using a multi-controlled PhaseShift.

In the special case where \(\alpha = \pi\), the PhaseShift becomes a Z gate. If \(\alpha = 0\) or \(\alpha = 2\pi\), the center block cancels out, leaving \(-I\). The cost for \(-I\) is calculated as \(X Z X Z = -I\).

Raises:
  • ValueError – if alpha is not a float within the range [0, 2pi]

  • ValueError – if at least one of num_wires or U is not provided

  • ValueError – if the wires provided don’t match the number of wires expected by the operator

See also

Reflection

Example

The resources for this operation are computed using:

>>> import pennylane.estimator as qre
>>> U = qre.Hadamard(wires=0)
>>> ref_op = qre.Reflection(U=U, alpha=0.1)
>>> print(qre.estimate(ref_op))
--- Resources: ---
 Total wires: 1
   algorithmic wires: 1
   allocated wires: 0
     zero state: 0
     any state: 0
 Total gates : 52
   'T': 44,
   'X': 4,
   'Z': 2,
   'Hadamard': 2

resource_keys

resource_params

Returns a dictionary containing the minimal information needed to compute the resources.

resource_keys = {'alpha', 'cmpr_U', 'num_wires'}
resource_params

Returns a dictionary containing the minimal information needed to compute the resources.

Returns:

A dictionary containing the resource parameters:
  • num_wires (int | None): number of wires the operator acts on

  • alpha (float | None): the angle of the operator, default is \(\pi\)

  • cmpr_U (CompressedResourceOp | None): the operator that prepares the state \(|\Psi\rangle\)

Return type:

dict

adjoint_resource_decomp(target_resource_params)

Returns a list representing the resources for the adjoint of the operator.

controlled_resource_decomp(num_ctrl_wires, ...)

Returns a list representing the resources for a controlled version of the operator.

resource_decomp([num_wires, alpha, cmpr_U])

Returns a list representing the resources of the operator.

resource_rep([num_wires, alpha, cmpr_U])

Returns a compressed representation containing only the parameters of the Operator that are needed to compute a resource estimation.

classmethod adjoint_resource_decomp(target_resource_params)[source]

Returns a list representing the resources for the adjoint of the operator.

Parameters:

target_resource_params (dict) – A dictionary containing the resource parameters of the target operator.

Resources:

Reflection operators are always self-inverse operators. This together with the fact that this is a unitary operator implies that it is self-adjoint.

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 controlled_resource_decomp(num_ctrl_wires, num_zero_ctrl, target_resource_params)[source]

Returns a list representing the resources for a controlled version of the operator.

Parameters:
  • num_ctrl_wires (int) – the number of qubits the operation is controlled on

  • num_zero_ctrl (int) – the number of control qubits, that are controlled when in the \(|0\rangle\) state

  • target_resource_params (dict) – A dictionary containing the resource parameters of the target operator.

Resources:

The controlled decomposition simplifies by observing that \(R(U, \alpha) = U R(\alpha) U^\dagger\) is a change of basis. Thus, we only need to control the center block \(R(\alpha)\), not the \(U\) or \(U^\dagger\) operations.

Controlling \(R(\alpha)\) involves controlling the global phase \(-I\) and the multi-controlled PhaseShift. The global phase \(-I\) is controlled using \(MCX \cdot Z \cdot MCX \cdot Z\).

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 resource_decomp(num_wires=None, alpha=3.141592653589793, cmpr_U=None)[source]

Returns a list representing the resources of the operator. Each object in the list represents a gate and the number of times it occurs in the circuit.

Parameters:
  • num_wires (int) – number of wires the operator acts on

  • alpha (float) – the angle of the operator, default is \(\pi\)

  • cmpr_U (CompressedResourceOp) – the operator that prepares the state \(|\Psi\rangle\)

Resources:

The resources are derived from the decomposition \(R(U, \alpha) = U R(\alpha) U^\dagger\). The center block \(R(\alpha)\) is implemented as a multi-controlled PhaseShift sandwiched by X gates on the target wire.

If \(\alpha = \pi\), the phase shift is replaced by a Z gate. If \(\alpha = 0\) or \(\alpha = 2\pi\), the operator simplifies to \(-I\), which costs \(X Z X Z\).

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 resource_rep(num_wires=None, alpha=3.141592653589793, cmpr_U=None)[source]

Returns a compressed representation containing only the parameters of the Operator that are needed to compute a resource estimation.

Parameters:
  • num_wires (int) – number of wires the operator acts on

  • alpha (float) – the angle of the operator, default is \(\pi\)

  • cmpr_U (CompressedResourceOp) – the operator that prepares the state \(|\Psi\rangle\)

Returns:

the operator in a compressed representation

Return type:

CompressedResourceOp

Contents

Using PennyLane

Release news

Development

API

Internals