TKET Compiler and Python API (pytket)

2.16.0 · active · verified Thu Apr 16

pytket is a Python module that provides an interface to TKET, a hardware-agnostic quantum computing toolkit and optimizing compiler developed by Quantinuum. It enables users to design, optimize, and execute quantum circuits on various backend devices and simulators. The library is actively maintained with frequent minor version releases, typically on a monthly cycle, and occasional patch releases for bug fixes, focusing on superior performance for NISQ (noisy intermediate-scale quantum) devices.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a simple Bell state circuit, compile it using a Qiskit Aer simulator backend (requires `pytket-qiskit`), and then execute it to retrieve measurement counts. This illustrates the basic workflow of circuit construction, compilation, and execution.

from pytket import Circuit
from pytket.extensions.qiskit import AerBackend

# 1. Create a quantum circuit (Bell state)
circ = Circuit(2) # 2 qubits
circ.H(0)        # Hadamard on qubit 0
circ.CX(0, 1)    # CNOT with control 0, target 1

# 2. Compile the circuit for a backend (using Qiskit Aer simulator for demonstration)
# Note: pytket-qiskit extension must be installed for AerBackend
backend = AerBackend()
compiled_circ = backend.get_compiled_circuit(circ)

# 3. Execute the circuit
# For real devices, this may involve authentication (e.g., IBMQ credentials)
# For local simulators, no special setup is typically needed.
# We'll run 100 shots and retrieve measurement counts.
handle = backend.process_circuit(compiled_circ, n_shots=100)
result = backend.get_result(handle)

print(f"Circuit: {circ}")
print(f"Compiled Circuit: {compiled_circ}")
print(f"Measurement counts: {result.get_counts()}")

view raw JSON →