TKET is an open-source, platform-independent quantum compiler developed by Quantinuum (originally Cambridge Quantum) that optimizes quantum circuits and adapts them to the constraints of specific hardware. In quantum software, it is accessed mainly through pytket, a Python package whose core is written in C++ for speed, and it is released under the Apache 2.0 license.
Unlike SDKs built around one vendor, TKET was designed as a retargetable compiler: the same circuit can be compiled for trapped-ion, superconducting or simulator backends through extension modules, which makes it a common choice for cross-platform work in quantum computing.
How the TKET compiler processes a circuit
TKET represents a program as a directed acyclic graph of operations and transforms it through a sequence of compilation passes. Each pass either rewrites the circuit to reduce cost, decomposes high-level constructs, or enforces a hardware constraint. Passes are composable objects, so users can chain them with sequence and repeat combinators or simply call a backend method that applies a default compilation pipeline.
A typical pipeline runs in four stages, summarized in the following table.
| Stage | What happens | Example passes |
|---|---|---|
| Decomposition | High-level boxes become explicit gates | DecomposeBoxes |
| Optimization | Gate count and depth are reduced | FullPeepholeOptimise, KAKDecomposition, CliffordSimp |
| Placement and routing | Logical qubits are mapped to physical qubits, SWAP gates added | PlacementPass, RoutingPass |
| Rebase | Gates are translated into the native gate set | AutoRebase or device-specific rebases |
After compilation, the backend validity check confirms that the circuit respects connectivity, native gates and other device predicates before it is submitted. This predicate system is a distinctive feature: every backend declares its requirements explicitly, and TKET can report which predicate a circuit violates.
Optimization techniques inside TKET
TKET combines local peephole rewrites with more global, structure-aware methods. Peephole passes cancel adjacent inverse gates, merge rotations and resynthesize two-qubit blocks using the KAK (Cartan) decomposition, which expresses any two-qubit unitary with at most three entangling gates.
For chemistry and optimization circuits, TKET offers Pauli gadget synthesis. Ansatz circuits such as unitary coupled cluster consist of many exponentials of Pauli strings, and TKET can represent them as PauliExpBox objects, then simultaneously diagonalize commuting sets to cut the number of CNOT gates. Clifford simplification and ZX-calculus-based rewriting provide further reductions on suitable circuits.
The table below compares the main optimization families and when they help most.
| Technique | Best suited for | Typical gain |
|---|---|---|
| Peephole optimization | General circuits | Removes redundant gates, modest depth reduction |
| KAK resynthesis | Dense two-qubit blocks | Caps blocks at three entangling gates |
| Pauli gadget synthesis | Chemistry and QAOA ansatz circuits | Large CNOT reductions in favorable cases |
| Clifford simplification | Clifford-heavy subcircuits | Shorter Clifford sections |
| Noise-aware placement | Devices with uneven error rates | Uses better qubits and couplers |
Gains depend heavily on circuit structure. No single pass is best for every workload, so heavy optimization can increase compile time without improving results on already compact circuits.
Backends and the pytket extension ecosystem
The pytket extension modules connect the compiler to hardware and simulators. Each extension defines a backend class with its own gate set, connectivity graph and job submission logic, so moving a workflow to another platform usually means changing one backend object rather than rewriting the circuit.
| Extension | Target | Purpose |
|---|---|---|
| pytket-quantinuum | Quantinuum trapped-ion systems and emulators | Native ZZ-phase and PhasedX compilation |
| pytket-qiskit | IBM devices and Qiskit Aer | Circuit conversion and execution |
| pytket-cirq | Cirq circuits and simulators | Interoperability with Google tooling |
| pytket-braket | Amazon Braket devices | Access to several hardware vendors |
| pytket-qulacs and others | Fast classical simulators | Testing and noise studies |
Converters also let developers import circuits from Qiskit, Cirq or OpenQASM, optimize them in TKET and export them again. This makes TKET usable as a standalone optimization stage inside pipelines that otherwise rely on another SDK.
TKET compared with other compilers
TKET overlaps with the transpiler in Qiskit and with Cirq optimizers, but its emphasis differs. The comparison below highlights the practical distinctions.
| Aspect | TKET | Qiskit transpiler | Cirq |
|---|---|---|---|
| Design goal | Vendor-neutral compilation | IBM hardware first, extensible | Google hardware first, research flexibility |
| Core language | C++ with Python bindings | Python with Rust components | Python |
| Distinctive strength | Pauli gadgets, predicate checks | Large plugin ecosystem | Fine control of moments and timing |
| Routing approach | Architecture-aware SWAP and bridge insertion | SABRE-based heuristics | Basic and contributed routers |
In practice teams often combine tools: they build a circuit in one framework and compare compiled two-qubit gate counts across compilers before choosing what to run.
Practical use, limitations and common mistakes
Most users call a backend method that returns a compiled circuit for a chosen optimization level, then submit it and retrieve shot results. Advanced users write custom pass sequences for specific algorithm families, such as preserving Pauli structure until late in compilation.
- Compiling before choosing the backend wastes effort, because routing and rebasing depend on the target device.
- Decomposing boxes too early destroys the structure that Pauli gadget synthesis needs.
- Ignoring compile time on large circuits can be costly, since the most aggressive levels scale poorly with circuit size.
- Pulse-level control is outside its scope: TKET works at the gate level, so pulse schedules belong to vendor tools.
Another frequent oversight concerns measurement and classical control. TKET supports mid-circuit measurement and conditional gates, but not every backend accepts them, and the predicate check will reject such circuits on devices without dynamic circuit support. Developers should also verify results on a noiseless simulator first, because a compilation that is formally valid can still hide a modeling error in the original circuit. Finally, versions of pytket and its extensions should be kept aligned, since mismatched releases are a common source of import and conversion failures.
In everyday language
Different quantum computers understand different basic operations and connect their qubits in different ways. A program written for one machine will often not run well, or at all, on another.
TKET is like a skilled translator and editor in one. It takes a quantum program, removes unnecessary steps, and rewrites it in the dialect of the chosen machine. Shorter programs mean fewer errors on today’s noisy hardware.
Seen in the real world
A research group studying small molecules builds a unitary coupled cluster circuit with 12 qubits and several hundred Pauli exponentials. Written naively, the circuit contains well over a thousand CNOT gates, far too many for current devices.
The group represents the ansatz with Pauli boxes and runs TKET Pauli gadget synthesis followed by peephole optimization and routing for a trapped-ion emulator. The compiled circuit uses substantially fewer two-qubit gates, and the same source code is then compiled for a superconducting backend through another extension. Comparing both runs lets the team choose the device with the lower expected error before spending paid hardware time.