qibocal.auto package

Autocalibration runner.

Submodules

qibocal.auto.execute module

Tasks execution.

qibocal.auto.execute.PLATFORM_DIR = 'platform'

Folder where platform will be dumped.

qibocal.auto.execute._register(name: str, obj)[source]

Register object as module.

With a small abuse of the Python module system, the object is registered as a module, with the given name. name may contain dots, cf. Executor.name for clarifications about their meaning.

Note

This is mainly used to register executors, such that the protocols can be bound to it through the import keyword, in order to construct an intuitive syntax, apparently purely functional, maintaining the context in a single Executor “global” object.

class qibocal.auto.execute.Executor(history: ~qibocal.auto.history.History, targets: list[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]] | list[~typing.Annotated[tuple[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], ~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]], ~pydantic.functional_validators.BeforeValidator(func=~qibocal.calibration.calibration.<lambda>, json_schema_input_type=PydanticUndefined), ~pydantic.functional_serializers.PlainSerializer(func=~qibocal.calibration.calibration.<lambda>, return_type=PydanticUndefined, when_used=always)]] | list[tuple[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], ...]], platform: ~qibocal.calibration.platform.CalibrationPlatform, update: bool = True, name: str | None = None, path: ~pathlib.Path | None = None, meta: ~qibocal.auto.output.Metadata | None = None)[source]

Bases: object

Execute a tasks’ graph and tracks its history.

history: History

The execution history, with results and exit states.

targets: list[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]] | list[~typing.Annotated[tuple[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], ~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]], ~pydantic.functional_validators.BeforeValidator(func=~qibocal.calibration.calibration.<lambda>, json_schema_input_type=PydanticUndefined), ~pydantic.functional_serializers.PlainSerializer(func=~qibocal.calibration.calibration.<lambda>, return_type=PydanticUndefined, when_used=always)]] | list[tuple[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], ...]]

Qubits/Qubit Pairs to be calibrated.

platform: CalibrationPlatform

Qubits’ platform.

update: bool = True

Runcard update mechanism.

name: str | None = None

Symbol for the executor.

This can be used generically to distinguish the executor, but its specific use is to register a module with this name in sys.modules. They can contain dots, ., that are interpreted as usual by the Python module system.

Note

As a special case, mainly used for internal purposes, names starting with . are also allowed, and they are interpreted relative to this package (in the top scope).

path: Path | None = None
meta: Metadata | None = None
classmethod create(name: str, platform: CalibrationPlatform | str | None = None)[source]

Load list of protocols.

run_protocol(protocol: ~qibocal.auto.operation.Routine, parameters: ~qibocal.auto.task.Action, mode: ~qibocal.auto.mode.ExecutionMode = <ExecutionMode.ACQUIRE|FIT: 3>) Completed[source]

Run single protocol in ExecutionMode mode.

_wrapped_protocol(protocol: Routine, operation: str)[source]

Create a bound protocol.

Returns a closure, already wrapping the current Executor instance, but specific to the protocol chosen. The parameters of this wrapper function maps to protocol’s ones, in particular:

  • the keyword argument mode is used as the execution mode (defaults to AUTOCALIBRATION)

  • the keyword argument id is used as the id for the given operation (defaults to protocol identifier, the same used to import and invoke it)

then the protocol specific are resolved, with the following priority:

  • explicit keyword arguments have the highest priorities

  • items in the dictionary passed with the keyword parameters

  • positional arguments, which are associated to protocols parameters in the same order in which they are defined (and documented) in their respective parameters classes

Attention

Despite the priority being clear, it is advised to use only one of the former schemes to pass parameters, to avoid confusion due to unexpected overwritten arguments.

E.g. for:

resonator_spectroscopy(1e7, 1e5, freq_width=1e8)

the freq_width will be 1e8, and 1e7 will be silently overwritten and ignored (as opposed to a regular Python function, where a TypeError would be raised).

The priority defined above is strictly and silently respected, so just pay attention during invocations.

unload()[source]

Unlist the executor from available modules.

