Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Ket Quantum Programming

PyPI Contributor Covenant REUSE status

Ket is a Python library for quantum programming. You write quantum code as ordinary Python functions and run it on the built-in simulator, on a GPU, or on IBM Quantum and Amazon Braket, so it works with NumPy, SciPy and the rest of the Python ecosystem. Learn more at https://quantumket.org.

Installation ⬇️

Ket needs Python 3.10 or newer, on Linux, Windows or macOS:

pip install ket-lang

On Linux or Windows with a non-x86_64 CPU (such as ARM), install Rust first. Optional features:

Extra Adds
ket-lang[plot] histograms and circuit drawings
ket-lang[ibm] IBM Quantum and Qiskit Aer (ket.ibm)
ket-lang[amazon] Amazon Braket (ket.amazon)

Quick start 🚀

from ket import *

p = Process()          # a quantum simulator
a, b = p.alloc(2)      # two qubits in |0⟩

H(a)                   # superposition
with control(a):       # entangle: flip b when a is |1⟩
    X(b)

print(sample(a + b).get())   # {0: ~1024, 3: ~1024}: always 00 or 11

with obs():
    zz = Z(a) * Z(b)
print(exp_value(zz).get())   # 1.0: a and b always agree

The main concepts:

  • Process runs the program. It uses the sparse simulator by default; pass simulator="dense" or "dense gpu", or a device such as ket.ibm.IBMDevice. In live execution (the default) results are ready immediately; batch execution runs the whole circuit at the end, like a QPU.
  • Gates are functions: H(q), CNOT(a, b), RX(θ, q). Your own functions are gates too, and adj(f), ctrl(c, f), with control(c): and with around(f, q): work on them.
  • Results: measure(q).value (one shot), sample(q).get() (counts), exp_value(h).get() (expectation value), and dump(q).show() (state vector).
  • ket.qulib has state preparation, oracles, Hamiltonians and QUBO solvers.

See examples/ for complete programs, from a Bell pair to QAOA.

Using an AI coding agent 🤖

Run this in your project to teach AI coding agents (Claude Code, Codex, Cursor, ...) how to write Ket code:

ket skills install

It adds the Ket skill to .claude/skills/ and .agents/skills/, and a pointer to it in AGENTS.md. Run it again after upgrading Ket to update it.

Logging 🔎

Ket logs through Python's logging. To see what the runtime and simulator do, such as how gates are decomposed or why an error happened:

import ket
ket.set_log_level("debug")   # or "info", "warning" (default), "error"

or set KET_LOG=debug in the environment. See examples/logs.py.

Development 🔨

  1. Install Rust and clone the repository with its submodules:

    git clone --recursive https://gitlab.com/quantum-ket/ket.git
    cd ket
    
  2. Install Ket in editable mode, with the development tools:

    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements_dev.txt
    pip install -e .
    

    The first import ket compiles the Rust libraries (Libket and KBW) in release mode. On Linux with glibc 2.34 or newer, KBW is built with the GPU (gpu) and CUDA (cuda) simulators; set KET_BUILD_GPU=0 or KET_BUILD_CUDA=0 to leave them out. To rebuild, delete libket.so and libkbw.so from src/ket/clib/libs/.

  3. Run the tests:

    pytest
    

To build the Rust libraries yourself, for example in debug mode:

cargo build --manifest-path src/ket/clib/libs/libket/Cargo.toml
cargo build --manifest-path src/ket/clib/libs/kbw/Cargo.toml  # add -F gpu,cuda for GPUs
ln -s libket/target/debug/libket.so src/ket/clib/libs/libket.so
ln -s kbw/target/debug/libkbw.so src/ket/clib/libs/libkbw.so

For Rust development, use the same rustc version as the current Ket release.

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. DOI: 10.1145/3474224

@article{ket,
   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}
}

Metadata

Release files for ket-lang 0.10.5.0b4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ket-lang 0.10.5.0b4
File Size Uploaded Provenance Actions
ket_lang-0.10.5.0b4.tar.gz 376.0 kB Without provenance Details for ket_lang-0.10.5.0b4.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for ket-lang 0.10.5.0b4
File Actions
ket_lang-0.10.5.0b4-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for ket_lang-0.10.5.0b4-py3-none-win_amd64.whl
ket_lang-0.10.5.0b4-py3-none-manylinux_2_34_x86_64.whl Python 3 none Linux glibc 2.34+ x86-64 Details for ket_lang-0.10.5.0b4-py3-none-manylinux_2_34_x86_64.whl
ket_lang-0.10.5.0b4-py3-none-manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.28+ x86-64 Details for ket_lang-0.10.5.0b4-py3-none-manylinux_2_28_x86_64.whl
ket_lang-0.10.5.0b4-py3-none-macosx_13_0_universal2.whl Python 3 none macOS 13.0+ universal2 (ARM64, x86-64) Details for ket_lang-0.10.5.0b4-py3-none-macosx_13_0_universal2.whl

Total release size: 61.0 MB

Release files / ket_lang-0.10.5.0b4.tar.gz

Download URL ket_lang-0.10.5.0b4.tar.gz
Size 376.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e18c5eaf6c01a06b81adb66e15da11db560d95996cf2bf6e5863bc3766c41a2f
BLAKE2b-256 checksum
How to use checksums
937772948edef99ad6f113a64f96c227cd47e8d964ed2ee6ae5da92e93f0bc71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.22

Release files / ket_lang-0.10.5.0b4-py3-none-win_amd64.whl

Download URL ket_lang-0.10.5.0b4-py3-none-win_amd64.whl
Size 4.4 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
fc756f80cfdb99661aaa38f380fe7edff438ecf38e905202d4fc25aca6d4d15b
BLAKE2b-256 checksum
How to use checksums
87958bdc15a1e8f51ba68fb69faef06b77751c5474cb0d3359bd13bf96731663
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.22

Release files / ket_lang-0.10.5.0b4-py3-none-manylinux_2_34_x86_64.whl

Download URL ket_lang-0.10.5.0b4-py3-none-manylinux_2_34_x86_64.whl
Size 45.2 MB
Tags Linux glibc 2.34+ x86-64 Python 3
SHA-256 checksum
How to use checksums
a785e3e5079e8c2fa75bca27a5395b45538d0bd26d74907db3cb42f5df9ff0db
BLAKE2b-256 checksum
How to use checksums
c9b6d24c14e5ad06bc622f01c64ddef8d757467cd8b5144e49de38912164d923
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.22

Release files / ket_lang-0.10.5.0b4-py3-none-manylinux_2_28_x86_64.whl

Download URL ket_lang-0.10.5.0b4-py3-none-manylinux_2_28_x86_64.whl
Size 3.2 MB
Tags Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
01ecb4f6e7ffacbc7a12c10af4b4327cfeb96f8e6e9ec778bcb0ab86b8ebc9fc
BLAKE2b-256 checksum
How to use checksums
9baf6c663a1e1449261a7cf7384f8dd485c4c2396a48f7bd47245ea6e76af4a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.22

Release files / ket_lang-0.10.5.0b4-py3-none-macosx_13_0_universal2.whl

Download URL ket_lang-0.10.5.0b4-py3-none-macosx_13_0_universal2.whl
Size 7.9 MB
Tags Python 3 macOS 13.0+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
ec1281c354c9ea72a5c8bc145ed3940254e5395d80819d633d9a180f1b3a1605
BLAKE2b-256 checksum
How to use checksums
41e83c64d6e7ec1b82310a9fbda2015cb39342c2ad32517e24c1bbc8ec4ca004
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.22

Security for ket-lang 0.10.5.0b4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page