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
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)
Built Distributions
Close
Hashes for ket_lang-0.1-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a448297de5c2d393a5ccdfd2082d774410b1c8833aa02519872d5839d1ae62ff |
|
MD5 | 50a677aa5fa7d8c0aab84b188562e4db |
|
BLAKE2b-256 | 5858e619529eebe50396b1e809f0947b799f7caee90b0c38b06146882c86f88c |
Close
Hashes for ket_lang-0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2eef0cfa618ce0817797f1a9bdd1a975be0ec054017eaf613113f9f42452140a |
|
MD5 | 5a28f3113c3993e5afd6b42fa6fb2382 |
|
BLAKE2b-256 | 0086bd1193b91c5f5e32a8e36e69256b19e0a7af8286ac8f7adb599e0f2a7b73 |
Close
Hashes for ket_lang-0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 721ee794667bc7ad8807f475c51ce1f4d3a5d17fb847c2eaa3cca1f9ca39abdc |
|
MD5 | c9ca1a39a66f472dbda1fb4e7b104de2 |
|
BLAKE2b-256 | 5eb3602f01d72c245d8c443c82775cf51615e4c9d0af2a22b43800ba5f2addc2 |
Close
Hashes for ket_lang-0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c951cf5fd6ac42a75beb5b7506199d1e405429a6d48c62e01eb940e9b5fb3a59 |
|
MD5 | 37cf707203c421d0bfb429162d759bf5 |
|
BLAKE2b-256 | 76e34ea8802bf37f622e662f271fcdb09e67bb73e2c1c6fb0aa58d29803161bb |
Close
Hashes for ket_lang-0.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 463c042d7d5f18f2d070e5b4aea6044674fe4586d924a2604e15a3a0acddf1a2 |
|
MD5 | 779f0d146267c97d60f3f4b07268f848 |
|
BLAKE2b-256 | 9c903877df2e7962e6b11276a46baf2c18ac5eeb73319b2a80eb12225ef5b69d |