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: History, targets: Union[list[Union[str, int]], list[Tuple[Union[str, int], Union[str, int]]], list[tuple[Union[str, int], ...]]], platform: Platform, update: bool = True, name: Optional[str] = None, path: Optional[Path] = None, meta: Optional[Metadata] = None)[source]#

Bases: object

Execute a tasks’ graph and tracks its history.

history: History#

The execution history, with results and exit states.

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.

update: bool = True#

Runcard update mechanism.

name: Optional[str] = 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: Optional[Path] = None#
meta: Optional[Metadata] = None#
classmethod create(name: str, platform: Optional[Union[Platform, str]] = None)[source]#

Load list of protocols.

run_protocol(protocol: ~qibocal.auto.operation.Routine, parameters: ~qibocal.auto.task.Action, mode: ~qibocal.auto.mode.ExecutionMode = ExecutionMode.None) 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: PathLike, force: bool = False, platform: Optional[Union[Platform, str]] = None, update: Optional[bool] = None, targets: Optional[Union[list[Union[str, int]], list[Tuple[Union[str, int], Union[str, int]]], list[tuple[Union[str, int], ...]]]] = None)[source]#

Initialize execution.

close(path: Optional[PathLike] = None)[source]#

Close execution.

classmethod open(name: str, path: PathLike, force: bool = False, platform: Optional[Union[Platform, str]] = None, update: Optional[bool] = None, targets: Optional[Union[list[Union[str, int]], list[Tuple[Union[str, int], Union[str, int]]], list[tuple[Union[str, int], ...]]]] = None)[source]#

Enter the execution context.

qibocal.auto.history module#

Track execution history.

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[qibocal.auto.task.Id, list[qibocal.auto.task.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[qibocal.auto.task.TaskId]#

Record of the execution order.

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

Iterate individual tasks according to the execution order.

items() Iterator[tuple[qibocal.auto.task.TaskId, qibocal.auto.task.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. :cls:`qibocal.auto.output.Output`.

flush(output: Optional[Path] = 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. :cls:`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)[source]#

Bases: Flag

Different execution modes.

ACQUIRE = 1#

Peform acquisition only.

FIT = 2#

Perform fitting only.

qibocal.auto.mode.AUTOCALIBRATION = ExecutionMode.None#

Perform acquisition and fitting.

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.

hardware_average: bool = False#

By default hardware average will be performed.

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.

_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: 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.

_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: 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.

_is_protocol = False#
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.

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: DummyRes, platform: Platform, qubit: Union[str, int, Tuple[Union[str, int], Union[str, int]]]) 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.1.0')[source]#

Bases: object

Versions of the main software used.

other: dict#
qibocal: str = '0.1.0'#
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: Optional[datetime], end_time: Optional[datetime], stats: dict[str, qibocal.auto.output.TaskStats], versions: Versions, author: Optional[str] = None, tag: Optional[str] = None, targets: Optional[Union[list[Union[str, int]], list[Tuple[Union[str, int], Union[str, int]]], list[tuple[Union[str, int], ...]]]] = None)[source]#

Bases: object

Execution metadata.

title: str#
backend: str#
platform: str#
start_time: Optional[datetime]#
end_time: Optional[datetime]#
stats: dict[str, qibocal.auto.output.TaskStats]#
versions: Versions#
author: Optional[str] = None#
tag: Optional[str] = None#
targets: Optional[Union[list[Union[str, int]], list[Tuple[Union[str, int], Union[str, int]]], list[tuple[Union[str, int], ...]]]] = 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: Optional[Platform] = None)[source]#

Bases: object

Output manager.

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

history: History#
meta: Metadata#
platform: Optional[Platform] = None#
static mkdir(path: Optional[Path] = 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: Platform, 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: 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', update: bool = True)[source]#

Bases: object

Structure of an execution runcard.

actions: list[qibocal.auto.task.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.

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.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.Id#

Action identifiers type.

alias of str

qibocal.auto.task.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], …]]]

class qibocal.auto.task.Action(id: Id, operation: OperationId, 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: OperationId#

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.

dump(path: Path)[source]#

Dump single action to yaml.

classmethod cast(source: Union[dict, Action], operation: Optional[str] = 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: 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 parameters#

Inputs parameters for self.operation.

property update#

Local update parameter.

run(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, mode: Optional[ExecutionMode] = None, folder: Optional[Path] = None) Completed[source]#
class qibocal.auto.task.Completed(task: Task, path: Optional[Path] = None, _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.

path: Optional[Path] = None#

Folder contaning data and results files for task.

_data: Optional[Data] = None#

Protocol data.

_results: Optional[Results] = 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[qibo.models.circuit.Circuit], qubit_maps: list[list[Union[str, int]]], backend: Backend, transpiler: Optional[Passes])[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[qibo.models.circuit.Circuit], qubit_maps: list[list[Union[str, int]]], backend: Backend, transpiler: Optional[Passes], 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[Union[str, int]], backend: Backend, transpiler: Optional[Passes], 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.dummy_transpiler(backend) Optional[Passes][source]#

If the backend is qibolab, a transpiler with just an unroller is returned, otherwise None.

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.