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
Ket program options:
  -h [ --help ]              Show this information.
  -o [ --out ]               KQASM output file.
  -s [ --kbw ]  (=127.0.0.1) Quantum execution (KBW) address.
  -p [ --port ]  (=4242)     Quantum execution (KBW) port.
  --seed                     Set RNG seed for quantum execution.
  --api-args                 Additional parameters for quantum execution.
  --no-execute               Does not execute KQASM, measurements return 0.
  --dump-to-fs               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

Install requirements:

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

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

Same requirements os installing with pip.

To install from source runs:

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

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

Download files

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

Source Distribution

ket-lang-0.1.tar.gz (35.9 kB view hashes)

Uploaded Source

Built Distributions

ket_lang-0.1-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

ket_lang-0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

ket_lang-0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

ket_lang-0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

ket_lang-0.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 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