ket-lang


Nameket-lang JSON
Version 0.8.1 PyPI version JSON
download
home_pagehttps://quantumket.org
SummaryKet quantum programming language interpreter and library
upload_time2024-12-18 20:03:52
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/01/70/e509333f7216b37070f22b2a35f22a8dbeb31b627597c2e674f8745ec221/ket_lang-0.8.1.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.1",
    "project_urls": {
        "Homepage": "https://quantumket.org",
        "Source": "https://gitlab.com/quantum-ket/ket"
    },
    "split_keywords": [
        "quantum computer",
        " quantum programming",
        " quantum simulator"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2fa5a6dddf1c95dce1b438ea846cbf5695b98c8a20f5f71ff5efaddddca6bf8d",
                "md5": "45cec4ae57db6e531a4f3fe33802fd5b",
                "sha256": "4683bb710b1b43176e805a847733ddfa4708eb88da69c287dc979d047f9855e9"
            },
            "downloads": -1,
            "filename": "ket_lang-0.8.1-py3-none-macosx_10_14_universal2.whl",
            "has_sig": false,
            "md5_digest": "45cec4ae57db6e531a4f3fe33802fd5b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 1941421,
            "upload_time": "2024-12-18T19:59:11",
            "upload_time_iso_8601": "2024-12-18T19:59:11.170117Z",
            "url": "https://files.pythonhosted.org/packages/2f/a5/a6dddf1c95dce1b438ea846cbf5695b98c8a20f5f71ff5efaddddca6bf8d/ket_lang-0.8.1-py3-none-macosx_10_14_universal2.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "68dceaf8b3ac790152ca8ce7f0904dff7ca666cb2407b12f8aa15179db5b1c0b",
                "md5": "7b3f80aea9c40d3b2e7f317189bcffd7",
                "sha256": "b8b510bda810dbb38aa997e4bfb088bbb06457ed94a9b06934fddbeb288ed9c5"
            },
            "downloads": -1,
            "filename": "ket_lang-0.8.1-py3-none-manylinux_2_28_x86_64.whl",
            "has_sig": false,
            "md5_digest": "7b3f80aea9c40d3b2e7f317189bcffd7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 1097820,
            "upload_time": "2024-12-18T20:03:46",
            "upload_time_iso_8601": "2024-12-18T20:03:46.599315Z",
            "url": "https://files.pythonhosted.org/packages/68/dc/eaf8b3ac790152ca8ce7f0904dff7ca666cb2407b12f8aa15179db5b1c0b/ket_lang-0.8.1-py3-none-manylinux_2_28_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ae771c99bbc1e0b7a4999c126600c7756eeb958947a452daeb4c988cae9d120f",
                "md5": "d14d297380cebc1f1e47a4ca09175ee9",
                "sha256": "357023772ac8981cfd78d9d7f455fc8ee18a35f85ca21cce1ff31c5d76b9889b"
            },
            "downloads": -1,
            "filename": "ket_lang-0.8.1-py3-none-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "d14d297380cebc1f1e47a4ca09175ee9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 2822954,
            "upload_time": "2024-12-18T20:03:49",
            "upload_time_iso_8601": "2024-12-18T20:03:49.710463Z",
            "url": "https://files.pythonhosted.org/packages/ae/77/1c99bbc1e0b7a4999c126600c7756eeb958947a452daeb4c988cae9d120f/ket_lang-0.8.1-py3-none-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0170e509333f7216b37070f22b2a35f22a8dbeb31b627597c2e674f8745ec221",
                "md5": "ab9d86883439987d0cdb2cd41e15524a",
                "sha256": "22c0393ac0183d2a250fdd8eab61e492fc4f9db0debf0ee29d7bf0a116d2967b"
            },
            "downloads": -1,
            "filename": "ket_lang-0.8.1.tar.gz",
            "has_sig": false,
            "md5_digest": "ab9d86883439987d0cdb2cd41e15524a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 93023,
            "upload_time": "2024-12-18T20:03:52",
            "upload_time_iso_8601": "2024-12-18T20:03:52.473931Z",
            "url": "https://files.pythonhosted.org/packages/01/70/e509333f7216b37070f22b2a35f22a8dbeb31b627597c2e674f8745ec221/ket_lang-0.8.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-18 20:03:52",
    "github": false,
    "gitlab": true,
    "bitbucket": false,
    "codeberg": false,
    "gitlab_user": "quantum-ket",
    "gitlab_project": "ket",
    "lcname": "ket-lang"
}
        
Elapsed time: 0.41511s