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).get()

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.get())
$ ket teleport.ket
Expected measure 1, result = 1

Usage

$ ket -h
usage: ket [-h] [--version] [-o OUT] [-s KBW] [-u USER] [-p PORT]
           [-P SSH_PORT] [--seed SEED] [--api-args API_ARGS] [--no-execute]
           [--dump2fs]
           .ket

Ket interpreter

positional arguments:
  .ket                  source code

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  -o OUT, --out OUT     KQASM output file
  -s KBW, --kbw KBW     quantum execution (KBW) IP address
  -u USER, --user USER  quantum execution (KBW) SSH user
  -p PORT, --port PORT  quantum execution (KBW) port
  -P SSH_PORT, --ssh-port SSH_PORT
                        quantum execution (KBW) SSH port
  --seed SEED           set RNG seed for quantum execution
  --api-args API_ARGS   additional parameters for quantum execution
  --no-execute          does not execute KQASM, measurements return 0
  --dump2fs             use the filesystem to transfer dump data

Installation

Ket Bitwise Simulator is required for quantum execution. See https://gitlab.com/quantum-ket/kbw#installation for installation instructions.

Available installation methods:

Install using pip

Installing from PyPI:

$ pip install ket-lang

Installing the last version from git:

$ pip install git+https://gitlab.com/quantum-ket/ket.git

Compiled manylinux wheel available here

Install from source

Install requirements:

  • C/C++ compiler
  • CMake
  • Ninja or GNU Make
  • Conan

To install from source runs:

$ git clone --recurse-submodules https://gitlab.com/quantum-ket/ket.git
$ cd ket
$ python setup.py install

Docker with Jupyter Notebook

$ docker run --rm -it -v `pbw`:/home/ket -p 8888:8888 evandrocrr/ket:0.2

This project is part of the Ket Quantum Programming, see the documentation for more information https://quantum-ket.gitlab.io.

Project details


Release history Release notifications | RSS feed

This version

0.2

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 Distributions

ket_lang-0.2-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.4 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

ket_lang-0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.4 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

ket_lang-0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.4 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

ket_lang-0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.4 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

ket_lang-0.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.4 MB view hashes)

Uploaded CPython 3.7m 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