qiboteam / qibolab

Quantum hardware module and drivers for Qibo.
https://qibo.science
Apache License 2.0
41 stars 12 forks source link

General execution interface #755

Closed alecandido closed 1 month ago

alecandido commented 7 months ago

The present situation is fragmented, both at the Platform level (frontend) and Instrument level (backend), because of the historical way the hardware optimization landed in Qibolab.

Platform

The Platform implements the support for sequence unrolling, by differentiating: https://github.com/qiboteam/qibolab/blob/47d1d550a32f455fa2cc149820fa0ce06ae96795/src/qibolab/platform.py#L193-L195 https://github.com/qiboteam/qibolab/blob/47d1d550a32f455fa2cc149820fa0ce06ae96795/src/qibolab/platform.py#L229-L231 even if they are reconvened later on in Platform._execute(). Moreover, sweepers require the usage of a separate method: https://github.com/qiboteam/qibolab/blob/47d1d550a32f455fa2cc149820fa0ce06ae96795/src/qibolab/platform.py#L269-L271 (also notice how **kwargs enter the first two, and not the latter - but they are always unused, so we could well drop them).

We could reconcile the frontend by having a single Platform.execute(), doing both sweeps and unrolling, possibly at the same time. The interface would be simply:

 def execute( 
     self, sequences: list[PulseSequence], options: ExecutionParameters, *sweepers: Sweeper 
 ): 

and the current three alternatives are obtained by passing a 1-element list for sequences, or no sweepers object, or both (I also wonder whether, for symmetry, we should have a list[Sweeper] - but that's a detail).

This will require some logic for the missing case of simultaneous sweep and unrolling. In particular, if a sequence containing sweepers is to be unrolled, we should definitely give the user the option to tell that is the same sweeper in all sequences, otherwise a nested loop will be attempted, as nested as the number of swept pulses fitting in the batch. To make it possible, #692 will be needed.

For the time being, if multiple sequences will be passed, the potential sweepers should be unrolled (generating even more lists), which is simpler to implement, and does not require any change in the user code (on the contrary, the mark for sweepers identity will have to be explicitly inserted by the user).

Controller

At the backend level, we have the Controller.play() and Controller.sweep() methods. But they are already collapsed somewhere, e.g. https://github.com/qiboteam/qibolab/blob/47d1d550a32f455fa2cc149820fa0ce06ae96795/src/qibolab/instruments/qm/driver.py#L111-L112 a suitable implementation of sweepers (with a proper recursion) for the other drivers will remove the necessity for the separation. At that point, we will just keep the Controller.play() with the strictly more general .sweep() interface.

alecandido commented 1 month ago

Completed in #861