state_preparation_error

GateCompiler.state_preparation_error(target_state, compiled, initial_state=None)

Return the error of a compiled preparation against the state it should produce.

The unitary counterpart is compilation_error(). A preparation is compared on one state instead, so the two numbers are not comparable.

Parameters:
  • target_state (Any) – State the circuit should prepare.

  • compiled (QuantumCircuit) – Circuit returned by compile_state().

  • initial_state (Any) – State the circuit is run from, in the same form compile_state() takes it. Pass the one the preparation was compiled for; None means the all-zero state.

Return type:

float

Returns:

One minus the fidelity of the produced state with the target. 0 is a perfect match; larger is worse.

Raises:

ValidationError – If a state’s norm is not 1, or compiled holds a Pauli readout, a reset or a measurement.