ket-lang


Nameket-lang JSON
Version 0.8.3 PyPI version JSON
download
home_pagehttps://quantumket.org
SummaryKet quantum programming language interpreter and library
upload_time2025-02-14 21:56:16
maintainerNone
docs_urlNone
authorEvandro Chagas Ribeiro da Rosa
requires_python>=3.9
licenseApache-2.0
keywords quantum computer quantum programming quantum simulator
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <!--
SPDX-FileCopyrightText: 2020 Evandro Chagas Ribeiro da Rosa <evandro@quantuloop.com>
SPDX-FileCopyrightText: 2020 Rafael de Santiago <r.santiago@ufsc.br>

SPDX-License-Identifier: Apache-2.0
-->

# Ket Quantum Programming

[![PyPI](https://img.shields.io/pypi/v/ket-lang.svg)](https://pypi.org/project/ket-lang/)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md)
[![REUSE status](https://api.reuse.software/badge/gitlab.com/quantum-ket/ket)](https://api.reuse.software/info/gitlab.com/quantum-ket/ket)

[[_TOC_]]

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

Python is the most widely used programming language for machine learning and data science and has been the language of choice for quantum programming. Ket is a Python-embedded language, but many can use it as a Python library in most cases. So you can use Ket together with NumPy, ScyPy, Pandas, and other popular Python libraries.

Ket's goal is to streamline the development of hardware-independent classical quantum applications by providing transparent interaction of classical and quantum data. See <https://quantumket.org> to learn more about Ket.

## Installation :arrow_down:

Ket requires Python 3.9 or newer and is available for Linux, Windows, and macOS (both Apple silicon and Intel). If you are using a non-x86_64 (Intel/AMD) CPU, such as ARM, on Linux or Windows, you will need to install [Rust](https://www.rust-lang.org/tools/install) before installing Ket.

You can install Ket using [`pip`](https://pip.pypa.io/en/stable/user_guide/). To do so, copy and paste the following command into your terminal:

```shell
pip install ket-lang
```

## Documentation :scroll:

Documentation available at <https://quantumket.org>.

## Examples :bulb:

### Grover's Algorithm

```py
from ket import *
from math import sqrt, pi


def grover(n: int, oracle) -> int:
    p = Process()
    qubits = H(p.alloc(n))
    steps = int((pi / 4) * sqrt(2**n))
    for _ in range(steps):
        oracle(qubits)
        with around(H, qubits):
            phase_oracle(0, qubits)
    return measure(qubits).value


n = 8
looking_for = 13
print(grover(n, phase_oracle(looking_for)))
# 13
```

### Quantum Teleportation

```py
from ket import *


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__":
    from math import pi

    p = Process()

    alice_message = PHASE(pi / 4, H(p.alloc()))

    alice_message_dump = dump(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)

    bob_qubit_dump = dump(bob_qubit)

    print("Alice Message:")
    print(alice_message_dump.show())

    print("Bob Qubit:")
    print(bob_qubit_dump.show())
# Alice Message:
# |0⟩     (50.00%)
#  0.707107               ≅      1/√2
# |1⟩     (50.00%)
#  0.500000+0.500000i     ≅  (1+i)/√4
# Bob Qubit:
# |0⟩     (50.00%)
#  0.707107               ≅      1/√2
# |1⟩     (50.00%)
#  0.500000+0.500000i     ≅  (1+i)/√4
```

## Setup for Ket Development :hammer:

To get started with Ket development, follow these steps:

1. **Rust Installation**
  
    Ensure that Rust is installed on your system. If not, follow the [Rust install guide](https://www.rust-lang.org/tools/install). After installation, set the Rust version to 1.82 using the following command:

    ```shell
    rustup default 1.82
    ```

2. **Clone and Compile**

    Clone the Ket repository and compile the Rust libraries:

    ```shell
    git clone --recursive https://gitlab.com/quantum-ket/ket.git
    cd ket

    cargo build --manifest-path src/ket/clib/libs/libket/Cargo.toml
    cargo build --manifest-path src/ket/clib/libs/kbw/Cargo.toml

    ln -s libket/target/debug/libket.so src/ket/clib/libs
    ln -s kbw/target/debug/libkbw.so src/ket/clib/libs
    ```

3. **Set Up Virtual Environment**

    Set up a virtual environment for Python:

    ```shell
    python3 -m venv venv
    source venv/bin/activate
    ```

4. **Install Dependencies**

    Upgrade pip and install development requirements:

    ```shell
    pip install -U pip
    pip install -r requirements_dev.txt
    ```

5. **Install Ket**

    Install Ket in editable mode:

    ```shell
    pip install -e .[full]
    ```

6. **Run Tests**

    To ensure everything is correctly installed, run the tests:

    ```shell
    pytest
    ```

You're now set up for Ket development! Happy coding! 🚀

## Cite Ket :book:

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](https://doi.org/10.1145/3474224)

```bibtex
@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}
}
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://quantumket.org",
    "name": "ket-lang",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "quantum computer, quantum programming, quantum simulator",
    "author": "Evandro Chagas Ribeiro da Rosa",
    "author_email": "evandro@quantuloop.com",
    "download_url": "https://files.pythonhosted.org/packages/b6/82/b08094d3fa10a34eba023670006d18cddc23252403fb49fc65cc2e3b3404/ket_lang-0.8.3.tar.gz",
    "platform": "linux",
    "description": "<!--\nSPDX-FileCopyrightText: 2020 Evandro Chagas Ribeiro da Rosa <evandro@quantuloop.com>\nSPDX-FileCopyrightText: 2020 Rafael de Santiago <r.santiago@ufsc.br>\n\nSPDX-License-Identifier: Apache-2.0\n-->\n\n# Ket Quantum Programming\n\n[![PyPI](https://img.shields.io/pypi/v/ket-lang.svg)](https://pypi.org/project/ket-lang/)\n[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md)\n[![REUSE status](https://api.reuse.software/badge/gitlab.com/quantum-ket/ket)](https://api.reuse.software/info/gitlab.com/quantum-ket/ket)\n\n[[_TOC_]]\n\nKet is an embedded programming language that introduces the ease of Python to quantum programming, letting anyone quickly prototype and test a quantum application.\n\nPython is the most widely used programming language for machine learning and data science and has been the language of choice for quantum programming. Ket is a Python-embedded language, but many can use it as a Python library in most cases. So you can use Ket together with NumPy, ScyPy, Pandas, and other popular Python libraries.\n\nKet's goal is to streamline the development of hardware-independent classical quantum applications by providing transparent interaction of classical and quantum data. See <https://quantumket.org> to learn more about Ket.\n\n## Installation :arrow_down:\n\nKet requires Python 3.9 or newer and is available for Linux, Windows, and macOS (both Apple silicon and Intel). If you are using a non-x86_64 (Intel/AMD) CPU, such as ARM, on Linux or Windows, you will need to install [Rust](https://www.rust-lang.org/tools/install) before installing Ket.\n\nYou can install Ket using [`pip`](https://pip.pypa.io/en/stable/user_guide/). To do so, copy and paste the following command into your terminal:\n\n```shell\npip install ket-lang\n```\n\n## Documentation :scroll:\n\nDocumentation available at <https://quantumket.org>.\n\n## Examples :bulb:\n\n### Grover's Algorithm\n\n```py\nfrom ket import *\nfrom math import sqrt, pi\n\n\ndef grover(n: int, oracle) -> int:\n    p = Process()\n    qubits = H(p.alloc(n))\n    steps = int((pi / 4) * sqrt(2**n))\n    for _ in range(steps):\n        oracle(qubits)\n        with around(H, qubits):\n            phase_oracle(0, qubits)\n    return measure(qubits).value\n\n\nn = 8\nlooking_for = 13\nprint(grover(n, phase_oracle(looking_for)))\n# 13\n```\n\n### Quantum Teleportation\n\n```py\nfrom ket import *\n\n\ndef entangle(a: Quant, b: Quant):\n    return CNOT(H(a), b)\n\n\ndef teleport(quantum_message: Quant, entangled_qubit: Quant):\n    adj(entangle)(quantum_message, entangled_qubit)\n    return measure(entangled_qubit).value, measure(quantum_message).value\n\n\ndef decode(classical_message: tuple[int, int], qubit: Quant):\n    if classical_message[0] == 1:\n        X(qubit)\n\n    if classical_message[1] == 1:\n        Z(qubit)\n\n\nif __name__ == \"__main__\":\n    from math import pi\n\n    p = Process()\n\n    alice_message = PHASE(pi / 4, H(p.alloc()))\n\n    alice_message_dump = dump(alice_message)\n\n    alice_qubit, bob_qubit = entangle(*p.alloc(2))\n\n    classical_message = teleport(\n        quantum_message=alice_message, entangled_qubit=alice_qubit\n    )\n\n    decode(classical_message, bob_qubit)\n\n    bob_qubit_dump = dump(bob_qubit)\n\n    print(\"Alice Message:\")\n    print(alice_message_dump.show())\n\n    print(\"Bob Qubit:\")\n    print(bob_qubit_dump.show())\n# Alice Message:\n# |0\u27e9     (50.00%)\n#  0.707107               \u2245      1/\u221a2\n# |1\u27e9     (50.00%)\n#  0.500000+0.500000i     \u2245  (1+i)/\u221a4\n# Bob Qubit:\n# |0\u27e9     (50.00%)\n#  0.707107               \u2245      1/\u221a2\n# |1\u27e9     (50.00%)\n#  0.500000+0.500000i     \u2245  (1+i)/\u221a4\n```\n\n## Setup for Ket Development :hammer:\n\nTo get started with Ket development, follow these steps:\n\n1. **Rust Installation**\n  \n    Ensure that Rust is installed on your system. If not, follow the [Rust install guide](https://www.rust-lang.org/tools/install). After installation, set the Rust version to 1.82 using the following command:\n\n    ```shell\n    rustup default 1.82\n    ```\n\n2. **Clone and Compile**\n\n    Clone the Ket repository and compile the Rust libraries:\n\n    ```shell\n    git clone --recursive https://gitlab.com/quantum-ket/ket.git\n    cd ket\n\n    cargo build --manifest-path src/ket/clib/libs/libket/Cargo.toml\n    cargo build --manifest-path src/ket/clib/libs/kbw/Cargo.toml\n\n    ln -s libket/target/debug/libket.so src/ket/clib/libs\n    ln -s kbw/target/debug/libkbw.so src/ket/clib/libs\n    ```\n\n3. **Set Up Virtual Environment**\n\n    Set up a virtual environment for Python:\n\n    ```shell\n    python3 -m venv venv\n    source venv/bin/activate\n    ```\n\n4. **Install Dependencies**\n\n    Upgrade pip and install development requirements:\n\n    ```shell\n    pip install -U pip\n    pip install -r requirements_dev.txt\n    ```\n\n5. **Install Ket**\n\n    Install Ket in editable mode:\n\n    ```shell\n    pip install -e .[full]\n    ```\n\n6. **Run Tests**\n\n    To ensure everything is correctly installed, run the tests:\n\n    ```shell\n    pytest\n    ```\n\nYou're now set up for Ket development! Happy coding! \ud83d\ude80\n\n## Cite Ket :book:\n\nWhen using Ket for research projects, please cite:\n\n> 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](https://doi.org/10.1145/3474224)\n\n```bibtex\n@article{ket,\n   author = {Evandro Chagas Ribeiro da Rosa and Rafael de Santiago},\n   title = {Ket Quantum Programming},\n   year = {2021},\n   issue_date = {January 2022},\n   publisher = {Association for Computing Machinery},\n   address = {New York, NY, USA},\n   volume = {18},\n   number = {1},\n   issn = {1550-4832},\n   url = {https://doi.org/10.1145/3474224},\n   doi = {10.1145/3474224},\n   journal = {J. Emerg. Technol. Comput. Syst.},\n   month = oct,\n   articleno = {12},\n   numpages = {25},\n   keywords = {Quantum programming, cloud quantum computation, qubit simulation}\n}\n```\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Ket quantum programming language interpreter and library",
    "version": "0.8.3",
    "project_urls": {
        "Homepage": "https://quantumket.org",
        "Source": "https://gitlab.com/quantum-ket/ket"
    },
    "split_keywords": [
        "quantum computer",
        " quantum programming",
        " quantum simulator"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "86e855c26b52fdd6d433e3e9428d1f3c42ff14166f36a35281a6ab288f7ddfca",
                "md5": "a74cd0241d6e44b264a4542234b4bcf3",
                "sha256": "cdce8f8fae8119631298751a38423b0e5c27a1e5ef42cf1c98e9f0832c426314"
            },
            "downloads": -1,
            "filename": "ket_lang-0.8.3-py3-none-macosx_10_14_universal2.whl",
            "has_sig": false,
            "md5_digest": "a74cd0241d6e44b264a4542234b4bcf3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 1943955,
            "upload_time": "2025-02-14T21:51:05",
            "upload_time_iso_8601": "2025-02-14T21:51:05.013141Z",
            "url": "https://files.pythonhosted.org/packages/86/e8/55c26b52fdd6d433e3e9428d1f3c42ff14166f36a35281a6ab288f7ddfca/ket_lang-0.8.3-py3-none-macosx_10_14_universal2.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "34298a5dff95bf611e990ace859d79d3511c4fef7975eeb3923e534bfe998285",
                "md5": "b7033e681d5f2dea815c224ff2829259",
                "sha256": "8ca80e6c6880be1f28447a5efa0ed5573a28f794912ed4e9ba5a71cc5a294acd"
            },
            "downloads": -1,
            "filename": "ket_lang-0.8.3-py3-none-manylinux_2_28_x86_64.whl",
            "has_sig": false,
            "md5_digest": "b7033e681d5f2dea815c224ff2829259",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 1101428,
            "upload_time": "2025-02-14T21:56:11",
            "upload_time_iso_8601": "2025-02-14T21:56:11.828222Z",
            "url": "https://files.pythonhosted.org/packages/34/29/8a5dff95bf611e990ace859d79d3511c4fef7975eeb3923e534bfe998285/ket_lang-0.8.3-py3-none-manylinux_2_28_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "78e0b4719052ba5eced54768e46eee883a8388ea253a4c9ab2defeaefc902058",
                "md5": "8196ffd07c689c6f45a80bdbb96967db",
                "sha256": "085445d8f8d4cf429965395d5ec2bc66cf1aaaf5ad14b83b60c91da1d9043026"
            },
            "downloads": -1,
            "filename": "ket_lang-0.8.3-py3-none-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "8196ffd07c689c6f45a80bdbb96967db",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 2826441,
            "upload_time": "2025-02-14T21:56:14",
            "upload_time_iso_8601": "2025-02-14T21:56:14.799446Z",
            "url": "https://files.pythonhosted.org/packages/78/e0/b4719052ba5eced54768e46eee883a8388ea253a4c9ab2defeaefc902058/ket_lang-0.8.3-py3-none-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "b682b08094d3fa10a34eba023670006d18cddc23252403fb49fc65cc2e3b3404",
                "md5": "164644b2e3a180ef732c65efb0a2aa88",
                "sha256": "a51f7f33e6f1f40759fcacfc01ec0c33c0fef6c531746b829f3fdd56fd507154"
            },
            "downloads": -1,
            "filename": "ket_lang-0.8.3.tar.gz",
            "has_sig": false,
            "md5_digest": "164644b2e3a180ef732c65efb0a2aa88",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 93970,
            "upload_time": "2025-02-14T21:56:16",
            "upload_time_iso_8601": "2025-02-14T21:56:16.941077Z",
            "url": "https://files.pythonhosted.org/packages/b6/82/b08094d3fa10a34eba023670006d18cddc23252403fb49fc65cc2e3b3404/ket_lang-0.8.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-14 21:56:16",
    "github": false,
    "gitlab": true,
    "bitbucket": false,
    "codeberg": false,
    "gitlab_user": "quantum-ket",
    "gitlab_project": "ket",
    "lcname": "ket-lang"
}
        
Elapsed time: 0.92172s