Skip to content

Commit

Permalink
Merge pull request #720 from qiboteam/flipping_unrolling
Browse files Browse the repository at this point in the history
Add support for sequence unrolling in flipping and flipping_signal
  • Loading branch information
andrea-pasquale authored Feb 21, 2024
2 parents b11efdd + b4a1dc4 commit ff4e2f5
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 28 deletions.
53 changes: 38 additions & 15 deletions src/qibocal/protocols/characterization/flipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class FlippingParameters(Parameters):
"""Maximum number of flips ([RX(pi) - RX(pi)] sequences). """
nflips_step: int
"""Flip step."""
unrolling: bool = False
"""If ``True`` it uses sequence unrolling to deploy multiple sequences in a single instrument call.
Defaults to ``False``."""


@dataclass
Expand Down Expand Up @@ -85,8 +88,18 @@ def _acquisition(
qubit: qubits[qubit].native_gates.RX.amplitude for qubit in qubits
},
)

options = ExecutionParameters(
nshots=params.nshots,
relaxation_time=params.relaxation_time,
acquisition_type=AcquisitionType.DISCRIMINATION,
averaging_mode=AveragingMode.SINGLESHOT,
)

# sweep the parameter
for flips in range(0, params.nflips_max, params.nflips_step):
sequences, all_ro_pulses = [], []
flips_sweep = range(0, params.nflips_max, params.nflips_step)
for flips in flips_sweep:
# create a sequence of pulses for the experiment
sequence = PulseSequence()
ro_pulses = {}
Expand All @@ -106,25 +119,35 @@ def _acquisition(
# add ro pulse at the end of the sequence
ro_pulses[qubit] = platform.create_qubit_readout_pulse(qubit, start=start1)
sequence.add(ro_pulses[qubit])
# execute the pulse sequence
results = platform.execute_pulse_sequence(
sequence,
ExecutionParameters(
nshots=params.nshots,
relaxation_time=params.relaxation_time,
acquisition_type=AcquisitionType.DISCRIMINATION,
averaging_mode=AveragingMode.SINGLESHOT,
),
)

sequences.append(sequence)
all_ro_pulses.append(ro_pulses)

# execute the pulse sequence
if params.unrolling:
results = platform.execute_pulse_sequences(sequences, options)

elif not params.unrolling:
results = [
platform.execute_pulse_sequence(sequence, options) for sequence in sequences
]

for ig, (flips, ro_pulses) in enumerate(zip(flips_sweep, all_ro_pulses)):
for qubit in qubits:
prob = results[qubit].probability(state=1)
serial = ro_pulses[qubit].serial
if params.unrolling:
result = results[serial][0]
else:
result = results[ig][serial]
prob = result.probability(state=1)
error = np.sqrt(prob * (1 - prob) / params.nshots)
data.register_qubit(
FlippingType,
(qubit),
dict(
flips=[flips],
prob=prob.tolist(),
error=np.sqrt(prob * (1 - prob) / params.nshots).tolist(),
flips=np.array([flips]),
prob=np.array([prob]),
error=np.array([error]),
),
)

Expand Down
42 changes: 30 additions & 12 deletions src/qibocal/protocols/characterization/flipping_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,18 @@ def _acquisition(
qubit: qubits[qubit].native_gates.RX.amplitude for qubit in qubits
},
)

options = ExecutionParameters(
nshots=params.nshots,
relaxation_time=params.relaxation_time,
acquisition_type=AcquisitionType.INTEGRATION,
averaging_mode=AveragingMode.CYCLIC,
)

# sweep the parameter
for flips in range(0, params.nflips_max, params.nflips_step):
sequences, all_ro_pulses = [], []
flips_sweep = range(0, params.nflips_max, params.nflips_step)
for flips in flips_sweep:
# create a sequence of pulses for the experiment
sequence = PulseSequence()
ro_pulses = {}
Expand All @@ -90,18 +100,26 @@ def _acquisition(
# add ro pulse at the end of the sequence
ro_pulses[qubit] = platform.create_qubit_readout_pulse(qubit, start=start1)
sequence.add(ro_pulses[qubit])
# execute the pulse sequence
results = platform.execute_pulse_sequence(
sequence,
ExecutionParameters(
nshots=params.nshots,
relaxation_time=params.relaxation_time,
acquisition_type=AcquisitionType.INTEGRATION,
averaging_mode=AveragingMode.CYCLIC,
),
)

sequences.append(sequence)
all_ro_pulses.append(ro_pulses)

# execute the pulse sequence
if params.unrolling:
results = platform.execute_pulse_sequences(sequences, options)

elif not params.unrolling:
results = [
platform.execute_pulse_sequence(sequence, options) for sequence in sequences
]

for ig, (flips, ro_pulses) in enumerate(zip(flips_sweep, all_ro_pulses)):
for qubit in qubits:
result = results[ro_pulses[qubit].serial]
serial = ro_pulses[qubit].serial
if params.unrolling:
result = results[serial][0]
else:
result = results[ig][serial]
data.register_qubit(
FlippingType,
(qubit),
Expand Down
2 changes: 1 addition & 1 deletion src/qibocal/protocols/characterization/ramsey.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def _acquisition(
for sequence in sequences
]

# We dont need ig as everty serial is different
# We dont need ig as every serial is different
for ig, (wait, ro_pulses) in enumerate(zip(waits, all_ro_pulses)):
for qubit in qubits:
serial = ro_pulses[qubit].serial
Expand Down
18 changes: 18 additions & 0 deletions tests/runcards/protocols.yml
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,24 @@ actions:
nflips_step: 1
nshots: 50

- id: flipping unrolling
priority: 0
operation: flipping
parameters:
nflips_max: 10
nflips_step: 1
nshots: 50
unrolling: True

- id: flipping_signal unrolling
priority: 0
operation: flipping_signal
parameters:
nflips_max: 10
nflips_step: 1
nshots: 50
unrolling: True


- id: dispersive shift
priority: 0
Expand Down

0 comments on commit ff4e2f5

Please sign in to comment.