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
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
Close
Hashes for ket_lang-0.4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f549739b62d7e388c5e6b34321b3fd40879afda59b38e1b32d11a4ced92c6a5c |
|
MD5 | 48a4d8881f07539966cf6fb27a42acfb |
|
BLAKE2-256 | 26977a43e2b5a7a9dfd03042b4c98a688cacb5fed4bd743d52d86b746782dbf3 |