# Setting up Boulder Opal with Qblox controllers

> Connect a Qblox cluster to Boulder Opal

Source: https://docs.q-ctrl.com/boulder-opal/autocalibration/discover/setting-up-boulder-opal-with-qblox-controllers

Qblox instruments provide modular control through dedicated RF and baseband modules for qubit drive, readout, and flux. The `boulderopalscaleup` package connects to a Qblox system through a `Runtime` object that manages the controller connection and routes experiment execution to the correct backend.

In this tutorial, you will configure a connection to a Qblox cluster, register it with the Boulder Opal runtime, instantiate the client, and create a virtual device from a YAML configuration.

You will need a Q-CTRL account with an API key and organization slug, a Qblox cluster reachable from your network with the `qblox-instruments` package installed, and a device configuration YAML provided by Q-CTRL.

**Note:** You will need to install `qblox-instruments`.


```python
%pip install qblox-instruments==1.1.1
```

## 1. Connect to the Qblox cluster

For a Qblox system, you describe each cluster with a `QbloxClusterInfo` object that carries the cluster name and host IP address. Replace the placeholder strings with the ones that apply to your device.

Once the system is described, you create the runtime with `Runtime.new()` and register the hardware with `runtime.add_system(QbloxSystemInfo(...))`.

**Note:** It is important to configure the `QbloxClusterInfo` and `QbloxSystemInfo` properly to reflect your controller's setup. Read the reference documentation for a complete explanation of all their parameters.


```python
from boulderopalscaleup.runtime import Runtime
from boulderopalscaleup.runtime.systems.qblox import QbloxClusterInfo, QbloxSystemInfo

qblox_clusters = [QbloxClusterInfo(name="<cluster name>", host="<cluster IP address>")]

runtime = Runtime.new()
runtime.add_system(QbloxSystemInfo(clusters=qblox_clusters))
```

## 2. Initialize the client

Create the client and pass it the runtime you just configured along with your Q-CTRL API key and organization slug. Replace the placeholder strings with the credentials issued by Q-CTRL.


```python
from boulderopalscaleup import QctrlScaleUpClient

client = QctrlScaleUpClient(
    runtime=runtime,
    api_key="<your API key>",
    organization_slug="<your organization slug>",
)
```

## 3. Create and select the virtual device

Before running any programs on your physical device, you must create a virtual device in the Q-CTRL environment. The [`client.create_device`](https://docs.q-ctrl.com/references/boulder-opal-scale-up/boulderopalscaleup/client/create_device.md) call uploads a YAML configuration file that describes the layout of your QPU and the wiring of the control hardware that drives it, and registers the new virtual device under your organization. During this step, make sure you use the correct configuration files that are specifically for Qblox controllers. This ensures the setup complies with the respective Qblox syntax and support modules.

**Note:** Q-CTRL provides a template YAML for each supported QPU model and supported controller. Replace `./device_config.yaml` with the name of the file provided to you.


```python
from pathlib import Path

# The YAML file defines the wiring and other configurations for your device
device_yaml_path = Path("./device_config.yaml")

# Give the virtual device a unique name
device_name = "device_name"

# Add this named virtual device to the Q-CTRL environment, if not already present
if device_name not in [device.name for device in await client.get_devices()]:
    await client.create_device(device_name, device_config=device_yaml_path)

# Mark that device as the current device to use in subsequent routines and experiments
await client.set_current_device(device_name)
```
