Skip to content

Commit 95330b4

Browse files
Merge pull request #903 from qiboteam/fix_library_tutorial
Fix Advanced example in doc
2 parents 0625d90 + 1305045 commit 95330b4

File tree

9 files changed

+291
-314
lines changed

9 files changed

+291
-314
lines changed

doc/source/protocols/flipping.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ Requirements
5353
^^^^^^^^^^^^
5454

5555
- :ref:`rabi`
56-
- :ref:`single_shot`
56+
- :ref:`single-shot`

doc/source/protocols/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ In this section we introduce the basics of all protocols supported by ``qibocal`
1616
resonator_spectroscopy
1717
resonator_punchout
1818
qubit_spectroscopy/qubit_spectroscopy
19+
rabi/rabi
1920
ramsey/ramsey
2021
t1/t1
2122
t2/t2
2223
t2_echo/t2_echo
2324
flux/single
2425
flux/crosstalk
25-
rabi/rabi
2626
singleshot
2727
dispersive_shift
2828
allxy

doc/source/protocols/qubit_spectroscopy/qubit_spectroscopy.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,4 @@ from state :math:`\ket{1}` to state :math:`\ket{2}`) are updated.
127127
Requirements
128128
^^^^^^^^^^^^
129129

130-
- :ref:`single_shot`
130+
- :ref:`single-shot`

doc/source/protocols/t1/t1.rst

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _t1:
2+
13
T1 experiments
24
==============
35

doc/source/tutorials/advanced.rst

+47-75
Original file line numberDiff line numberDiff line change
@@ -7,107 +7,79 @@ How to use Qibocal as a library
77
Qibocal also allows executing protocols without the standard :ref:`interface <interface>`.
88

99
In the following tutorial we show how to run a single protocol using Qibocal as a library.
10-
For this particular example we will focus on the `single shot classification protocol
11-
<https://github.com/qiboteam/qibocal/blob/main/src/qibocal/protocols/characterization/classification.py>`_.
10+
For this particular example we will focus on the `t1_signal protocol
11+
<https://github.com/qiboteam/qibocal/blob/main/src/qibocal/protocols/coherence/t1_signal.py>`_ (see also :ref:`t1`).
1212

1313
.. code-block:: python
1414
15-
from qibocal.protocols.characterization import Operation
15+
import pathlib
1616
from qibolab import create_platform
1717
18+
from qibocal.auto.execute import Executor
19+
from qibocal.auto.mode import ExecutionMode
20+
from qibocal.protocols import t1_signal
21+
1822
# allocate platform
1923
platform = create_platform("....")
20-
# get qubits from platform
21-
qubits = platform.qubits
2224
23-
# we select the protocol
24-
protocol = Operation.single_shot_classification.value
25+
#creare executor
26+
executor = Executor.create(
27+
platform=platform,
28+
output=pathlib.Path("experiment_data")
29+
)
2530
26-
``protocol`` is a `Routine <https://qibo.science/qibocal/stable/api-reference/qibocal.auto.html#qibocal.auto.operation.Routine>`_ object which contains all the necessary
31+
The executor is responsible of running the routines on a platform and eventually store the history of multiple experiments.
32+
``t1_signal``, that we import, is a :class:`qibocal.auto.operation.Routine` object which contains all the necessary
2733
methods to execute the experiment.
2834

29-
In order to run a protocol the user needs to specify the parameters.
35+
In order to run an experiment the user needs to specify its parameters.
3036
The user can check which parameters need to be provided either by checking the
3137
documentation of the specific protocol or by simply inspecting ``protocol.parameters_type``.
32-
For ``single_shot_classification`` we can pass just the number of shots
33-
in the following way:
38+
For ``t1_signal`` we define the parameters in the following way:
3439

