-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #949 from qiboteam/exec-ctx-manager
Executor context manager
- Loading branch information
Showing
4 changed files
with
155 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,75 @@ | ||
from qibocal.auto.execute import Executor | ||
from qibocal.cli.report import report | ||
|
||
executor = Executor.create(name="myexec", platform="dummy") | ||
|
||
from myexec import close, drag_tuning, init, rabi_amplitude, ramsey | ||
|
||
target = 0 | ||
platform = executor.platform | ||
platform.settings.nshots = 2048 | ||
init("test_rx_calibration", force=True, targets=[target]) | ||
with Executor.open( | ||
"myexec", | ||
path="test_rx_calibration", | ||
platform="dummy", | ||
targets=[target], | ||
update=True, | ||
force=True, | ||
) as e: | ||
e.platform.settings.nshots = 2000 | ||
|
||
rabi_output = rabi_amplitude( | ||
min_amp_factor=0.5, | ||
max_amp_factor=1.5, | ||
step_amp_factor=0.01, | ||
pulse_length=platform.qubits[target].native_gates.RX.duration, | ||
) | ||
# update only if chi2 is satisfied | ||
if rabi_output.results.chi2[target][0] > 2: | ||
raise RuntimeError( | ||
f"Rabi fit has chi2 {rabi_output.results.chi2[target][0]} greater than 2. Stopping." | ||
rabi_output = e.rabi_amplitude( | ||
min_amp_factor=0.5, | ||
max_amp_factor=1.5, | ||
step_amp_factor=0.01, | ||
pulse_length=e.platform.qubits[target].native_gates.RX.duration, | ||
) | ||
rabi_output.update_platform(platform) | ||
# update only if chi2 is satisfied | ||
if rabi_output.results.chi2[target][0] > 2: | ||
raise RuntimeError( | ||
f"Rabi fit has chi2 {rabi_output.results.chi2[target][0]} greater than 2. Stopping." | ||
) | ||
|
||
ramsey_output = ramsey( | ||
delay_between_pulses_start=10, | ||
delay_between_pulses_end=5000, | ||
delay_between_pulses_step=100, | ||
detuning=1_000_000, | ||
) | ||
if ramsey_output.results.chi2[target][0] > 2: | ||
raise RuntimeError( | ||
f"Ramsey fit has chi2 {ramsey_output.results.chi2[target][0]} greater than 2. Stopping." | ||
ramsey_output = e.ramsey( | ||
delay_between_pulses_start=10, | ||
delay_between_pulses_end=5000, | ||
delay_between_pulses_step=100, | ||
detuning=1_000_000, | ||
update=False, | ||
) | ||
if ramsey_output.results.delta_phys[target][0] < 1e4: | ||
print( | ||
f"Ramsey frequency not updated, correction too small { ramsey_output.results.delta_phys[target][0]}" | ||
) | ||
else: | ||
ramsey_output.update_platform(platform) | ||
if ramsey_output.results.chi2[target][0] > 2: | ||
raise RuntimeError( | ||
f"Ramsey fit has chi2 {ramsey_output.results.chi2[target][0]} greater than 2. Stopping." | ||
) | ||
if ramsey_output.results.delta_phys[target][0] < 1e4: | ||
print( | ||
f"Ramsey frequency not updated, correction too small { ramsey_output.results.delta_phys[target][0]}" | ||
) | ||
else: | ||
ramsey_output.update_platform(e.platform) | ||
|
||
rabi_output_2 = rabi_amplitude( | ||
min_amp_factor=0.5, | ||
max_amp_factor=1.5, | ||
step_amp_factor=0.01, | ||
pulse_length=platform.qubits[target].native_gates.RX.duration, | ||
) | ||
# update only if chi2 is satisfied | ||
if rabi_output_2.results.chi2[target][0] > 2: | ||
raise RuntimeError( | ||
f"Rabi fit has chi2 {rabi_output_2.results.chi2[target][0]} greater than 2. Stopping." | ||
rabi_output_2 = e.rabi_amplitude( | ||
min_amp_factor=0.5, | ||
max_amp_factor=1.5, | ||
step_amp_factor=0.01, | ||
pulse_length=e.platform.qubits[target].native_gates.RX.duration, | ||
) | ||
rabi_output_2.update_platform(platform) | ||
# update only if chi2 is satisfied | ||
if rabi_output_2.results.chi2[target][0] > 2: | ||
raise RuntimeError( | ||
f"Rabi fit has chi2 {rabi_output_2.results.chi2[target][0]} greater than 2. Stopping." | ||
) | ||
|
||
drag_output = drag_tuning(beta_start=-4, beta_end=4, beta_step=0.5) | ||
if drag_output.results.chi2[target][0] > 2: | ||
raise RuntimeError( | ||
f"Drag fit has chi2 {drag_output.results.chi2[target][0]} greater than 2. Stopping." | ||
) | ||
drag_output.update_platform(platform) | ||
drag_output = e.drag_tuning(beta_start=-4, beta_end=4, beta_step=0.5) | ||
if drag_output.results.chi2[target][0] > 2: | ||
raise RuntimeError( | ||
f"Drag fit has chi2 {drag_output.results.chi2[target][0]} greater than 2. Stopping." | ||
) | ||
|
||
rabi_output_3 = rabi_amplitude( | ||
min_amp_factor=0.5, | ||
max_amp_factor=1.5, | ||
step_amp_factor=0.01, | ||
pulse_length=platform.qubits[target].native_gates.RX.duration, | ||
) | ||
# update only if chi2 is satisfied | ||
if rabi_output_3.results.chi2[target][0] > 2: | ||
raise RuntimeError( | ||
f"Rabi fit has chi2 {rabi_output_3.results.chi2[target][0]} greater than 2. Stopping." | ||
rabi_output_3 = e.rabi_amplitude( | ||
min_amp_factor=0.5, | ||
max_amp_factor=1.5, | ||
step_amp_factor=0.01, | ||
pulse_length=e.platform.qubits[target].native_gates.RX.duration, | ||
) | ||
rabi_output_3.update_platform(platform) | ||
# update only if chi2 is satisfied | ||
if rabi_output_3.results.chi2[target][0] > 2: | ||
raise RuntimeError( | ||
f"Rabi fit has chi2 {rabi_output_3.results.chi2[target][0]} greater than 2. Stopping." | ||
) | ||
|
||
close() | ||
report(executor.path, executor.history) | ||
report(e.path, e.history) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,30 @@ | ||
from qibocal.auto.execute import Executor | ||
from qibocal.cli.report import report | ||
"""Minimal Qibocal script example. | ||
In this example, the default Qibocal executor is used. Additional | ||
configurations can still be passed through the `init()` call, but there | ||
is no explicit API to access the execution details. | ||
If more fine grained control is needed, refer to the `rx_calibration.py` example. | ||
executor = Executor.create(name="myexec", platform="dummy") | ||
.. note:: | ||
from myexec import close, init, single_shot_classification | ||
though simple, this example is not limited to single protocol execution, but | ||
multiple protocols can be added as well, essentially in the same fashion of a plain | ||
runcard - still with the advantage of handling execution and results | ||
programmatically | ||
""" | ||
|
||
from pathlib import Path | ||
|
||
from qibocal.cli.report import report | ||
from qibocal.routines import close, init, single_shot_classification | ||
|
||
init("test_x", force=True) | ||
path = Path("test_x") | ||
init(platform="dummy", path=path, force=True) | ||
|
||
completed = single_shot_classification(nshots=1000) | ||
# Here | ||
ssc = single_shot_classification(nshots=1000) | ||
print("\nfidelities:\n", ssc.results.fidelity, "\n") | ||
|
||
close() | ||
report(executor.path, executor.history) | ||
report(path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters