Skip to content

Commit

Permalink
Merge pull request #461 from qiboteam/david/qblox_exec_params
Browse files Browse the repository at this point in the history
David/qblox exec params
  • Loading branch information
scarrazza committed Jun 7, 2023
2 parents ae8f1e6 + f1c4397 commit e5dc74f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 22 deletions.
8 changes: 3 additions & 5 deletions src/qibolab/instruments/qblox.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,9 +863,7 @@ def process_pulse_sequence(self, instrument_pulses: PulseSequence, nshots: int,
body += initial_wait_instruction

for n in range(pulses.count):
if (self.ports["i1"].hardware_demod_en or self.ports["o1"].hardware_mod_en) and pulses[
n
].relative_phase != 0:
if self.ports["i1"].hardware_demod_en or self.ports["o1"].hardware_mod_en:
# Set phase
phase = (pulses[n].relative_phase * 360 / (2 * np.pi)) % 360
phase = int(phase / 360 * 1e9)
Expand Down Expand Up @@ -1927,7 +1925,7 @@ def process_pulse_sequence(self, instrument_pulses: PulseSequence, nshots: int,
raise Exception(
f"The minimum delay between pulses is {minimum_delay_between_instructions}ns."
)
if self.ports[port].hardware_mod_en and pulses[n].relative_phase != 0:
if self.ports[port].hardware_mod_en:
# Set phase
phase = (pulses[n].relative_phase * 360 / (2 * np.pi)) % 360
phase = int(phase / 360 * 1e9)
Expand Down Expand Up @@ -2629,7 +2627,7 @@ def process_pulse_sequence(self, instrument_pulses: PulseSequence, nshots: int,
raise Exception(
f"The minimum delay between pulses is {minimum_delay_between_instructions}ns."
)
if self.ports[port].hardware_mod_en and pulses[n].relative_phase != 0:
if self.ports[port].hardware_mod_en:
# Set phase
phase = (pulses[n].relative_phase * 360 / (2 * np.pi)) % 360
phase = int(phase / 360 * 1e9)
Expand Down
54 changes: 37 additions & 17 deletions src/qibolab/platforms/multiqubit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@
import yaml
from qibo.config import log, raise_error

from qibolab import AcquisitionType, AveragingMode
from qibolab.channels import ChannelMap
from qibolab.platform import Platform
from qibolab.pulses import PulseSequence, PulseType
from qibolab.qubits import Qubit
from qibolab.result import IntegratedResults
from qibolab.result import (
AveragedIntegratedResults,
AveragedRawWaveformResults,
AveragedSampleResults,
IntegratedResults,
RawWaveformResults,
SampleResults,
)
from qibolab.sweeper import Parameter


Expand Down Expand Up @@ -279,12 +287,22 @@ def disconnect(self):
self.instruments[name].disconnect()
self.is_connected = False

def execute_pulse_sequence(self, sequence: PulseSequence, nshots=None):
def execute_pulse_sequence(self, sequence, options, **kwargs):
if not self.is_connected:
raise_error(RuntimeError, "Execution failed because instruments are not connected.")
if nshots is None:

if options.averaging_mode == AveragingMode.SINGLESHOT:
nshots = 1
self.average = False
elif options.averaging_mode == AveragingMode.CYCLIC:
nshots = options.nshots
self.average = True

if options.nshots is None:
nshots = self.nshots

relaxation_time = options.relaxation_time

instrument_pulses = {}
changed = {}

Expand Down Expand Up @@ -332,16 +350,23 @@ def execute_pulse_sequence(self, sequence: PulseSequence, nshots=None):
acquisition_results[key].update(value)
else:
acquisition_results[key] = value

data = {}
for serial in acquisition_results:
for if_pulse, original in changed.items():
if serial == if_pulse.serial:
data[original] = data[if_pulse.qubit] = IntegratedResults(acquisition_results[serial])
if options.acquisition_type is AcquisitionType.DISCRIMINATION:
exp_res = acquisition_results[serial][2]
if self.average:
exp_res = np.mean(exp_res, axis=0)
else:
ires = acquisition_results[serial][0][0]
qres = acquisition_results[serial][1][0]
exp_res = ires + 1j * qres

data[original] = data[if_pulse.qubit] = options.results_type(exp_res)
return data

def sweep(self, sequence, *sweepers, nshots=1024, average=True, relaxation_time=None):
def sweep(self, sequence, options, *sweepers, **kwargs):
results = {}
sweeper_pulses = {}
# create copy of the sequence
Expand All @@ -360,10 +385,8 @@ def sweep(self, sequence, *sweepers, nshots=1024, average=True, relaxation_time=
self._sweep_recursion(
copy_sequence,
copy.deepcopy(sequence),
options,
*sweepers,
nshots=nshots,
average=average,
relaxation_time=relaxation_time,
results=results,
sweeper_pulses=sweeper_pulses,
map_original_shifted=map_original_shifted,
Expand All @@ -375,10 +398,8 @@ def _sweep_recursion(
self,
sequence,
original_sequence,
options,
*sweepers,
nshots=1024,
average=True,
relaxation_time=None,
results=None,
sweeper_pulses=None,
map_original_shifted=None,
Expand All @@ -397,20 +418,19 @@ def _sweep_recursion(
self._sweep_recursion(
sequence,
original_sequence,
options,
*sweepers[1:],
nshots=nshots,
average=average,
relaxation_time=relaxation_time,
results=results,
sweeper_pulses=sweeper_pulses,
map_original_shifted=map_original_shifted,
)
else:
new_sequence = copy.deepcopy(sequence)
result = self.execute_pulse_sequence(new_sequence, nshots)
result = self.execute_pulse_sequence(new_sequence, options)

# colllect result and append to original pulse
for original_pulse, new_serial in map_original_shifted.items():
acquisition = result[new_serial].average if average else result[new_serial]
acquisition = result[new_serial]

if original_pulse.serial in results:
results[original_pulse.serial] += acquisition
Expand Down

0 comments on commit e5dc74f

Please sign in to comment.