Ket Quantum Programming Language interpreter and library.
Project description
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-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://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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for ket_lang-0.3-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a8fcb4d2f074d037fdeb1c28ff33c69c0d7dd605afba2090548d45423e0b17c |
|
MD5 | aaefdf5212b680d3596e4ea8a8426707 |
|
BLAKE2b-256 | 8c7e4f405ea43dacd623847272c85b4fa9925e255abeb80c7420dc44bf0d7dee |