quantum-serverless


Namequantum-serverless JSON
Version 0.10.1 PyPI version JSON
download
home_pageNone
SummaryNone
upload_time2024-04-29 20:37:58
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords quantum serverless qiskit
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Stability](https://img.shields.io/badge/stability-alpha-f4d03f.svg)](https://github.com/Qiskit-Extensions/quantum-serverless/releases)
[![Client verify process](https://github.com/Qiskit-Extensions/quantum-serverless/actions/workflows/client-verify.yaml/badge.svg)](https://github.com/Qiskit-Extensions/quantum-serverless/actions/workflows/client-verify.yaml)
[![License](https://img.shields.io/github/license/qiskit-community/quantum-prototype-template?label=License)](https://github.com/qiskit-community/quantum-prototype-template/blob/main/LICENSE.txt)
[![Code style: Black](https://img.shields.io/badge/Code%20style-Black-000.svg)](https://github.com/psf/black)
[![Python](https://img.shields.io/badge/Python-3.8%20%7C%203.9%20%7C%203.10-informational)](https://www.python.org/)
[![Qiskit](https://img.shields.io/badge/Qiskit-%E2%89%A5%200.39.0-6133BD)](https://github.com/Qiskit/qiskit)

# Quantum Serverless client

![diagram](https://raw.githubusercontent.com/Qiskit-Extensions/quantum-serverless/main/docs/images/qs_diagram.png)

# Installation

```shell
pip install quantum_serverless
```

## Documentation

Full docs can be found at https://qiskit-extensions.github.io/quantum-serverless/

## Usage

### Step 1: write pattern

```python
  from quantum_serverless import distribute_task, get, get_arguments, save_result

   from qiskit import QuantumCircuit
   from qiskit.circuit.random import random_circuit
   from qiskit.primitives import Sampler
   from qiskit.quantum_info import SparsePauliOp

   # 1. let's annotate out function to convert it
   # to distributed async function
   # using `distribute_task` decorator
   @distribute_task()
   def distributed_sample(circuit: QuantumCircuit):
       """Calculates quasi dists as a distributed function."""
       return Sampler().run(circuit).result().quasi_dists[0]


   # 2. our program will have one arguments
   # `circuits` which will store list of circuits
   # we want to sample in parallel.
   # Let's use `get_arguments` funciton
   # to access all program arguments
   arguments = get_arguments()
   circuits = arguments.get("circuits", [])

   # 3. run our functions in a loop
   # and get execution references back
   function_references = [
       distributed_sample(circuit)
       for circuit in circuits
   ]

   # 4. `get` function will collect all
   # results from distributed functions
   collected_results = get(function_references)

   # 5. `save_result` will save results of program execution
   # so we can access it later
   save_result({
       "quasi_dists": collected_results
   })
```
 

### Step 2: run pattern

```python
   from quantum_serverless import ServerlessProvider, QiskitPattern
   from qiskit.circuit.random import random_circuit

   serverless = ServerlessProvider(
       username="<USERNAME>", 
       password="<PASSWORD>",
       host="<GATEWAY_ADDRESS>",
   )

   # create program
   program = QiskitPattern(
       title="Quickstart",
       entrypoint="pattern.py",
       working_dir="./src"
   )

   # create inputs to our program
   circuits = []
   for _ in range(3):
       circuit = random_circuit(3, 2)
       circuit.measure_all()
       circuits.append(circuit)

   # run program
   job = serverless.run(
       program=program,
       arguments={
           "circuits": circuits
       }
   )
```

### Step 3: monitor job status

```python
   job.status()
   # 'DONE'
    
   # or get logs
   job.logs()
```


### Step 4: get results

```python
   job.result()
   # {"quasi_dists": [
   #  {"0": 0.25, "1": 0.25, "2": 0.2499999999999999, "3": 0.2499999999999999},
   #  {"0": 0.1512273969460124, "1": 0.0400459556274728, "6": 0.1693190975212014, "7": 0.6394075499053132},
   #  {"0": 0.25, "1": 0.25, "4": 0.2499999999999999, "5": 0.2499999999999999}
   # ]}
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "quantum-serverless",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "quantum serverless qiskit",
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/19/7a/ec5e521c47557a751c6d63bef1f63b7801010332cb952b6715b9def7358d/quantum_serverless-0.10.1.tar.gz",
    "platform": null,
    "description": "[![Stability](https://img.shields.io/badge/stability-alpha-f4d03f.svg)](https://github.com/Qiskit-Extensions/quantum-serverless/releases)\n[![Client verify process](https://github.com/Qiskit-Extensions/quantum-serverless/actions/workflows/client-verify.yaml/badge.svg)](https://github.com/Qiskit-Extensions/quantum-serverless/actions/workflows/client-verify.yaml)\n[![License](https://img.shields.io/github/license/qiskit-community/quantum-prototype-template?label=License)](https://github.com/qiskit-community/quantum-prototype-template/blob/main/LICENSE.txt)\n[![Code style: Black](https://img.shields.io/badge/Code%20style-Black-000.svg)](https://github.com/psf/black)\n[![Python](https://img.shields.io/badge/Python-3.8%20%7C%203.9%20%7C%203.10-informational)](https://www.python.org/)\n[![Qiskit](https://img.shields.io/badge/Qiskit-%E2%89%A5%200.39.0-6133BD)](https://github.com/Qiskit/qiskit)\n\n# Quantum Serverless client\n\n![diagram](https://raw.githubusercontent.com/Qiskit-Extensions/quantum-serverless/main/docs/images/qs_diagram.png)\n\n# Installation\n\n```shell\npip install quantum_serverless\n```\n\n## Documentation\n\nFull docs can be found at https://qiskit-extensions.github.io/quantum-serverless/\n\n## Usage\n\n### Step 1: write pattern\n\n```python\n  from quantum_serverless import distribute_task, get, get_arguments, save_result\n\n   from qiskit import QuantumCircuit\n   from qiskit.circuit.random import random_circuit\n   from qiskit.primitives import Sampler\n   from qiskit.quantum_info import SparsePauliOp\n\n   # 1. let's annotate out function to convert it\n   # to distributed async function\n   # using `distribute_task` decorator\n   @distribute_task()\n   def distributed_sample(circuit: QuantumCircuit):\n       \"\"\"Calculates quasi dists as a distributed function.\"\"\"\n       return Sampler().run(circuit).result().quasi_dists[0]\n\n\n   # 2. our program will have one arguments\n   # `circuits` which will store list of circuits\n   # we want to sample in parallel.\n   # Let's use `get_arguments` funciton\n   # to access all program arguments\n   arguments = get_arguments()\n   circuits = arguments.get(\"circuits\", [])\n\n   # 3. run our functions in a loop\n   # and get execution references back\n   function_references = [\n       distributed_sample(circuit)\n       for circuit in circuits\n   ]\n\n   # 4. `get` function will collect all\n   # results from distributed functions\n   collected_results = get(function_references)\n\n   # 5. `save_result` will save results of program execution\n   # so we can access it later\n   save_result({\n       \"quasi_dists\": collected_results\n   })\n```\n \n\n### Step 2: run pattern\n\n```python\n   from quantum_serverless import ServerlessProvider, QiskitPattern\n   from qiskit.circuit.random import random_circuit\n\n   serverless = ServerlessProvider(\n       username=\"<USERNAME>\", \n       password=\"<PASSWORD>\",\n       host=\"<GATEWAY_ADDRESS>\",\n   )\n\n   # create program\n   program = QiskitPattern(\n       title=\"Quickstart\",\n       entrypoint=\"pattern.py\",\n       working_dir=\"./src\"\n   )\n\n   # create inputs to our program\n   circuits = []\n   for _ in range(3):\n       circuit = random_circuit(3, 2)\n       circuit.measure_all()\n       circuits.append(circuit)\n\n   # run program\n   job = serverless.run(\n       program=program,\n       arguments={\n           \"circuits\": circuits\n       }\n   )\n```\n\n### Step 3: monitor job status\n\n```python\n   job.status()\n   # 'DONE'\n    \n   # or get logs\n   job.logs()\n```\n\n\n### Step 4: get results\n\n```python\n   job.result()\n   # {\"quasi_dists\": [\n   #  {\"0\": 0.25, \"1\": 0.25, \"2\": 0.2499999999999999, \"3\": 0.2499999999999999},\n   #  {\"0\": 0.1512273969460124, \"1\": 0.0400459556274728, \"6\": 0.1693190975212014, \"7\": 0.6394075499053132},\n   #  {\"0\": 0.25, \"1\": 0.25, \"4\": 0.2499999999999999, \"5\": 0.2499999999999999}\n   # ]}\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": null,
    "version": "0.10.1",
    "project_urls": null,
    "split_keywords": [
        "quantum",
        "serverless",
        "qiskit"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8038c559c14db8484d760e8e045212ff027939079fd9e68fd8cb91ab86966867",
                "md5": "480f74322bf45e2b31d58c4771854a78",
                "sha256": "2985218fc76b8f4f5d9a7545ed8a531d72e39c15eed40ede762015bd75496536"
            },
            "downloads": -1,
            "filename": "quantum_serverless-0.10.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "480f74322bf45e2b31d58c4771854a78",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 49346,
            "upload_time": "2024-04-29T20:37:56",
            "upload_time_iso_8601": "2024-04-29T20:37:56.113475Z",
            "url": "https://files.pythonhosted.org/packages/80/38/c559c14db8484d760e8e045212ff027939079fd9e68fd8cb91ab86966867/quantum_serverless-0.10.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "197aec5e521c47557a751c6d63bef1f63b7801010332cb952b6715b9def7358d",
                "md5": "0d76a984c34a049e457b2d6f24ed2bc0",
                "sha256": "238a020a7ae77eae667ac0cda7b67d837823824179072862364ff4b414598ee8"
            },
            "downloads": -1,
            "filename": "quantum_serverless-0.10.1.tar.gz",
            "has_sig": false,
            "md5_digest": "0d76a984c34a049e457b2d6f24ed2bc0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 33425,
            "upload_time": "2024-04-29T20:37:58",
            "upload_time_iso_8601": "2024-04-29T20:37:58.029130Z",
            "url": "https://files.pythonhosted.org/packages/19/7a/ec5e521c47557a751c6d63bef1f63b7801010332cb952b6715b9def7358d/quantum_serverless-0.10.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-29 20:37:58",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "quantum-serverless"
}
        
Elapsed time: 0.38470s