Skip to content

Commit

Permalink
Merge pull request #821 from qiboteam/qbloxbiassweep
Browse files Browse the repository at this point in the history
Qblox bias sweeper
  • Loading branch information
stavros11 authored Mar 7, 2024
2 parents f06f0b3 + fa20bd2 commit d080141
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 7 deletions.
91 changes: 91 additions & 0 deletions extras/test819.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import numpy as np
from qibo.backends import GlobalBackend

from qibolab import Platform
from qibolab.execution_parameters import (
AcquisitionType,
AveragingMode,
ExecutionParameters,
)
from qibolab.instruments.qblox.controller import QbloxController
from qibolab.platform import NS_TO_SEC
from qibolab.pulses import PulseSequence
from qibolab.sweeper import Parameter, Sweeper, SweeperType

GlobalBackend.set_backend("qibolab", "spinq10q")
platform: Platform = GlobalBackend().platform
controller: QbloxController = platform.instruments["qblox_controller"]

sequence = PulseSequence()
ro_pulses = {}

qid = 0
qubit = platform.qubits[qid]
qubits = {qid: qubit}

ro_pulse = platform.create_qubit_readout_pulse(qid, start=0)
ro_pulse.frequency = int(2e9)
sequence.add(ro_pulse)

freq_width = 2e7
freq_step = 2e5
bias_width = 0.8
bias_step = 0.01
nshots = 1024
relaxation_time = 5000

navgs = nshots
repetition_duration = sequence.finish + relaxation_time

# define the parameters to sweep and their range:
delta_frequency_range = np.arange(-freq_width // 2, freq_width // 2, freq_step)
freq_sweeper = Sweeper(
Parameter.frequency, delta_frequency_range, [ro_pulse], type=SweeperType.OFFSET
)

delta_bias_range = np.arange(-bias_width / 2, bias_width / 2, bias_step)
bias_sweeper = Sweeper(
Parameter.bias, delta_bias_range, qubits=[qubit], type=SweeperType.OFFSET
)

options = ExecutionParameters(
nshots=nshots,
relaxation_time=relaxation_time,
acquisition_type=AcquisitionType.INTEGRATION,
averaging_mode=AveragingMode.CYCLIC,
)
time = (sequence.duration + relaxation_time) * nshots * NS_TO_SEC
sweepers = (bias_sweeper, freq_sweeper)
for sweep in sweepers:
time *= len(sweep.values)

# mock
controller.is_connected = True


class Sequencers:
def __getitem__(self, index):
return self

def set(self, *args):
pass


class Device:
sequencers = Sequencers()


for mod in controller.modules.values():
mod.device = Device()
mod._device_num_sequencers = 0
# end mock

# for name, mod in controller.modules.items():
# if "qcm_rf" in name:
# continue

mod = controller.modules["qcm_bb0"]
channels = controller._set_module_channel_map(mod, qubits)
pulses = sequence.get_channel_pulses(*channels)
mod.process_pulse_sequence(qubits, pulses, navgs, nshots, repetition_duration, sweepers)
print(mod._sequencers["o1"][0].program)
4 changes: 4 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
forEachSystem
(system: let
pkgs = nixpkgs.legacyPackages.${system};
pwd = builtins.getEnv "PWD";
platforms = builtins.toPath "${pwd}/../qibolab_platforms_qrc/";
in {
default = devenv.lib.mkShell {
inherit inputs pkgs;
Expand All @@ -43,6 +45,8 @@
{
packages = with pkgs; [pre-commit poethepoet jupyter stdenv.cc.cc.lib zlib];

env.QIBOLAB_PLATFORMS = platforms;

languages.c = {
enable = true;
};
Expand Down
12 changes: 7 additions & 5 deletions src/qibolab/instruments/qblox/cluster_qcm_bb.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,12 @@ def connect(self, cluster: QbloxCluster = None):
self._ports[port].hardware_mod_en = True
self._ports[port].nco_freq = 0
self._ports[port].nco_phase_offs = 0
self._ports[port].offset = self._ports[port].offset
except Exception as error:
raise RuntimeError(
f"Unable to initialize port parameters on module {self.name}: {error}"
)

self.is_connected = True

def setup(self, **settings):
Expand Down Expand Up @@ -213,7 +215,9 @@ def _get_next_sequencer(self, port, frequency, qubits: dict):
# select the qubit with flux line, if present, connected to the specific port
qubit = None
for _qubit in qubits.values():
if _qubit.flux is not None and _qubit.flux.port == self.ports(port):
name = _qubit.flux.port.name
module = _qubit.flux.port.module
if _qubit.flux is not None and (name, module) == (port, self):
qubit = _qubit

# select a new sequencer and configure it as required
Expand Down Expand Up @@ -488,9 +492,7 @@ def process_pulse_sequence(
)

else: # qubit_sweeper_parameters
if sweeper.qubits and sequencer.qubit in [
_.name for _ in sweeper.qubits
]:
if sequencer.qubit in [qubit.name for qubit in sweeper.qubits]:
# plays an active role
if sweeper.parameter == Parameter.bias:
reference_value = self._ports[port].offset
Expand Down Expand Up @@ -639,7 +641,7 @@ def process_pulse_sequence(
)
body_block += final_reset_block

footer_block = Block("cleaup")
footer_block = Block("cleanup")
footer_block.append(f"stop")

# wrap pulses block in sweepers loop blocks
Expand Down
2 changes: 1 addition & 1 deletion src/qibolab/instruments/qblox/cluster_qcm_rf.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ def process_pulse_sequence(

body_block += final_reset_block

footer_block = Block("cleaup")
footer_block = Block("cleanup")
footer_block.append(f"stop")

# wrap pulses block in sweepers loop blocks
Expand Down
2 changes: 1 addition & 1 deletion src/qibolab/instruments/qblox/cluster_qrm_rf.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ def process_pulse_sequence(

body_block += final_reset_block

footer_block = Block("cleaup")
footer_block = Block("cleanup")
footer_block.append(f"stop")

# wrap pulses block in sweepers loop blocks
Expand Down

0 comments on commit d080141

Please sign in to comment.