diff --git a/src/qibolab/instruments/zhinst/executor.py b/src/qibolab/instruments/zhinst/executor.py index 05ea9ecccd..15fc1f7301 100644 --- a/src/qibolab/instruments/zhinst/executor.py +++ b/src/qibolab/instruments/zhinst/executor.py @@ -13,7 +13,7 @@ from qibolab.couplers import Coupler from qibolab.instruments.abstract import Controller from qibolab.instruments.port import Port -from qibolab.pulses import FluxPulse, PulseSequence, PulseType +from qibolab.pulses import DrivePulse, FluxPulse, PulseSequence, PulseType from qibolab.qubits import Qubit from qibolab.sweeper import Parameter, Sweeper from qibolab.unrolling import Bounds @@ -701,11 +701,10 @@ def play_sweep(exp, channel_name, pulse): def rearrange_rt_sweepers( sweepers: list[Sweeper], ) -> tuple[Optional[tuple[int, int]], list[Sweeper]]: - """Rearranges list of real-time sweepers based on hardware limitations. + """Rearranges list of real-time sweepers based on heuristic + discoveries. - The only known limitation currently is that frequency sweepers must be applied before (on the outer loop) other - (e.g. amplitude) sweepers. Consequently, the only thing done here is to swap the frequency sweeper with the - first sweeper in the list. + The only thing this function currently does is either swap two sweeper or do nothing. Args: sweepers: Sweepers to rearrange. @@ -718,12 +717,17 @@ def rearrange_rt_sweepers( iter(s for s in sweepers if s.parameter is Parameter.frequency), None ) if freq_sweeper: + # If readout frequency sweep, swap it with the outermost loop + # If drive, swap it with the innermost sweep + swap_idx = 0 + if any(isinstance(pulse.type, DrivePulse) for pulse in freq_sweeper.pulses): + swap_idx = len(sweepers) - 1 sweepers_copy = sweepers.copy() freq_sweeper_idx = sweepers_copy.index(freq_sweeper) - sweepers_copy[freq_sweeper_idx] = sweepers_copy[0] - sweepers_copy[0] = freq_sweeper + sweepers_copy[freq_sweeper_idx] = sweepers_copy[swap_idx] + sweepers_copy[swap_idx] = freq_sweeper log.warning("Sweepers were reordered") - return (0, freq_sweeper_idx), sweepers_copy + return (swap_idx, freq_sweeper_idx), sweepers_copy return None, sweepers def sweep(self, qubits, couplers, sequence: PulseSequence, options, *sweepers):