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.
- 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.
- 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).
- 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.
- 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.
- 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.
- items() Iterator[tuple[qibocal.auto.task.TaskId, qibocal.auto.task.Completed]] [source]#
Consistent iteration over individual tasks and their ids.
- 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`.
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.ParameterValue#
Valid value for a routine and runcard parameter.
- 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.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.
- class qibocal.auto.operation.AbstractData(data: dtype[+_ScalarType_co]]]] = None)[source]#
Bases:
object
Abstract data class.
- 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.
- class qibocal.auto.operation.Results[source]#
Bases:
AbstractData
Generic runcard update.
- 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.
- _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.
- class qibocal.auto.operation.DummyData[source]#
Bases:
Data
Dummy data.
- _to_npz(path: Path, filename: str)#
Helper function to use np.savez while converting keys into strings.
- property pairs#
Access qubit pairs ordered alphanumerically from data structure.
- property qubits#
Access qubits from data structure.
- register_qubit(dtype, data_keys, data_dict)#
Store output for single qubit.
- class qibocal.auto.operation.DummyRes[source]#
Bases:
Results
Dummy results.
- 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.1')[source]#
Bases:
object
Versions of the main software used.
- class qibocal.auto.output.TaskStats(acquisition: float, fit: float)[source]#
Bases:
object
Statistics about task execution.
- 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.
- stats: dict[str, qibocal.auto.output.TaskStats]#
- targets: Optional[Union[list[Union[str, int]], list[Tuple[Union[str, int], Union[str, int]]], list[tuple[Union[str, int], ...]]]] = None#
- 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.
- 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).
- 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.
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.
qibocal.auto.serialize module#
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.
qibocal.auto.task module#
Action execution tracker.
- 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.
- class qibocal.auto.task.TaskId(id: Id, iteration: int)[source]#
Bases:
object
Unique identifier for executed tasks.
- id: Id#
- 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
- 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.
- 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.
- property data#
Access task’s data.
- property results#
Access task’s results.
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.