Breakpoint
from mpqp import Breakpoint
In some cases, you might need to debug the circuit you just created. We simplify this by adding a breakpoint. As in other languages, a breakpoint is a special instruction that stops the execution of the program and allows you to dig into the state of the program. In order to enable this, a run with breakpoints is in fact once per breakpoint, and for each run the circuit is truncated up to the breakpoint.
- class Breakpoint(draw_circuit=False, enabled=True, label=None)[source]
Bases:
Instruction
A breakpoint is a special instruction that will display the state of the circuit at the desired state.
- Parameters
draw_circuit (bool) – If
True
in addition of displaying the current state vector, it will draw the circuit at this step.enabled (bool) – A breakpoint can be kept in the circuit but temporarily disabled using this argument.
label (str | None) – A breakpoint can be given a label for easier traceability.
Example
>>> r = run( ... QCircuit([H(0), Breakpoint(), CNOT(0,1), Breakpoint(draw_circuit=True, label="final")]), ... IBMDevice.AER_SIMULATOR, ... ) DEBUG: After instruction 1, state is 0.707|00⟩ + 0.707|10⟩ DEBUG: After instruction 2, at breakpoint `final`, state is 0.707|00⟩ + 0.707|11⟩ and circuit is ┌───┐ q_0: ┤ H ├──■── └───┘┌─┴─┐ q_1: ─────┤ X ├ └───┘
- to_other_language(language=Language.QISKIT, qiskit_parameters=None)[source]
Transforms this instruction into the corresponding object in the language specified in the
language
arg.By default, the instruction is translated to the corresponding one in Qiskit, since it is the interface we use to generate the OpenQASM code.
In the future, we will generate the OpenQASM code on our own, and this method will be used only for complex objects that are not tractable by OpenQASM (like hybrid structures).
- Parameters
language (Language) – Enum representing the target language.
qiskit_parameters (Optional[set['Parameter']]) – We need to keep track of the parameters passed to qiskit in order not to define twice the same parameter. Defaults to
set()
.
- Returns
The corresponding instruction (gate or measure) in the target language.
- Return type
str