### Minimal instrument coordinator setup Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/reference/qblox_scheduler_backend.md Minimal setup for the instrument coordinator, adding the QbloxSchedulerInstrumentCoordinatorComponent. ```python from quantify.instrument_coordinator import InstrumentCoordinator from quantify.instrument_coordinator.components import ( QbloxSchedulerInstrumentCoordinatorComponent, ) instrument_coordinator = InstrumentCoordinator( "instrument_coordinator", add_default_generic_icc=False ) instrument_coordinator.add_component( QbloxSchedulerInstrumentCoordinatorComponent() ) quantum_device.instr_instrument_coordinator(instrument_coordinator.name) ``` -------------------------------- ### Install qblox-scheduler directly Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/reference/qblox_scheduler_backend.md Install qblox-scheduler directly, useful for pre-release versions. ```bash pip install --pre "qblox-scheduler>=1.0.0b3" ``` -------------------------------- ### Example hardware configuration Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/reference/qblox_scheduler_backend.md Example of a hardware configuration for QbloxSchedulerHardwareCompilationConfig, including cluster details and module types. ```python quantum_device.hardware_config({ "config_type": "quantify.backends.qblox_scheduler.backend.QbloxSchedulerHardwareCompilationConfig", "hardware_description": {"cluster0": {...}}, "hardware_options": {...}, "connectivity": {...}, }) ``` -------------------------------- ### Install Quantify with Legacy Pip Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/user/installation.md Alternative installation command for developers who prefer using legacy pip. ```shell pip install -e ".[dev,test]" ``` -------------------------------- ### Install qblox-scheduler extra Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/reference/qblox_scheduler_backend.md Install the optional qblox-scheduler extra for Quantify. ```bash pip install -e ".[qblox-scheduler]" ``` -------------------------------- ### Start Instrument Monitor Publisher Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/howto/instrument-monitor/juice-instrument-monitor.md Run this code in your Juice service or notebook to start the Instrument Monitor. The `orangeqs_juice_ext.device_and_instruments.instrument_monitor` extension must be installed. ```python from orangeqs.juice_ext.device_and_instruments.instrument_monitor import InstrumentMonitorPublisher InstrumentMonitorPublisher().start() ``` -------------------------------- ### Start a New Experiment Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/howto/plotmon/communication.md Use the START command to register a new experiment, identified by a unique TUID. This prepares data sources for the experiment. ```json { "event": { "data_source_name": "default_source", "tuid": "tuid_123" }, "timestamp": "2025-09-29_12-01-00_UTC", "event_type": "START" } ``` -------------------------------- ### Install Quantify from Source with uv Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/user/installation.md Clone the quantify repository and install it from source using uv, including development and test dependencies. ```shell git clone https://gitlab.com/quantify-os/quantify.git cd quantify uv sync --extra dev --extra test uv run --active pytest -v ``` -------------------------------- ### Install Quantify Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/howto/instrument-monitor/getting-started.md Install the Quantify package using pip. This is a prerequisite for using the instrument monitor. ```bash pip install quantify ``` -------------------------------- ### Prepare, Start, and Retrieve Acquisition Data Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/reference/hardware_backends.md Prepares the hardware settings, starts the acquisition, and retrieves the acquisition data. This is typically done by the mock backend to format retrieved data before returning it to users. ```python settings = compiled_schedule["compiled_instructions"]["mock_rom"] rom_icc.prepare(settings) rom_icc.start() rom_icc.retrieve_acquisition() ``` -------------------------------- ### Set up Local Development Environment Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/user/installation.md Create and activate a virtual environment, then install Quantify with development and testing dependencies. ```shell uv venv --python 3.12 source .venv/bin/activate # Windows: .venv\Scripts\activate uv sync --extra dev --extra test ``` -------------------------------- ### Launch Instrument Monitor (Quick Start) Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/howto/instrument-monitor/getting-started.md Launch the instrument monitor and access its URL. Remember to stop the monitor when done. ```python from quantify.visualization.instrument_monitor import launch_instrument_monitor handle = launch_instrument_monitor() print(handle.url) # Select a parameter row in the Current State table to edit it. # ... run experiments ... handle.stop() ``` -------------------------------- ### Install Quantify from Source with pip Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/user/installation.md Alternative method to install quantify from source using legacy pip, including development and test extras, and run tests. ```shell pip install -e ".[dev,test]" pytest -v ``` -------------------------------- ### Create and Activate Virtual Environment on Windows Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/user/installation.md After installing uv, use these commands to create a virtual environment with Python 3.12, activate it, and install Quantify. ```shell uv venv --python 3.12 .venv\Scripts\activate uv pip install quantify ``` -------------------------------- ### Create and Activate Virtual Environment on Linux/macOS Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/user/installation.md After installing uv, use these commands to create a virtual environment with Python 3.12, activate it, and install Quantify. ```shell uv venv --python 3.12 source .venv/bin/activate uv pip install quantify ``` -------------------------------- ### Initial Setup: MeasurementControl and InstrumentCoordinator Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/tutorials/Tutorial_1._Running_an_Experiment.ipynb Initializes the data directory, MeasurementControl, and InstrumentCoordinator. Use this to set up the core components for running experiments. ```python from quantify import InstrumentCoordinator, MeasurementControl from quantify.data import handling as dh # Where datasets and compiled schedules are stored _ = dh.set_datadir(dh.default_datadir()) meas_ctrl = MeasurementControl("meas_ctrl") ic = InstrumentCoordinator("ic") ``` -------------------------------- ### Setup Mock Transmon and Create Schedule Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/user/quantify-compilers.md Sets up a mock transmon device and creates an echo schedule. This is a prerequisite for compiling schedules. ```python import numpy as np from quantify.device_under_test.mock_setup import set_up_mock_transmon_setup, set_standard_params_transmon from quantify.schedules.timedomain_schedules import echo_sched # instantiate the instruments of the mock setup mock_setup = set_up_mock_transmon_setup() # provide some sensible values to allow compilation without errors set_standard_params_transmon(mock_setup) echo_schedule = echo_sched(times=np.arange(0, 60e-6, 1.5e-6), qubit="q0", repetitions=1024) ``` -------------------------------- ### Install uv on Windows Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/user/installation.md Use this command to install the uv package manager on Windows via PowerShell. ```powershell powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" ``` -------------------------------- ### Start Instrument Monitor Stream Consumer Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/howto/instrument-monitor/technical-architecture.md Public extension point for starting streaming consumers. Requires a handler function and other parameters. ```python Streaming consumers: `start_instrument_monitor_stream(handler, ...)` ``` -------------------------------- ### Install rich pretty printing Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/reference/acquisition_framework.md Installs the rich pretty printing library for more readable output in the console. ```python from rich import pretty pretty.install() ``` -------------------------------- ### Install uv on Linux/macOS Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/user/installation.md Use this command to install the uv package manager on Linux and macOS systems. ```shell curl -LsSf https://astral.sh/uv/install.sh | sh ``` -------------------------------- ### Install Pre-commit Hooks Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/user/installation.md Set up pre-commit to automatically run code quality checks before each commit. ```shell pre-commit install ``` -------------------------------- ### Hardware Setup: Mock Backend Configuration Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/tutorials/Tutorial_1._Running_an_Experiment.ipynb Configures the hardware compilation settings using a mock backend. This includes setting modulation frequencies and adding a MockReadoutModule to the InstrumentCoordinator. ```python from copy import deepcopy from quantify.backends.mock.mock_rom import ( MockReadoutModule, MockROMInstrumentCoordinatorComponent, ) from quantify.backends.mock.mock_rom import ( hardware_compilation_config as mock_hardware_compilation_config, ) hardware_comp_cfg = deepcopy(mock_hardware_compilation_config) hardware_comp_cfg["hardware_options"]["modulation_frequencies"]["q0:mw-q0.01"] = { "interm_freq": 50e6 } device.hardware_config(hardware_comp_cfg) rom = MockReadoutModule("mock_rom") ic.add_component(MockROMInstrumentCoordinatorComponent(mock_rom=rom)) ``` -------------------------------- ### Generate Example xarray.Dataset for Acquisitions Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/user/user-guide.md This example demonstrates the structure of an xarray.Dataset returned by InstrumentCoordinator.retrieve_acquisition() when a schedule involves multiple acquisition channels and measurements. ```python import numpy as np import xarray as xr num_repetitions = 5 num_meas_0 = 3 num_meas_1 = 2 shape_0 = (num_repetitions, num_meas_0) shape_1 = (num_repetitions, num_meas_1) ds = xr.merge([ xr.DataArray( np.random.rand(*shape_0).round(3) + 1j * np.random.rand(*shape_0).round(3), dims=("repetition", "acq_index_0"), name=0, ), xr.DataArray( np.random.rand(*shape_1).round(3) + 1j * np.random.rand(*shape_1).round(3), dims=("repetition", "acq_index_1"), name=1, ), ]) ds ``` -------------------------------- ### Create Schedule for Trace Acquisitions Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/reference/hardware_backends.md Example of creating a schedule for a trace acquisition on a specific channel. ```python schedule = Schedule("example") schedule.add(Measure(qubit="q0", acq_channel="ch_0", acq_protocol="Trace")) ``` -------------------------------- ### Import necessary modules Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/tutorials/Tutorial_7._Adaptive_Measurements.ipynb Imports standard libraries for adaptive measurements, QCoDes, SciPy, and Quantify. Ensure these are installed before running. ```python import time import adaptive import numpy as np from qcodes import Instrument, ManualParameter from scipy import optimize from quantify.analysis.interpolation_analysis import InterpolationAnalysis2D import quantify.analysis.optimization_analysis as oa from quantify.data.handling import default_datadir, set_datadir from quantify.measurement.control import MeasurementControl from quantify.visualization.instrument_monitor import launch_instrument_monitor ``` -------------------------------- ### Create Schedule for Binned Acquisitions Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/reference/hardware_backends.md Example of creating a schedule with multiple binned measurements on the same acquisition channel. ```python schedule = Schedule("example") schedule.add(Measure(qubit="q0", acq_channel="ch_0", coords={"freq": 100})) schedule.add(Measure(qubit="q0", acq_channel="ch_0", coords={"freq": 200})) schedule.add(Measure(qubit="q0", acq_channel="ch_0", coords={"freq": 300})) ``` -------------------------------- ### Create a mock instrument for demonstration Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/user/advanced/Controlling_a_basic_experiment_using_MeasurementControl.ipynb Creates a mock instrument that emulates a physical setup, generating a cosine wave with added noise. This is used for demonstrating the measurement process without actual hardware. ```python # We create an instrument to contain all the parameters of our model to ensure ``` -------------------------------- ### Creating a custom colormap Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/howto/visualization.ipynb This example demonstrates how to create a custom colormap using a list of base colors, adjusting their saturation and transparency. ```python import colorsys import matplotlib.colors as mplc import matplotlib.pyplot as plt import numpy as np from quantify.visualization.color_utilities import set_hlsa color_cycle = ["#1f77b4", "#ff7f0e", "#2ca02c", "#d62728"] all_colors = [] for col in color_cycle: hls = colorsys.rgb_to_hls(*mplc.to_rgb(mplc.to_rgb(col))) sat_vals = (np.linspace(0.0, 1.0, 20) ** 2) * hls[2] alpha_vals = np.linspace(0.4, 1.0, 20) colors = [list(set_hlsa(col, s=s)) for s, a in zip(sat_vals, alpha_vals)] all_colors += colors cmap = mplc.ListedColormap(all_colors) np.random.seed(19680801) data = np.random.randn(30, 30) fig, ax = plt.subplots(1, 1, figsize=(6, 3), constrained_layout=True) psm = ax.pcolormesh(data, cmap=cmap, rasterized=True, vmin=-4, vmax=4) fig.colorbar(psm, ax=ax) plt.show() ``` -------------------------------- ### Launch Instrument Monitor on Fixed Port Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/howto/instrument-monitor/getting-started.md If the monitor does not start, try launching it on a specific port. ```python launch_instrument_monitor(port=5008) ``` -------------------------------- ### Device Setup: QuantumDevice and BasicTransmonElement Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/tutorials/Tutorial_1._Running_an_Experiment.ipynb Defines a QuantumDevice and adds a BasicTransmonElement (a single transmon qubit) to it. Configure element properties like readout amplitude, frequency, and pulse parameters. ```python from quantify import BasicTransmonElement, QuantumDevice READOUT_AMP = 0.1 READOUT_FREQ = 4.3e9 FREQ_01 = 4.0e9 PI_PULSE_AMP = 0.15 ACQ_DELAY = 100e-9 device = QuantumDevice("device") device.instr_instrument_coordinator(ic.name) q0 = BasicTransmonElement("q0") device.add_element(q0) q0.measure.pulse_amp(READOUT_AMP) q0.clock_freqs.readout(READOUT_FREQ) q0.clock_freqs.f01(FREQ_01) q0.measure.acq_delay(ACQ_DELAY) q0.rxy.amp180(PI_PULse_AMP) ``` -------------------------------- ### Instantiate a basic transmon element Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/tutorials/Tutorial_8._Custom_Operations.ipynb Creates a basic transmon element instance named 'baseq0'. This serves as a starting point for building a quantum device configuration. ```python q0 = BasicTransmonElement("baseq0") ``` -------------------------------- ### Hardware description with IP address Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/reference/qblox_scheduler_backend.md Example hardware description for a Qblox cluster, emphasizing the necessity of the 'ip' field for proper instrument operation. ```python "hardware_description": { "cluster0": { "instrument_type": "Cluster", "ref": "internal", "ip": "192.168.0.2", # without this, all acquisitions return NaN "modules": { "6": {"instrument_type": "QCM_RF"}, "12": {"instrument_type": "QRM_RF"}, }, }, } ``` -------------------------------- ### Instantiate MeasurementControl and launch Instrument Monitor Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/user/advanced/Controlling_a_basic_experiment_using_MeasurementControl.ipynb Initializes the MeasurementControl for managing experiments and optionally launches an Instrument Monitor for an overview of instrument parameters. Ensure MeasurementControl is instantiated before starting measurements. ```python meas_ctrl = MeasurementControl("meas_ctrl") # Optional: Plotmon for live plotting # meas_ctrl.attach_plotmon() # Instrument Monitor: overview of instrument parameters insmon = launch_instrument_monitor(open_browser=False) ``` -------------------------------- ### Minimal Custom Data Source Publisher Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/howto/plotmon/custom_data_source.md This example shows a minimal custom data source that streams all supported message types to Plot Monitor. Adapt this to any backend, simulation, or data pipeline. ```python import asyncio import time from orangeqs.juice.client.pubsub import publisher_async from orangeqs.juice_ext.device_and_instruments.plotmon.schemas import PlotmonMessageEvent from quantify.visualization.plotmon.utils.communication import ( PlotmonConfig, StartExperimentMessage, StopExperimentMessage, UpdateDataMessage, Data, Message, CommandType ) from orangeqs.juice_ext.device_and_instruments.measurement_control.measurement_control import PlotmonUI def stream_to_plotmon(): # 1. Instatiate helper tool which sends data to Plot Monitor ui = PlotmonUI() ui.init("client") # 2. Send PlotmonConfig to configure the graph layout plotmon_config = PlotmonConfig( title="My experiment", data_source_name="client", graph_configs=[ [{"plot_name": "my_plot", "type": "1d", "xlabel": "x", "ylabel": "y"}] ] ) msg_config = Message( event=plotmon_config, timestamp=str(time.time()), ) ui.callback(msg_config) # 3. Send StartExperimentMessage to start the experiment start_msg = StartExperimentMessage( data_source_name="client", tuid="unique-experiment-id" ) msg_start = Message( event=start_msg, timestamp=str(time.time()), ) ui.callback(msg_start) # 4. Send UpdateDataMessage to update a specific graph for i in range(10): update_msg = UpdateDataMessage( data_source_name="client", tuid="unique-experiment-id", plot_name="my_plot", data=Data( sequence_ids=[i], tuid=["unique-experiment-id"], x=[i], y=[i**2] ), ) msg_update = Message( event=update_msg, timestamp=str(time.time()), ) ui.callback(msg_update) time.sleep(1) # 5. Send StopExperimentMessage to end the experiment stop_msg = StopExperimentMessage( data_source_name="client", tuid="unique-experiment-id" ) msg_stop = Message( event=stop_msg, timestamp=str(time.time()), ) ui.callback(msg_stop) stream_to_plotmon() ``` -------------------------------- ### Create ScheduleGettable and Retrieve Data Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/reference/hardware_backends.md Creates a `ScheduleGettable` for executing a schedule and retrieving data. It takes the `QuantumDevice` and schedule parameters, then calls `get()` to acquire I and Q data. ```python from quantify.gettables import ScheduleGettable from quantify.schedules.trace_schedules import trace_schedule schedule_gettable = ScheduleGettable( quantum_device=quantum_device, schedule_function=trace_schedule, schedule_kwargs=dict( pulse_amp=0.1, pulse_duration=1e-7, pulse_delay=0, frequency=3e9, acquisition_delay=0, integration_time=2e-7, port="q0:res", clock="q0.ro" ), batched=True ) I, Q = schedule_gettable.get() ``` -------------------------------- ### Launch Instrument Monitor Source: https://gitlab.com/quantify-os/quantify/-/blob/main/quantify/visualization/instrument_monitor/README.md Starts a Bokeh server in a background thread for live instrument monitoring. Returns a handle that can be used to access the monitor's URL and stop it. ```APIDOC ## launch_instrument_monitor ### Description Starts a Bokeh server in a background thread for live instrument monitoring. ### Method Python function call ### Parameters #### Keyword Arguments - **host** (str) - Optional - The host to bind the Bokeh server to. Defaults to "localhost". - **port** (int) - Optional - The port to bind the Bokeh server to. If None, a random port is chosen. - **log_level** (str) - Optional - The logging level for the instrument monitor. Defaults to "INFO". ### Returns A `MonitorHandle` object with `url` attribute and `stop()` method. ### Request Example ```python from quantify.visualization.instrument_monitor import launch_instrument_monitor handle = launch_instrument_monitor( host="localhost", port=None, log_level="INFO", ) print(handle.url) handle.stop() ``` ### Response Example ``` http://localhost:5006/ ``` ``` -------------------------------- ### Initialize QuantumDevice Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/user/user-guide.md Initialize a QuantumDevice instance, which is required for generating device and hardware configuration files for each iteration of the experiment. ```python from quantify.device_under_test.quantum_device import QuantumDevice device = QuantumDevice(name="quantum_sample") ``` -------------------------------- ### Start Instrument Monitor Stream Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/howto/instrument-monitor/index.md Starts a stream to consume instrument and parameter updates without the UI. Updates are delivered to a specified handler function. ```APIDOC ## start_instrument_monitor_stream ### Description Consumes instrument and parameter updates programmatically without launching the UI. ### Method ```python start_instrument_monitor_stream( handler: Callable[[dict], None], **kwargs ) ``` ### Parameters - **handler** (Callable[[dict], None]): A callback function that will be called with each update. The update dictionary contains keys like `mode`, `readings`, `change_events`, and a `current_state()` method. - **kwargs**: Additional keyword arguments are passed to `launch_instrument_monitor`. ### Request Example ```python from quantify.visualization.instrument_monitor import start_instrument_monitor_stream def on_update(update): # update.mode: "snapshot" | "delta" # update.readings: list[Reading] # update.change_events: list[ChangeEvent] # update.current_state(): latest full state print(f"Received update mode: {update['mode']}") pass stream = start_instrument_monitor_stream(on_update) # ... run experiments ... stream.stop() ``` ### Response The function returns a stream object with a `stop` method. ``` -------------------------------- ### InstrumentCoordinator Setup for Hardware Execution Source: https://context7.com/quantify-os/quantify/llms.txt Initialize the InstrumentCoordinator and associated components for translating schedules into instrument instructions and retrieving acquisition data. This setup is for hardware execution coordination. ```python from quantify.instrument_coordinator.instrument_coordinator import InstrumentCoordinator from quantify.instrument_coordinator.components.generic import GenericInstrumentCoordinatorComponent from quantify.backends.graph_compilation import SerialCompiler from quantify.device_under_test.quantum_device import QuantumDevice from quantify.device_under_test.transmon_element import BasicTransmonElement from quantify.schedules.schedule import Schedule from quantify.operations.gate_library import Reset, X, Measure # Setup q0 = BasicTransmonElement("q0") q0.clock_freqs.f01(5.1e9) q0.clock_freqs.readout(7.0e9) q0.rxy.amp180(0.5) q0.measure.acq_delay(100e-9) device = QuantumDevice("device_ic") device.add_element(q0) ic = InstrumentCoordinator("ic", add_default_generic_icc=True) device.instr_instrument_coordinator("ic") ``` -------------------------------- ### Start Instrument Monitor Streaming API Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/howto/instrument-monitor/index.md Starts a streaming connection to consume instrument monitor updates without launching the UI. The provided handler function processes updates, which can be snapshots or deltas. ```python from quantify.visualization.instrument_monitor import start_instrument_monitor_stream def on_update(update): # update.mode: "snapshot" | "delta" # update.readings: list[Reading] # update.change_events: list[ChangeEvent] # update.current_state(): latest full state pass stream = start_instrument_monitor_stream(on_update) # ... run experiments ... stream.stop() ``` -------------------------------- ### Instantiate QuantumDevice Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/reference/hardware_backends.md Creates an empty `QuantumDevice` instance. This device will later be configured with hardware-specific compilation details. ```python from quantify.device_under_test.quantum_device import QuantumDevice quantum_device = QuantumDevice("quantum_device") ``` -------------------------------- ### Setup Resonator Instrument for Adaptive Sampling Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/tutorials/Tutorial_7._Adaptive_Measurements.ipynb Configures a 'Resonator' instrument with frequency and amplitude parameters, and defines a Lorenzian model function for S21 transmission. This setup is used to simulate a device with an unknown resonance frequency within a known range. ```python res = Instrument("Resonator") res.add_parameter("freq", unit="Hz", label="Frequency", parameter_class=ManualParameter) res.add_parameter("amp", unit="V", label="Amplitude", parameter_class=ManualParameter) _fwhm = 15e6 # pretend you don't know what this value is _res_freq = 6.78e9 # pretend you don't know what this value is _noise_level = 0.1 def lorenz(): """A Lorenz model function.""" time.sleep(0.02) # for display purposes, just so we can watch the graph update return ( 1 - ( res.amp() * ((_fwhm / 2.0) ** 2) / ((res.freq() - _res_freq) ** 2 + (_fwhm / 2.0) ** 2) ) + _noise_level * np.random.rand(1) ) res.add_parameter("S21", unit="V", label="Transmission amp. S21", get_cmd=lorenz) ``` -------------------------------- ### Configure Quantum Device and Elements Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/tutorials/Tutorial_3._Compiling_to_Hardware.ipynb Set up a QuantumDevice and add a BasicTransmonElement. Configure essential parameters like clock frequencies, pulse amplitude, and acquisition delay. Assign the hardware configuration to the device. ```python from quantify import BasicTransmonElement, QuantumDevice quantum_device = QuantumDevice("device") q0 = BasicTransmonElement("q0") quantum_device.add_element(q0) # Minimal parameters for readout q0.clock_freqs.readout(7e9) q0.measure.pulse_amp(0.1) q0.measure.acq_delay(100e-9) quantum_device.hardware_config(hardware_comp_cfg) ``` -------------------------------- ### Initialize MeasurementControl and Parameters Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/howto/measurement-control.ipynb Sets up the data directory, initializes MeasurementControl, and defines manual and signal parameters. These are necessary for setting up measurement routines. ```python from pathlib import Path import matplotlib.pyplot as plt import numpy as np from qcodes import ManualParameter, Parameter import xarray as xr import quantify.data.handling as dh from quantify.measurement import MeasurementControl dh.set_datadir(Path.home() / "quantify-data") meas_ctrl = MeasurementControl("meas_ctrl") par0 = ManualParameter(name="x0", label="X0", unit="s") par1 = ManualParameter(name="x1", label="X1", unit="s") par2 = ManualParameter(name="x2", label="X2", unit="s") par3 = ManualParameter(name="x3", label="X3", unit="s") sig = Parameter(name="sig", label="Signal", unit="V", get_cmd=lambda: np.exp(par0())) ``` -------------------------------- ### Launch Instrument Monitor using Context Manager Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/howto/instrument-monitor/getting-started.md Use the instrument monitor as a context manager for automatic startup and shutdown. ```python from quantify.visualization.instrument_monitor import launch_instrument_monitor with launch_instrument_monitor() as monitor: print(monitor.url) # ... experiments ... ``` -------------------------------- ### Build Documentation Locally (Unix) Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/user/installation.md Build the project documentation locally on Unix-based systems. ```shell cd docs uv run --active make html ``` -------------------------------- ### Downgrade Quantify to a Specific Version Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/user/installation.md Install a specific version of the quantify package using uv pip. ```shell uv pip install quantify==0.3.0 ``` -------------------------------- ### Build Documentation Locally (Windows) Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/user/installation.md Build the project documentation locally on Windows systems using the make.bat script. ```shell cd docs uv run --active ./make.bat html ``` -------------------------------- ### Instrument Monitor Practical Profiles Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/howto/instrument-monitor/configuration.md Demonstrates practical configurations for the instrument monitor, including fast startup, high event throughput, and conservative memory usage. ```python # Fast startup launch_instrument_monitor(warmup_total_passes=2, warmup_interval_s=0.5) ``` ```python # High event throughput launch_instrument_monitor(event_batch_limit=50000) ``` ```python # Conservative memory usage launch_instrument_monitor(event_batch_limit=2000) ``` -------------------------------- ### Create Mock Instrument for Optimization Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/tutorials/Tutorial_7._Adaptive_Measurements.ipynb Sets up a mock instrument with parameters to simulate a parabolic function with added noise. This is used to test adaptive measurement strategies. ```python np.random.seed(0) para = Instrument("parabola") para.add_parameter("x", unit="m", label="X", parameter_class=ManualParameter) para.add_parameter("y", unit="m", label="Y", parameter_class=ManualParameter) para.add_parameter( "noise", unit="V", label="white noise amplitude", parameter_class=ManualParameter ) para.add_parameter( "acq_delay", initial_value=0.1, unit="s", parameter_class=ManualParameter ) def _amp_model() -> float: time.sleep( para.acq_delay() ) # for display purposes, just so we can watch the live plot update return para.x() ** 2 + para.y() ** 2 + para.noise() * np.random.rand(1) para.add_parameter("amp", unit="V", label="Amplitude", get_cmd=_amp_model) ``` -------------------------------- ### Create xarray Dataset for Trace Acquisitions Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/reference/hardware_backends.md Example of constructing an xarray.Dataset for trace acquisition data, including time dimension. ```python import xarray xarray.Dataset( data_vars=dict( ch_0=(["acq_index_ch_0", "time_ch0"], [[2.5, 2.6, 2.7, 2.8, 2.9, 3.0]]), ), coords=dict( time_ch0=[0.0, 0.001, 0.002, 0.003, 0.004, 0.005], acq_index_ch_0=[0], ), ) ``` -------------------------------- ### Launch Instrument Monitor with Default Settings Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/howto/instrument-monitor/configuration.md Launches the instrument monitor with default host, port, and logging configurations. The monitor will open in the default browser. ```python from quantify.visualization.instrument_monitor import launch_instrument_monitor handle = launch_instrument_monitor( host="localhost", port=None, open_browser=True, log_level="INFO", websocket_origins=None, set_value_handler=None, ) ``` -------------------------------- ### Build a Schedule with Qubit Operations in Python Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/tutorials/Tutorial_4._Operations_and_Qubits.ipynb Shows how to construct a schedule by adding various qubit operations like Reset, X90, and Measure. Imports and Schedule initialization are necessary. ```python from quantify import Schedule from quantify.operations import X90, Measure, Reset sched = Schedule("two_qubit_ops") sched.add(Reset("q0", "q1")) sched.add(X90("q0")) sched.add(X90("q1"), ref_pt="start") sched.add(Measure("q0")) sched.add(Measure("q1"), ref_pt="start") ``` -------------------------------- ### Add OrangeQS Juice Service Configuration Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/dev/juice/run_id.md If you haven't configured a service yet, add this section to `orchestration.toml`. This step requires system administrator access. ```toml [services.""] # No configuration options yet. ``` -------------------------------- ### Create xarray Dataset for Binned Acquisitions Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/reference/hardware_backends.md Example of constructing an xarray.Dataset for binned acquisition data, including data variables and coordinates. ```python import xarray xarray.Dataset( data_vars=dict( ch_0=(["acq_index_ch_0"], [0.0, 0.2, 0.4]), ), coords=dict( freq=(["acq_index_ch_0"], [100, 200, 300]), acq_index_ch_0=[0, 1, 2], ), ) ``` -------------------------------- ### SSBIntegrationComplex with BinMode.AVERAGE Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/reference/acquisition_protocols.ipynb Example of structuring an xarray.Dataset for SSBIntegrationComplex with BinMode.AVERAGE. The repetition dimension is reduced, leaving only the acquisition index dimension for each channel. ```python xr.Dataset( { 0: demodulated_trace.reduce(np.average, "trace_index").expand_dims( {"acq_index_0": 3} ), 2: demodulated_trace.reduce(np.average, "trace_index").expand_dims( {"acq_index_2": 2} ), } ) ``` -------------------------------- ### Launch Instrument Monitor with Ingestion Parameters Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/howto/instrument-monitor/configuration.md Initializes the instrument monitor with specific warmup passes, interval, and event batch limits for controlling data ingestion behavior. ```python handle = launch_instrument_monitor( warmup_total_passes=5, warmup_interval_s=1.0, event_batch_limit=10000, ) ``` -------------------------------- ### Timetag Data Array Example Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/reference/acquisition_protocols.ipynb Illustrates the structure of the data returned by a Timetag acquisition when using BinMode.APPEND. The data is represented as an xarray DataArray. ```python data_array = xr.DataArray( np.array([5438.2, 756.16, 1059.2]).reshape((3, 1)), dims=["repetition", "acq_index_0"], coords={"acq_index_0": [0]}, attrs={"acq_protocol": "Timetag"}, ) xr.Dataset({0: data_array}) ``` -------------------------------- ### Format Code and Run Tests Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/user/installation.md Format the codebase and run the test suite with coverage. ```shell uv run --active ruff format . uv run --active pytest --cov ``` -------------------------------- ### Import necessary modules for Quantify Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/user/advanced/Controlling_a_basic_experiment_using_MeasurementControl.ipynb Imports core modules for analysis, data handling, measurement control, and example support. Ensure these are imported before proceeding. ```python import numpy as np from quantify.analysis import base_analysis as ba from quantify.analysis import cosine_analysis as ca from quantify.data.handling import ( default_datadir, set_datadir, ) from quantify.measurement import MeasurementControl from quantify.utilities.examples_support import mk_cosine_instrument from quantify.utilities.inspect_utils import display_source_code from quantify.visualization.instrument_monitor import launch_instrument_monitor ``` -------------------------------- ### Compile Schedule to Device Layer in Python Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/tutorials/Tutorial_4._Operations_and_Qubits.ipynb Illustrates the process of compiling a circuit-level schedule to a device-level representation. This involves setting up a QuantumDevice with TransmonElements and configuring it before compilation. ```python from quantify import BasicTransmonElement, QuantumDevice, SerialCompiler # Example device with two transmons device = QuantumDevice("device") q0 = BasicTransmonElement("q0") q1 = BasicTransmonElement("q1") device.add_element(q0) device.add_element(q1) # Minimal example parameters (replace with calibrated values) q0.clock_freqs.f01(5.0e9) q0.clock_freqs.readout(6.2e9) q0.rxy.amp180(0.2) q0.measure.pulse_amp(0.1) q0.measure.acq_delay(100e-9) q1.clock_freqs.f01(5.1e9) q1.clock_freqs.readout(6.1e9) q1.rxy.amp180(0.2) q1.measure.pulse_amp(0.1) q1.measure.acq_delay(100e-9) config = device.generate_compilation_config() compiler = SerialCompiler(name="compiler") compiled = compiler.compile(schedule=sched, config=config) ``` -------------------------------- ### Add DRAG Pulse to Schedule Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/tutorials/Tutorial_2._Schedules_and_Pulses.ipynb Adds a DRAG pulse to a schedule, aligning it to the start of a reference operation. This is useful for implementing complex pulse sequences. ```python from quantify.operations import DRAGPulse sched.add( DRAGPulse( G_amp=0.5, D_amp=0.5, duration=1e-6, phase=0, port="q0:mw", clock="q0.01" ), ref_op=square_pulse, ref_pt="start", ) sched.add_resource(ClockResource(name="q0.01", freq=7e9)) comp_sched = device_compiler.compile(sched) comp_sched.plot_pulse_diagram() ``` -------------------------------- ### Import necessary libraries Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/user/advanced/Advanced_capabilities_of_the_MeasurementControl.ipynb Imports essential libraries for measurement control, data handling, visualization, and numerical operations. This setup is required before instrument instantiation or measurement. ```python import os import signal import sys import time from lmfit import Model import numpy as np from qcodes import ManualParameter from quantify.data.handling import default_datadir, set_datadir from quantify.measurement.control import MeasurementControl from quantify.visualization.instrument_monitor import launch_instrument_monitor rng = np.random.default_rng(seed=222222) # random number generator ``` -------------------------------- ### Thresholded Acquisition with Raw Trigger Data Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/reference/acquisition_protocols.ipynb Example showing raw trigger data being formatted into an xarray Dataset for Thresholded Acquisition. This is typically used before thresholding. ```python trigger_data = np.array([6, 3, 8, 1, 3]) xr.Dataset( {0: xr.DataArray(trigger_data.reshape(1, 5), dims=["acq_index_0", "repetitions"])} ) ``` -------------------------------- ### Thresholded Acquisition with BinMode.AVERAGE Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/reference/acquisition_protocols.ipynb Example of Thresholded Acquisition using BinMode.AVERAGE. The resulting dataset contains the mean of the binary threshold comparison results across all repetitions. ```python xr.Dataset( {0: xr.DataArray(np.mean(thresholded_data, keepdims=1), dims=["acq_index_0"])} ) ``` -------------------------------- ### SSBIntegrationComplex with BinMode.APPEND Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/reference/acquisition_protocols.ipynb Example of structuring an xarray.Dataset for SSBIntegrationComplex with BinMode.APPEND. Dimension names for acquisition channels are suffixed to avoid conflicts, and the repetition dimension is named 'repetition'. ```python xr.Dataset( { 0: demodulated_trace.reduce(np.average, "trace_index").expand_dims( {"repetition": 5, "acq_index_0": 3} ), 2: demodulated_trace.reduce(np.average, "trace_index").expand_dims( {"repetition": 5, "acq_index_2": 2} ), } ) ``` -------------------------------- ### Full Heatmap Configuration Example Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/howto/plotmon/graphs.md This JSON object shows all configurable fields for plotting heatmaps in Plotmon, including labels, units, dimensions, and color palette. ```json { "plot_type": "heatmap", "image_key": "image", "x_key": "x", "y_key": "y", "dw_key": "dw", "dh_key": "dh", "plot_name": "generic_heatmap", "x_label": "X", "y_label": "Y", "z_label": "Z", "x_units": "", "y_units": "", "z_units": "", "title": "2D Heatmap", "width": 750, "height": 600, "palette": "Viridis256" } ``` -------------------------------- ### Generate Compilation Config and Print Backend Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/user/quantify-compilers.md Generates the CompilationConfig from a quantum device and prints the backend name. This helps identify the suitable compilation backend. ```python quantum_device = mock_setup["quantum_device"] config = quantum_device.generate_compilation_config() print(config.backend) ``` -------------------------------- ### Load Mock Hardware Compilation Configuration Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/tutorials/Tutorial_3._Compiling_to_Hardware.ipynb Import and assign the mock hardware compilation configuration for testing or simulation purposes. ```python from quantify.backends.mock.mock_rom import ( hardware_compilation_config as mock_hardware_compilation_config, ) hardware_comp_cfg = mock_hardware_compilation_config ``` -------------------------------- ### Set the data directory for experiments Source: https://gitlab.com/quantify-os/quantify/-/blob/main/docs/source/user/advanced/Controlling_a_basic_experiment_using_MeasurementControl.ipynb Sets the default directory where experiment data will be saved. It is recommended to set this once at the start of your kernel and use a consistent directory for all experiments. ```python set_datadir(default_datadir()) # change me! ``` -------------------------------- ### Running BaseAnalysis and Accessing Results Source: https://context7.com/quantify-os/quantify/llms.txt Shows how to instantiate and run a built-in analysis class like QubitFluxSpectroscopyAnalysis and access its results. Customize global analysis settings before running. ```python from quantify.analysis.base_analysis import BaseAnalysis, settings from quantify.data.handling import set_datadir import lmfit import numpy as np set_datadir("tests/test_data") # Customize global analysis settings settings["mpl_dpi"] = 300 settings["mpl_fig_formats"] = ["png", "svg"] settings["mpl_transparent_background"] = False # Use a built-in analysis: QubitSpectroscopyAnalysis from quantify.analysis.spectroscopy_analysis import QubitFluxSpectroscopyAnalysis analysis = ( QubitFluxSpectroscopyAnalysis(tuid="20230309-235354-353-9c94c5") .run() ) # Access results print(analysis.quantities_of_interest) # {'fit_result': {...}, 'frequency_offset': ..., ...} # Access figures (lazy-loaded, LRU-cached) fig = analysis.figs_mpl["QubitFluxSpectroscopy_Magnitude"] ax = analysis.axs_mpl["QubitFluxSpectroscopy_Magnitude"] # Display in Jupyter analysis.display_figs_mpl() ```