[![Stability](https://img.shields.io/badge/stability-alpha-f4d03f.svg)](https://github.com/Qiskit/qiskit-serverless/releases)
[![Client verify process](https://github.com/Qiskit/qiskit-serverless/actions/workflows/client-verify.yaml/badge.svg)](https://github.com/Qiskit/qiskit-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.11-informational)](https://www.python.org/)
[![Qiskit](https://img.shields.io/badge/Qiskit-%E2%89%A5%200.39.0-6133BD)](https://github.com/Qiskit/qiskit)
# Qiskit Serverless client
![diagram](https://raw.githubusercontent.com/Qiskit/qiskit-serverless/main/docs/images/qs_diagram.png)
# Installation
```shell
pip install qiskit_serverless
```
## Documentation
Full docs can be found at https://qiskit.github.io/qiskit-serverless/
## Usage
### Step 1: write funtion in ./src/function.py
```python
from qiskit_serverless import distribute_task, get, get_arguments, save_result
from qiskit import QuantumCircuit
from qiskit.circuit.random import random_circuit
from qiskit.primitives import StatevectorSampler as 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()[0].data.meas.get_counts()
# 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 function
```python
from qiskit_serverless import ServerlessClient, QiskitFunction
from qiskit.circuit.random import random_circuit
client = ServerlessClient(
token="<TOKEN>",
host="<GATEWAY_ADDRESS>",
)
# create function
function = QiskitFunction(
title="Quickstart",
entrypoint="program.py",
working_dir="./src"
)
client.upload(function)
# create inputs to our program
circuits = []
for _ in range(3):
circuit = random_circuit(3, 2)
circuit.measure_all()
circuits.append(circuit)
# run program
my_function = client.get("Quickstart")
job = my_function.run(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': [
# {'101': 902, '011': 66, '110': 2, '111': 37, '100': 17},
# {'100': 626, '101': 267, '001': 49, '000': 82},
# {'010': 145, '100': 126, '011': 127, '001': 89, '110': 173, '111': 166, '000': 94, '101': 104}
# ]}
```
Raw data
{
"_id": null,
"home_page": null,
"name": "qiskit-serverless",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": null,
"keywords": "qiskit serverless quantum computing",
"author": null,
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/b5/a3/fa76a667fc38b33dfb5892151d83627b9994ac36794d1ae65b57f097135d/qiskit_serverless-0.18.0.tar.gz",
"platform": null,
"description": "[![Stability](https://img.shields.io/badge/stability-alpha-f4d03f.svg)](https://github.com/Qiskit/qiskit-serverless/releases)\n[![Client verify process](https://github.com/Qiskit/qiskit-serverless/actions/workflows/client-verify.yaml/badge.svg)](https://github.com/Qiskit/qiskit-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.11-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# Qiskit Serverless client\n\n![diagram](https://raw.githubusercontent.com/Qiskit/qiskit-serverless/main/docs/images/qs_diagram.png)\n\n# Installation\n\n```shell\npip install qiskit_serverless\n```\n\n## Documentation\n\nFull docs can be found at https://qiskit.github.io/qiskit-serverless/\n\n## Usage\n\n### Step 1: write funtion in ./src/function.py\n\n```python\nfrom qiskit_serverless import distribute_task, get, get_arguments, save_result\n\nfrom qiskit import QuantumCircuit\nfrom qiskit.circuit.random import random_circuit\nfrom qiskit.primitives import StatevectorSampler as Sampler\nfrom 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()\ndef distributed_sample(circuit: QuantumCircuit):\n \"\"\"Calculates quasi dists as a distributed function.\"\"\"\n return Sampler().run([(circuit)]).result()[0].data.meas.get_counts()\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\narguments = get_arguments()\ncircuits = arguments.get(\"circuits\", [])\n\n# 3. run our functions in a loop\n# and get execution references back\nfunction_references = [\n distributed_sample(circuit)\n for circuit in circuits\n]\n\n# 4. `get` function will collect all\n# results from distributed functions\ncollected_results = get(function_references)\n\n# 5. `save_result` will save results of program execution\n# so we can access it later\nsave_result({\n \"quasi_dists\": collected_results\n})\n```\n\n\n### Step 2: run function\n\n```python\nfrom qiskit_serverless import ServerlessClient, QiskitFunction\nfrom qiskit.circuit.random import random_circuit\n\nclient = ServerlessClient(\n token=\"<TOKEN>\",\n host=\"<GATEWAY_ADDRESS>\",\n)\n\n# create function\nfunction = QiskitFunction(\n title=\"Quickstart\",\n entrypoint=\"program.py\",\n working_dir=\"./src\"\n)\nclient.upload(function)\n\n# create inputs to our program\ncircuits = []\nfor _ in range(3):\n circuit = random_circuit(3, 2)\n circuit.measure_all()\n circuits.append(circuit)\n\n# run program\nmy_function = client.get(\"Quickstart\")\njob = my_function.run(circuits=circuits)\n```\n\n### Step 3: monitor job status\n\n```python\njob.status()\n# 'DONE'\n\n# or get logs\njob.logs()\n```\n\n\n### Step 4: get results\n\n```python\njob.result()\n# {'quasi_dists': [\n# {'101': 902, '011': 66, '110': 2, '111': 37, '100': 17},\n# {'100': 626, '101': 267, '001': 49, '000': 82},\n# {'010': 145, '100': 126, '011': 127, '001': 89, '110': 173, '111': 166, '000': 94, '101': 104}\n# ]}\n```\n",
"bugtrack_url": null,
"license": null,
"summary": null,
"version": "0.18.0",
"project_urls": null,
"split_keywords": [
"qiskit",
"serverless",
"quantum",
"computing"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "40df55dadbba06c0b053af85f32e377990b307903f97394ce69fbb92bb627f0e",
"md5": "b7092cb73259dfca216aa8c66e792d4c",
"sha256": "6da48e1764f4cd97a53d365bcaeb5324e58c712b1a6fa2e7814e14f29555a5ae"
},
"downloads": -1,
"filename": "qiskit_serverless-0.18.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b7092cb73259dfca216aa8c66e792d4c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 48377,
"upload_time": "2024-11-04T14:26:32",
"upload_time_iso_8601": "2024-11-04T14:26:32.903464Z",
"url": "https://files.pythonhosted.org/packages/40/df/55dadbba06c0b053af85f32e377990b307903f97394ce69fbb92bb627f0e/qiskit_serverless-0.18.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b5a3fa76a667fc38b33dfb5892151d83627b9994ac36794d1ae65b57f097135d",
"md5": "92d53a441d76d568953e9f8d3fe01b6b",
"sha256": "155fcc6050797186d587c9a47b06e1c38cc704d233d3caf4996d6c9c9481f2d1"
},
"downloads": -1,
"filename": "qiskit_serverless-0.18.0.tar.gz",
"has_sig": false,
"md5_digest": "92d53a441d76d568953e9f8d3fe01b6b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 31904,
"upload_time": "2024-11-04T14:26:33",
"upload_time_iso_8601": "2024-11-04T14:26:33.970517Z",
"url": "https://files.pythonhosted.org/packages/b5/a3/fa76a667fc38b33dfb5892151d83627b9994ac36794d1ae65b57f097135d/qiskit_serverless-0.18.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-04 14:26:33",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "qiskit-serverless"
}