Skip to content

Commit

Permalink
Merge pull request #682 from qiboteam/remove_qubits_dict
Browse files Browse the repository at this point in the history
Use only `QubitId` or `QubitPairId` in protocols
  • Loading branch information
andrea-pasquale authored Feb 22, 2024
2 parents ff4e2f5 + 2a223f7 commit 9c7a34c
Show file tree
Hide file tree
Showing 75 changed files with 924 additions and 917 deletions.
4 changes: 2 additions & 2 deletions doc/source/getting-started/example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ presented in :ref:`runcard`, we can use this runcard.

.. code-block:: yaml
platform: qw5q_gold_qblox
platform: qw5q_gold
qubits: [0]
targets: [0]
actions:
- id: resonator high power high amplitude
Expand Down
6 changes: 3 additions & 3 deletions doc/source/getting-started/runcard.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Down below we present how to write a runcard to execute a single protocol using
platform: <qibolab platform name>
qubits: <list of qubit ids where all the protocols will be performed.>
targets: <list of targets where all protocols will be executed.>
actions:
Expand All @@ -33,8 +33,8 @@ Here is a description of the global parameters to be specified:
* ``platform``: QPU where the experiments will be executed. Possible choices
for TII users are available in this `repository <https://github.com/qiboteam/qibolab_platforms_qrc>`_.
For non-TII users it is possible a setup a custom platform using `Qibolab <https://qibo.science/qibolab/stable/tutorials/lab.html>`_.
* ``qubits``: list of qubit names for a specific platform. It can also be a list of qubit pairs
in the case of protocols for qubit pairs.
* ``targets``: list of ``QubitId`` for a specific platform. It can also be a list of ``QubitPairId``
in the case of protocols for qubit pairs, or a ``list[list[QubitId]]`` for protocols targeting groups of qubits.

Under ``actions`` are listed the protocols that will be executed.

Expand Down
66 changes: 33 additions & 33 deletions doc/source/tutorials/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ in the following way:
After defining the parameters, the user can perform the acquisition using
``experiment.acquisition`` which accepts the following parameters:

