qiboteam / qibolab

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

Program API #917

Open alecandido opened 4 months ago

alecandido commented 4 months ago

The current Qibolab design requires the user to know in advance the whole pulse sequence, before requesting the execution.

However, this limits the possible experiments to be run, since, e.g., it should be possible to branch in real-time based on the acquired data (e.g. #592).

This is hard to represent as a pulse sequence, since the sequence will be the result, but not the instructions describing the execution. Moreover, other real-time operations could be possible (e.g. sampling random numbers), that have no reasonable description in terms of pulses.

Because of this, the proposal is to deprecate the sequence API (not the pulses themselves, of course) to move towards a program-oriented API, where instructions are specified (which could be pulses, but not only).

The program will have an AST representation, and possibly a textual one (to read it and manually write, while programmatic creation should use the AST types). We will then turn drivers into compiler backends, just receiving a program and compiling it into the assembly of the device (or whatever representation is exposed to us).

As side remarks:

alecandido commented 2 months ago

The PulseSequence should be kept, because, when no runtime instruction is involved, the sequence format provides more explicit information. So, it would be nice to have a partial function compile(Program) -> PulseSequence, failing when there is no valid representation as a sequence.

E.g., an align instruction is much more expressive as part of a Program (targeting many channels), and directly compiled into the akin instruction in the various drivers (when present). But it should be possible to compile it as a sequence with delays, essentially how it is done in https://github.com/qiboteam/qibolab/blob/9031fd57583f9c6b19eafd5487a1268545689e9a/src/qibolab/sequence.py#L103 (though it might also be compiled as another Program with delays, when possible, as this transformation is sometimes useful, both for simpler drivers missing a native align, that could often make use of just the PulseSequence, with no difference, and for those supporting it, but forcing it at runtime - while delay compilation will attempt making it static)