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

This code is essentially copy-pasted from commutative_analysis.py. This code cleverly hashes commutativity and non-commutativity results between DAG nodes and seems quite efficient for large Clifford circuits. They may be other possible efficiency improvements: using rule-based commutativity analysis, evicting from the cache less useful entries, etc.


Methods

Parameters

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

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)

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.

Returns

whether two operations commute.

Return type

bool

commute_nodes

commute_nodes(op1, op2, max_num_qubits=3)

GitHub

Checks if two DAGOpNodes commute.

Parameters

max_num_qubits (int) –

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.