QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
HomeLearnCatalogRanksPlaygroundDocs
07 · Two languages: OpenQASM 3 and Qiskit0%

You are reading without signing in. Sign in or continue as guest to take quizzes and climb the ranks.

Learn/QC 102Gates and Circuits·Lesson 7 of 7

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.

Beginner10 min read4 sections · 2 questions+45
By the end you will be able to
  1. 01Translate a short Qiskit script to OpenQASM 3 by hand.
  2. 02Know which Python constructs the translator accepts.
  3. 03Explain how the IDE's translator differs from running Python in the Playground sandbox.
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])
Same circuit, two spellings. Qubit indices become q[i]; measure(q, c) becomes c[i] = measure q[j].
Sign in to run (nothing is saved)
Open the Python in the IDE Run in the Playground

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.
Hands-on

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
OPENQASM 3.0;
include "stdgates.inc";
qubit[2] q;
bit[2] c;
h q[0];
cx q[0], q[1];
c = measure q;
Sign in to run (nothing is saved)
Open in the IDE Open in the Playground
Knowledge check

2 questions · one try each counts

Question 1

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.

Question 2

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.

Key takeaway

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.

Finished reading?

Knowledge check: 2 questions waiting above. Questions are optional. Mark it complete, or press Next: moving on marks it complete too.

Up next
QC 201 · Dynamic Circuits · 10 min
Measuring in the middle
What changes when a measurement is followed by more gates, and why statevector tools step aside.
Further reading
  • Docs: OpenQASM 3 reference
More in Gates and Circuits
  • Pauli gates: X, Y, Z
  • Phase and rotation gates
  • Two-qubit gates: CNOT, CZ, SWAP
Reading a circuit: depth, width and costMeasuring in the middle
In this lesson0%
  1. Introduction
  2. Try it: Round trip
  3. Knowledge check
  4. Key takeaway
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in