How qm-labs/qm-qua-sdk-public works
1. What this repo is
- qm-qua is a Python SDK for Quantum Machines’ OPX/QOP stack.
- It serves two main roles: a Pythonic DSL for writing QUA programs, and a client layer for submitting, running, simulating, and monitoring those programs on external Quantum Machines services/hardware.
2. Public package boundary
- The top-level qm package exposes the main user-facing objects such as the quantum machine manager and quantum machine abstractions.
- Everything else is organized as supporting layers: language construction, program conversion, API clients, job/result handling, simulation, and Octave integration.
3. QUA language layer
- qm/qua is the DSL implementation.
- It contains scope management, expression handling, type hints, variable handling, pulses/waits/play/measure primitives, stream processing, and iterator extensions.
- This layer is where users build a QUA program in Python before it is serialized or submitted.
4. Program construction and serialization
- qm/program and qm/serialization are the bridge from Python DSL objects to backend-facing program/config representations.
- The program layer validates and normalizes configuration data, fills defaults, and converts dict-based configs into protobuf-friendly structures.
- The serialization layer walks QUA AST-like structures and emits the script/protocol payloads expected by the backend.
5. Configuration and element modeling
- qm/elements, qm/elements_db.py, and qm/containers model hardware elements, inputs/outputs, and capability metadata.
- qm/type_hinting and qm/utils/config_utils.py support structured config objects and validation.
- This is the boundary where user configuration is turned into a machine-usable description of channels, pulses, mixers, oscillators, and integrations.
6. Backend API layer
- qm/api contains the client APIs for talking to QOP-related services.
- It includes frontend, info, job manager, job result, simulation, server detection, and model classes.
- qm/api/v2 is a newer API surface with job APIs, job-result APIs, and QMM/QM clients; qm/api/stubs and qm/api/models support compatibility and structured transport data.
- The repo clearly separates transport/API concerns from the DSL and business logic.
7. Job lifecycle and execution tracking
- qm/jobs models job states and transitions: pending, running, simulated, queueing, and deprecated/legacy queue paths.
- This layer sits between “submitted program” and “live execution,” and it abstracts over old and new API behaviors.
- Job objects likely own metadata, identifiers, execution state, and access to results.
8. Live result streaming
- qm/_stream_results manages streaming result retrieval, including single-stream and multi-stream fetchers plus a streams manager.
- This is the data plane for incremental measurement results rather than only final outputs.
- The design suggests asynchronous or chunked consumption from backend result channels, with utility code for coordinating multiple streams.
9. Simulation path
- qm/simulate provides simulation interfaces, loopback support, raw simulation, and credentials.
- qm/results/simulator_samples.py and the simulated job APIs connect simulated execution to the same job/result abstractions used by real hardware runs.
- This keeps simulation close to production semantics while still being a separate execution path.
10. Octave subsystem
- qm/octave and qm/octave_sdk are dedicated to Octave hardware integration and calibration workflows.
- They include Octave client communication, connectivity, health monitoring, conflict management, calibration DB/configuration, and mixer calibration utilities.
- Architecturally, this is a distinct hardware-control boundary used to configure and maintain RF/control hardware alongside the OPX workflow.
11. Operational and support utilities
- qm/logger.py, qm/logging_utils.py, qm/datadog_api.py, and qm/persistence.py support observability and state persistence.
- qm/exceptions.py, qm/utils, and qm/type_hinting provide shared error handling, helpers, and typing support.
- qm/waveform_report and qm/results provide reporting/inspection utilities for generated waveforms and simulation samples.
12. Overall data flow
- Typical flow: user writes QUA in qm/qua → program/config are validated and serialized → API clients submit to QOP/OPX services → job objects track execution → result streams are consumed through _stream_results → optional waveform/reporting tools render outputs.
- Simulation and Octave calibration are parallel subsystems that feed into the same program/job execution boundary, but they interact with different external services/hardware.
Main entry points: v2 API v2 · qua QUA DSL · program Program build · utils Utils
Components 21
QUA DSL
Python-side language building and scope management
- QUA DSL · Python DSL for building QUA programs
qm/qua - Scopes · Scope stack and lifecycle control for nested QUA construction
qm/qua/_scope_management - Expressions · Expression objects, type hints, and shared DSL utilities
qm/qua/_expressions.py - Primitives · Play, measure, wait, phase, stream, and variable primitives
qm/qua/_dsl - Streams · Input/output streams and stream processing constructs
qm/qua/_dsl/stream_processing
Program build
Configuration validation and script serialization
- Program build · Validates config and prepares backend-facing program structures
qm/program - Validate config · Schema checks and default filling for configuration data
qm/program/_validate_config_schema.py - Config convert · Converts dict-based config into protobuf-friendly backend structures
qm/program/_dict_to_pb_converter - Serialize · Walks QUA AST-like structures and emits script/protocol payloads
qm/serialization
Runtime APIs
Submission, job control, and result access
- API v2 · Newer client surface for QMM, QM, job, and result APIs
qm/api/v2 - API v1 · Legacy frontend, info, job manager, and simulation APIs
qm/api - Jobs · Pending, running, simulated, and queueing job state abstractions
qm/jobs - Result streams · Incremental result retrieval and multi-stream coordination
qm/_stream_results - Simulation · Simulation interfaces, loopback, raw simulation, and credentials
qm/simulate
Hardware integration
Octave and machine-facing control layers
- Octave · Octave integration, calibration, health, and connectivity management
qm/octave - Octave SDK · Lower-level Octave client, connectivity, and conflict handling
qm/octave_sdk
Support
Shared utilities, types, and reporting
Other components
- qm · Top-level user-facing package boundary exposing manager and machine objects
qm/__init__.py - Quantum machine · Machine/session abstraction bridging user code to backend execution
qm/QuantumMachine.py - Manager · Quantum machines manager and high-level orchestration entrypoint
qm/quantum_machines_manager.py
Connections 25
- qm → Manager: exposes · Public package exports the manager entrypoint
- qm → Quantum machine: exposes · Public package exports machine/session objects
- Manager → API v2: uses · Manager orchestrates modern API clients
- Quantum machine → API v2: uses · Machine object submits jobs and reads results through client APIs
- QUA DSL → Scopes: depends on · DSL constructs rely on scope tracking
- QUA DSL → Expressions: depends on · DSL primitives build and combine expressions
- QUA DSL → Primitives: contains · Core measurement, pulse, wait, and variable operations
- QUA DSL → Streams: contains · Stream processing and stream declarations live here
- QUA DSL → Program build: builds into · DSL output is normalized into backend-ready program structures
- Program build → Validate config: validates · Program layer checks and fills configuration defaults
- Program build → Config convert: normalizes · Turns config dictionaries into protobuf-friendly objects
- Program build → Serialize: feeds · Prepared program data is serialized for backend submission
- Serialize → API v2: payload for · Serialized scripts and protocol payloads are sent through APIs
- API v1 → Jobs: creates · Legacy APIs still surface job abstractions
- API v2 → Jobs: creates · Job APIs instantiate and manage execution objects
- Jobs → Result streams: reads · Job objects expose incremental result consumption
- API v2 → Result streams: streams · Result APIs provide live and final result transport
- API v2 → Simulation: supports · Client APIs cover simulation execution paths
- Simulation → Results: produces · Simulation path reuses sample/result representations
- Octave → Octave SDK: built on · High-level Octave workflows sit on the lower-level SDK
- Octave → Manager: configures · Octave calibration and setup support machine orchestration
- Results → Result streams: consumed by · Result helpers complement streamed measurement consumption
- Utils → Program build: supports · Config and protobuf utilities back program construction
- Utils → API v2: supports · Shared helpers and type utilities support clients and transport
- Utils → QUA DSL: supports · General helpers and type support are shared by the DSL