QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
HomeLearnCatalogRanksPlaygroundDocs
03 · Transpilation and basis gates0%

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

Learn/QC 203Hardware and Compilation·Lesson 3 of 6

Transpilation and basis gates

What the compiler does in four stages, what the optimisation levels change, and how to read the Compile preview.

Intermediate12 min read4 sections · 2 questions+45
By the end you will be able to
  1. 01List the four transpiler stages.
  2. 02Rewrite an H gate in the {rz, sx, x} basis.
  3. 03Choose an optimisation level and justify it.
  • Init: unroll custom gates to the standard library.
  • Layout: assign each virtual qubit to a physical one, preferring well-connected, low-error qubits.
  • Routing: insert SWAPs so every two-qubit gate acts on neighbours.
  • Translation and optimisation: rewrite in the basis gates and cancel what cancels.
H=Rz​(2π​)X​Rz​(2π​);;(up to a global phase)
IBM machines only run rz, sx, x and one two-qubit gate (CZ on Heron). Every other gate is rewritten; rz is free because it is implemented as a frame change in software.
Hands-on

Watch H become three gates

Press Compile for a fake backend: the preview lists depth and ops before and after, and 'View circuit' shows rz, sx, rz on each qubit plus the native two-qubit gate. Click 'Edit this circuit' to work with the compiled form.

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
LevelWhat it doesUse when
0layout + routing + translation onlyyou want to see the raw mapping
1light optimisation, cancels adjacent inversesdefault for quick runs
2commutation analysis, better layout searchmost hardware jobs
3heavy resynthesis of two-qubit blocksfinal submission, slower compile
Knowledge check

2 questions · one try each counts

Question 1

Why are rz gates essentially free on IBM hardware?

Sign in to answer and climb the ranks; you will come back to this lesson.

Question 2

Compare levels shows level 3 with fewer two-qubit gates than level 1. What is the cost?

Sign in to answer and climb the ranks; you will come back to this lesson.

Key takeaway

The transpiler lays out, routes, translates and optimises. Read the before/after numbers, prefer level 2 or 3 for hardware, and remember that rz is free while every SWAP is three two-qubit gates.

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
Lesson 4 · 12 min
Circuit Identities & Gate Cancellation
The handful of rewrite rules an optimiser uses, and a bloated circuit you can watch shrink from level 0 to level 3.
Further reading
  • Docs: compile chapter
More in Hardware and Compilation
  • From an abstract qubit to a device
  • Classical Compiler vs. Quantum Transpiler
  • Topology and SWAP cost
Classical Compiler vs. Quantum TranspilerCircuit Identities & Gate Cancellation
In this lesson0%
  1. Introduction
  2. Try it: Watch H become three gates
  3. Knowledge check
  4. Key takeaway
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in