Skip to content

Commit

Permalink
Merge pull request #665 from qiboteam/singleshot_unrolling
Browse files Browse the repository at this point in the history
Add singleshot unrolling
  • Loading branch information
andrea-pasquale authored Feb 1, 2024
2 parents 2a16946 + bb224e6 commit e068708
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 46 deletions.
91 changes: 45 additions & 46 deletions src/qibocal/protocols/characterization/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
class SingleShotClassificationParameters(Parameters):
"""SingleShotClassification runcard inputs."""

unrolling: bool = False
"""If ``True`` it uses sequence unrolling to deploy multiple sequences in a single instrument call.
Defaults to ``False``."""
classifiers_list: Optional[list[str]] = field(
default_factory=lambda: [DEFAULT_CLASSIFIER]
)
Expand Down Expand Up @@ -172,20 +175,22 @@ def _acquisition(
# state1_sequence: RX - MZ

# taking advantage of multiplexing, apply the same set of gates to all qubits in parallel
state0_sequence = PulseSequence()
state1_sequence = PulseSequence()

RX_pulses = {}
ro_pulses = {}
for qubit in qubits:
RX_pulses[qubit] = platform.create_RX_pulse(qubit, start=0)
ro_pulses[qubit] = platform.create_qubit_readout_pulse(
qubit, start=RX_pulses[qubit].finish
)
sequences, all_ro_pulses = [], []
for state in [0, 1]:
sequence = PulseSequence()
RX_pulses = {}
ro_pulses = {}
for qubit in qubits:
RX_pulses[qubit] = platform.create_RX_pulse(qubit, start=0)
ro_pulses[qubit] = platform.create_qubit_readout_pulse(
qubit, start=RX_pulses[qubit].finish
)
if state == 1:
sequence.add(RX_pulses[qubit])
sequence.add(ro_pulses[qubit])

state0_sequence.add(ro_pulses[qubit])
state1_sequence.add(RX_pulses[qubit])
state1_sequence.add(ro_pulses[qubit])
sequences.append(sequence)
all_ro_pulses.append(ro_pulses)

data = SingleShotClassificationData(
nshots=params.nshots,
Expand All @@ -196,41 +201,35 @@ def _acquisition(
savedir=params.savedir,
)

# execute the first pulse sequence
state0_results = platform.execute_pulse_sequence(
state0_sequence,
ExecutionParameters(
nshots=params.nshots,
relaxation_time=params.relaxation_time,
acquisition_type=AcquisitionType.INTEGRATION,
),
options = ExecutionParameters(
nshots=params.nshots,
relaxation_time=params.relaxation_time,
acquisition_type=AcquisitionType.INTEGRATION,
)

# retrieve and store the results for every qubit
for qubit in qubits:
result = state0_results[ro_pulses[qubit].serial]
data.register_qubit(
ClassificationType,
(qubit),
dict(i=result.voltage_i, q=result.voltage_q, state=[0] * params.nshots),
)
# execute the second pulse sequence
state1_results = platform.execute_pulse_sequence(
state1_sequence,
ExecutionParameters(
nshots=params.nshots,
relaxation_time=params.relaxation_time,
acquisition_type=AcquisitionType.INTEGRATION,
),
)
# retrieve and store the results for every qubit
for qubit in qubits:
result = state1_results[ro_pulses[qubit].serial]
data.register_qubit(
ClassificationType,
(qubit),
dict(i=result.voltage_i, q=result.voltage_q, state=[1] * params.nshots),
)
if params.unrolling:
results = platform.execute_pulse_sequences(sequences, options)
else:
results = [
platform.execute_pulse_sequence(sequence, options) for sequence in sequences
]

for ig, (state, ro_pulses) in enumerate(zip([0, 1], all_ro_pulses)):
for qubit in qubits:
serial = ro_pulses[qubit].serial
if params.unrolling:
result = results[serial][ig]
else:
result = results[ig][serial]
data.register_qubit(
ClassificationType,
(qubit),
dict(
i=result.voltage_i,
q=result.voltage_q,
state=[state] * params.nshots,
),
)

return data

Expand Down
8 changes: 8 additions & 0 deletions tests/runcards/protocols.yml
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,14 @@ actions:
priority: 0
operation: single_shot_classification
parameters:
unrolling: False
nshots: 10

- id: single shot classification with unrolling
priority: 0
operation: single_shot_classification
parameters:
unrolling: True
nshots: 10

- id: single shot classification with classifiers
Expand Down

0 comments on commit e068708

Please sign in to comment.