Skip to content

Commit 02fcc2f

Browse files
committed
do batching only in the driver instead of a method shared for all drivers
there was a loop in _core.platform.platform.py that generated batches. This takes away the possiblity to do the batching/unrolling efficiently at the driver-level. In this commit we also use the maximum number of lines to optimise the unrolling
1 parent 827812d commit 02fcc2f

File tree

5 files changed

+32
-11
lines changed

5 files changed

+32
-11
lines changed

src/qibolab/_core/instruments/qblox/cluster.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from .validate import (
3939
ACQUISITION_MEMORY,
4040
ACQUISITION_NUMBER,
41+
QCM_INSTRUCTION_MEMORY,
4142
assert_channels_exclusion,
4243
validate_sequence,
4344
)
@@ -144,7 +145,6 @@ def play(
144145
sweepers: list[ParallelSweepers],
145146
) -> dict[PulseId, Result]:
146147
"""Execute the given experiment."""
147-
assert options.relaxation_time is not None
148148

149149
results = {}
150150
log = Logger(configs)
@@ -155,25 +155,38 @@ def play(
155155
batch = []
156156
batch_memory = 0
157157
batch_acquisitions = 0
158+
# an offset number of lines that is always there regardless of the nubmer of
159+
# pulses played.
160+
bach_instructions_memory = 50
158161
for ps in sequences:
159162
acquisitions = len(ps.acquisitions)
160163
per_shot_memory = get_per_shot_memory(ps, sweepers, options)
164+
# the factor 1.59 is determined heuristically, for large number of gates
165+
# and iterations the ratio of ps.data objects to Lines is approx 1.56
166+
instructions_memory = len(ps.data) * 1.59
161167

162168
if (
163-
batch_memory + per_shot_memory > ACQUISITION_MEMORY
169+
# we take the QCM memory as limit since that is likely to have
170+
# a larger number of instructions
171+
bach_instructions_memory + instructions_memory
172+
> QCM_INSTRUCTION_MEMORY
173+
or batch_memory + per_shot_memory > ACQUISITION_MEMORY
164174
or batch_acquisitions + acquisitions > ACQUISITION_NUMBER
165175
):
166176
batched_list.append(batch)
167177
batch = []
168178
batch_memory = 0
169179
batch_acquisitions = 0
180+
bach_instructions_memory = 50
170181

171182
batch_acquisitions += acquisitions
172183
batch_memory += per_shot_memory
184+
bach_instructions_memory += instructions_memory
173185
batch.append(ps)
174186
if batch:
175187
batched_list.append(batch)
176188

189+
assert options.relaxation_time is not None
177190
batched_seqs = []
178191
for batch in batched_list:
179192
batched = batch[0]

src/qibolab/_core/instruments/qblox/config/sequencer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,4 @@ def apply(self, seq: Sequencer):
143143
for name in self.model_fields_set - applied:
144144
value = getattr(self, name)
145145
if value is not None:
146-
seq.set(name, value)
146+
seq.parameters[name].set(value)

src/qibolab/_core/instruments/qblox/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def batch_shots(
3939
"""
4040
assert options.nshots is not None
4141

42-
if options.averaging_mode is not AveragingMode.SINGLESHOT:
42+
if options.averaging_mode.average:
4343
return [options.nshots]
4444

4545
per_shot_memory = get_per_shot_memory(sequence, sweepers, options)

src/qibolab/_core/instruments/qblox/validate.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from qibolab._core.identifier import ChannelId
2+
from qibolab._core.instruments.qblox.q1asm.ast_ import Line
23
from qibolab._core.instruments.qblox.sequence.acquisition import Acquisition, Weight
34
from qibolab._core.instruments.qblox.sequence.sequence import Q1Sequence
45
from qibolab._core.sequence import PulseSequence
@@ -18,6 +19,14 @@
1819
https://docs.qblox.com/en/main/cluster/q1_sequence_processor.html#waveform-memory
1920
"""
2021

22+
QCM_INSTRUCTION_MEMORY = 2**14
23+
QRM_INSTRUCTION_MEMROY = 12288
24+
"""Maximum number of instructions per program for the QCM and QRM modules.
25+
26+
https://docs.qblox.com/en/v0.16.0/cluster/q1_sequence_processor.html#instruction-memory
27+
"""
28+
29+
2130
WEIGHT_MEMORY = 2**14
2231
"""Maximum waveform memory available.
2332
@@ -74,8 +83,13 @@ def assert_acquisition_memory(acquisitions: list[Acquisition]) -> None:
7483
assert sum(a.num_bins for a in acquisitions) <= ACQUISITION_MEMORY
7584

7685

86+
def assert_instruction_memory(elements: list[Line]):
87+
assert len(elements) <= QCM_INSTRUCTION_MEMORY
88+
89+
7790
def validate_sequence(sequence: Q1Sequence) -> None:
7891
"""Validate sequence elements."""
92+
assert_instruction_memory(list(sequence.program.elements))
7993
assert_acquisition_memory(list(sequence.acquisitions.values()))
8094
assert_waveform_memory(list(sequence.waveforms.values()))
8195
assert_weight_memory(list(sequence.weights.values()))

src/qibolab/_core/platform/platform.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from ..qubits import Qubit
2525
from ..sequence import PulseSequence
2626
from ..sweeper import ParallelSweepers
27-
from ..unrolling import Bounds, batch
2827

2928
__all__ = ["Platform"]
3029

@@ -267,12 +266,7 @@ def execute(
267266
if name in self.instruments:
268267
self.instruments[name].setup(**cfg.model_dump(exclude={"kind"}))
269268

270-
results = {}
271-
# pylint: disable=unsubscriptable-object
272-
bounds = self.parameters.configs[self._controller.bounds]
273-
assert isinstance(bounds, Bounds)
274-
for b in batch(sequences, bounds):
275-
results |= self._execute(b, options, configs, sweepers)
269+
results = self._execute(sequences, options, configs, sweepers)
276270

277271
return results
278272

0 commit comments

Comments
 (0)