init(path: ~os.PathLike, force: bool = False, platform: ~qibocal.calibration.platform.CalibrationPlatform | str | None = None, update: bool | None = None, targets: list[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]] | list[~typing.Annotated[tuple[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], ~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]], ~pydantic.functional_validators.BeforeValidator(func=~qibocal.calibration.calibration.<lambda>, json_schema_input_type=PydanticUndefined), ~pydantic.functional_serializers.PlainSerializer(func=~qibocal.calibration.calibration.<lambda>, return_type=PydanticUndefined, when_used=always)]] | list[tuple[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], ...]] | None = None)[source]

Initialize execution.

close(path: PathLike | None = None)[source]

Close execution.

classmethod open(name: str, path: ~os.PathLike, force: bool = False, platform: ~qibocal.calibration.platform.CalibrationPlatform | str | None = None, update: bool | None = None, targets: list[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]] | list[~typing.Annotated[tuple[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], ~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]], ~pydantic.functional_validators.BeforeValidator(func=~qibocal.calibration.calibration.<lambda>, json_schema_input_type=PydanticUndefined), ~pydantic.functional_serializers.PlainSerializer(func=~qibocal.calibration.calibration.<lambda>, return_type=PydanticUndefined, when_used=always)]] | list[tuple[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], ...]] | None = None)[source]

Enter the execution context.

qibocal.auto.history module

Track execution history.

qibocal.auto.history.HISTORY = 'history.json'

File where protocols order is dumped.

class qibocal.auto.history.History(_tasks: dict[~qibocal.auto.task.Id, list[~qibocal.auto.task.Completed]] = <factory>, _order: list[~qibocal.auto.task.TaskId] = <factory>)[source]

Bases: object

Execution history.

This is not only used for logging and debugging, but it is an actual part of the execution itself, since later routines can retrieve the output of former ones from here.

_tasks: dict[Id, list[Completed]]

List of completed tasks.

Note

Representing the object as a map of sequences makes it smoother to identify the iterations of a given task, since they are already grouped together.

_order: list[TaskId]

Record of the execution order.

property _serialized_order: list[str]

JSON friendly _order attribute.

_order, which is a list of TaskId objects, is not JSON serializable, it is converted into a list of strings which match the data folder for each protocol.

_(key: TaskId) Completed[source]
values() Iterator[Completed][source]

Iterate individual tasks according to the execution order.

items() Iterator[tuple[TaskId, Completed]][source]

Consistent iteration over individual tasks and their ids.

push(completed: Completed) TaskId[source]

Adding completed task to history.

static route(task_id: TaskId, folder: Path) Path[source]

Determine the path related to a completed task given TaskId.

folder should be usually the general output folder, used by Qibocal to store all the execution results. Cf. qibocal.auto.output.Output.

flush(output: Path | None = None)[source]

Flush all content to disk.

Specifying output is possible to select which folder should be considered as the general Qibocal output folder. Cf. qibocal.auto.output.Output.

class qibocal.auto.history.DummyHistory[source]

Bases: object

Empty History object, used by qq compare.

Used for comparing multiple reports, as their history is not saved.

flush(output=None)[source]
items()[source]

qibocal.auto.mode module

class qibocal.auto.mode.ExecutionMode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Flag

Different execution modes.

ACQUIRE = 1

Peform acquisition only.

FIT = 2

Perform fitting only.

_generate_next_value_(start, count, last_values)

Generate the next value when not given.

name: the name of the member start: the initial start value or None count: the number of existing members last_values: the last value assigned or None

_numeric_repr_()

Return the canonical string representation of the object.

For many object types, including most builtins, eval(repr(obj)) == obj.

classmethod _iter_member_by_value_(value)

Extract all members from the value in definition (i.e. increasing value) order.

classmethod _iter_member_(value)

Extract all members from the value in definition (i.e. increasing value) order.

classmethod _iter_member_by_def_(value)

Extract all members from the value in definition order.

classmethod _missing_(value)

Create a composite member containing all canonical members present in value.

If non-member values are present, result depends on _boundary_ setting.

_get_value(flag)
_boundary_ = 'strict'
_flag_mask_ = 3
_singles_mask_ = 3
_all_bits_ = 3
_inverted_ = None
qibocal.auto.mode.AUTOCALIBRATION = <ExecutionMode.ACQUIRE|FIT: 3>

