pytket is a python module for interfacing with CQC t|ket>, a set of quantum programming tools. We currently support circuits and device architectures from Google Cirq, IBM Qiskit, AQT, Honeywell, QSharp, Pyzx, ProjectQ and Rigetti pyQuil, allowing the t|ket> tools to be used in conjunction with projects on these platforms.

Getting Started

pytket is available for Python 3.6, 3.7 and 3.8, on Linux and MacOS. To install, run

pip install pytket

To use pytket, you can simply import the appropriate modules into your python code or in an interactive Python notebook. We can build circuits directly using the pytket interface by creating a blank circuit and adding gates in the order we want to apply them.

from pytket import Circuit
c = Circuit(2,2) # define a circuit with 2 qubits and 2 bits
c.H(0)           # add a Hadamard gate to qubit 0
c.Rz(0.25, 0)    # add an Rz gate of angle 0.25*pi to qubit 0
c.CX(1,0)        # add a CX gate with control qubit 1 and target qubit 0
c.measure_all()  # measure qubits 0 and 1, recording the results in bits 0 and 1

Some of the extension modules define Backend s, allowing the circuits to be run on simulators or real quantum hardware. For example, pytket-qiskit grants access to the AerBackend simulator which can sample from measurements.

from import AerBackend
b = AerBackend()                # connect to the backend
b.compile_circuit(c)            # compile the circuit to satisfy the backend's requirements
handle = b.process_circuit(c, 100)  # submit the job to run the circuit 100 times
counts = b.get_counts(handle)   # retrieve and summarise the results

This prints out a summary of readouts (the final values of the classical bits) and their frequencies.

{(0, 0): 49, (1, 0): 51}

See the Getting Started page for a basic tutorial on using pytket. To get more in depth on features, see the examples.


To use pytket in conjunction with other platforms you must download an additional separate module for each. Each one of these adds either some new methods to the pytket package to convert between the circuit representations, or some new backends to submit circuits to within pytket.

For each extension module:

Qiskit: pip install pytket-qiskit

Cirq: pip install pytket-cirq

PyQuil: pip install pytket-pyquil

ProjectQ: pip install pytket-projectq

AQT: pip install pytket-aqt

Honeywell: pip install pytket-honeywell

QSharp: pip install pytket-qsharp

PyZX: pip install pytket-pyzx

Submodule names

The pytket._tket submodule provides, through its various submodules, access to the native library that is at the core of pytket. For example, pytket._tket.device provides device-related classes. The _tket part of the name can always be omitted when importing (e.g. one can just do from pytket.device import Device), though it is included in the API documentation. Other submodules (such as pytket.utils) are pure Python.


Copyright 2020 Cambridge Quantum Computing

Licensed under a Non-Commercial Use Software Licence (the “Licence”); you may not use this product except in compliance with the Licence. You may view a copy of the Licence on the LICENCE page.

Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Licence for the specific language governing permissions and limitations under the Licence, but note it is strictly for non-commercial use.

Indices and tables