3540
.. code-block:: python
3641
37-
parameters = experiment.parameters_type.load(dict(nshots=1024))
42+
t1_params = {
43+
"id": "t1_experiment",
44+
"targets": [0], # we are defining here which qubits to analyze
45+
"operation": "t1_signal",
46+
"parameters": {
47+
"delay_before_readout_start": 0,
48+
"delay_before_readout_end": 20_000,
49+
"delay_before_readout_step": 50,
50+
},
51+
}
3852
3953
4054
After defining the parameters, the user can perform the acquisition using
41-
``experiment.acquisition`` which accepts the following parameters:
42-
43-
* ``params`` (`experiment.parameters_type <https://qibo.science/qibocal/latest/api-reference/qibocal.auto.html#qibocal.auto.operation.Routine.parameters_type>`_): input parameters for the experiment
44-
* ``platform`` (`qibolab.platform.Platform <https://qibo.science/qibolab/latest/api-reference/qibolab.html#qibolab.platform.Platform>`_): Qibolab platform class
45-
* ``targets`` (Union[list[`QubitId <https://qibo.science/qibolab/latest/api-reference/qibolab.html#qibolab.qubits.QubitId>`_],list[`QubitPairId <https://qibo.science/qibolab/latest/api-reference/qibolab.html#qibolab.qubits.QubitPairId>`_], list[list[`QubitId <https://qibo.science/qibolab/latest/api-reference/qibolab.html#qibolab.qubits.QubitId>`_]]]) list with qubits where the acquisition will run
46-
47-
and returns the following:
55+
``executor.run_protocol`` which accepts the following parameters:
4856

49-
* ``data`` (`experiment.data_type <https://qibo.science/qibocal/latest/api-reference/qibocal.auto.html#qibocal.auto.operation.Routine.data_type>`_): data acquired
50-
* ``acquisition_time`` (float): acquisition time on hardware
57+
* ``protocol`` (:class:`qibocal.auto.operation.Routine`): protocol
58+
* ``parameters`` (Dict): parameters dictionary
59+
* ``mode`` (:class:`qibocal.auto.mode.ExecutionMode`): can be ExecutionMode.ACQUIRE or ExecutionMode.FIT
5160

5261
.. code-block:: python
5362
54-
data, acquisition_time = experiment.acquisition(params=parameters, platform=platform, qubits=qubits)
63+
executor.run_protocol(t1_signal, t1_params, ExecutionMode.ACQUIRE)
64+
executor.run_protocol(t1_signal, t1_params, ExecutionMode.FIT)
5565
66+
In this way we have first executed the acquisition part of the experiment and then performed the fit on the acquired data.
5667

5768
The user can now use the raw data acquired by the quantum processor to perform
5869
an arbitrary post-processing analysis. This is one of the main advantages of this API
5970
compared to the cli execution.
6071

61-
The fitting corresponding to the experiment (``experiment.fit``) can be launched in the
62-
following way:
63-
64-
.. code-block:: python
65-
66-
fit, fit_time = experiment.fit(data)
67-
68-
To be more specific the user should pass as input ``data`` which is of type
69-
``experiment.data_type`` and the outputs are the following:
70-
71-
* ``fit``: (`experiment.results_type <https://qibo.science/qibocal/latest/api-reference/qibocal.auto.html#qibocal.auto.operation.Routine.results_type>`_) input parameters for the experiment
72-
* ``fit_time`` (float): post-processing time
73-
74-
75-
It is also possible to access the plots and the tables generated in the
76-
report using ``experiment.report`` which accepts the following parameters:
77-
78-
* ``data``: (`experiment.data_type <https://qibo.science/qibocal/latest/api-reference/qibocal.auto.html#qibocal.auto.operation.Routine.data_type>`_) data structure used by ``experiment``
79-
* ``target`` (dict[`QubitId <https://qibo.science/qibolab/latest/api-reference/qibolab.html#qibolab.qubits.QubitId>`_, `QubitPairId <https://qibo.science/qibolab/latest/api-reference/qibolab.html#qibolab.qubits.QubitPairId>`_]): qubit / qubit pair to be plotted
80-
* ``fit``: (`experiment.results_type <https://qibo.science/qibocal/latest/api-reference/qibocal.auto.html#qibocal.auto.operation.Routine.results_type>`_): data structure for post-processing used by ``experiment``
81-
82-
.. code-block:: python
83-
84-
# Plot for qubit 0
85-
target = 0
86-
figs, html_content = experiment.report(data=data, target=target, fit=fit)
87-
88-
``experiment.report`` returns the following:
89-
90-
* figs: list of plotly figures
91-
* html_content: raw html with additional information usually in the form of a table
92-
93-
In our case we get the following figure for qubit 0:
94-
95-
.. code-block:: python
96-
97-
figs[0]
98-
99-
100-
.. image:: classification_plot.png
101-
102-
and we can render the html content in the following way:
72+
The history, that contains both the raw data (added with :attr:`qibocal.auto.mode.ExecutionMode.ACQUIRE`) and the fit data (added with :attr:`qibocal.auto.mode.ExecutionMode.FIT`) can be accessed:
10373

