fiqci.ems.transpiler_passes.basis_measurement#

Functions

get_measurement_settings(op)

Return the measurement settings for a SparsePauliOp.

get_obs_subcircuits(subcircuits, observable)

Generate modified subcircuits for each measurement group derived from the observable.

Classes

ModifyMeasurementBasis(*args, **kwargs)

A transpiler pass that modifies the measurement basis of a circuit according to specified settings.

class ModifyMeasurementBasis(*args, **kwargs)#

Bases: TransformationPass

A transpiler pass that modifies the measurement basis of a circuit according to specified settings. It adds the necessary gates to change the measurement basis to X or Y as needed, and appends measurements in the Z basis. This allows for flexible measurement settings to be applied to circuits before execution, enabling the calculation of expectation values for different observables without needing to manually modify the circuits.

Parameters:
  • measurement_settings – A list of dictionaries, where each dictionary maps qubit indices to measurement bases (“X”, “Y”, or “Z”). Each dictionary represents a different measurement setting to apply to the circuit.

  • ops – An optional dictionary mapping measurement basis labels (e.g., “X-meas”, “Y-meas”) to custom Instruction objects that implement the necessary basis change. If provided, these custom instructions will be used instead of the default H and Sdg+H gates for X and Y basis changes, respectively.

__init__(measurement_settings: list[dict[int, str]], ops: dict[str, Instruction] | None = None)#
run(dag: DAGCircuit) DAGCircuit#

Run a pass on the DAGCircuit. This is implemented by the pass developer.

Parameters:

dag – the dag on which the pass is run.

Raises:

NotImplementedError – when this is left unimplemented for a pass.

get_obs_subcircuits(subcircuits: list[QuantumCircuit], observable: SparsePauliOp, ops: dict[str, Instruction] | None = None) list[dict[int, QuantumCircuit]]#

Generate modified subcircuits for each measurement group derived from the observable.

Measurement groups are determined automatically via get_measurement_settings. Each group produces one circuit per input subcircuit with the appropriate basis-rotation gates and measurements appended.

Parameters:
  • subcircuits – A list of QuantumCircuit objects.

  • observable – The SparsePauliOp observable to measure.

  • ops – An optional dictionary mapping measurement basis labels to custom Instruction objects.

Returns:

A list of dictionaries mapping circuit indices to their corresponding modified subcircuits, one dict per measurement group.

get_measurement_settings(op: SparsePauliOp) list[dict[int, str]]#

Return the measurement settings for a SparsePauliOp.

Groups Pauli operators by qubit-wise commutativity. Each returned dict maps qubit index to Pauli basis (“X”, “Y”, or “Z”) and represents one circuit run. Paulis in the same group have no conflicting basis requirements on any qubit and can be measured together.

Parameters:

op – The SparsePauliOp to analyze.

Returns:

A list of dicts mapping qubit index to measurement basis, one per measurement group.