TKET Cheat Sheet
Background and History
tket (pronounced “ticket”) is a quantum compiler and circuit optimization toolkit originally developed by Cambridge Quantum Computing (CQC), a UK-based quantum software company founded in 2014 by Ilyas Khan. CQC began developing tket around 2018 as an advanced circuit compilation engine focused on reducing two-qubit gate counts, which are the primary source of error on near-term quantum hardware. The Python interface, pytket, was released to provide accessible programmatic access to tket’s compilation passes.
In June 2021, Cambridge Quantum Computing merged with Honeywell Quantum Solutions (which operated trapped-ion quantum processors) to form Quantinuum. This merger placed tket under the same corporate umbrella as the H-Series trapped-ion hardware, making it the native compiler for Quantinuum’s processors. The tket source code was open-sourced in late 2021 under the Apache 2.0 license, making the full compiler stack available for community inspection and contribution.
tket’s core strength is its compiler pass infrastructure. Passes such as FullPeepholeOptimise, CliffordSimp, and SynthesiseTket apply local rewriting rules and resynthesis techniques to minimize circuit depth and gate count. These optimizations are hardware-aware: when targeting a specific backend, tket respects the device’s connectivity constraints and native gate set while optimizing. Independent benchmarks have shown tket producing competitive or superior two-qubit gate counts compared to other compilers across multiple hardware platforms.
A distinctive feature of tket is its cross-platform backend system. Through extension packages (pytket-qiskit, pytket-cirq, pytket-braket, pytket-quantinuum, and others), tket can accept circuits from most major frameworks and compile them for most major hardware targets. This makes it useful as a universal optimization layer regardless of which frontend or backend a team prefers. As of 2026, pytket is actively maintained by Quantinuum with regular releases on the 2.x series. It has a dedicated user community, particularly among researchers who need aggressive circuit optimization for near-term experiments and among Quantinuum hardware users.
Installation
pip install pytket
Backend extensions (one per target):
pip install pytket-qiskit # IBM / Aer
pip install pytket-cirq # Google Cirq
pip install pytket-quantinuum # Quantinuum compilation and local emulation
pip install pytket-braket # Amazon Braket
pip install qnexus # job submission to Quantinuum hardware (Nexus platform)
Key Imports
from pytket import Circuit, OpType
from pytket.extensions.qiskit import AerBackend
from pytket.passes import FullPeepholeOptimise, DecomposeBoxes
Circuit Construction
from pytket import Circuit
circ = Circuit(2, 2) # 2 qubits, 2 classical bits
circ = Circuit(3) # 3 qubits, no classical bits
# Qubits and bits are indexed from 0
circ.H(0) # Hadamard on qubit 0
circ.CX(0, 1) # CNOT: control=0, target=1
circ.measure_all() # measure all qubits into matching classical bits
Gates
circ.H(q) # Hadamard
circ.X(q) # Pauli-X
circ.Y(q) # Pauli-Y
circ.Z(q) # Pauli-Z
circ.S(q) # S gate
circ.Sdg(q) # S-dagger (inverse S)
circ.T(q) # T gate
circ.Tdg(q) # T-dagger (inverse T)
circ.CX(control, target) # CNOT
circ.CZ(q1, q2) # Controlled-Z
circ.SWAP(q1, q2) # SWAP
circ.CCX(q1, q2, q3) # Toffoli
# Rotation gates (angles in half-turns: 1.0 = π radians)
circ.Rx(0.5, q) # Rx(π/2)
circ.Ry(0.5, q) # Ry(π/2)
circ.Rz(0.5, q) # Rz(π/2)
# Parameterised gates (for variational algorithms)
from pytket.circuit import fresh_symbol
theta = fresh_symbol('theta')
circ.Ry(theta, 0)
tket uses half-turns: a rotation of 1.0 = π radians, so Rx(0.5) = Rx(π/2). Multiply standard radian values by 1/π.
Measurement
circ.measure_all() # measure all qubits
circ.Measure(qubit, classical_bit) # measure specific qubit
# Measure a whole QubitRegister into a named classical register
qreg = circ.get_q_register('q') # default qubit register
circ.measure_register(qreg, 'm')
Compiler Passes
tket’s main value is its compiler. Passes reduce gate count and adapt circuits to backend constraints.
from pytket.passes import (
FullPeepholeOptimise,
SynthesiseTket,
CliffordSimp,
RemoveRedundancies,
SequencePass,
)
# Apply a single pass
FullPeepholeOptimise().apply(circ)
# Chain passes
SequencePass([RemoveRedundancies(), FullPeepholeOptimise()]).apply(circ)
Common passes:
| Pass | What it does |
|---|---|
RemoveRedundancies() | Cancels adjacent inverse gates |
CliffordSimp() | Optimises Clifford sub-circuits |
FullPeepholeOptimise() | Heavy local rewriting for 2-qubit count |
SynthesiseTket() | Full circuit resynthesis |
DecomposeBoxes() | Unfolds boxed sub-circuits |
Backends
# Aer simulator (via pytket-qiskit)
from pytket.extensions.qiskit import AerBackend
backend = AerBackend()
# Compile the circuit for the backend first
compiled = backend.get_compiled_circuit(circ)
handle = backend.process_circuit(compiled, n_shots=1024)
result = backend.get_result(handle)
print(result.get_counts())
print(result.get_shots()) # raw shot array
print(result.get_probability_distribution()) # dict: outcome tuple -> probability
Statevector simulation
from pytket.extensions.qiskit import AerStateBackend
backend = AerStateBackend()
state = backend.run_circuit(circ).get_state()
Quantinuum hardware
Since pytket-quantinuum 0.56, the extension handles compilation and local emulation only; the old QuantinuumBackend(...).login() submission flow no longer reaches hardware. Jobs are submitted to Quantinuum systems through the Quantinuum Nexus platform using the qnexus package. Note also that the System Model H1 machines (such as H1-1) were retired from commercial operation in October 2025; H2 and later systems are the current targets.
# Compilation and local emulation (pytket-quantinuum, no cloud account needed;
# install the local emulator with: pip install pytket-quantinuum[pecos])
from pytket.extensions.quantinuum import QuantinuumBackend
backend = QuantinuumBackend(device_name='H2-1LE') # local emulator
compiled = backend.get_compiled_circuit(circ, optimisation_level=2)
result = backend.run_circuit(compiled, n_shots=100)
# Hardware submission goes through Quantinuum Nexus
import qnexus as qnx
qnx.login()
# Create a project, upload the circuit, and start compile/execute jobs
# via the qnexus API; see https://docs.quantinuum.com/nexus/ for the workflow.
tket vs. Qiskit’s Transpiler
Both tket and Qiskit ship a circuit optimizer, and in practice the choice comes down to how locked in a team already is to one ecosystem.
| Aspect | tket (pytket) | Qiskit transpiler |
|---|---|---|
| Scope | Framework-agnostic: takes circuits from Qiskit, Cirq, or Braket via extension packages | Native to Qiskit circuits |
| Optimisation approach | Dedicated passes such as FullPeepholeOptimise and CliffordSimp, focused on 2-qubit gate reduction | Preset optimization_level 0-3, mostly rule-based rewriting |
| Best fit | Teams needing aggressive optimization across multiple backends, or Quantinuum hardware users | Teams staying entirely within the Qiskit/IBM stack |
| Maintainer | Quantinuum | IBM |
Choose tket when a circuit needs to move between backends or is headed to Quantinuum hardware. Choose Qiskit’s built-in transpiler when the rest of the pipeline, circuits, backends, and primitives, is already Qiskit-native and an extra dependency isn’t worth it.
Common Patterns
Bell state
from pytket import Circuit
from pytket.extensions.qiskit import AerBackend
circ = Circuit(2, 2)
circ.H(0)
circ.CX(0, 1)
circ.measure_all()
backend = AerBackend()
compiled = backend.get_compiled_circuit(circ)
result = backend.run_circuit(compiled, n_shots=1024)
print(result.get_counts())
Circuit inspection
print(circ.n_qubits) # number of qubits
print(circ.n_gates) # total gate count
print(circ.depth()) # circuit depth
print(circ.n_2qb_gates()) # two-qubit gate count (main hardware cost)
print(circ.get_commands()) # list of all operations
Symbolic compilation
from sympy import symbols, pi
from pytket import Circuit
theta = symbols('theta')
circ = Circuit(1)
circ.Ry(theta / pi, 0) # tket angles are in half-turns
circ.symbol_substitution({theta: 1.57})