* 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
* platform (`qibolab.platform.Platform <https://qibo.science/qibolab/latest/api-reference/qibolab.html#qibolab.platform.Platform>`_): Qibolab platform class
* qubits (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>`_]) dictionary with qubits where the acquisition will run
* ``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
* ``platform`` (`qibolab.platform.Platform <https://qibo.science/qibolab/latest/api-reference/qibolab.html#qibolab.platform.Platform>`_): Qibolab platform class
* ``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

and returns the following:

* data (`experiment.data_type <https://qibo.science/qibocal/latest/api-reference/qibocal.auto.html#qibocal.auto.operation.Routine.data_type>`_): data acquired
* acquisition_time (float): acquisition time on hardware
* ``data`` (`experiment.data_type <https://qibo.science/qibocal/latest/api-reference/qibocal.auto.html#qibocal.auto.operation.Routine.data_type>`_): data acquired
* ``acquisition_time`` (float): acquisition time on hardware

.. code-block:: python
Expand All @@ -68,22 +68,22 @@ following way:
To be more specific the user should pass as input ``data`` which is of type
``experiment.data_type`` and the outputs are the following:

* 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
* fit_time (float): post-processing time
* ``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
* ``fit_time`` (float): post-processing time


It is also possible to access the plots and the tables generated in the
report using ``experiment.report`` which accepts the following parameters:

* 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``
* qubit (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
* 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``
* ``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``
* ``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
* ``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``

.. code-block:: python
# Plot for qubit 0
qubit = 0
figs, html_content = experiment.report(data=data, qubit=0, fit=fit)
target = 0
figs, html_content = experiment.report(data=data, target=target, fit=fit)
``experiment.report`` returns the following:

Expand Down Expand Up @@ -122,16 +122,16 @@ Currently, characterization/calibration protocols are divided in three steps: `a

The relationship between steps and data structures are summarized in the following bullets:

* `acquisition` receives as input `parameters` and outputs `data`
* `fit` receives as input `data` and outputs `results`
* `plot` receives as input `data` and `results` to visualize the protocol
* ``acquisition`` receives as input ``parameters`` and outputs ``data``
* ``fit`` receives as input ``data`` and outputs ``results``
* ``plot`` receives as input ``data`` and ``results`` to visualize the protocol

This approach is flexible enough to allow the data acquisition without performing a post-processing analysis.

Step by step tutorial
~~~~~~~~~~~~~~~~~~~~~

All protocols are located in `src/qibocal/protocols/characterization <https://github.com/qiboteam/qibocal/tree/main/src/qibocal/protocols/characterization>`_.
All protocols are located in ``src/qibocal/protocols/characterization <https://github.com/qiboteam/qibocal/tree/main/src/qibocal/protocols/characterization>``_.
Suppose that we want to code a protocol to perform a RX rotation for different
angles.
Expand Down Expand Up @@ -165,7 +165,7 @@ In this case you define a range for the angle to be probed alongside the number
of shots.

.. note::
It is advised to use `dataclasses`. If you are not familiar
It is advised to use ``dataclasses``. If you are not familiar
have a look at the official `documentation <https://docs.python.org/3/library/dataclasses.html>`_.


Expand Down Expand Up @@ -219,30 +219,30 @@ In the acquisition function we are going to perform the experiment.
.. code-block:: python
from qibolab.platform import Platform
from ...auto.operation import Qubits
from qibolab.qubits import QubitId,, QubitPairId
from typing import Union
def acquisition(params: RoutineParameters, platform: Platform, qubits: Qubits) -> RoutineData
""" A generic acquisition function."""
def acquisition(params: RoutineParameters, platform: Platform, targets: Union[list[QubitId], list[QubitPairId], list[list[QubitId]]]) -> RoutineData
"""A generic acquisition function."""
where `Qubits` is a `dict[QubitId, Qubit]`.
.. code-block:: python
from qibolab.platform import Platform
from ...auto.operation import Qubits
from qibolab.qubits import QubitId

def acquisition(
params: RotationParameters,
platform: Platform,
qubits: Qubits,
targets: list[QubitId],
) -> RotationData:
r"""
Data acquisition for rotation routine.

Args:
params (:class:`RotationParameters`): input parameters
platform (:class:`Platform`): Qibolab's platform
qubits (dict): dict of target :class:`Qubit` objects to be characterized
targets (list): list with target qubits

Returns:
data (:class:`RotationData`)
Expand Down Expand Up @@ -343,16 +343,16 @@ use `plotly <https://plotly.com/python/>`_ in order to properly generate the rep
import plotly.graph_objects as go
def plot(data: RoutineData, fit: RoutineResults, qubit: QubitId) -> list[go.Figure(), str]
def plot(data: RoutineData, fit: RoutineResults, target: QubitId) -> list[go.Figure(), str]
""" A generic plotting function."""
The `str` in output can be used to create a table, which has 3 columns `qubit`, `Fitting Parameter`
and `Value`. Here is the syntax necessary to insert a raw in the table.
The ``str`` in output can be used to create a table, which has 3 columns ``target``, ``Fitting Parameter``
and ``Value``. Here is the syntax necessary to insert a raw in the table.
.. code-block:: python
report = ""
qubit = 0
target = 0
angle = 3.14
report += f" {qubit} | rotation angle: {angle:.3f}<br>"
Expand All @@ -365,15 +365,16 @@ Here is the plotting function for the protocol that we are coding:
.. code-block:: python
import plotly.graph_objects as go
from qibolab.qubits import QubitId
def plot(data: RotationData, fit: RotationResults, qubit):
def plot(data: RotationData, fit: RotationResults, target: QubitId):
"""Plotting function for rotation."""
figures = []
fig = go.Figure()
fitting_report = ""
qubit_data = data[qubit]
qubit_data = data[target]
fig.add_trace(
go.Scatter(
Expand All @@ -392,7 +393,7 @@ Here is the plotting function for the protocol that we are coding:
x=qubit_data.theta,
y=cos_fit(
qubit_data.theta,
*fit.fitted_parameters[qubit],
*fit.fitted_parameters[target],
),
name="Fit",
line=go.scatter.Line(dash="dot"),
Expand All @@ -402,7 +403,6 @@ Here is the plotting function for the protocol that we are coding:
# last part
fig.update_layout(
showlegend=True,
uirevision="0", # ``uirevision`` allows zooming while live plotting
xaxis_title="Theta [rad]",
yaxis_title="Probability",
)
Expand Down Expand Up @@ -447,7 +447,7 @@ To launch the protocol a possible runcard could be the following one:
platform: dummy
qubits: [0,1]
targets: [0,1]
actions:
Expand Down
16 changes: 8 additions & 8 deletions runcards/actions_qq.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
platform: dummy

qubits: [0,1]
targets: [0,1]


actions:
Expand Down Expand Up @@ -422,7 +422,7 @@ actions:
# - id: standard rb bootstrap
# priority: 0
# operation: standard_rb
# qubits: [1]
# targets: [1]
# parameters:
# depths: [1, 2, 3, 5]
# niter: 5
Expand All @@ -434,7 +434,7 @@ actions:
# - id: standard rb inhomogeneous
# priority: 0
# operation: standard_rb
# qubits: [0, 1, 3]
# targets: [0, 1, 3]
# parameters:
# depths: [1, 3, 3, 5]
# niter: 5
Expand All @@ -448,7 +448,7 @@ actions:
# - id: CHSH with pulses
# priority: 0
# operation: chsh_pulses
# qubits: [[0,1],[1,2],[0,3]]
# targets: [[0,1],[1,2],[0,3]]
# parameters:
# nshots: 1000
# ntheta: 10
Expand All @@ -459,7 +459,7 @@ actions:
# - id: CHSH with natives
# priority: 0
# operation: chsh_circuits
# qubits: [[0,1],[1,2]]
# targets: [[0,1],[1,2]]
# parameters:
# nshots: 1000
# ntheta: 10
Expand All @@ -471,7 +471,7 @@ actions:
# - id: CHSH with circuits
# priority: 0
# operation: chsh_circuits
# qubits: [[0,1],[1,2]]
# targets: [[0,1],[1,2]]
# parameters:
# nshots: 1000
# ntheta: 10
Expand All @@ -481,7 +481,7 @@ actions:
# - id: readout_mitigation_matrix pulses
# priority: 0
# operation: readout_mitigation_matrix
# qubits: [[0,1,2],[1,2]]
# targets: [[0,1,2],[1,2]]
# parameters:
# nshots: 100
# pulses: True
Expand All @@ -490,7 +490,7 @@ actions:
# - id: readout_mitigation_matrix circuits
# priority: 0
# operation: readout_mitigation_matrix
# qubits: [[0,1,2],[1,2]]
# targets: [[0,1,2],[1,2]]
# parameters:
# nshots: 100
# pulses: False
14 changes: 7 additions & 7 deletions src/qibocal/auto/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

from .graph import Graph
from .history import History
from .runcard import Id, Runcard
from .task import Qubits, Task
from .runcard import Id, Runcard, Targets
from .task import Task


@dataclass
Expand All @@ -24,8 +24,8 @@ class Executor:
"""The execution history, with results and exit states."""
output: Path
"""Output path."""
qubits: Qubits
"""Qubits to be calibrated."""
targets: Targets
"""Qubits/Qubit Pairs to be calibrated."""
platform: Platform
"""Qubits' platform."""
max_iterations: int
Expand All @@ -44,7 +44,7 @@ def load(
card: Runcard,
output: Path,
platform: Platform = None,
qubits: Qubits = None,
targets: Targets = None,
update: bool = True,
):
"""Load execution graph and associated executor from a runcard."""
Expand All @@ -55,7 +55,7 @@ def load(
max_iterations=card.max_iterations,
output=output,
platform=platform,
qubits=qubits,
targets=targets,
update=update,
)

Expand Down Expand Up @@ -142,7 +142,7 @@ def run(self, mode):
completed = task.run(
max_iterations=self.max_iterations,
platform=self.platform,
qubits=self.qubits,
targets=self.targets,
folder=self.output,
mode=mode,
)
Expand Down
4 changes: 2 additions & 2 deletions src/qibocal/auto/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,9 @@ def platform_dependent(self):
return "platform" in inspect.signature(self.acquisition).parameters

@property
def qubits_dependent(self):
def targets_dependent(self):
"""Check if acquisition involves qubits."""
return "qubits" in inspect.signature(self.acquisition).parameters
return "targets" in inspect.signature(self.acquisition).parameters


@dataclass
Expand Down
12 changes: 6 additions & 6 deletions src/qibocal/auto/runcard.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
from functools import cached_property
from typing import Any, NewType, Optional, Union

from pydantic import Field
from pydantic.dataclasses import dataclass
from qibo.backends import Backend, GlobalBackend
from qibolab.platform import Platform
from qibolab.qubits import QubitId
from qibolab.qubits import QubitId, QubitPairId

from .operation import OperationId
from .validation import Validator

Id = NewType("Id", str)
"""Action identifiers type."""

Targets = Union[list[QubitId], list[QubitPairId], list[tuple[QubitId, ...]]]
"""Elements to be calibrated by a single protocol."""

MAX_ITERATIONS = 5
"""Default max iterations."""

Expand All @@ -34,9 +36,7 @@ class Action:
"""Alternative subsequent actions, branching from the current one."""
priority: Optional[int] = None
"""Priority level, determining the execution order."""
qubits: Union[list[QubitId], list[tuple[QubitId, QubitId]], list[list[QubitId]]] = (
Field(default_factory=list)
)
targets: Optional[Targets] = None
"""Local qubits (optional)."""
update: bool = True
"""Runcard update mechanism."""
Expand All @@ -56,7 +56,7 @@ class Runcard:

actions: list[Action]
"""List of action to be executed."""
qubits: Optional[Union[list[QubitId], list[tuple[QubitId, QubitId]]]] = None
targets: Optional[Targets] = None
"""Qubits to be calibrated."""
backend: str = "qibolab"
"""Qibo backend."""
Expand Down
Loading

0 comments on commit 9c7a34c

Please sign in to comment.