You are reading without signing in. Sign in or continue as guest to take quizzes and keep XP.
Two languages: OpenQASM 3 and Qiskit
How the same circuit is written in both, and how QubitLab keeps them in sync without running your code.
- Translate a short Qiskit script to OpenQASM 3 by hand.
- Know which Python constructs the translator accepts.
- Explain why the Playground never executes Python.
from qiskit import QuantumCircuit from numpy import pi qc = QuantumCircuit(2, 2) qc.h(0) qc.cx(0, 1) qc.rz(pi/4, 1) qc.measure([0, 1], [0, 1])
OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; bit[2] c; h q[0]; cx q[0], q[1]; rz(pi/4) q[1]; c[0] = measure q[0]; c[1] = measure q[1];
QubitLab treats OpenQASM 3 as the single source of truth: the composer, the simulators and the hardware jobs all read QASM. Python is read by a translator that walks the abstract syntax tree and recognises QuantumCircuit calls, gate methods, measure, barrier, for-range loops, constant arithmetic with pi, and the control-flow builders (if_test, while_loop, for_loop, switch). Nothing is executed, so a script can never read your files or call the network.
- Accepted: qc.h(0), qc.cx(0, 1), qc.rx(pi/2, 0), qc.measure(0, 0), qc.measure_all(), qc.barrier(), for i in range(n): …, with qc.if_test((c[0], 1)): …
- Ignored with a warning: transpile(), AerSimulator(), draw(), print()
- Rejected with a line number: anything whose value is not a literal, such as random numbers or file reads.
Round trip
Open the circuit, switch the code panel to Python: QubitLab writes the Qiskit script from the circuit. Edit a line (change cx to cz) and watch the QASM and the drawing follow.
OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; bit[2] c; h q[0]; cx q[0], q[1]; c = measure q;
What does QubitLab do with a Python script you paste?
Sign in to answer and earn XP; you will come back to this lesson.
Which OpenQASM 3 line measures qubit 2 into bit 0?
Sign in to answer and earn XP; you will come back to this lesson.
OpenQASM 3 is the circuit; Qiskit Python is a convenient way to write it. QubitLab translates between them by reading syntax, never by executing code.
Up next: Measuring in the middle · Dynamic Circuits