You are reading without signing in. Sign in or continue as guest to take quizzes and climb the ranks.
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.
- 01Translate a short Qiskit script to OpenQASM 3 by hand.
- 02Know which Python constructs the translator accepts.
- 03Explain how the IDE's translator differs from running Python in the Playground sandbox.
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])QubitLab treats OpenQASM 3 as the single source of truth: the composer, the simulators and the hardware jobs all read QASM. In the IDE's code panel, 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 there. The Playground is different: its Python files really run, but in an isolated sandbox with no network, no files and no secrets.
- 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;
2 questions · one try each counts
What does QubitLab do with a Python script you paste?
Sign in to answer and climb the ranks; you will come back to this lesson.
Which OpenQASM 3 line measures qubit 2 into bit 0?
Sign in to answer and climb the ranks; you will come back to this lesson.