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 2025, pytket is actively maintained by Quantinuum with regular releases. 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 H-Series hardware
pip install pytket-braket # Amazon Braket
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
circ.measure_register(circ.qubits, 'c') # measure into named register
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_distribution()) # dict: state → probability
Statevector simulation
from pytket.extensions.qiskit import AerStateBackend
backend = AerStateBackend()
state = backend.run_circuit(circ).get_state()
Quantinuum hardware
from pytket.extensions.quantinuum import QuantinuumBackend
backend = QuantinuumBackend(device_name='H1-1')
backend.login()
compiled = backend.get_compiled_circuit(circ, optimisation_level=2)
handle = backend.process_circuit(compiled, n_shots=100)
result = backend.get_result(handle)
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})