qrisp.CircuitPass.compare_unitary#

CircuitPass.compare_unitary(qc: QuantumCircuit, precision: int = 4, ignore_gphase: bool = False) bool[source]#

Verify that this CircuitPass leaves the unitary invariant when applied to the given QuantumCircuit.

The method copies qc, applies the pass to the copy, and then compares the original and transformed unitaries using QuantumCircuit.compare_unitary().

Measurements are not allowed because they break unitarity and would cause the underlying unitary computation to fail.

Parameters:
qcQuantumCircuit

The input quantum circuit to test the pass against.

precisionint, optional

The precision passed to QuantumCircuit.compare_unitary(). The default is 4.

ignore_gphasebool, optional

If True, ignore global phase differences. The default is False.

Returns:
bool

True if the pass preserves the unitary up to the given precision, False otherwise.

Raises:
TypeError

If qc is not a QuantumCircuit.

ValueError

If either the input or the transformed circuit contains measurement instructions.