compilation_error

GateCompiler.compilation_error(circuit, compiled)

Return a compiled gate-level circuit’s error against its source circuit.

Note

This builds the dense \(2^n \times 2^n\) unitary of both circuits (via qiskit.quantum_info.Operator), so its cost grows exponentially in the qubit count. It is practical up to about 10 qubits.

The two circuits may be passed in either order: both are turned into unitaries via from_circuit() (which applies a circuit’s .layout if it has one and is otherwise equivalent to Operator), and average gate fidelity is symmetric, so compilation_error(circuit, compiled) and compilation_error(compiled, circuit) return the same value.

Parameters:
  • circuit (QuantumCircuit) – One of the circuits to compare (typically the original circuit before gate-level compilation).

  • compiled (QuantumCircuit) – The other circuit (typically the compiled circuit returned by compile()). Its .layout (a Qiskit TranspileLayout) is consumed by from_circuit(), so any input/output qubit relabeling is undone transparently – a non-trivial layout is handled the same way as a transpiled circuit’s.

Return type:

float

Returns:

Compilation error between the two circuits (1 minus their average gate fidelity), with either circuit’s layout accounted for. 0 is a perfect match; larger is worse.

Raises:

ValidationError – If a circuit holds a Pauli readout, a reset or a measurement.