Skip to content

Commit

Permalink
Merge pull request #438 from qiboteam/rmsettings
Browse files Browse the repository at this point in the history
  • Loading branch information
alecandido committed May 29, 2023
2 parents 4a3fb86 + c55de5e commit 7a5b331
Show file tree
Hide file tree
Showing 52 changed files with 1,388 additions and 2,290 deletions.
4 changes: 2 additions & 2 deletions examples/fidelity_example.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from qibolab import Platform
from qibolab import create_platform
from qibolab.paths import qibolab_folder

# Define platform and load specific runcard
runcard = qibolab_folder / "runcards" / "tii5q.yml"
platform = Platform("tii5q", runcard)
platform = create_platform("tii5q", runcard)

# Connects to lab instruments using the details specified in the calibration settings.
platform.connect()
Expand Down
4 changes: 2 additions & 2 deletions examples/minimum_working_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from qibolab import Platform
from qibolab import create_platform
from qibolab.paths import qibolab_folder
from qibolab.pulses import Pulse, PulseSequence, ReadoutPulse

Expand Down Expand Up @@ -33,7 +33,7 @@

# Define platform and load specific runcard
runcard = qibolab_folder / "runcards" / "tii1q.yml"
platform = Platform("tii1q", runcard)
platform = create_platform("tii1q", runcard)

# Connects to lab instruments using the details specified in the calibration settings.
platform.connect()
Expand Down
338 changes: 163 additions & 175 deletions poetry.lock

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ qibo = "^0.1.12"
networkx = "^3.0"
more-itertools = "^9.1.0"
pyyaml = "^6.0"
qblox-instruments = {version = "0.9.0", optional = true}
qcodes = {version ="^0.37.0", optional = true}
qcodes_contrib_drivers = {version ="0.18.0", optional = true}
pyvisa-py = {version ="0.5.3", optional = true}
qm-qua = {version ="==1.1.1", optional = true}
qualang-tools = {version ="==0.14.0", optional = true}
laboneq = {version ="==2.4.0", optional = true}
qblox-instruments = { version = "0.9.0", optional = true }
qcodes = { version = "^0.37.0", optional = true }
qcodes_contrib_drivers = { version = "0.18.0", optional = true }
pyvisa-py = { version = "0.5.3", optional = true }
qm-qua = { version = "==1.1.1", optional = true }
qualang-tools = { version = "==0.14.0", optional = true }
laboneq = { version ="==2.5.0", optional = true }

[tool.poetry.group.docs]
optional = true
Expand Down Expand Up @@ -62,7 +62,7 @@ optional = true
pylint = ">=2.16.0"

[tool.poetry.extras]
qblox = ["qblox-instruments", "qcodes", "qcodes_contrib_drivers", "pyvisa-py"]
qblox = ["qblox-instruments", "qcodes", "qcodes_contrib_drivers", "pyvisa-py"]
qm = ["qm-qua", "qualang-tools"]
zh = ["laboneq"]

Expand Down
45 changes: 45 additions & 0 deletions src/qibolab/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import importlib.metadata as im
import importlib.util
import os
from dataclasses import dataclass
from enum import Enum, auto
from pathlib import Path
from typing import Optional

from qibo.config import raise_error

from qibolab.platform import Platform
from qibolab.result import (
AveragedIntegratedResults,
Expand All @@ -15,6 +20,46 @@

__version__ = im.version(__package__)

PLATFORMS = "QIBOLAB_PLATFORMS"


def get_platforms_path():
"""Get path to repository containing the platforms.
Path is specified using the environment variable QIBOLAB_PLATFORMS.
"""
profiles = os.environ.get(PLATFORMS)
if profiles is None or not os.path.exists(profiles):
raise_error(RuntimeError, f"Profile directory {profiles} does not exist.")
return Path(profiles)


def create_platform(name, runcard=None):
"""Platform for controlling quantum devices.
Args:
name (str): name of the platform. Options are 'tiiq', 'qili' and 'icarusq'.
Returns:
The plaform class.
"""
if name == "dummy":
from qibolab.paths import qibolab_folder
from qibolab.platform import create_dummy

return create_dummy(qibolab_folder / "runcards" / "dummy.yml")

platform = get_platforms_path() / f"{name}.py"
if not platform.exists():
raise_error(ValueError, f"Platform {name} does not exist.")

spec = importlib.util.spec_from_file_location("platform", platform)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)

