CommutationChecker
class qiskit.circuit.CommutationChecker(standard_gate_commutations=None, cache_max_entries=1000000, *, gates=None)
Bases: object
Check commutations of two operations.
Two unitaries and on qubits commute if
where
and we set to 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
check_commutation_entries
check_commutation_entries(first_op, first_qargs, second_op, second_qargs)
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
clear_cached_commutations
commute
commute(op1, qargs1, cargs1, op2, qargs2, cargs2, max_num_qubits=3, approximation_degree=1.0)
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
commute_nodes
commute_nodes(op1, op2, max_num_qubits=3, approximation_degree=1.0)
Checks if two DAGOpNodes commute.
Parameters
Return type