Perform acquisition and fitting.

qibocal.auto.operation module

class qibocal.auto.operation.OperationId

Identifier for a calibration routine.

alias of str

qibocal.auto.operation.ParameterValue

Valid value for a routine and runcard parameter.

alias of float | int

qibocal.auto.operation.Qubits

Convenient way of passing qubit pairs in the routines.

alias of dict[Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode=’left_to_right’)])], Qubit]

qibocal.auto.operation.DATAFILE = 'data'

Name of the file where data are dumped.

qibocal.auto.operation.RESULTSFILE = 'results'

Name of the file where results are dumped.

qibocal.auto.operation.show_logs(func)[source]

Decorator to add logs.

qibocal.auto.operation.DEFAULT_PARENT_PARAMETERS = {'nshots': None, 'relaxation_time': None}

Default values of the parameters of Parameters

class qibocal.auto.operation.Parameters[source]

Bases: object

Generic action parameters.

Implement parameters as Algebraic Data Types (similar to), by subclassing this marker in actual parameters specification for each calibration routine.

The actual parameters structure is only used inside the routines themselves.

nshots: int

Number of executions on hardware.

relaxation_time: float

Wait time for the qubit to decohere back to the gnd state.

hardware_average: bool = False

By default hardware average will be performed.

class qibocal.auto.operation.AbstractData(data: dict[tuple[Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], int] | Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], ndarray[tuple[Any, ...], dtype[_ScalarT]]] = None)[source]

Bases: object

Abstract data class.

property params: dict

Convert non-arrays attributes into dict.

save(path: Path, filename: str)[source]

Dump class to file.

_to_npz(path: Path, filename: str)[source]

Helper function to use np.savez while converting keys into strings.

_to_json(path: Path, filename: str)[source]

Helper function to dump to json.

static load_data(path: Path, filename: str)[source]

Load data stored in a npz file.

static load_params(path: Path, filename: str)[source]

Load parameters stored in a json file.

class qibocal.auto.operation.Data(data: dict[tuple[Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], int] | Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], ndarray[tuple[Any, ...], dtype[_ScalarT]]] = None)[source]

Bases: AbstractData

Data resulting from acquisition routine.

property qubits

Access qubits from data structure.

property pairs

Access qubit pairs ordered alphanumerically from data structure.

register_qubit(dtype, data_keys, data_dict)[source]

Store output for single qubit.

Parameters:
  • data_keys (tuple) – Keys of Data.data.

  • data_dict (dict) – The keys are the fields of dtype and

  • arrays. (the values are the related)

save(path: Path)[source]

Store data to file.

_to_json(path: Path, filename: str)

Helper function to dump to json.

_to_npz(path: Path, filename: str)

Helper function to use np.savez while converting keys into strings.

static load_data(path: Path, filename: str)

Load data stored in a npz file.

static load_params(path: Path, filename: str)

Load parameters stored in a json file.

property params: dict

Convert non-arrays attributes into dict.

class qibocal.auto.operation.Results[source]

Bases: AbstractData

Generic runcard update.

save(path: Path)[source]

Store results to file.

_to_json(path: Path, filename: str)

Helper function to dump to json.

_to_npz(path: Path, filename: str)

Helper function to use np.savez while converting keys into strings.

static load_data(path: Path, filename: str)

Load data stored in a npz file.

static load_params(path: Path, filename: str)

Load parameters stored in a json file.

property params: dict

Convert non-arrays attributes into dict.

class qibocal.auto.operation.Routine(acquisition: Callable[[_ParametersT], _DataT], fit: Callable[[_DataT], _ResultsT] = None, report: Callable[[_DataT, _ResultsT], None] = None, update: Callable[[_ResultsT, Platform], None] = None, two_qubit_gates: bool | None = False)[source]

Bases: Generic[_ParametersT, _DataT, _ResultsT]

A wrapped calibration routine.

acquisition: Callable[[_ParametersT], _DataT]

Data acquisition function.

fit: Callable[[_DataT], _ResultsT] = None

Post-processing function.

report: Callable[[_DataT, _ResultsT], None] = None

Plotting function.

update: Callable[[_ResultsT, Platform], None] = None

