qibocal.auto package#

Autocalibration runner.

Submodules#

qibocal.auto.execute module#

Tasks execution.

class qibocal.auto.execute.Executor(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, update: bool = True)[source]#

Bases: object

Execute a tasks’ graph and tracks its history.

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.

update: bool = True#

Runcard update mechanism.

classmethod create(platform: Optional[Union[Platform, str]] = None, output: Optional[Union[str, bytes, PathLike]] = None)[source]#

Load list of protocols.

run_protocol(protocol: ~qibocal.auto.operation.Routine, parameters: ~typing.Union[dict, ~qibocal.auto.runcard.Action], mode: ~qibocal.auto.mode.ExecutionMode = ExecutionMode.None) Completed[source]#

Run single protocol in ExecutionMode mode.

qibocal.auto.execute.run(runcard: Runcard, output: Path, mode: ExecutionMode)[source]#

Run runcard and dump to output.

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[Id, 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.

clear() None.  Remove all items from D.#
copy() a shallow copy of D#
fromkeys(value=None, /)#

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None, /)#

Return the value for key if key is in the dictionary, else default.

items() a set-like object providing a view on D's items#
keys() a set-like object providing a view on D's keys#
pop(k[, d]) v, remove specified key and return the corresponding value.#

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem()#

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

setdefault(key, default=None, /)#

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from dict/iterable E and F.#

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() an object providing a view on D's values#

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.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.RUNCARD = 'runcard.yml'#

Runcard filename.

class qibocal.auto.runcard.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

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', update: bool = True)[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.

update: bool = True#
property backend_obj: Backend#

Allocate backend.

property platform_obj: Platform#

Allocate platform.

dump(path)[source]#

Dump runcard object to yaml.

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.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, 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: ~typing.Optional[~qibolab.platform.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: Optional[Data] = None#

Protocol data.

_results: Optional[Results] = None#

Fitting output.

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.

dump(path)[source]#

test

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

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

qibocal.auto.transpile module#

qibocal.auto.transpile.execute_transpiled_circuits(circuits: list[qibo.models.circuit.Circuit], qubit_maps: list[list[int]], backend: Backend, initial_states=None, nshots=1000, transpiler: Optional[Passes] = None)[source]#

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[int], backend: Backend, initial_state=None, nshots=1000, transpiler: Optional[Passes] = None)[source]#

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.