qpe_toolbox.circuit.gate_count

Functions

count_gates(circ)

Count quantum gates appearing in a circuit or gate-instruction list.

count_swaps(qubits, controls)

Estimate the number of SWAP gates required for a gate.

distance_qubits(i, j)

Compute the distance between two qubits.

count_gates_by_qb(gate_count)

Group gate counts by the number of qubits they act on.

Module Contents

qpe_toolbox.circuit.gate_count.count_gates(circ)[source]

Count quantum gates appearing in a circuit or gate-instruction list.

Gates are grouped by label, with controlled gates prefixed by 'C' for each control qubit (e.g. 'CCX' for a doubly controlled X).

An estimate of the number of SWAP gates required to implement the circuit on a 1D nearest-neighbor architecture is also included.

Parameters:

circ (Circuit, CircuitMPS, or list) – Circuit object or list of gate instructions of the form (label, params, qubits, controls).

Returns:

Dictionary mapping gate labels to their counts. The key 'SWAP' contains the estimated number of SWAP gates required due to connectivity constraints.

Return type:

dict

Notes

  • SWAP counting assumes a linear qubit layout with nearest-neighbor connectivity.

  • For quimb circuits, gate information is extracted from circ.gates.

qpe_toolbox.circuit.gate_count.count_swaps(qubits, controls)[source]

Estimate the number of SWAP gates required for a gate.

The estimate assumes a 1D nearest-neighbor qubit layout and counts the minimal number of SWAPs required to bring all involved qubits next to a common interaction point.

Parameters:
  • qubits (int or iterable of of int or None) – Target qubit(s) of the gate.

  • controls (iterable of int or None) – Control qubits.

Returns:

Estimated number of SWAP gates required.

Return type:

int

Notes

  • This is a heuristic estimate and does not correspond to an explicit routing algorithm.

qpe_toolbox.circuit.gate_count.distance_qubits(i, j)[source]

Compute the distance between two qubits.

This function defines the qubit connectivity metric and can be customized for different hardware topologies.

Parameters:
  • i (int) – Qubit indices.

  • j (int) – Qubit indices.

Returns:

Distance between qubits i and j.

Return type:

int

qpe_toolbox.circuit.gate_count.count_gates_by_qb(gate_count)[source]

Group gate counts by the number of qubits they act on.

Gates are classified as: - '1qb': single-qubit gates - '2qb': two-qubit gates (including singly controlled gates) - '3+qb': gates acting on three or more qubits

Parameters:

gate_count (dict) – Dictionary mapping gate labels to counts as produced by qpe_toolbox.estimation.quantum_phase_estimation.qpe_energy().

Returns:

Dictionary with keys '1qb', '2qb', and '3+qb'.

Return type:

dict