Skip to main content

No project description provided

Project description

Stability Client verify process License Code style: Black Python Qiskit

Qiskit Serverless client

diagram

Installation

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

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

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

job.status()
# 'DONE'

# or get logs
job.logs()

Step 4: get results

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}
# ]}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qiskit_serverless-0.18.0.tar.gz (31.9 kB view details)

Uploaded Source

Built Distribution

qiskit_serverless-0.18.0-py3-none-any.whl (48.4 kB view details)

Uploaded Python 3

File details

Details for the file qiskit_serverless-0.18.0.tar.gz.

File metadata

  • Download URL: qiskit_serverless-0.18.0.tar.gz
  • Upload date:
  • Size: 31.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for qiskit_serverless-0.18.0.tar.gz
Algorithm Hash digest
SHA256 155fcc6050797186d587c9a47b06e1c38cc704d233d3caf4996d6c9c9481f2d1
MD5 92d53a441d76d568953e9f8d3fe01b6b
BLAKE2b-256 b5a3fa76a667fc38b33dfb5892151d83627b9994ac36794d1ae65b57f097135d

See more details on using hashes here.

File details

Details for the file qiskit_serverless-0.18.0-py3-none-any.whl.

File metadata

File hashes

Hashes for qiskit_serverless-0.18.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6da48e1764f4cd97a53d365bcaeb5324e58c712b1a6fa2e7814e14f29555a5ae
MD5 b7092cb73259dfca216aa8c66e792d4c
BLAKE2b-256 40df55dadbba06c0b053af85f32e377990b307903f97394ce69fbb92bb627f0e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page