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)
     H(q)
     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)
    H(alice)

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

    if m1 == 1:
        X(bob_b)
    if m0 == 1:
        Z(bob_b)

    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

Usage

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

Ket interpreter

positional arguments:
  .ket                  source code

options:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  -o OUT, --out OUT     KQASM output file
  -s SEED, --seed SEED  set RNG seed for quantum execution

Installation

Available installation methods:

Installing with pip

Installing from PyPI:

$ pip install ket-lang

Installing latest Gitlab CI build:

$ pip install "https://gitlab.com/quantum-ket/ket/-/jobs/artifacts/master/raw/wheelhouse/ket_lang-0.3.2-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl?job=wheelhouse"

Installing from source

Requirements:

  • C++ compiler
  • CMake
  • Conan

To install from source runs:

$ git clone --recurse-submodules https://gitlab.com/quantum-ket/ket.git
$ mkdir ket/build
$ cd ket/build
$ cmake ../libket -DCMAKE_BUILD_TYPE=Release
$ make -j8
$ python setup.py install

This project is part of the Ket Quantum Programming, see the documentation for more information https://quantumket.org.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

ket_lang-0.3.3-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (466.3 kB view hashes)

Uploaded Python 3 manylinux: glibc 2.17+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page