|q⟩ Bad Qubits

advanced · Programming · Advanced Circuit Construction & Transpilation

Checkpoint: Compile to a Gate Set

This checkpoint brings the module together. You have learned to decompose gates into rotations, synthesize multi-qubit gates, simplify with circuit identities, and route around limited connectivity. The remaining piece of a transpiler's front end is basis translation: rewriting a circuit so that every gate belongs to the device's native set — most importantly, replacing the abstract two-qubit gate the programmer used with the one the hardware actually provides.

CX is not always native

Many architectures do not implement CNOT directly. Superconducting devices with tunable couplers naturally realize the controlled-Z (CZ\mathrm{CZ}), and some realize an iSWAP-family gate; trapped ions favour the Mølmer–Sørensen (XXXX) interaction. Whatever the native entangler, a compiler must express the programmer's CNOTs in terms of it plus single-qubit gates.

CX from CZ by a basis change

The cleanest example uses the identity HZH=XHZH = X. Conjugating the target of a controlled-ZZ by Hadamards converts it into a controlled-XX:

CX01=(IH)CZ0,1(IH).\mathrm{CX}_{0\to 1} = (I\otimes H)\,\mathrm{CZ}_{0,1}\,(I\otimes H).

The logic is exactly the conditional version of HZH=XHZH = X: when the control is 1|1\rangle, the CZ applies ZZ to the target, and the surrounding Hadamards turn that conditional ZZ into a conditional XX — a CNOT. When the control is 0|0\rangle, the two Hadamards cancel (HH=IHH = I) and nothing happens, exactly as a CNOT requires.

Putting the module together

A full compilation of an arbitrary circuit onto a CZ-native, line-connected device would now run the whole pipeline you have studied: decompose high-level gates, lay out and route qubits with SWAPs (each itself three CNOTs, each CNOT then translated to CZ + Hadamards), translate single-qubit gates into the native rotation set, and finally optimize away the redundant Hadamards and rotations the translation introduced. This checkpoint isolates the single most common translation step at the heart of that pipeline.

Try it

Compile CX(0,1)\mathrm{CX}(0,1) into the {H,CZ}\{H, \mathrm{CZ}\} basis — no cx(). The grader compares the full two-qubit unitary up to global phase, so your translated circuit must implement exactly the same CNOT.

Run your code to see the quantum state.

Sign in on the full site to ask questions and join the discussion.