use examples

Loading OQFT Circuits Into Qiskit, the Same CX Count After Transpiling but Less Than a Third of the Depth

OQFT writes OpenQASM 3 with three gates from the standard library, h, cp and swap. Anything that reads OpenQASM 3 can take it. Qiskit is the toolkit most people will try first, so this example loads OQFT’s output there, checks it, and runs it through Qiskit’s transpiler.

You need Python with qiskit and qiskit_qasm3_import, and oqft on your PATH.

pip install qiskit qiskit_qasm3_import

Output of the Qiskit example: the 6-qubit oqft QFT equals Qiskit’s QFT matrix; the 256-qubit OQFT loads with 9,400 cp, 496 h and 128 swap gates at depth 158; after transpiling, OQFT has 19,184 CX at depth 624 and Qiskit’s textbook QFT 19,224 CX at depth 2,044.

Load and Check

import subprocess
from qiskit import qasm3
from qiskit.quantum_info import Operator
from qiskit.synthesis import synth_qft_full
import numpy as np

qasm = subprocess.run(["oqft", "gen", "-n", "6"],
                      capture_output=True, text=True, check=True).stdout
circuit = qasm3.loads(qasm)
same = np.allclose(Operator(circuit).data,
                   Operator(synth_qft_full(6, do_swaps=True)).data)
print(same)  # True

OQFT’s 6-qubit textbook QFT has the same matrix as Qiskit’s own, sign and qubit order included. Qubit 0 is the least significant bit in both, so nothing needs reversing.

A 256-Qubit OQFT

qasm = subprocess.run(["oqft", "gen", "--type", "oqft", "-n", "256", "--eps", "0.01"],
                      capture_output=True, text=True, check=True).stdout
big = qasm3.loads(qasm)
print(big.count_ops(), big.depth())

It loads as 9,400 cp, 496 h and 128 swap gates at depth 158, the same counts oqft stats gives. Loading took about 30 seconds on our machine, which is the Python parser working through 10,000 lines. Save the circuit with qpy if you’ll load it again.

Through the Transpiler

Transpiled to cx, rz and sx at optimisation level 1, the optimistic circuit came out at 19,184 CX gates and depth 624. Qiskit’s own textbook QFT, transpiled the same way, came out at 19,224 CX and depth 2,044.

The CX counts are nearly the same, and that’s worth understanding. The textbook circuit on 256 qubits has 32,640 controlled rotations, which would be about 65,000 CX gates. Most of those rotations are so small they change nothing at double precision, and Qiskit’s transpiler drops them. OQFT drops most of the same ones by design. What the transpiler can’t do is reorder the survivors so blocks run side by side. That’s where the depth difference comes from, and it held up after transpiling: 624 layers against 2,044.

The full script is examples/qiskit/load_oqft.py in the repository, and its output is recorded with the Qiskit version it ran on.