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

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-`wget -O- -q https://gitlab.com/quantum-ket/ket/-/raw/master/ket/__version__.py | awk -F\' '{print $2}'`-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl?job=wheelhouse"

Installing from source

Requirements:

To install from source runs:

$ git clone https://gitlab.com/quantum-ket/ket.git
$ cd ket
$ ./util/make_libs.sh
$ python setup.py install

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

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