← Quantum Store · Guides · Lessons · Glossary · Packages · About · Türkçe
Quantinuum
Circuit compilation and optimisation with TKET
Official source: Quantinuum/tket
Download ZIP (free)TKET, Quantinuum's hardware-independent quantum compiler: an example that removes unnecessary gates and checks with a unitary comparison that the circuit still does the same thing.
What is TKET?
TKET is a compiler that adapts quantum circuits to the gate set and
connectivity of the target hardware while reducing the gate count and circuit
depth. Its Python interface is pytket; with extensions it works with Qiskit,
Cirq, Braket and Quantinuum devices.
When to use it
- When you want to make a circuit as small as possible, since every CX gate adds error on noisy hardware.
- When moving a circuit written in one SDK to other hardware.
The example in this package
derleme_ornegi.py simplifies a three-qubit circuit with deliberately
unnecessary gates using FullPeepholeOptimise and translates it into the
{CX, Rz, H} gate set. In testing the circuit went from 11 gates to 7 and
from 5 CX gates to 3; the circuit's unitary matrix did not change.
Windows note
On the Windows 10 machine we used to prepare this package, pytket (versions
2.10, 2.17 and 2.18) crashed while building circuits; the same code ran
without problems on Linux (Ubuntu 24.04). If you have trouble on Windows, use
WSL.
Next steps
- Bring Qiskit circuits into TKET with
pip install pytket-qiskit. - Place the circuit on a specific qubit connectivity map with
DefaultMappingPass.
Installation and running
pip install pytket
python derleme_ornegi.py
Tested with: pytket 2.18.5, Python 3.12 (Linux).
Official source
- Repository: Quantinuum/tket
- Latest release: v2.18.5 — 8 October 2026
- Licence: Apache-2.0
- Stars: 318
- Default branch commit when the catalogue was built:
4a554cbc2699(8 October 2026)
Links
Package contents
derleme_ornegi.pyREADME.en.md— this fileREADME.md— the same guide in TurkishLICENSE— the licence of the files in this packageKAYNAK.json— a machine-readable summary of the official sourceUPSTREAM-LICENSE.txt— the licence text of the official projectCITATION.cff— citation information of the official project
Licence
The example code and the guide in this package were written by the Quantum Store editors and are MIT licensed. The project it uses is subject to its own licence (Apache-2.0).
Quantum Store — https://hakanerdogan.com/en
Example code
The example shipped in the package, run and checked. Comments and printed messages are in Turkish; the code is the same in any language. Everything is in the ZIP.
derleme_ornegi.py
"""TKET (pytket) ile devre optimizasyonu ve kapı setine çevirme.
Gereksiz kapılar içeren bir devreyi FullPeepholeOptimise ile sadeleştirir,
sonra {CX, Rz, H} kapı setine çevirir ve kapı sayılarını karşılaştırır.
Çalıştırma:
pip install pytket
python derleme_ornegi.py
"""
from pytket import Circuit, OpType
from pytket.passes import AutoRebase, FullPeepholeOptimise
from pytket.utils import compare_unitaries
circ = Circuit(3)
circ.H(0).CX(0, 1).CX(1, 2).CX(0, 1).H(0)
circ.CX(1, 2).CX(1, 2) # birbirini götüren iki CX
circ.Rz(0.25, 2).Rz(-0.25, 2) # birbirini götüren iki dönüş
circ.T(0).Tdg(0)
original = circ.copy()
print(f"Önce : {circ.n_gates} kapı, {circ.n_gates_of_type(OpType.CX)} CX")
FullPeepholeOptimise().apply(circ)
AutoRebase({OpType.CX, OpType.Rz, OpType.H}).apply(circ)
print(f"Sonra: {circ.n_gates} kapı, {circ.n_gates_of_type(OpType.CX)} CX")
assert circ.n_gates < original.n_gates
assert compare_unitaries(original.get_unitary(), circ.get_unitary())
print("Tamam: devre küçüldü ve aynı işlemi (üniterliği) koruyor.")
Related concepts
- CNOT gate · The CNOT (controlled-NOT) gate is a two-qubit gate that flips the target qubit when the control qubit is 1; it is the basic tool for creating entanglement.