qibocal.auto package#

Autocalibration runner.

Submodules#

qibocal.auto.execute module#

Tasks execution.

class qibocal.auto.execute.Executor(actions: list[qibocal.auto.runcard.Action], history: History, output: Path, targets: Union[list[Union[str, int]], list[Tuple[Union[str, int], Union[str, int]]], list[tuple[Union[str, int], ...]]], platform: Platform, max_iterations: int, update: bool = True)[source]#

Bases: object

Execute a tasks’ graph and tracks its history.

actions: list[qibocal.auto.runcard.Action]#

List of actions.

history: History#

The execution history, with results and exit states.

output: Path#

Output path.

targets: Union[list[Union[str, int]], list[Tuple[Union[str, int], Union[str, int]]], list[tuple[Union[str, int], ...]]]#

Qubits/Qubit Pairs to be calibrated.

platform: Platform#

Qubits’ platform.

max_iterations: int#

Maximum number of iterations.

update: bool = True#

Runcard update mechanism.

classmethod load(card: Runcard, output: Path, platform: Optional[Platform] = None, targets: Optional[Union[list[Union[str, int]], list[Tuple[Union[str, int], Union[str, int]]], list[tuple[Union[str, int], ...]]]] = None, update: bool = True)[source]#

Load execution graph and associated executor from a runcard.

run(mode)[source]#

Actual execution.

The platform’s update method is called if: - self.update is True and task.update is None - task.update is True

qibocal.auto.history module#

Track execution history.

qibocal.auto.history.add_timings_to_meta(meta, history)[source]#
class qibocal.auto.history.History[source]#

Bases: dict[tuple[Id, int], Completed]

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.

push(completed: Completed)[source]#

Adding completed task to history.

iterations(task_id: Id)[source]#

Count task id present in history.

qibocal.auto.mode module#

class qibocal.auto.mode.ExecutionMode(value)[source]#

Bases: Enum

An enumeration.

acquire = 'acquire'#
fit = 'fit'#
autocalibration = 'autocalibration'#
report = 'report'#

qibocal.auto.operation module#

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 Union[float, int]

qibocal.auto.operation.Qubits#

Convenient way of passing qubit pairs in the routines.

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

classmethod load(input_parameters)[source]#

Load parameters from runcard.

Possibly looking into previous steps outputs. Parameters defined in Parameters class are removed from parameters before cls is created. Then nshots and relaxation_time are assigned to cls.

class qibocal.auto.operation.AbstractData(data: dtype[+_ScalarType_co]]]] = 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.

classmethod load(path: Path, filename: str)[source]#

Generic load method.

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: dtype[+_ScalarType_co]]]] = 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.

classmethod load(path: Path)[source]#

Load data and parameters.

class qibocal.auto.operation.Results[source]#

Bases: AbstractData

Generic runcard update.

classmethod load(path: Path)[source]#

Load results.

save(path: Path)[source]#

Store results to file.