Update function platform.

_is_protocol = False
two_qubit_gates: bool | None = False

Flag to determine whether to allocate list of Qubits or Pairs.

property parameters_type

Input parameters type.

property data_type

Data object type return by data acquisition.

property results_type

Results object type returned by data acquisition.

property platform_dependent

Check if acquisition involves platform.

property targets_dependent

Check if acquisition involves qubits.

class qibocal.auto.operation.DummyPars[source]

Bases: Parameters

Dummy parameters.

hardware_average: bool = False

By default hardware average will be performed.

nshots: int

Number of executions on hardware.

relaxation_time: float

Wait time for the qubit to decohere back to the gnd state.

class qibocal.auto.operation.DummyData[source]

Bases: Data

Dummy data.

_to_json(path: Path, filename: str)

Helper function to dump to json.

_to_npz(path: Path, filename: str)

Helper function to use np.savez while converting keys into strings.

static load_data(path: Path, filename: str)

Load data stored in a npz file.

static load_params(path: Path, filename: str)

Load parameters stored in a json file.

property pairs

Access qubit pairs ordered alphanumerically from data structure.

property params: dict

Convert non-arrays attributes into dict.

property qubits

Access qubits from data structure.

register_qubit(dtype, data_keys, data_dict)

Store output for single qubit.

Parameters:
  • data_keys (tuple) – Keys of Data.data.

  • data_dict (dict) – The keys are the fields of dtype and

  • arrays. (the values are the related)

save(path)[source]

Dummy method for saving data.

class qibocal.auto.operation.DummyRes[source]

Bases: Results

Dummy results.

_to_json(path: Path, filename: str)

Helper function to dump to json.

_to_npz(path: Path, filename: str)

Helper function to use np.savez while converting keys into strings.

static load_data(path: Path, filename: str)

Load data stored in a npz file.

static load_params(path: Path, filename: str)

Load parameters stored in a json file.

property params: dict

Convert non-arrays attributes into dict.

save(path: Path)

Store results to file.

qibocal.auto.operation._dummy_acquisition(pars: DummyPars, platform: Platform) DummyData[source]

Dummy data acquisition.

qibocal.auto.operation._dummy_update(results: ~qibocal.auto.operation.DummyRes, platform: ~qibolab._core.platform.platform.Platform, qubit: ~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])] | ~typing.Annotated[tuple[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], ~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]], ~pydantic.functional_validators.BeforeValidator(func=~qibocal.calibration.calibration.<lambda>, json_schema_input_type=PydanticUndefined), ~pydantic.functional_serializers.PlainSerializer(func=~qibocal.calibration.calibration.<lambda>, return_type=PydanticUndefined, when_used=always)]) None[source]

Dummy update function.

qibocal.auto.operation.dummy_operation = Routine(acquisition=<function _dummy_acquisition>, fit=<function show_logs.<locals>.wrapper>, report=None, update=<function _dummy_update>, two_qubit_gates=False)

Example of a dummy operation.

qibocal.auto.output module

class qibocal.auto.output.Versions(other: dict, qibocal: str = '0.2.2')[source]

Bases: object

Versions of the main software used.

other: dict
qibocal: str = '0.2.2'
class qibocal.auto.output.TaskStats(acquisition: float, fit: float)[source]

Bases: object

Statistics about task execution.

acquisition: float

Acquisition timing.

fit: float

Fitting timing.

property tot: float

Total execution time.

class qibocal.auto.output.Metadata(title: str, backend: str, platform: str, start_time: ~datetime.datetime | None, end_time: ~datetime.datetime | None, stats: dict[str, ~qibocal.auto.output.TaskStats], versions: ~qibocal.auto.output.Versions, author: str | None = None, tag: str | None = None, targets: list[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]] | list[~typing.Annotated[tuple[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], ~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]], ~pydantic.functional_validators.BeforeValidator(func=~qibocal.calibration.calibration.<lambda>, json_schema_input_type=PydanticUndefined), ~pydantic.functional_serializers.PlainSerializer(func=~qibocal.calibration.calibration.<lambda>, return_type=PydanticUndefined, when_used=always)]] | list[tuple[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], ...]] | None = None)[source]

