AddSpectatorMeasures

class AddSpectatorMeasures(*args, **kwargs)[source]

Bases: TransformationPass

Add measurements on spectator qubits.

An active qubit is a qubit acted on in the circuit by a non-barrier instruction. A terminated qubit is one whose last action is a measurement. A spectator qubit is a qubit that is inactive, but adjacent to an active qubit under the coupling map. This pass adds a measurement to all spectator qubits and, optionally via include_unmeasured, to all active qubits that are not terminated qubits.

The added measurements write to a new register that has one bit per spectator qubit and name spectator_creg_name.

Note

When this pass encounters a control flow operation, it iterates through all of its blocks. It marks as “active” every qubit that is active within at least one of the blocks, and as “terminated” every qubit that is terminated in every one of the blocks.

Initialize the pass.

Parameters:
  • coupling_map – A coupling map or a list of tuples indicating pairs of neighboring qubits.

  • include_unmeasured – Whether the qubits that are active but are not terminated by a measurement should also be treated as spectators. If True, a terminal measurement is added on each of them.

  • spectator_creg_name – The name of the classical register added for the measurements on the spectator qubits.

  • add_barrier – Whether to add a barrier acting on all active and spectator qubits prior to the spectator measurements.

Attributes

is_analysis_pass

Check if the pass is an analysis pass.

If the pass is an AnalysisPass, that means that the pass can analyze the DAG and write the results of that analysis in the property set. Modifications on the DAG are not allowed by this kind of pass.

is_transformation_pass

Check if the pass is a transformation pass.

If the pass is a TransformationPass, that means that the pass can manipulate the DAG, but cannot modify the property set (but it can be read).

Methods

execute(passmanager_ir, state, callback=None)

Execute optimization task for input Qiskit IR.

Parameters:
  • passmanager_ir (Any) – Qiskit IR to optimize.

  • state (PassManagerState) – State associated with workflow execution by the pass manager itself.

  • callback (Callable | None) – A callback function which is caller per execution of optimization task.

Returns:

Optimized Qiskit IR and state of the workflow.

Return type:

tuple[Any, PassManagerState]

name()

Name of the pass.

Return type:

str

run(dag)[source]

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

Parameters:

dag (DAGCircuit) – the dag on which the pass is run.

Raises:

NotImplementedError – when this is left unimplemented for a pass.

update_status(state, run_state)

Update workflow status.

Parameters:
  • state (PassManagerState) – Pass manager state to update.

  • run_state (RunState) – Completion status of current task.

Returns:

Updated pass manager state.

Return type:

PassManagerState