{"id":21665,"library":"oqpy","title":"oqpy","description":"oqpy is a Python library for generating OpenQASM 3 + OpenPulse programs programmatically. Current version is 0.3.10, with a monthly-to-quarterly release cadence.","status":"active","version":"0.3.10","language":"python","source_language":"en","source_url":"https://github.com/openqasm/oqpy","tags":["openqasm","quantum","openpulse","quantum-circuit","qasm3"],"install":[{"cmd":"pip install oqpy","lang":"bash","label":"default"}],"dependencies":[],"imports":[{"note":"Program is exported at the top-level oqpy package.","wrong":"from oqpy.program import Program","symbol":"Program","correct":"from oqpy import Program"},{"note":"No common mistake.","symbol":"Measurement","correct":"from oqpy import Measurement"}],"quickstart":{"code":"from oqpy import Program\n\n# Create a quantum program\nprogram = Program()\n# Declare a qubit register\nq = program.declare_qubit('q', size=2)\n# Add a gate\nprogram.gate(\"h\", q[0])\n# Measure\nprogram.measure(q[0], program.declare_bit('c'))\n# Output OpenQASM 3\nprint(program.to_qasm())","lang":"python","description":"Create a simple OpenQASM 3 program with two qubits, apply Hadamard, and measure."},"warnings":[{"fix":"Update to use `declare_qubit`, `declare_bit`, `declare_float`, etc.","message":"In v0.3.0, the API for declaring variables changed. Use `program.declare_qubit()` instead of `program.qubit()`.","severity":"breaking","affected_versions":"<0.3.0"},{"fix":"Add `return_type` argument to `program.extern()` calls.","message":"The `extern` function signature changed; now requires `return_type` parameter.","severity":"deprecated","affected_versions":"<0.3.5"},{"fix":"Use `oqpy.slice(start, stop, step)` instead of Python's built-in slice.","message":"When using array indexing, results in oqpy types are not automatically converted to Python slices. Use `oqpy.slice()` to avoid bugs.","severity":"gotcha","affected_versions":">=0.3.2"},{"fix":"Always use `DurationLiteral` for duration values.","message":"Duration literals must be constructed with `oqpy.DurationLiteral(value, unit)`; plain numbers are not automatically converted.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use `from oqpy import Program`.","cause":"Incorrect import: many examples online use `from oqpy.program import Program` but the correct import is `from oqpy import Program`.","error":"AttributeError: module 'oqpy' has no attribute 'Program'"},{"fix":"Add `return_type` to extern declaration, e.g., `program.extern('my_extern', return_type=oqpy.FloatVar)`.","cause":"In oqpy 0.3.5+, `extern()` requires a `return_type` argument.","error":"TypeError: extern() missing 1 required positional argument: 'return_type'"},{"fix":"Wrap the value in `DurationLiteral`, e.g., `oqpy.DurationLiteral(0, 'ns')`.","cause":"Using plain integers/float where a duration type is expected.","error":"ValueError: Cannot convert value 0 to an OQPY duration"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}