Bases: object

Execution metadata.

title: str
backend: str
platform: str
start_time: datetime | None
end_time: datetime | None
stats: dict[str, TaskStats]
versions: Versions
author: str | None = None
tag: str | None = None
targets: list[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]] | list[~typing.Annotated[tuple[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], ~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]], ~pydantic.functional_validators.BeforeValidator(func=~qibocal.calibration.calibration.<lambda>, json_schema_input_type=PydanticUndefined), ~pydantic.functional_serializers.PlainSerializer(func=~qibocal.calibration.calibration.<lambda>, return_type=PydanticUndefined, when_used=always)]] | list[tuple[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], ...]] | None = None
classmethod generate(name: str, backend)[source]

Generate template metadata.

The purpose is to fill the arguments with defaults, or extract them from the few arguments.

start()[source]

Register start time.

end()[source]

Register completion time.

dump() dict[source]

Dump to serializable to dictionary.

qibocal.auto.output._new_output() Path[source]
class qibocal.auto.output.Output(history: History, meta: Metadata, platform: CalibrationPlatform | None = None)[source]

Bases: object

Output manager.

This object represents the output folder, serializing from and deserialing to it.

history: History
meta: Metadata
platform: CalibrationPlatform | None = None
static mkdir(path: Path | None = None, force: bool = False) Path[source]

Create output directory.

If a path is given and existing, it is overwritten only in the case force is enabled, otherwise an error is thrown. If not already existing, it is just used.

If no path is given, a default one is generated (according to user name and time stamp).

dump(path: Path)[source]

Dump output content to an output folder.

static update_platform(platform: CalibrationPlatform, path: Path)[source]

Dump platform used.

If the original one is not defined, use the current one as the original, else update the new one.

_export_stats()[source]

Export task statistics.

Extract statistics from the history, and record them in the metadata.

process(output: Path, mode: ExecutionMode, update: bool = True, force: bool = False)[source]

Process existing output.

qibocal.auto.runcard module

Specify runcard layout, handles (de)serialization.

qibocal.auto.runcard.RUNCARD = 'runcard.yml'

Runcard filename.

class qibocal.auto.runcard.Runcard(actions: list[~qibocal.auto.task.Action], targets: list[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]] | list[~typing.Annotated[tuple[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], ~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]], ~pydantic.functional_validators.BeforeValidator(func=~qibocal.calibration.calibration.<lambda>, json_schema_input_type=PydanticUndefined), ~pydantic.functional_serializers.PlainSerializer(func=~qibocal.calibration.calibration.<lambda>, return_type=PydanticUndefined, when_used=always)]] | list[tuple[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], ...]] | None = None, backend: str = 'qibolab', platform: str = 'mock', update: bool = True)[source]

Bases: object

Structure of an execution runcard.

actions: list[Action]

List of action to be executed.

targets: list[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]] | list[~typing.Annotated[tuple[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], ~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]], ~pydantic.functional_validators.BeforeValidator(func=~qibocal.calibration.calibration.<lambda>, json_schema_input_type=PydanticUndefined), ~pydantic.functional_serializers.PlainSerializer(func=~qibocal.calibration.calibration.<lambda>, return_type=PydanticUndefined, when_used=always)]] | list[tuple[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], ...]] | None = None

Qubits to be calibrated.

If None the protocols will be executed on all qubits available in the platform.

backend: str = 'qibolab'

Qibo backend.

platform: str = 'mock'

Qibolab platform.

update: bool = True
dump(path)[source]

Dump runcard object to yaml.

run(output: Path, platform: Platform, mode: ExecutionMode, update: bool = True) History[source]

Run runcard and dump to output.

qibocal.auto.serialize module

qibocal.auto.serialize.deserialize(raw: dict)[source]

Deserialization of nested dict.

qibocal.auto.serialize.serialize(raw: dict)[source]

JSON-friendly serialization for nested dict.

qibocal.auto.serialize._nested_list_to_tuples(raw)[source]

Convert nested lists to nested tuples.

qibocal.auto.status module

Describe the status of a completed task.

Simple and general statuses are defined here, but more of them can be defined by individual calibrations routines, and user code as well:

