qml.estimator.resource_operator.GateCount

class GateCount(gate, count=1)[source]

Bases: object

Stores a lightweight representation of a gate and its number of occurrences in a decomposition.

The decomposition of a resource operator is tracked as a sequence of gates and the corresponding number of times those gates occur in the decomposition. For a given resource operator, this decomposition can be accessed with the operator’s .resource_decomp() method. The method returns a sequence of GateCount objects where each object groups the two pieces of information, gate and counts, for the decomposition.

For example, the decomposition of the Quantum Fourier Transform (QFT) contains 3 Hadamard gates, 1 SWAP gate and 3 ControlledPhaseShift gates.

>>> import pennylane.estimator as qre
>>> lst_of_gate_counts = qre.QFT.resource_decomp(num_wires=3)
>>> lst_of_gate_counts
[(3 x Hadamard), (1 x SWAP), (3 x ControlledPhaseShift)]

Example

This example creates an object to count 5 instances of QFT acting on three wires:

>>> import pennylane.estimator as qre
>>> qft = qre.resource_rep(qre.QFT, {"num_wires": 3})
>>> counts = qre.GateCount(qft, 5)
>>> counts
(5 x QFT(3))
Parameters:
  • gate (CompressedResourceOp) – The compressed resource representation of the gate being counted.

  • counts (int | None) – The number of occurrences of the quantum gate in the circuit or decomposition. Defaults to 1.

Returns:

The container object holding both pieces of information.

Return type:

GateCount