qibolab
qibolab copied to clipboard
Compiler interface
The current compiler is a bit verbose in pulses creation, requiring a lot of details from the platform structure.
We may restrict it to receive and return minimal information. E.g. a rule like: https://github.com/qiboteam/qibolab/blob/2020c26bf4da2f2009b709a08555fea80ea93fca/src/qibolab/compilers/default.py#L28-L35 may be turned into:
def gpi2_rule(gate: Gate) -> Native:
"""Rule for GPI2."""
qubit = gate.target_qubits[0]
theta = gate.parameters[0]
return RX90(qubit, relative_phase=theta)
(further simplification would require a wrapper around a Qibo class or modification of its interface, which for the time being is suboptimal, since already familiar to some users)
The rest of the work can be done by the compiler infrastructure, supporting all the following combinations:
Phases = dict[Qubit, float]
NativeSequence = Union[Native, list[Native]]
RuleOutput = Union[NativeSequence, tuple[NativeSequence, Phases]]
with Native
a set of representative tokens (they could even be generated on the fly, i.e. at runtime, we are just interested in the string as an identifier), that accept qubits as positional arguments, and arbitrary parameters (for native parameters' replacements) as keyword arguments.
The main motivation to improve the interface is to make it simpler to implement custom compiler, and potentially make use of arbitrary pulses (cf. #947).