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] [-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
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
Close
Hashes for ket_lang-0.2-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70e4510f56126444d18ebc714c1b3a64a5414c4dff3798bae0563df2f1602f91 |
|
MD5 | 9debd4d7053ad7e745a041bb1f989479 |
|
BLAKE2b-256 | 37e6a101786cec5aa8739599d1df77ae485e1b8be1a3f7c876ea8f06a1b6baad |
Close
Hashes for ket_lang-0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f0de2fc9d82783581cb5f9ff84a9408b114c39bf697cebaa497084e97cc1122 |
|
MD5 | 72e695c5c194e7bae1e1dead8e4c446b |
|
BLAKE2b-256 | c9513a9e2000445850b4d65087af9c3182f16de1fb251dba8a715ab5583dde8c |
Close
Hashes for ket_lang-0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 658b4aafb589de5860a2a327f985baaf5cb75d1a65773858480b30ed8d9f2a17 |
|
MD5 | 91f61520ba86d2781714ca0f9978f192 |
|
BLAKE2b-256 | a26d3f5ed13fbadfb6016c34b910a8cff692f6ab722874b33f55b7003548387b |
Close
Hashes for ket_lang-0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61994a60ec50fc0788df820b7f8b4949b87eb70d5ed4800bfa5f57ae2f049b7a |
|
MD5 | 6df3b77d668f89623e16677fbd716cbb |
|
BLAKE2b-256 | 956499d008da5e51d06ff807c956c7d2520422a7005fd76e47203c91edf0b398 |
Close
Hashes for ket_lang-0.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a132b652687cc70e2d18da7aa13e706c57f16a7a42f5b14411c571928e0403f |
|
MD5 | 68fc05cafb453a5484fb909b8cbdf95e |
|
BLAKE2b-256 | 54db9d997fcab04b7f4e396ec9768dc93ed8ebc031ce603e9fac65cd7ec9ec8c |