### Import LabOne Q Example Helpers Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/04_quantum_processing_unit/tutorials/01_quantum_elements.ipynb Imports necessary packages for generating device setups in LabOne Q examples. ```python from __future__ import annotations import laboneq.serializers # Import required packages from laboneq.contrib.example_helpers.generate_device_setup import ( generate_device_setup, ) ``` -------------------------------- ### Programmatic Device Setup with Instrument Options Source: https://docs.zhinst.com/labone_q_user_manual/release_notes/previous_versions.html Example of programmatically constructing a device setup, emphasizing the requirement to include instrument options. This can be done via the 'options' field or the `device_options` argument. ```python device_setup = DeviceSetup( instruments=[ { "name": "hdawg_1", "device_options": {"port_width": 1000}, "options": {"னமாக": True} } ] ) ``` -------------------------------- ### Using generate_device_setup Helper Function Source: https://docs.zhinst.com/labone_q_user_manual/release_notes/previous_versions.html Demonstrates the usage of the `generate_device_setup` helper function from `contrib` to automatically query instruments for installed options when constructing a device setup. ```python from zhinst.laboneqt.contrib.device_setup_helpers import generate_device_setup setup = generate_device_setup(connection_info=connection_info, device_ids=device_ids) ``` -------------------------------- ### Import Example Helpers Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/10_advanced_topics/tutorials/06_context_based_dsl.ipynb Imports helper functions for generating device setups and plotting simulation results, useful for creating and visualizing experiments. ```python # Example device setup creator: from laboneq.contrib.example_helpers.generate_device_setup import ( generate_device_setup_qubits, ) # Helpers: from laboneq.contrib.example_helpers.plotting.plot_helpers import plot_simulation ``` -------------------------------- ### Programmatic Device Setup Generation Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/00_device_setup/tutorials/00_device_setup.ipynb Generate a large-scale device setup programmatically by adding instruments and connections. This example demonstrates setting up a PQSC and multiple SHFSG instruments for controlling 64 qubits. ```python scaled_setup = DeviceSetup("my_scaled_setup") scaled_setup.add_dataserver(host="111.22.33.44", port="8004") scaled_setup.add_instruments( PQSC(uid="pqsc", address="dev10001", reference_clock_source="internal") ) ``` ```python for i in range(8): scaled_setup.add_instruments(SHFSG(uid=f"shfsg_{i}", address=f"dev1212{i}")) scaled_setup.add_connections( f"shfsg_{i}", *[ create_connection( to_signal=f"q{i * 8 + _}/drive", ports=f"SGCHANNELS/{_}/OUTPUT" ``` -------------------------------- ### Generate Device Setup and Qubits Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/08_openqasm/tutorials/00_program_to_experiment.ipynb Generates a device setup and qubit objects using a helper function. This setup is used for subsequent examples. ```python from laboneq.contrib.example_helpers.generate_device_setup import ( generate_device_setup_qubits, ) # Select the number of qubits number_of_qubits = 3 # Generate the device setup and the qubit objects using a helper function device_setup, qubits = generate_device_setup_qubits( number_qubits=number_of_qubits, pqsc=[{"serial": "DEV10001"}], hdawg=[ { "serial": "DEV8001", "zsync": 0, "number_of_channels": 8, "options": None, } ], shfqa=[ { "serial": "DEV12001", "zsync": 1, "readout_multiplex": 6, "options": None, } ], shfsg=[ { "serial": "DEV12002", "zsync": 2, "number_of_channels": 8, "options": None, } ], include_flux_lines=True, server_host="localhost", setup_name=f"my_{number_of_qubits}_tunable_qubit_setup", ) ``` -------------------------------- ### Configure Device Setup Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/05_experiment/tutorials/00_experiment_definition_reference.ipynb Load a device setup from a descriptor, specifying server details and setup name. This is a prerequisite for running experiments. ```python device_setup = DeviceSetup.from_descriptor( descriptor, server_host="111.22.33.44", server_port="8004", setup_name="ZI_QCCS", ) calibrate_devices(device_setup) ``` -------------------------------- ### Initialize a demonstration QuantumPlatform and Device Setup Source: https://docs.zhinst.com/labone_q_user_manual/applications_library/tutorials/sources/writing_experiments.ipynb Sets up a pre-configured QuantumPlatform with tunable-transmon qubits and a corresponding Device_Setup. This is useful for testing and development when a custom setup is not yet available. ```python # Create a demonstration QuantumPlatform for a six-tunable-transmon QPU: qt_platform = demo_platform(n_qubits=3) # The platform contains a setup, which is an ordinary LabOne Q DeviceSetup: setup = qt_platform.setup # And a tunable-transmon QPU: qpu = qt_platform.qpu # Inside the QPU, we have quantum elements, which is a list of six LabOne Q Application # Library TunableTransmonQubit qubits: qubits = qpu.quantum_elements ``` -------------------------------- ### Load QPU and Device Setup from Files Source: https://docs.zhinst.com/labone_q_user_manual/applications_library/how-to-guides/sources/01_superconducting_qubits/01_workflows/10_dispersive_shift.ipynb Load existing DeviceSetup and QPU objects from JSON files. This is useful when you have previously saved your setup configuration. ```python from laboneq import serializers setup = serializers.load(full_path_to_device_setup_file) qpu = serializers.load(full_path_to_qpu_file) qubits = qpu.quantum_elements qops = qpu.quantum_operations ``` -------------------------------- ### Initialize Device Setup and Signals Source: https://docs.zhinst.com/labone_q_user_manual/applications_library/how-to-guides/sources/03_color_centers/00_shfsg_basic_experiments.ipynb Initializes the device setup and retrieves the address of the first instrument and the logical signals for 'q0'. This is a preparatory step before establishing a session. ```python device_setup = create_device_setup() shfsg_address = device_setup.instruments[0].address q0 = device_setup.logical_signal_groups["q0"].logical_signals ``` -------------------------------- ### Install LabOne Q Applications Library Source: https://docs.zhinst.com/labone_q_user_manual/getting_started/installation.html Installs the Applications Library for ready-to-use solutions. Run this within your Python environment. ```bash pip install --upgrade laboneq_applications ``` -------------------------------- ### Run Ramsey Experiment Workflow Source: https://docs.zhinst.com/labone_q_user_manual/applications_library/reference/experiments/ramsey.html This example demonstrates how to configure and run the Ramsey experiment workflow. It shows how to set experiment options, define the device setup, and call the experiment workflow with specified parameters. ```python options = experiment_workflow.options() options.create_experiment.count(10) options.create_experiment.transition("ge") setup = DeviceSetup("my_device") qpu = QPU( quantum_elements=[TunableTransmonQubit("q0"), TunableTransmonQubit("q1")], quantum_operations=TunableTransmonOperations(), ) temp_qubits = qpu.copy_quantum_elements() result = experiment_workflow( session=session, qpu=qpu, qubits=temp_qubits, delays=[[0.1, 0.5, 1], [0.1, 0.5, 1]], detunings = {'q0':1e6,'q1':1.346e6}, options=options, ).run() ``` -------------------------------- ### Start LabOne Q Session and Connect to Device Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/10_advanced_topics/tutorials/08_output_router.ipynb Initializes and connects to the LabOne Q session using the defined device setup. The `do_emulation` parameter can be set to `True` for simulation or `False` for real hardware connection. ```python # start the session my_session = Session(device_setup=device_setup) my_session.connect(do_emulation=emulate) ``` -------------------------------- ### Create Device Setup from Descriptor Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/10_advanced_topics/tutorials/01_neartime_callbacks.ipynb Creates a device setup from a descriptor, specifying server connection details and a setup name. This function is used to initialize the device configuration for experiments. ```python # Emulation mode does not create connection to the devices do_emulation = True # Function returning a calibrated device setup def create_device_setup(): device_setup = DeviceSetup.from_descriptor( descriptor, server_host="111.22.33.44", # ip address of the LabOne dataserver used to communicate with the instruments server_port="8004", # port number of the dataserver - default is 8004 setup_name="ZI_QCCS", # setup name ) calibrate_devices(device_setup) return device_setup # create device setup device_setup = create_device_setup() ``` -------------------------------- ### Install Benchmark Package Source: https://docs.zhinst.com/labone_q_user_manual/core/benchmarking/benchmarking.html Install the standalone benchmarking package from the source folder. This requires an existing LabOne Q installation (minimum version 2.41.0). ```bash uv pip install -e . ``` -------------------------------- ### Define Device Setup Source: https://docs.zhinst.com/labone_q_user_manual/applications_library/how-to-guides/sources/02_spin_qubits/01_QCoDeS_sweeps.html?h=node+sweeping Creates a device setup descriptor and initializes a DeviceSetup object for connecting to LabOne instruments. Ensure 'your_ip_address' is replaced with the actual server IP. ```python descriptor = """ instruments: MFLI: - address: DEV5534 uid: device_mfli """ device_setup = DeviceSetup.from_descriptor( descriptor, server_host="your_ip_address", server_port=8004, setup_name="MySetup", ) ``` -------------------------------- ### Import Helper for Device Setup and Qubits Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/04_quantum_processing_unit/tutorials/00_quantum_operations.ipynb Imports the necessary helper function to generate a device setup and qubits for quantum experiments. ```python from __future__ import annotations # needed for type setting in python 3.9 from laboneq.contrib.example_helpers.generate_device_setup import ( generate_device_setup_qubits, ) ``` -------------------------------- ### Initialize Device Setup and Calibration Source: https://docs.zhinst.com/labone_q_user_manual/applications_library/how-to-guides/sources/01_superconducting_qubits/02_pulse_sequences/02_advanced_qubit_experiments/02_active_qudit_reset_shfsg_shfqa_shfqc.ipynb Initializes the device setup and retrieves/sets calibration parameters for active reset. This is crucial for defining the experimental parameters for qubit control. ```python active_reset_calibration = Calibration() active_reset_calibration["/logical_signal_groups/q0/measure"] = ( device_setup.get_calibration()["/logical_signal_groups/q0/measure"] ) active_reset_calibration["/logical_signal_groups/q3/measure"] = ( device_setup.get_calibration()["/logical_signal_groups/q0/measure"] ) active_reset_calibration["/logical_signal_groups/q0/acquire"] = ( device_setup.get_calibration()["/logical_signal_groups/q0/acquire"] ) active_reset_calibration["/logical_signal_groups/q0/acquire"].oscillator = None device_setup.set_calibration(active_reset_calibration) ``` -------------------------------- ### Create Device Setup from Descriptor Source: https://docs.zhinst.com/labone_q_user_manual/applications_library/how-to-guides/sources/02_spin_qubits/02_MFLI_cw_acquisition.ipynb Initializes a device setup using a descriptor string, specifying instruments (MFLI, HDAWG) and their connections. It also includes calibration of devices. ```python descriptor = """ instruments: MFLI: - address: DEV5534 uid: device_mfli HDAWG: - address: DEV8434 uid: device_hdawg interface: usb connections: device_hdawg: - iq_signal: q0/drive_line ports: [SIGOUTS/4, SIGOUTS/5] - rf_signal: q0/coulomb_line_1 ports: [SIGOUTS/0] - rf_signal: q0/coulomb_line_2 ports: [SIGOUTS/1] # - external_clock_signal """ device_setup = DeviceSetup.from_descriptor( descriptor, server_host="your_ip_address", server_port=8004, setup_name="MySetup", ) calibrate_devices(device_setup) ``` -------------------------------- ### Create Device Setup Function Source: https://docs.zhinst.com/labone_q_user_manual/applications_library/how-to-guides/sources/03_color_centers/00_shfsg_basic_experiments.ipynb A function to create a device setup, accepting a descriptor and server host. This is a boilerplate function for setting up LabOne Q experiments. ```python def create_device_setup( descriptor=descriptor_shfsg_nv, serverhost="localhost", ): ``` -------------------------------- ### Device Setup with PQSC, SHFQA, and SHFsg Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/00_device_setup/tutorials/00_device_setup.ipynb Configures a device setup including a PQSC, SHFQA, and SHFsg. This setup is useful for complex experiments requiring multiple instruments. ```python descriptor = """\ instruments: SHFSG: - address: DEV10001 uid: shfsg options: SHFQA2/16W PQSC: - address: DEV10000 uid: pqsc options: PQSC connections: shfsg: - iq_signal: q0/drive ports: SGCHANNELS/0/OUTPUT shfqa: - iq_signal: q0/measure ports: QACHANNELS/0/OUTPUT - acquire_signal: q0/acquire ports: QACHANNELS/0/INPUT """ device_setup_pqsc_shf_instruments = DeviceSetup.from_descriptor( descriptor, server_host="111.22.33.44", server_port="8004", ) ``` -------------------------------- ### Device Setup Construction Source: https://docs.zhinst.com/labone_q_user_manual/core/reference/dsl/device.html Methods for constructing device setups from Python dictionaries or YAML files. ```APIDOC ## `from_dicts(*, instrument_list=None, instruments=None, connections=None, dataservers=None, server_host=None, server_port=None, setup_name=None)` `classmethod` Construct the device setup from Python dicts, same structure as yaml Parameters: Name | Type | Description | Default ---|---|---|--- `instrument_list` | `dict` | List of instruments in the setup (deprecated; for backwards compatibility) | `None` `instruments` | `dict` | List of instruments in the setup | `None` `connections` | `dict` | Connections between devices | `None` `server_host` | `str | None` | Server host of the setup that should be created. | `None` `server_port` | `str | int | None` | Port of the server that should be created. | `None` `setup_name` | `str | None` | Name of the setup that should be created. | `None` ## `from_yaml(filepath, server_host=None, server_port=None, setup_name=None)` `classmethod` Construct the device setup from a YAML file. Parameters: Name | Type | Description | Default ---|---|---|--- `filepath` | `str` | Path to the YAML file containing the device description. | _required_ `server_host` | `str` | Server host of the setup that should be created. | `None` `server_port` | `str` | Port of the server that should be created. | `None` `setup_name` | `str` | Name of the setup that should be created. | `None` ``` -------------------------------- ### Create Device Setup Source: https://docs.zhinst.com/labone_q_user_manual/applications_library/how-to-guides/sources/03_color_centers/00_shfsg_basic_experiments.ipynb Creates a device setup from a YAML descriptor. Ensure the server host and port are correctly specified. This function is used to initialize the connection to the SHFSG. ```python device_setup = DeviceSetup.from_descriptor( yaml_text=descriptor, server_host=serverhost, server_port="8004", setup_name="SHFSG_Standalone", ) calibrate_devices(device_setup) return device_setup ``` -------------------------------- ### Get Baseline Calibration Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/02_logical_signals/tutorials/01_calibration.ipynb Retrieves a baseline calibration object from the device setup. This object represents the current hardware configuration and is used as a starting point for further calibrations. ```python calibration = device_setup.get_calibration() ``` -------------------------------- ### Set up Demo Platform and Session Source: https://docs.zhinst.com/labone_q_user_manual/applications_library/tutorials/sources/experiment_workflow_automation.ipynb Initializes a demo platform with six qubits, sets up the QPU and qubits, and establishes a connected session for emulation. ```python qt_platform = demo_platform(n_qubits=6) setup = qt_platform.setup qpu = qt_platform.qpu qubits = qpu.quantum_elements session = Session(setup) session.connect(do_emulation=True) ``` -------------------------------- ### Linear Frequency Sweep Example Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/03_sections_pulses/tutorials/03_frequency_sweep_examples.ipynb This example demonstrates how to set up and simulate a linear frequency sweep. It defines the start, stop, and count for the sweep parameters and then calls the simulation function. ```python # Linear frequency sweep parameters freq_sweep_linear = LinearSweepParameter( uid="linear_frequency", start=50e6, # -50 MHz relative to LO (6.95 GHz) stop=100e6, # +50 MHz relative to LO (7.05 GHz) count=5, # 101 frequency points (1 MHz steps) ) compile_and_simulate_experiment(freq_sweep_linear) ``` -------------------------------- ### General Imports and Definitions Source: https://docs.zhinst.com/labone_q_user_manual/applications_library/how-to-guides/sources/01_superconducting_qubits/02_pulse_sequences/02_advanced_qubit_experiments/04_parallel_qubit_tuneup_shfqc_hdawg_pqsc.ipynb Imports essential libraries for LabOne Q, plotting, and device setup generation. Ensure these are installed before running. ```python # LabOne Q: import matplotlib.pyplot as plt import numpy as np from laboneq.contrib.example_helpers.generate_device_setup import ( generate_device_setup_qubits, ) # plotting functionality from laboneq.contrib.example_helpers.plotting.plot_helpers import ( plot_results, ) from laboneq.simple import * ``` -------------------------------- ### Import LabOne Q and Helper Modules Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/03_sections_pulses/tutorials/01_pulse_library.html Imports necessary libraries for LabOne Q, plotting, and device setup generation. Ensure these are installed. ```python # LabOne Q: import matplotlib.pyplot as plt import numpy as np # Helpers: from laboneq.contrib.example_helpers.generate_device_setup import ( generate_device_setup_qubits, ) from laboneq.contrib.example_helpers.plotting.plot_helpers import plot_simulation from laboneq.simple import * ``` -------------------------------- ### Define device setup and connect to session Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/10_advanced_topics/tutorials/07_PRNG_usage.ipynb Configures the device setup, including adding a data server and instruments like SHFQC, and establishes connections for signal routing. A minimal calibration is also applied. ```python device_setup = DeviceSetup(uid="my_QCCS") device_setup.add_dataserver(host="localhost", port="8004") device_setup.add_instruments( SHFQC(uid="device_shfqc", address="dev12345", device_options="SHFQC/QC6CH") ) device_setup.add_connections( "device_shfqc", create_connection(to_signal="q0/drive_line", ports="SGCHANNELS/0/OUTPUT"), create_connection(to_signal="q0/measure_line", ports="QACHANNELS/0/OUTPUT"), create_connection(to_signal="q0/acquire_line", ports="QACHANNELS/0/INPUT"), ) # set a minimal calibration to device setup drive_lo = Oscillator(frequency=1e9) measure_lo = Oscillator(frequency=4e9) cal = Calibration() cal["/logical_signal_groups/q0/drive_line"] = SignalCalibration( local_oscillator=drive_lo ) cal["/logical_signal_groups/q0/measure_line"] = SignalCalibration( ``` -------------------------------- ### Create LabOne Q Session and Connect Source: https://docs.zhinst.com/labone_q_user_manual/applications_library/how-to-guides/sources/01_superconducting_qubits/02_pulse_sequences/02_advanced_qubit_experiments/01_randomized_benchmarking.ipynb Initializes a LabOne Q session with the defined device setup and connects to the LabOne server. Set `emulate` to `True` for simulation without hardware. ```python emulate = True # perform experiments in emulation mode only? my_session = Session(device_setup=device_setup) my_session.connect(do_emulation=emulate) ``` -------------------------------- ### Python Imports for LabOne Q Examples Source: https://docs.zhinst.com/labone_q_user_manual/applications_library/how-to-guides/sources/01_superconducting_qubits/02_pulse_sequences/01_tuneup/12_length_rabi_experiment_shfsg_shfqa_shfqc_hdawg.ipynb Imports necessary helper functions for device setup and plotting, along with core LabOne Q functionalities. ```python # Helpers: from laboneq.contrib.example_helpers.generate_device_setup import ( generate_device_setup_qubits, ) from laboneq.contrib.example_helpers.plotting.plot_helpers import * # LabOne Q: from laboneq.simple import * ``` -------------------------------- ### Python Imports for LabOne Q Examples Source: https://docs.zhinst.com/labone_q_user_manual/applications_library/how-to-guides/sources/01_superconducting_qubits/02_pulse_sequences/01_tuneup/09_e-f_gate_tuneup_shfsg_shfqc.ipynb Imports necessary helper functions for device setup and plotting, along with the core LabOne Q library. ```python # Helpers: from laboneq.contrib.example_helpers.generate_device_setup import ( generate_device_setup_qubits, ) from laboneq.contrib.example_helpers.plotting.plot_helpers import plot_simulation # LabOne Q: from laboneq.simple import * ``` -------------------------------- ### Define and configure a simple device setup Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/10_advanced_topics/tutorials/04_advanced_sweeping_examples.ipynb Sets up a basic device configuration including a dataserver and instruments like SHFQC. It also defines signal connections and applies a minimal calibration with local oscillator frequencies. ```python # construct a simple device setup device_setup = DeviceSetup(uid="my_QCCS") device_setup.add_dataserver(host="localhost", port="8004") device_setup.add_instruments( SHFQC(uid="device_shfqc", address="dev12345", device_options="SHFQC/QC6CH"), ) device_setup.add_connections( "device_shfqc", create_connection(to_signal="q0/drive_line", ports="SGCHANNELS/0/OUTPUT"), create_connection(to_signal="q1/drive_line", ports="SGCHANNELS/1/OUTPUT"), create_connection(to_signal="q2/drive_line", ports="SGCHANNELS/2/OUTPUT"), create_connection(to_signal="q0/measure_line", ports="QACHANNELS/0/OUTPUT"), create_connection(to_signal="q0/acquire_line", ports="QACHANNELS/0/INPUT"), ) # set a minimal calibration to the device setup drive_lo = Oscillator(frequency=1e9) measure_lo = Oscillator(frequency=4e9) cal = Calibration() cal["/logical_signal_groups/q0/drive_line"] = SignalCalibration( local_oscillator=drive_lo ) cal["/logical_signal_groups/q1/drive_line"] = SignalCalibration( local_oscillator=drive_lo ) cal["/logical_signal_groups/q2/drive_line"] = SignalCalibration( local_oscillator=drive_lo ) cal["/logical_signal_groups/q0/measure_line"] = SignalCalibration( local_oscillator=measure_lo ) cal["/logical_signal_groups/q0/acquire_line"] = SignalCalibration( local_oscillator=measure_lo ) device_setup.set_calibration(cal) ``` -------------------------------- ### Calibrate Devices Function Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/10_advanced_topics/tutorials/01_neartime_callbacks.ipynb A function to modify calibration settings on a given device setup. This example shows how to access and set parameters for qubit drive lines. ```python # functions that modifies the calibration on a given device setup def calibrate_devices(device_setup): ## qubit 0 # calibration setting for drive line for qubit 0 device_setup.logical_signal_groups["q0"].logical_signals[ "drive_line" ] ``` -------------------------------- ### Initialize DeviceSetup Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/00_device_setup/tutorials/00_device_setup.ipynb Creates a new DeviceSetup instance, typically named after the system it represents, like "ZI_QCCS". ```python device_setup = DeviceSetup("ZI_QCCS") ``` -------------------------------- ### Update Qubit Calibration Parameters Source: https://docs.zhinst.com/labone_q_user_manual/applications_library/how-to-guides/sources/01_superconducting_qubits/02_pulse_sequences/02_advanced_qubit_experiments/04_parallel_qubit_tuneup_shfqc_hdawg_pqsc.ipynb Provides a commented-out example for updating qubit parameters, such as readout resonator frequency, and applying these updates to the device setup calibration. ```python # update qubit parameters from analysis # for qubit in my_qubits: # qubit.parameters.readout_resonator_frequency = my_new_frequency # device_setup.set_calibration(qubit.calibration()) ``` -------------------------------- ### Import necessary libraries for LabOne Q Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/10_advanced_topics/tutorials/04_advanced_sweeping_examples.ipynb Imports standard libraries and specific modules from LabOne Q for experiment setup, DSL, and plotting. Ensure these are installed in your environment. ```python from __future__ import annotations import numpy as np from laboneq.contrib.example_helpers.plotting.plot_helpers import plot_simulation from laboneq.dsl.experiment.builtins import * from laboneq.simple import * ``` -------------------------------- ### Connect and Run Experiment Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/05_experiment/tutorials/00_experiment_definition_reference.ipynb Establish a session with the device setup and connect to the server, optionally enabling emulation. Then, run the defined experiment and retrieve the results. ```python session = Session(device_setup=device_setup) session.connect(do_emulation=True) my_results = session.run(exp) ``` -------------------------------- ### Import LabOne Q Packages Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/03_sections_pulses/tutorials/00_section_tutorial.ipynb Import necessary modules from the LabOne Q library for creating experiments and generating device setups. Ensure LabOne Q is installed. ```python # Import required packages from laboneq.contrib.example_helpers.generate_device_setup import ( generate_device_setup_qubits, ) from laboneq.simple import * ``` -------------------------------- ### Handle Duplicate Instrument IDs Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/00_device_setup/tutorials/00_device_setup.ipynb Attempting to add an instrument with an ID that already exists in the device setup will raise a LabOneQException. This example demonstrates how to catch this expected exception. ```python try: device_setup.add_instruments(PQSC(uid="pqsc")) except: print("LabOneQException as expected: Instrument already in device setup") ``` -------------------------------- ### Load Device Setup and QPU from Files Source: https://docs.zhinst.com/labone_q_user_manual/applications_library/how-to-guides/sources/01_superconducting_qubits/03_tuneup_guides/02_tuneup_twpa.ipynb Loads a pre-existing DeviceSetup and QPU object from JSON files using the serializers module. This is an alternative to creating them from scratch. ```python from laboneq import serializers setup = serializers.load(full_path_to_device_setup_file) qpu = serializers.load(full_path_to_qpu_file) twpas = qpu.twpas qops = qpu.quantum_operations ``` -------------------------------- ### Set up a demonstration quantum platform Source: https://docs.zhinst.com/labone_q_user_manual/applications_library/tutorials/sources/logbooks.ipynb Creates a `QuantumPlatform` for a tunable-transmon QPU with 6 qubits. This includes the `DeviceSetup`, `QPU` object, and a list of `TunableTransmonQubit` elements. ```python # Create a demonstration QuantumPlatform for a tunable-transmon QPU: qt_platform = demo_platform(n_qubits=6) # The platform contains a setup, which is an ordinary LabOne Q DeviceSetup: setup = qt_platform.setup # And a tunable-transmon QPU: qpu = qt_platform.qpu # Inside the QPU, we have quantum elements, which is a list of six LabOne Q Application # Library TunableTransmonQubit qubits: qubits = qpu.quantum_elements ``` -------------------------------- ### LabOne Q Imports and Helper Functions Source: https://docs.zhinst.com/labone_q_user_manual/applications_library/how-to-guides/sources/01_superconducting_qubits/02_pulse_sequences/01_tuneup/01_spec_uhfqa_hdawg.ipynb Imports necessary modules from `laboneq.simple` and helper functions for device setup and plotting. Ensure these imports are present before running the examples. ```python from pathlib import Path # Helpers: from laboneq.contrib.example_helpers.generate_device_setup import ( generate_device_setup_qubits, ) from laboneq.contrib.example_helpers.plotting.plot_helpers import ( plot_results, plot_simulation, ) # LabOne Q: from laboneq.simple import * ``` -------------------------------- ### Python Imports for LabOne Q Examples Source: https://docs.zhinst.com/labone_q_user_manual/applications_library/how-to-guides/sources/01_superconducting_qubits/02_pulse_sequences/01_tuneup/14_Ramsey_experiment_sampled_pulse_shfsg_shfqa_shfqc_hdawg.ipynb Imports necessary libraries including NumPy and helper functions for device setup and plotting, along with core LabOne Q functionalities. ```python import numpy as np # Helpers: from laboneq.contrib.example_helpers.generate_device_setup import ( generate_device_setup_qubits, ) from laboneq.contrib.example_helpers.plotting.plot_helpers import * # LabOne Q: from laboneq.simple import * ``` -------------------------------- ### Connect Session and Run Experiment Source: https://docs.zhinst.com/labone_q_user_manual/applications_library/how-to-guides/sources/02_spin_qubits/04_HDAWG_pulse_sequences.ipynb Establishes a connection to the device setup, sets the signal map for the experiment, and runs the compiled experiment. Ensure `DO_EMULATION` is set appropriately. ```python # create and connect to session session = Session(device_setup=device_setup) session.connect(do_emulation=DO_EMULATION) # set signal map exp.set_signal_map(map_q0) _ = session.run(exp) ``` -------------------------------- ### LabOne Q Imports Source: https://docs.zhinst.com/labone_q_user_manual/applications_library/how-to-guides/sources/01_superconducting_qubits/02_pulse_sequences/01_tuneup/01_cw_resonator_spec_shfsg_shfqa_shfqc.ipynb Imports necessary modules from `laboneq.simple` and helper functions for generating device setups and plotting results. This is the standard starting point for LabOne Q experiments. ```python import time from pathlib import Path # Helpers: from laboneq.contrib.example_helpers.generate_device_setup import ( generate_device_setup_qubits, ) from laboneq.contrib.example_helpers.plotting.plot_helpers import plot_results # LabOne Q: from laboneq.simple import * ``` -------------------------------- ### Create a demo QuantumPlatform Source: https://docs.zhinst.com/labone_q_user_manual/applications_library/tutorials/sources/experiment_workflows.ipynb Initializes a demonstration QuantumPlatform for a tunable-transmon QPU with a specified number of qubits. This is used for running experiments in emulation mode. ```python # Create a demonstration QuantumPlatform for a tunable-transmon QPU: qt_platform = demo_platform(n_qubits=6) ``` -------------------------------- ### General Imports for LabOne Q Source: https://docs.zhinst.com/labone_q_user_manual/applications_library/how-to-guides/sources/02_spin_qubits/03_UHFLI_pulsed_acquisition.ipynb Imports necessary libraries for LabOne Q, including logging, time, unittest.mock, matplotlib, numpy, and the simple API. This setup is required for running the subsequent code examples. ```python # additional import for the purpose of demonstration import logging import time from unittest.mock import MagicMock import matplotlib.pyplot as plt import numpy as np from laboneq.simple import * mylogger = logging.getLogger("neartime_callback") ``` -------------------------------- ### Create DeviceSetup from Descriptor String Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/00_device_setup/concepts/index.html Instantiate a DeviceSetup object using a descriptor string, specifying server host, port, and a setup name. This method is useful for defining setups directly within your code. ```python device_setup = DeviceSetup.from_descriptor( descriptor, server_host="111.22.33.44", server_port="8004", setup_name="ZI_QCCS", ) ``` -------------------------------- ### Create Device Setup from Descriptor Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/00_device_setup/tutorials/00_device_setup.ipynb Construct a `DeviceSetup` instance from a device descriptor string. This method allows for defining instruments, their addresses, UIDs, options, and connections in a human-readable format. Ensure the server host and port are correctly specified. ```python descriptor = """\ instruments: PQSC: - address: dev10001 uid: pqsc options: PQSC SHFQA: - address: dev12000 uid: shfqa options: SHFQA4 SHFSG: - address: dev12001 uid: shfsg options: SHFSG8/RTR connections: shfsg: - iq_signal: q0/drive ports: SGCHANNELS/0/OUTPUT shfqa: - iq_signal: q0/measure ports: QACHANNELS/0/OUTPUT - acquire_signal: q0/acquire ports: QACHANNELS/0/INPUT """ device_setup_from_descriptor = DeviceSetup.from_descriptor( descriptor, server_host="111.22.33.44", server_port="8004", ) ``` -------------------------------- ### Device Descriptor for PQSC and SHF Instruments Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/00_device_setup/tutorials/00_device_setup.ipynb A device descriptor example for setups using SHF series instruments (SHFSG, SHFQA, SHFQC), highlighting their single-port requirement per signal line due to integrated conversion. ```yaml descriptor = """\ instruments: SHFSG: - address: DEV12000 uid: shfsg options: SHFSG8/RTR SHFQA: - address: DEV12001 uid: shfqa ``` -------------------------------- ### Create Device Setup Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/10_advanced_topics/tutorials/03_waveform_replacement.ipynb Generates a device setup and qubit objects using helper functions. Specify the number of qubits and optionally configure SHFQCs and server details. This function is useful for setting up a multi-qubit system. ```python # specify the number of qubits you want to use number_of_qubits = 2 # generate the device setup and the qubit objects using a helper function device_setup, qubits = generate_device_setup_qubits( number_qubits=number_of_qubits, shfqc=[ { "serial": "DEV12001", "zsync": 1, "number_of_channels": 6, "readout_multiplex": 6, "options": None, } ], include_flux_lines=False, server_host="localhost", setup_name=f"my_{number_of_qubits}_fixed_qubit_setup", ) q0, q1 = qubits[:2] ``` -------------------------------- ### Initialize LabOne Q Session with Emulation Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/10_advanced_topics/tutorials/00_output_simulator.ipynb Initializes a LabOne Q session with the generated device setup. Set `do_emulation=True` to use the output simulator without hardware. ```python use_emulation = True # create a session session = Session(device_setup) # connect to session session.connect(do_emulation=use_emulation) ``` -------------------------------- ### Device Setup for a Single HDAWG Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/00_device_setup/tutorials/00_device_setup.ipynb Configures a device setup for a standalone HDAWG. This setup is used when only an HDAWG is needed for signal generation. ```python descriptor = """\ instruments: HDAWG: - address: dev8000 uid: hdawg options: HDAWG8/CNT/MF/ME/PC/SKW/IQ connections: hdawg: - iq_signal: q0/drive ports: [SIGOUTS/0, SIGOUTS/1] - rf_signal: q0/flux ports: [SIGOUTS/2] """ device_single_hdawg = DeviceSetup.from_descriptor( descriptor, server_host="111.22.33.44", server_port="8004", ) ``` -------------------------------- ### Install scikit-optimize Source: https://docs.zhinst.com/labone_q_user_manual/applications_library/how-to-guides/sources/01_superconducting_qubits/02_pulse_sequences/02_advanced_qubit_experiments/03_neartime_gate_fidelity_optimization.ipynb Installs the scikit-optimize package required for this notebook. ```python # Package installation for this notebook %pip install scikit-optimize ``` -------------------------------- ### Configure Device Setup and Session Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/03_sections_pulses/tutorials/04_subsampling.ipynb Sets up a LabOne Q device configuration, including connecting to a data server, defining an HDAWG instrument, setting up signal connections, and applying calibration. Finally, it establishes a session with the LabOne data server, enabling emulation. ```python # Create the `DeviceSetup` and add the information about the data server it should connect to. device_setup = DeviceSetup("ZI_HDAWG") device_setup.add_dataserver( host="localhost", port="8004", ) # Create a `HDAWG` instrument, which was imported from `laboneq.simple`, and add it to the `DeviceSetup`. # When creating the instrument instance, you need to specify the device ID under `address`; for example, `dev8123`. hdawg = HDAWG( uid="hdawg", interface="1GbE", address="dev8123", device_options="HDAWG8/MF/ME/CNT/PC", reference_clock_source="internal", ) device_setup.add_instruments(hdawg) # Create a flux lines for a qubit (signal type is "rf") device_setup.add_connections( "hdawg", create_connection(to_signal="q0/flux", ports="SIGOUTS/0", type="rf"), ) # Configure the `Calibration` of the signal lines of the `DeviceSetup`. config = Calibration() config["q0/flux"] = SignalCalibration(voltage_offset=0.0, range=5.0) # Apply the configuration to the DeviceSetup device_setup.set_calibration(config) # Connect to the LabOne data server via the LabOne Q Session session = Session(device_setup) session.connect(do_emulation=True) # do_emulation=True when at a physical setup ``` -------------------------------- ### Load Qubits from Device Setup Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/04_quantum_processing_unit/tutorials/01_quantum_elements.ipynb Load qubit objects from a previously generated device setup. Ensure the `Transmon` class matches the quantum element type in your setup. ```python qubits = Transmon.from_device_setup(device_setup) ``` -------------------------------- ### Device Setup with SHFQA LRT Option Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/10_advanced_topics/tutorials/10_long_readout_time.ipynb Generates a device setup including qubits, specifying the SHFQA instrument with the 'SHFQA4/LRT' option enabled. This setup is for a tuneable qubit system. ```python # specify the number of qubits you want to use number_of_qubits = 2 # generate the device setup and the qubit objects using a helper function device_setup, qubits = generate_device_setup_qubits( number_qubits=number_of_qubits, pqsc=[{"serial": "DEV10056"}], shfsg=[ { "serial": "DEV12001", "zsync": 1, "number_of_channels": 8, "options": "SHFSG8/RTR", } ], shfqa=[ { "serial": "DEV12002", "zsync": 2, "number_of_channels": 4, "readout_multiplex": 6, "options": "SHFQA4/LRT", } ], include_flux_lines=False, server_host="localhost", setup_name=f"my_{number_of_qubits}_tuneable_qubit_setup", ) q0, q1 = qubits[:2] ``` -------------------------------- ### Run Calibrate Cancellation Workflow Source: https://docs.zhinst.com/labone_q_user_manual/applications_library/reference/contrib/experiments/calibrate_cancellation.html This example demonstrates how to set up and run the `experiment_workflow` for cancellation tone calibration. It shows how to configure workflow options, define the QPU with a parametric amplifier, and pass the required cancellation parameters. The `.run()` method executes the workflow. ```python options = experiment_workflow.options() options.create_experiment.count(10) pa = TWPA("twpa0") qpu = QPU( qubits=[pa], quantum_operations=TWPAOperations(), ) temp_pas = qpu_copy_elements() result = experiment_workflow( session=session, qpu=qpu, parametric_amplifier=pa, cancel_phase=[0.0, 0.1], cancel_attenuation=[0.1, 0.5], options=options, ).run() ``` -------------------------------- ### Generate Device Setup Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/02_logical_signals/tutorials/01_calibration.ipynb Generates a device setup for a specified number of qubits, configuring instruments like PQSC, HDAWG, SHFQA, and SHFSG. This setup is a prerequisite for creating calibrations. ```python # specify the number of qubits you want to use number_of_qubits = 1 # generate the device setup and the qubit objects using a helper function device_setup, qubits = generate_device_setup_qubits( number_qubits=number_of_qubits, pqsc=[{"serial": "DEV10001"}], hdawg=[ { "serial": "DEV8001", "number_of_channels": 8, "options": None, } ], shfqa=[ { "serial": "DEV12001", "readout_multiplex": 6, "options": None, } ], shfsg=[ { "serial": "DEV12002", "number_of_channels": 8, "options": None, } ], include_flux_lines=True, server_host="localhost", setup_name=f"my_{number_of_qubits}_tunable_qubit_setup", ) ``` -------------------------------- ### Device Setup with Single HDAWG and Single UHFQA Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/00_device_setup/tutorials/00_device_setup.ipynb Configures a device setup for a single HDAWG and a single UHFQA. This setup is suitable for experiments that require both signal generation and measurement capabilities. ```python descriptor = """\ instruments: HDAWG: - address: dev8000 uid: hdawg options: HDAWG8/CNT/MF/ME/PC/SKW/IQ UHFQA: - address: dev2000 uid: uhfqa options: UHFQA/AWG/DIG/RUB connections: hdawg: - iq_signal: q0/drive ports: [SIGOUTS/0, SIGOUTS/1] - to: uhfqa port: DIOS/0 uhfqa: - iq_signal: q0/measure ports: [SIGOUTS/0, SIGOUTS/1] - acquire_signal: q0/acquire """ device_setup_small = DeviceSetup.from_descriptor( descriptor, server_host="111.22.33.44", server_port="8004", ) ``` -------------------------------- ### OpenQASM Exception Example Source: https://docs.zhinst.com/labone_q_user_manual/core/reference/openqasm3.html An example of an OpenQASM exception highlighting an error in the source code. ```text Unknown identifier 'frame0' | play(frame0, 10ns); ^ ``` -------------------------------- ### Create DeviceSetup for SHFQC+ Source: https://docs.zhinst.com/labone_q_user_manual/applications_library/how-to-guides/sources/01_superconducting_qubits/01_workflows/02_resonator_spectroscopy_dcbias.ipynb Instantiate a DeviceSetup for an SHFQC+ instrument with a PQSC. Adjust device numbers and parameters to match your hardware configuration. ```python device_setup = DeviceSetup( instruments=[ Instrument( name="shfsg_1", type=InstrumentType.SHFSG, device_id="DEV12345", port_map=[ PortMapping(port=1, signal="sg_1") ], ), Instrument( name="shfqa_1", type=InstrumentType.SHFQA, device_id="DEV67890", port_map=[ PortMapping(port=1, signal="qa_1") ], ), Instrument( name="pqsc", type=InstrumentType.PQSC, device_id="DEV11223", ), ], connect_args=ConnectArgs(setup_device=True), ) ``` -------------------------------- ### Generate SHFQC Device Setup Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/10_advanced_topics/tutorials/09_signal_muting.ipynb Creates a device setup for SHFQC instruments, specifying the number of qubits and instrument configurations. ```python # specify the number of qubits you want to use number_of_qubits = 6 # generate the device setup and the qubit objects using a helper function device_setup, qubits = generate_device_setup_qubits( number_qubits=number_of_qubits, pqsc=[{"serial": "DEV10001"}], hdawg=[{"serial": "DEV8001", "zsync": 0, "number_of_channels": 8, "options": None}], shfqc=[ { "serial": "DEV12001", "zsync": 1, "number_of_channels": 6, "readout_multiplex": 6, "options": None, } ], include_flux_lines=True, server_host="localhost", setup_name=f"my_{number_of_qubits}_tuneable_qubit_setup", ) ``` -------------------------------- ### Specify Number of Qubits Source: https://docs.zhinst.com/labone_q_user_manual/core/functionality_and_concepts/04_quantum_processing_unit/tutorials/00_quantum_operations.ipynb Sets the desired number of qubits for the quantum setup. This variable is used in the device setup generation. ```python # specify the number of qubits you want to use number_of_qubits = 3 ```