No project description provided
Project description
Quantum Serverless client
Installation
pip install quantum_serverless
Documentation
Full docs can be found at https://qiskit-extensions.github.io/quantum-serverless/
Usage
Step 1: write pattern
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
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
job.status()
# 'DONE'
# or get logs
job.logs()
Step 4: get results
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}
# ]}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
quantum_serverless-0.10.1.tar.gz
(33.4 kB
view details)
Built Distribution
File details
Details for the file quantum_serverless-0.10.1.tar.gz
.
File metadata
- Download URL: quantum_serverless-0.10.1.tar.gz
- Upload date:
- Size: 33.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 238a020a7ae77eae667ac0cda7b67d837823824179072862364ff4b414598ee8 |
|
MD5 | 0d76a984c34a049e457b2d6f24ed2bc0 |
|
BLAKE2b-256 | 197aec5e521c47557a751c6d63bef1f63b7801010332cb952b6715b9def7358d |
File details
Details for the file quantum_serverless-0.10.1-py3-none-any.whl
.
File metadata
- Download URL: quantum_serverless-0.10.1-py3-none-any.whl
- Upload date:
- Size: 49.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2985218fc76b8f4f5d9a7545ed8a531d72e39c15eed40ede762015bd75496536 |
|
MD5 | 480f74322bf45e2b31d58c4771854a78 |
|
BLAKE2b-256 | 8038c559c14db8484d760e8e045212ff027939079fd9e68fd8cb91ab86966867 |