← Quantum Store · Guides · Lessons · Glossary · Packages · About · Türkçe

Quantinuum

Circuit compilation and optimisation with TKET

SoftwareCompilation and optimisationLicence: Apache-2.0Version: 2.18.58.7 KB

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

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

  1. Bring Qiskit circuits into TKET with pip install pytket-qiskit.
  2. 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

Links

Package contents

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

← All packages

Share: X · LinkedIn