Skip to content

Commit

Permalink
Add split_batches test
Browse files Browse the repository at this point in the history
  • Loading branch information
stavros11 committed Nov 13, 2023
1 parent 765ea21 commit 43cc7ca
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/qibolab/instruments/qblox/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
from qibolab.pulses import PulseSequence, PulseType
from qibolab.sweeper import Parameter, Sweeper, SweeperType

MAX_BATCH_SIZE = 30
"""Maximum number of sequences that can be unrolled in a single one (independent of measurements)."""


class QbloxController(Controller):
"""A controller to manage qblox devices.
Expand Down Expand Up @@ -236,7 +239,7 @@ def play(self, qubits, couplers, sequence, options):
return self._execute_pulse_sequence(qubits, sequence, options)

def split_batches(self, sequences):
return chunked(sequences, 30)
return chunked(sequences, MAX_BATCH_SIZE)

def play_sequences(self, *args, **kwargs):
raise_error(NotImplementedError, "play_sequences is not implemented in qblox driver yet.")
Expand Down
4 changes: 3 additions & 1 deletion src/qibolab/instruments/zhinst.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
SWEEPER_BIAS = {"bias"}
SWEEPER_START = {"start"}

MAX_MEASUREMENTS = 32
"""Maximum number of readout pulses in a single sequence."""


def select_pulse(pulse, pulse_type):
"""Pulse translation"""
Expand Down Expand Up @@ -1250,7 +1253,6 @@ def sweep_recursion_nt(self, qubits, couplers, options, exp, exp_calib):
self.define_exp(qubits, couplers, options, exp, exp_calib)

def split_batches(self, sequences):
MAX_MEASUREMENTS = 34
batch_measurements, batch = 0, []
for sequence in sequences:
nmeasurements = len(sequence.ro_pulses)
Expand Down
4 changes: 2 additions & 2 deletions src/qibolab/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def execute_pulse_sequence(self, sequence: PulseSequence, options: ExecutionPara
options = self.settings.apply(options)

time = (sequence.duration + options.relaxation_time) * options.nshots * 1e-9
log.info(f"Minimal execution time (sec): {time}")
log.info(f"Minimal execution time (sequence): {time}")

return self._execute("play", sequence, options, **kwargs)

Expand All @@ -221,7 +221,7 @@ def execute_pulse_sequences(self, sequences: List[PulseSequence], options: Execu

duration = sum(seq.duration for seq in sequences)
time = (duration + len(sequences) * options.relaxation_time) * options.nshots * 1e-9
log.info(f"Minimal execution time (sec): {time}")
log.info(f"Minimal execution time (unrolling): {time}")

try:
return self._execute("play_sequences", sequences, options, **kwargs)
Expand Down
18 changes: 18 additions & 0 deletions tests/test_instruments_zhinst.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,24 @@ def test_sim(dummy_qrc):
sequence.add(qf_pulses[qubit])


def test_split_batches(dummy_qrc):
platform = create_platform("zurich")
platform.setup()
instrument = platform.controller

sequence = PulseSequence()
sequence.add(platform.create_RX_pulse(0, start=0))
sequence.add(platform.create_RX_pulse(1, start=0))
measurement_start = sequence.finish
sequence.add(platform.create_MZ_pulse(0, start=measurement_start))
sequence.add(platform.create_MZ_pulse(1, start=measurement_start))

batches = list(instrument.split_batches(20 * [sequence]))
assert len(batches) == 2
assert len(batches[0]) == 16
assert len(batches[1]) == 4


@pytest.fixture(scope="module")
def instrument(connected_platform):
return get_instrument(connected_platform, Zurich)
Expand Down

0 comments on commit 43cc7ca

Please sign in to comment.