if runcard is None:
return module.create()
return module.create(runcard)


class AcquisitionType(Enum):
"""Data acquisition from hardware"""
Expand Down
6 changes: 3 additions & 3 deletions src/qibolab/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@

from qibolab import ExecutionParameters
from qibolab import __version__ as qibolab_version
from qibolab import create_platform
from qibolab.compilers import Compiler
from qibolab.platform import Platform
from qibolab.platforms.abstract import AbstractPlatform
from qibolab.transpilers import Pipeline


class QibolabBackend(NumpyBackend):
def __init__(self, platform, runcard=None):
super().__init__()
self.name = "qibolab"
if isinstance(platform, AbstractPlatform):
if isinstance(platform, Platform):
self.platform = platform
else:
self.platform = Platform(platform, runcard)
self.platform = create_platform(platform, runcard)
self.versions = {
"qibo": qibo_version,
"numpy": self.np.__version__,
Expand Down
16 changes: 11 additions & 5 deletions src/qibolab/designs/channels.py → src/qibolab/channels.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass, field
from typing import List, Optional
from typing import Dict, List, Optional

from qibo.config import raise_error

Expand Down Expand Up @@ -34,9 +34,10 @@ class Channel:
Not applicable for setups that do not use local oscillators because the controller
can send sufficiently high frequencies.
"""
gain: Optional[int] = 0
"""Channel amplification in dB."""
power_range: Optional[float] = None
"""Channel amplification or attenuation of the selected on the device
"""
"""Channel amplification or attenuation of the selected on the device."""
_bias: Optional[float] = None
"""DC offset that should be applied in the channel in order to shift the
frequency of the qubit, usually to put it in its sweetspot.
Expand Down Expand Up @@ -121,9 +122,14 @@ def attenuation(self, attenuation):

@dataclass
class ChannelMap:
"""Collection of :class:`qibolab.designs.channel.Channel` objects identified by name."""
"""Collection of :class:`qibolab.designs.channel.Channel` objects identified by name.
Essentially, it allows creating a mapping of names to channels just
specifying the names.
"""

_channels: dict = field(default_factory=dict)
_channels: Dict[str, Channel] = field(default_factory=dict)

@classmethod
def from_names(cls, *names):
Expand Down
2 changes: 0 additions & 2 deletions src/qibolab/designs/__init__.py

This file was deleted.

84 changes: 0 additions & 84 deletions src/qibolab/designs/design.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/qibolab/instruments/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from qibolab import AcquisitionType, AveragingMode, ExecutionParameters
from qibolab.instruments.abstract import AbstractInstrument
from qibolab.platforms.abstract import Qubit
from qibolab.platform import Qubit
from qibolab.pulses import PulseSequence, PulseType
from qibolab.sweeper import Parameter, Sweeper

Expand Down
19 changes: 12 additions & 7 deletions src/qibolab/instruments/qm.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from qualang_tools.units import unit

from qibolab import AcquisitionType, AveragingMode
from qibolab.designs.channels import check_max_bias
from qibolab.channels import check_max_bias
from qibolab.instruments.abstract import AbstractInstrument
from qibolab.pulses import Pulse, PulseType, Rectangular
from qibolab.result import (
Expand Down Expand Up @@ -144,7 +144,7 @@ def register_readout_element(self, qubit, intermediate_frequency=0, time_of_flig
}
if "analog_inputs" not in controllers[con]:
controllers[con]["analog_inputs"] = {}
controllers[con]["analog_inputs"][port] = {"offset": 0.0, "gain_db": 0}
controllers[con]["analog_inputs"][port] = {"offset": 0.0, "gain_db": qubit.feedback.gain}

# register element
lo_frequency = math.floor(qubit.readout.local_oscillator.frequency)
Expand Down Expand Up @@ -919,16 +919,21 @@ def sweep_bias(self, sweepers, qubits, qmsequence, relaxation_time):

sweeper = sweepers[0]
bias0 = []
for q in sweeper.qubits:
b0 = qubits[q].flux.bias
max_bias = qubits[q].flux.max_bias
for qubit in sweeper.qubits:
b0 = qubit.flux.bias
max_bias = qubit.flux.max_bias
max_value = self.maximum_sweep_value(sweeper.values, b0)
check_max_bias(max_value, max_bias)
bias0.append(declare(fixed, value=b0))
b = declare(fixed)
with for_(*from_array(b, sweeper.values)):
for q, b0 in zip(sweeper.qubits, bias0):
set_dc_offset(f"flux{q}", "single", b + b0)
for qubit, b0 in zip(sweeper.qubits, bias0):
with qua.if_((b + b0) >= 0.49):
set_dc_offset(f"flux{qubit.name}", "single", 0.49)
with qua.elif_((b + b0) <= -0.49):
set_dc_offset(f"flux{qubit.name}", "single", -0.49)
with qua.else_():
set_dc_offset(f"flux{qubit.name}", "single", (b + b0))

self.sweep_recursion(sweepers[1:], qubits, qmsequence, relaxation_time)

Expand Down
2 changes: 1 addition & 1 deletion src/qibolab/instruments/rfsoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from qibolab import AcquisitionType, AveragingMode, ExecutionParameters
from qibolab.instruments.abstract import AbstractInstrument
from qibolab.platforms.abstract import Qubit
from qibolab.platform import Qubit
from qibolab.pulses import PulseSequence, PulseType
from qibolab.result import IntegratedResults, SampleResults
from qibolab.sweeper import Parameter, Sweeper
Expand Down
22 changes: 20 additions & 2 deletions src/qibolab/instruments/rohde_schwarz.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@


class SGS100A(LocalOscillator):
def __init__(self, name, address):
def __init__(self, name, address, ref_osc_source="EXT"):
super().__init__(name, address)
self.device: LO_SGS100A = None
self._power: float = None
self._frequency: float = None
self._ref_osc_source: str = None
self.ref_osc_source = ref_osc_source
self._device_parameters = {}

@property
Expand All @@ -42,6 +44,18 @@ def power(self, x):
if self.is_connected:
self._set_device_parameter("power", x)

@property
def ref_osc_source(self):
if self.is_connected:
return self.device.ref_osc_source
return self._ref_osc_source

@ref_osc_source.setter
def ref_osc_source(self, x):
self._ref_osc_source = x
if self.is_connected:
self.device.ref_osc_source = x

def connect(self):
"""
Connects to the instrument using the IP address set in the runcard.
Expand All @@ -66,6 +80,7 @@ def connect(self):
self._set_device_parameter("frequency", self._frequency)
if self._power is not None:
self._set_device_parameter("power", self._power)
self.device.ref_osc_source = self._ref_osc_source

def _set_device_parameter(self, parameter: str, value):
"""Sets a parameter of the instrument, if it changed from the last stored in the cache.
Expand Down Expand Up @@ -93,7 +108,7 @@ def _erase_device_parameters_cache(self):
"""Erases the cache of instrument parameters."""
self._device_parameters = {}

def setup(self, frequency=None, power=None, **kwargs):
def setup(self, frequency=None, power=None, ref_osc_source=None, **kwargs):
"""Configures the instrument.
A connection to the instrument needs to be established beforehand.
Expand All @@ -108,11 +123,14 @@ def setup(self, frequency=None, power=None, **kwargs):
frequency = self.frequency
if power is None:
power = self.power
if ref_osc_source is None:
ref_osc_source = self.ref_osc_source

if self.is_connected:
# Load settings
self.power = power
self.frequency = frequency
self.ref_osc_source = ref_osc_source
else:
raise Exception("There is no connection to the instrument")

Expand Down
Loading

0 comments on commit 7a5b331

Please sign in to comment.