class PinkFirst(Status):
    '''Follow the pink arrow as the next one.'''

@dataclass
class ParametrizedException(Status):
    '''Trigger exceptional workflow, passing down a further parameter.

    Useful if the handler function is using some kind of threshold, or can
    make somehow use of the parameter to decide, but in a way that is not
    completely established, so it should not be hardcoded in the status
    type.

    '''
    myvalue: int

@dataclass
class ExceptionWithInput(Status):
    '''Pass to next routine as input.'''
    routine_x_input: float

In general, statuses can encode a predetermined decision about what to do next, so the decision has been handled by the fitting function, or an open decision, that is left up to the handler function.

class qibocal.auto.status.Status[source]

Bases: object

The exit status of a calibration routine.

class qibocal.auto.status.Normal[source]

Bases: Status

All green.

class qibocal.auto.status.Failure[source]

Bases: Status

Unrecoverable.

qibocal.auto.task module

Action execution tracker.

class qibocal.auto.task.Id

Action identifiers type.

alias of str

qibocal.auto.task.Targets

Elements to be calibrated by a single protocol.

alias of list[Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode=’left_to_right’)])]] | list[Annotated[tuple[Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode=’left_to_right’)])], Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode=’left_to_right’)])]], BeforeValidator(func=~qibocal.calibration.calibration., json_schema_input_type=PydanticUndefined), PlainSerializer(func=~qibocal.calibration.calibration., return_type=PydanticUndefined, when_used=always)]] | list[tuple[Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode=’left_to_right’)])], …]]

class qibocal.auto.task.Action(id: ~qibocal.auto.task.Id, operation: ~qibocal.auto.operation.OperationId, targets: list[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]] | list[~typing.Annotated[tuple[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], ~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]], ~pydantic.functional_validators.BeforeValidator(func=~qibocal.calibration.calibration.<lambda>, json_schema_input_type=PydanticUndefined), ~pydantic.functional_serializers.PlainSerializer(func=~qibocal.calibration.calibration.<lambda>, return_type=PydanticUndefined, when_used=always)]] | list[tuple[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], ...]] | None = None, update: bool = True, parameters: dict[str, ~typing.Any] | None = None)[source]

Bases: object

Action specification in the runcard.

id: Id

Action unique identifier.

operation: OperationId

Operation to be performed by the executor.

targets: list[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]] | list[~typing.Annotated[tuple[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], ~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]], ~pydantic.functional_validators.BeforeValidator(func=~qibocal.calibration.calibration.<lambda>, json_schema_input_type=PydanticUndefined), ~pydantic.functional_serializers.PlainSerializer(func=~qibocal.calibration.calibration.<lambda>, return_type=PydanticUndefined, when_used=always)]] | list[tuple[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], ...]] | None = None

Local qubits (optional).

update: bool = True

Runcard update mechanism.

parameters: dict[str, Any] | None = None

Input parameters, either values or provider reference.

dump(path: Path)[source]

Dump single action to yaml.

classmethod cast(source: dict | Action, operation: str | None = None)[source]

Cast an action source to an action.

class qibocal.auto.task.TaskId(id: Id, iteration: int)[source]

Bases: object

Unique identifier for executed tasks.

id: Id
iteration: int
qibocal.auto.task.DEFAULT_NSHOTS = 100

Default number on shots when the platform is not provided.

class qibocal.auto.task.Task(action: qibocal.auto.task.Action, operation: qibocal.auto.operation.Routine)[source]

Bases: object

action: Action

Action object parsed from Runcard.

operation: Routine
dump(path)[source]
property targets: list[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]] | list[~typing.Annotated[tuple[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], ~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]], ~pydantic.functional_validators.BeforeValidator(func=~qibocal.calibration.calibration.<lambda>, json_schema_input_type=PydanticUndefined), ~pydantic.functional_serializers.PlainSerializer(func=~qibocal.calibration.calibration.<lambda>, return_type=PydanticUndefined, when_used=always)]] | list[tuple[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], ...]]

Protocol targets.

property id: Id

Task Id.

property parameters

Inputs parameters for self.operation.

property update

Local update parameter.

