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).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] [-p 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
-p PORT, --port PORT quantum execution (KBW) 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
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.1.tar.gz
(38.9 kB
view hashes)
Built Distributions
Close
Hashes for ket_lang-0.1.1-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b0ef9aa9b26a51fa993b0730fec8e697c772c729a1a120b2daf55947c55c469 |
|
MD5 | 6c45d13cafd924eab6dfa4b67276d3f2 |
|
BLAKE2b-256 | eae0eafa3f89fe4104ed36b650d2d287bf357d87508f6a7f64ccbf848603d874 |
Close
Hashes for ket_lang-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a58550ecb0745ef8af51c1bc9a2cf4c0d72d05968a965ed86ec5bc869f4f55b |
|
MD5 | 8ebae766cf4a07643b4962c5cc62e7b3 |
|
BLAKE2b-256 | 2ca94272c32871124c32f657e837642d0b1f226577b660a3ab9879ffd5f04e7d |
Close
Hashes for ket_lang-0.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8a7bbab9a766120487ab68a45f607a927d56633716abf8e74c2fea18e5aaf51 |
|
MD5 | 685d472eda5d6f2b3268defe792d5f67 |
|
BLAKE2b-256 | 86ebdfdca7438f38e0f31046e242e83ef936b6ce0d6b1ba633a784ab71b31f9c |
Close
Hashes for ket_lang-0.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e57e8f610fe45434aff012f72ecc1c4b3f474b0a3cf79e27a424f4746c04b6d1 |
|
MD5 | b95e5c918d704f210983246e69e0133c |
|
BLAKE2b-256 | ea8b24f66fadcb9edee6d75d3f7eb9d885c705f0e140119d160da658e9952204 |
Close
Hashes for ket_lang-0.1.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 719ec420b91303b5daa4cfdeca997c379283ec2149449ac5e2e64e1fa0448532 |
|
MD5 | 0095f46094c7f3e079eaa1b60680b1db |
|
BLAKE2b-256 | d308f40c52f1e8ebb3e957ae03306004df29e8769694c14d7288751a1fa0c9d4 |