10474
.. code-block:: python
10575
106-
import IPython
107-
IPython.display.HTML(html_content)
76+
history = executor.history
77+
t1_res = history["t1_experiment"] # id of the protocol
10878
109-
.. image:: classification_table.png
79+
data = t1_res.data # raw data
80+
results = t1_res.results # fit data
11081
82+
In particular, the history object returns a dictionary that links the id of the experiments with the :class:`qibocal.auto.task.Completed` object
11183

11284
How to add a new protocol
11385
-------------------------
@@ -131,11 +103,11 @@ This approach is flexible enough to allow the data acquisition without performin
131103
Step by step tutorial
132104
~~~~~~~~~~~~~~~~~~~~~
133105

134-
All protocols are located in ``src/qibocal/protocols/characterization <https://github.com/qiboteam/qibocal/tree/main/src/qibocal/protocols/characterization>``_.
106+
All protocols are located in :mod:`qibocal.protocols`.
135107
Suppose that we want to code a protocol to perform a RX rotation for different
136108
angles.
137109

138-
We create a file ``rotate.py`` in ``src/qibocal/protocols/characterization``.
110+
We create a file ``rotate.py`` in ``src/qibocal/protocols``.
139111

140112

141113

@@ -219,7 +191,7 @@ In the acquisition function we are going to perform the experiment.
219191
.. code-block:: python
220192
221193
from qibolab.platform import Platform
222-
from qibolab.qubits import QubitId,, QubitPairId
194+
from qibolab.qubits import QubitId, QubitPairId
223195
from typing import Union
224196
225197
def acquisition(params: RoutineParameters, platform: Platform, targets: Union[list[QubitId], list[QubitPairId], list[list[QubitId]]]) -> RoutineData
@@ -432,17 +404,18 @@ Add routine to `Operation` Enum
432404
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
433405
434406
The last step is to add the routine that we just created
435-
to the ``Operation`` `Enum` in `src/qibocal/protocols/characterization/__init__.py <https://github.com/qiboteam/qibocal/tree/main/src/qibocal/protocols/characterization/__init__.py>`_:
407+
to the available protocols in `src/qibocal/protocols/__init__.py <https://github.com/qiboteam/qibocal/tree/main/src/qibocal/protocols/__init__.py>`_:
436408
437409
.. code-block:: python
438410
439411
# other imports...
440412
from rotate import rotation
441413
442414
443-
class Operation(Enum):
444-
### other protocols...
445-
rotation = rotation
415+
__all__ = [
416+
# other protocols....
417+
"rotation",
418+
]
446419
447420
Write a runcard
448421
^^^^^^^^^^^^^^^
@@ -459,7 +432,6 @@ To launch the protocol a possible runcard could be the following one:
459432
460433
actions:
461434
- id: rotate
462-
463435
operation: rotation
464436
parameters:
465437
theta_start: 0
-170 KB
Binary file not shown.
-30.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)