Skip to main content

Ket Quantum Programming Language interpreter and library.

Project description

PyPI AppImage

Ket Quantum Programming Language

Ket is a Python-embedded language for hybridity classical-quantum programming.

Table of contents:

Code examples

Random Number Generation

# random.ket
def random(n_bits):
  with run():
     q = quant(n_bits)
     return measure(q).value

n_bits = 32
print(n_bits, 'bits random number:', random(n_bits))
$ ket random.ket
32 bits random number: 3830764503

Quantum Teleportation:

# teleport.ket
def teleport(alice : quant) -> quant:
    alice_b, bob_b = quant(2)
    ctrl(H(alice_b), X, bob_b)

    ctrl(alice, X, alice_b)

    m0 = measure(alice)
    m1 = measure(alice_b)

    if m1 == 1:
    if m0 == 1:

    return bob_b

alice = quant(1)         # alice = |0⟩
H(alice)                 # alice = |+⟩
Z(alice)                 # alice = |–⟩
bob = teleport(alice)    # bob  <- alice
H(bob)                   # bob   = |1⟩
bob_m = measure(bob)

print('Expected measure 1, result =', bob_m.value)
$ ket teleport.ket
Expected measure 1, result = 1


$ ket -h
usage: ket [-h] [--version] [-o OUT] [-s SEED] .ket

Ket interpreter

positional arguments:
  .ket                  source code

  -h, --help            show this help message and exit
  --version             show program's version number and exit


Available installation methods:

Installing with pip

Installing from PyPI:

$ pip install ket-lang

Installing latest Gitlab CI build:

$ pip install "`wget -O- -q | awk -F\' '{print $2}'`-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl?job=wheelhouse"

Installing from source


To install from source runs:

$ git clone
$ cd ket
$ ./util/
$ python install

This project is part of the Ket Quantum Programming, see the documentation for more information

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Built Distribution

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page