Skip to main contentIBM Quantum Documentation
This page is from the dev version of Qiskit SDK. Go to the stable version.

CommutationChecker

class qiskit.circuit.CommutationChecker(standard_gate_commutations=None, cache_max_entries=1000000, *, gates=None)

GitHub

Bases: object

Check commutations of two operations.

Two unitaries AA and BB on nn qubits commute if

2nFprocess(AB,BA)+12n+1>1ε,\frac{2^n F_{\text{process}}(AB, BA) + 1}{2^n + 1} > 1 - \varepsilon,

where

Fprocess(U1,U2)=Tr(U1U2)2n2,F_{\text{process}}(U_1, U_2) = \left|\frac{\mathrm{Tr}(U_1 U_2^\dagger)}{2^n} \right|^2,

and we set ε\varepsilon to 101210^{-12} to account for round-off errors on few-qubit systems. This metric is chosen for consistency with other closeness checks in Qiskit.

When possible, commutation relations are queried from a lookup table. This is the case for standard gates without parameters (such as XGate or HGate) or gates with free parameters (such as RXGate with a ParameterExpression as angle). Otherwise, a matrix-based check is performed, where two operations are said to commute, if the average gate fidelity of performing the commutation is above a certain threshold (see approximation_degree). The result of this commutation is then added to the cached lookup table.


Methods

Parameters

  • standard_gate_commutations (dict) –
  • cache_max_entries (int) –
  • gates (Optional[Set[str]]) –

check_commutation_entries

check_commutation_entries(first_op, first_qargs, second_op, second_qargs)

GitHub

Returns stored commutation relation if any

Parameters

  • first_op (Operation) – first operation.
  • first_qargs (List) – first operation’s qubits.
  • second_op (Operation) – second operation.
  • second_qargs (List) – second operation’s qubits.

Returns

True if the gates commute and false if it is not the case.

Return type

bool

clear_cached_commutations

clear_cached_commutations()

GitHub

Clears the dictionary holding cached commutations

commute

commute(op1, qargs1, cargs1, op2, qargs2, cargs2, max_num_qubits=3, approximation_degree=1.0)

GitHub

Checks if two Operations commute. The return value of True means that the operations truly commute, and the return value of False means that either the operations do not commute or that the commutation check was skipped (for example, when the operations have conditions or have too many qubits).

Parameters

  • op1 (Operation) – first operation.
  • qargs1 (List) – first operation’s qubits.
  • cargs1 (List) – first operation’s clbits.
  • op2 (Operation) – second operation.
  • qargs2 (List) – second operation’s qubits.
  • cargs2 (List) – second operation’s clbits.
  • max_num_qubits (int) – the maximum number of qubits to consider, the check may be skipped if the number of qubits for either operation exceeds this amount.
  • approximation_degree (float) – If the average gate fidelity in between the two operations is above this number (up to 1e-12) they are assumed to commute.

Returns

whether two operations commute.

Return type

bool

commute_nodes

commute_nodes(op1, op2, max_num_qubits=3, approximation_degree=1.0)

GitHub

Checks if two DAGOpNodes commute.

Parameters

  • max_num_qubits (int) –
  • approximation_degree (float) –

Return type

bool

num_cached_entries

num_cached_entries()

GitHub

Returns number of cached entries

Was this page helpful?
Report a bug or request content on GitHub.