class qibocal.auto.operation.Routine(acquisition: Callable[[_ParametersT], _DataT], fit: Optional[Callable[[_DataT], _ResultsT]] = None, report: Optional[Callable[[_DataT, _ResultsT], None]] = None, update: Optional[Callable[[_ResultsT, Platform], None]] = None, two_qubit_gates: Optional[bool] = 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.

two_qubit_gates: Optional[bool] = 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.

class qibocal.auto.operation.DummyData[source]#

Bases: Data

Dummy data.

save(path)[source]#

Dummy method for saving data

class qibocal.auto.operation.DummyRes[source]#

Bases: Results

Dummy results.

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.runcard module#

Specify runcard layout, handles (de)serialization.

qibocal.auto.runcard.Id#

Action identifiers type.

alias of str

qibocal.auto.runcard.Targets#

Elements to be calibrated by a single protocol.

alias of Union[list[Union[str, int]], list[Tuple[Union[str, int], Union[str, int]]], list[tuple[Union[str, int], …]]]

qibocal.auto.runcard.MAX_ITERATIONS = 5#

Default max iterations.

class qibocal.auto.runcard.Action(id: Id, operation: Optional[OperationId] = None, targets: Optional[Union[list[Union[str, int]], list[Tuple[Union[str, int], Union[str, int]]], list[tuple[Union[str, int], ...]]]] = None, update: bool = True, parameters: Optional[dict[str, Any]] = None)[source]#

Bases: object

Action specification in the runcard.

id: Id#

Action unique identifier.

operation: Optional[OperationId] = None#

Operation to be performed by the executor.

targets: Optional[Union[list[Union[str, int]], list[Tuple[Union[str, int], Union[str, int]]], list[tuple[Union[str, int], ...]]]] = None#

Local qubits (optional).

update: bool = True#

Runcard update mechanism.

parameters: Optional[dict[str, Any]] = None#

Input parameters, either values or provider reference.

class qibocal.auto.runcard.Runcard(actions: list[qibocal.auto.runcard.Action], targets: Optional[Union[list[Union[str, int]], list[Tuple[Union[str, int], Union[str, int]]], list[tuple[Union[str, int], ...]]]] = None, backend: str = 'qibolab', platform: str = 'dummy', max_iterations: int = 5)[source]#

Bases: object

Structure of an execution runcard.

actions: list[qibocal.auto.runcard.Action]#

List of action to be executed.

targets: Optional[Union[list[Union[str, int]], list[Tuple[Union[str, int], Union[str, int]]], list[tuple[Union[str, int], ...]]]] = 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 = 'dummy'#

Qibolab platform.

max_iterations: int = 5#

Maximum number of iterations.

property backend_obj: Backend#

Allocate backend.

property platform_obj: Platform#

Allocate platform.

classmethod load(params: dict)[source]#

Load a runcard (dict).

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.load(key)[source]#

Evaluate key converting string of lists to 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.

qibocal.auto.task.MAX_PRIORITY = 1000000000#

A number bigger than whatever will be manually typed. But not so insanely big not to fit in a native integer.

qibocal.auto.task.DEFAULT_NSHOTS = 100#

Default number on shots when the platform is not provided.

qibocal.auto.task.TaskId#

Unique identifier for executed tasks.

qibocal.auto.task.PLATFORM_DIR = 'platform'#

Folder where platform will be dumped.

class qibocal.auto.task.Task(action: qibocal.auto.runcard.Action, iteration: int = 0)[source]#

Bases: object

action: Action#

Action object parsed from Runcard.

iteration: int = 0#

Task iteration.

property targets: Union[list[Union[str, int]], list[Tuple[Union[str, int], Union[str, int]]], list[tuple[Union[str, int], ...]]]#

Protocol targets.

property id: Id#

Task Id.

property uid: tuple[qibocal.auto.runcard.Id, int]#

Task unique Id.

property operation#

Routine object from Operation Enum.

property parameters#

Inputs parameters for self.operation.

property update#

Local update parameter.

run(max_iterations: int, platform: ~typing.Optional[~qibolab.platform.Platform] = None, targets: ~typing.Union[list[typing.Union[str, int]], list[typing.Tuple[typing.Union[str, int], typing.Union[str, int]]], list[tuple[typing.Union[str, int], ...]]] = <class 'list'>, mode: ~typing.Optional[~qibocal.auto.mode.ExecutionMode] = None, folder: ~typing.Optional[~pathlib.Path] = None)[source]#
class qibocal.auto.task.Completed(task: Task, folder: Path, _data: Optional[Data] = None, _results: Optional[Results] = 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.

folder: Path#

Folder with data and results.

data_time: float = 0#

Protocol data.

results_time: float = 0#

Fitting output.

property datapath#

Path contaning data and results file for task.

property results#

Access task’s results.

property data#

Access task’s data.

update_platform(platform: Platform, update: bool)[source]#

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