Ket Quantum Programming#

Ket Quantum Programming is an open-source platform that provides dynamic interaction between classical and quantum data at the programming level, streamlining classical-quantum development. The platform has three main projects:

  • Ket is an embedded programming language that introduces the ease of Python to quantum programming, letting anyone quickly prototype and test a quantum application. (Ket repo)

  • Libket is the runtime library for the Ket language, but one can use it for quantum acceleration on embedded systems using C/C++ or Rust. (Libket repo)

  • Ket Bitwise Simulator (KBW) is a noise-free quantum computer simulator that allows anyone to test quantum applications on classical computers. KBW features two simulation methods: Dense simulation based on state vector simulation and Sparse simulation based on the Bitwise representation. (KBW repo)

Getting started with Ket#

Installation#

Ket requires Python 3.8 or newer and is available for Linux, Windows, and macOS.
If you are not using an x86_64 (Intel/AMD) CPU, you must install Rust before installing Ket.
Ket is available in the Python Package Index (PyPI), and you can install it using pip.
To do so, copy and paste the following command into your terminal:
python3 -m pip install ket-lang

Usage#

You can execute a quantum application using Python interpreter. For example:

# bell.py
from ket import *
p = Process()
a, b = p.alloc(2)
CNOT(H(a), b)
print(dump(a+b).show())

To run the code above, use the command python3 bell.py.

$ python3 bell.py
|00⟩    (50.00%)
    0.707107               ≅      1/√2
|11⟩    (50.00%)
    0.707107               ≅      1/√2

Example: Quantum Teleportation#

With the quantum teleportation protocol, one can transfer quantum information from one qubit to another using a pair of entangled qubits and quantum measurements.

# teleport.py
import ket

def entangle(a: Quant, b: Quant):
    return CNOT(H(a), b)

def teleport(quantum_message: Quant, entangled_qubit: Quant):
    adj(entangle)(quantum_message, entangled_qubit)
    return measure(entangled_qubit).value, measure(quantum_message).value

def decode(classical_message: tuple[int, int], qubit: Quant):
    if classical_message[0] == 1:
        X(qubit)

    if classical_message[1] == 1:
        Z(qubit)

if __name__ == "__main__":
    p = ket.Process(execution="live")

    alice_message = p.alloc()  # alice_message = |0⟩
    ket.H(alice_message)       # alice_message = |+⟩
    ket.Z(alice_message)       # alice_message = |–⟩

    alice_qubit, bob_qubit = entangle(p.alloc(2))

    classical_message = teleport(
        quantum_message=alice_message,
        entangled_qubit=alice_qubit
    )

    decode(classical_message, bob_qubit)

    ket.H(bob_qubit)  # bob_qubit = |1⟩
    bob_m = ket.measure(bob_qubit)
    print("Expected measure 1, result =", bob_m.value)
$ python teleport.py
Expected measure 1, result = 1

Used by#

Otto M. Pires, Rafael de Santiago and Jerusa Marchi, “Two Stage Quantum Optimization for the School Timetabling Problem”, 2021 IEEE Congress on Evolutionary Computation (CEC), 2021, pp. 2347-2353, doi: 10.1109/CEC45853.2021.9504701.

Portable GPU-Accelerated Quantum Computer Simulator QuBOX at Universidade Federal de Santa Catarina (Brazil).

Cite Ket#

When using Ket for research projects, please cite:

Evandro Chagas Ribeiro da Rosa and Rafael de Santiago. 2021. Ket Quantum Programming. J. Emerg. Technol. Comput. Syst. 18, 1, Article 12 (January 2022), 25 pages. https://doi.org/10.1145/3474224

@article{ket2021,
    author = {Evandro Chagas Ribeiro da Rosa and Rafael de Santiago},
    title = {Ket Quantum Programming},
    year = {2021},
    issue_date = {January 2022},
    publisher = {Association for Computing Machinery},
    address = {New York, NY, USA},
    volume = {18},
    number = {1},
    issn = {1550-4832},
    url = {https://doi.org/10.1145/3474224},
    doi = {10.1145/3474224},
    journal = {J. Emerg. Technol. Comput. Syst.},
    month = {oct},
    articleno = {12},
    numpages = {25},
    keywords = {Quantum programming, cloud quantum computation, qubit simulation}
}

Download the original article that proposes the Ket language: pdf

Ket API Documentation#

ket

Ket Quantum Programming Platform.


Sponsored by Quantuloop Sponsored by Quantuloop