qml.estimator.templates.QPE

class QPE(base, num_estimation_wires, adj_qft_op=None, wires=None)[source]

Bases: ResourceOperator

Resource class for QuantumPhaseEstimation (QPE).

Parameters:
  • base (ResourceOperator) – the phase estimation operator

  • num_estimation_wires (int) – the number of wires used for measuring out the phase

  • adj_qft_op (ResourceOperator | None) – An optional argument to set the subroutine used to perform the adjoint QFT operation.

  • wires (Sequence[int], None) – the wires the operation acts on

Resources:

The resources are obtained from the standard decomposition of QPE as presented in (Section 5.2) Nielsen, M.A. and Chuang, I.L. (2011) Quantum Computation and Quantum Information.

See also

The corresponding PennyLane operation QuantumPhaseEstimation.

Example

The resources for this operation are computed using:

>>> import pennylane.estimator as qre
>>> gate_set = {"Hadamard", "Adjoint(QFT(5))", "CRX"}
>>> qpe = qre.QPE(qre.RX(precision=1e-3), 5)
>>> print(qre.estimate(qpe, gate_set))
--- Resources: ---
 Total wires: 6
    algorithmic wires: 6
    allocated wires: 0
     zero state: 0
     any state: 0
 Total gates : 11
  'CRX': 5,
  'Adjoint(QFT(5))': 1,
  'Hadamard': 5

Additionally, we can customize the implementation of the QFT operator we wish to use within the textbook QPE algorithm. This allows users to optimize the implementation of QPE by using more efficient implementations of the QFT.

For example, consider the cost using the default QFT implementation below:

>>> import pennylane.estimator as qre
>>> qpe = qre.QPE(qre.RX(precision=1e-3), 5, adj_qft_op=None)
>>> print(qre.estimate(qpe))
--- Resources: ---
 Total wires: 6
    algorithmic wires: 6
    allocated wires: 0
         zero state: 0
         any state: 0
 Total gates : 1.586E+3
  'T': 1.530E+3,
  'CNOT': 36,
  'Hadamard': 20

Now we use the AQFT:

>>> aqft = qre.AQFT(order=3, num_wires=5)
>>> adj_aqft = qre.Adjoint(aqft)
>>> qpe = qre.QPE(qre.RX(precision=1e-3), 5, adj_qft_op=adj_aqft)
>>> print(qre.estimate(qpe))
--- Resources: ---
 Total wires: 8
    algorithmic wires: 6
     allocated wires: 2
     zero state: 2
    any state: 0
Total gates : 321
 'Toffoli': 7,
 'T': 222,
 'CNOT': 34,
 'X': 4,
 'Z': 8,
 'S': 8,
 'Hadamard': 38

resource_keys

resource_params

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

resource_keys = {'adj_qft_cmpr_op', 'base_cmpr_op', 'num_estimation_wires'}
resource_params

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

Returns:

A dictionary containing the resource parameters:
  • base_cmpr_op (CompressedResourceOp): A compressed resource operator, corresponding to the phase estimation operator.

  • num_estimation_wires (int): the number of wires used for measuring out the phase

  • adj_qft_cmpr_op (CompressedResourceOp | None]): An optional compressed resource operator, corresponding to the adjoint QFT routine. If None, the default QFT will be used.

Return type:

dict

resource_decomp(base_cmpr_op, ...[, ...])

Returns a list representing the resources of the operator.

resource_rep(base_cmpr_op, num_estimation_wires)

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

tracking_name(base_cmpr_op, num_estimation_wires)

Returns the tracking name built with the operator's parameters.

classmethod resource_decomp(base_cmpr_op, num_estimation_wires, adj_qft_cmpr_op=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:
  • base_cmpr_op (CompressedResourceOp) – A compressed resource operator, corresponding to the phase estimation operator.

  • num_estimation_wires (int) – the number of wires used for measuring out the phase

  • adj_qft_cmpr_op (CompressedResourceOp | None) – An optional compressed resource operator, corresponding to the adjoint QFT routine. If None, the default QFT will be used.

Resources:

The resources are obtained from the standard decomposition of QPE as presented in (section 5.2) Nielsen, M.A. and Chuang, I.L. (2011) Quantum Computation and Quantum Information.

classmethod resource_rep(base_cmpr_op, num_estimation_wires, adj_qft_cmpr_op=None)[source]

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

Parameters:
  • base_cmpr_op (CompressedResourceOp) – A compressed resource operator, corresponding to the phase estimation operator.

  • num_estimation_wires (int) – the number of wires used for measuring out the phase

  • adj_qft_cmpr_op (CompressedResourceOp | None) – An optional compressed resource operator, corresponding to the adjoint QFT routine. If None, the default QFT will be used.

Returns:

the operator in a compressed representation

Return type:

CompressedResourceOp

static tracking_name(base_cmpr_op, num_estimation_wires, adj_qft_cmpr_op=None)[source]

Returns the tracking name built with the operator’s parameters.

Contents

Using PennyLane

Release news

Development

API

Internals