run(platform: ~qibolab._core.platform.platform.Platform | None = None, targets: list[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]] | list[~typing.Annotated[tuple[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], ~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]], ~pydantic.functional_validators.BeforeValidator(func=~qibocal.calibration.calibration.<lambda>, json_schema_input_type=PydanticUndefined), ~pydantic.functional_serializers.PlainSerializer(func=~qibocal.calibration.calibration.<lambda>, return_type=PydanticUndefined, when_used=always)]] | list[tuple[~typing.Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])], ...]] | None = None, mode: ~qibocal.auto.mode.ExecutionMode | None = None, folder: ~pathlib.Path | None = None) Completed[source]
class qibocal.auto.task.Completed(task: Task, path: Path | None = None, _data: Data | None = None, _results: Results | None = None, data_time: float = 0, results_time: float = 0)[source]

Bases: object

A completed task.

task: Task

A snapshot of the task when it was completed.

path: Path | None = None

Folder contaning data and results files for task.

_data: Data | None = None

Protocol data.

_results: Results | None = None

Fitting output.

data_time: float = 0

Protocol data.

results_time: float = 0

Fitting output.

property data

Access task’s data.

property results

Access task’s results.

dump()[source]

Dump object to disk.

flush()[source]

Dump disk, and release from memory.

update_platform(platform: Platform)[source]

Perform update on platform’ parameters by looping over qubits or pairs.

qibocal.auto.transpile module

qibocal.auto.transpile.transpile_circuits(circuits: list[Circuit], qubit_maps: list[list[Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]]], backend: Backend, transpiler: Passes | None)[source]

Transpile and pad circuits according to the platform.

Apply the transpiler to circuits and pad them in circuits with the same number of qubits in the platform. Before manipulating the circuits, this function check that the qubit_maps contain string ids and in the positive case it remap them in integers, following the ids order provided by the platform.

Note

In this function we are implicitly assume that the qubit ids are all string or all integers.

qibocal.auto.transpile.execute_transpiled_circuits(circuits: list[Circuit], qubit_maps: list[list[Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]]], backend: Backend, transpiler: Passes | None, initial_states=None, nshots=1000)[source]

Transpile circuits.

If the qibolab backend is used, this function pads the circuits in new ones with a number of qubits equal to the one provided by the platform. At the end, the circuits are transpiled, executed and the results returned. The input transpiler is optional, but it should be provided if the backend is qibolab. For the qubit map look dummy_transpiler(). This function returns the list of transpiled circuits and the execution results.

qibocal.auto.transpile.execute_transpiled_circuit(circuit: Circuit, qubit_map: list[Annotated[int | str, FieldInfo(annotation=NoneType, required=True, metadata=[_PydanticGeneralMetadata(union_mode='left_to_right')])]], backend: Backend, transpiler: Passes | None, initial_state=None, nshots=1000)[source]

Transpile circuit.

If the qibolab backend is used, this function pads the circuit in new a one with a number of qubits equal to the one provided by the platform. At the end, the circuit is transpiled, executed and the results returned. The input transpiler is optional, but it should be provided if the backend is qibolab. For the qubit map look dummy_transpiler(). This function returns the transpiled circuit and the execution results.

qibocal.auto.transpile.natives(platform) dict[str, NativeContainer][source]

Return the dict of native gates name with the associated native container defined in the platform. This function assumes the native gates to be the same for each qubit and pair.

qibocal.auto.transpile.create_rule(name, natives)[source]

Create rule for gate name given container natives.

qibocal.auto.transpile.set_compiler(backend, natives_)[source]

Set the compiler to execute the native gates defined by the platform.

qibocal.auto.transpile.dummy_transpiler(backend: Backend) Passes[source]

If the backend is qibolab, a transpiler with just an unroller is returned, otherwise None. This function overwrites the compiler defined in the backend, taking into account the native gates defined in the`platform` (see set_compiler()).

qibocal.auto.transpile.pad_circuit(nqubits, circuit: Circuit, qubit_map: list[int]) Circuit[source]

Pad circuit in a new one with nqubits qubits, according to qubit_map. qubit_map is a list [i, j, k, …], where the i-th physical qubit is mapped into the 0th logical qubit and so on.