Qiskit Serverless client
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
@distribute_task()
def distributed_sample(circuit: QuantumCircuit):
"""Calculates quasi dists as a distributed function."""
return Sampler().run([(circuit)]).result()[0].data.meas.get_counts()
arguments = get_arguments()
circuits = arguments.get("circuits", [])
function_references = [
distributed_sample(circuit)
for circuit in circuits
]
collected_results = get(function_references)
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>",
)
function = QiskitFunction(
title="Quickstart",
entrypoint="program.py",
working_dir="./src"
)
client.upload(function)
circuits = []
for _ in range(3):
circuit = random_circuit(3, 2)
circuit.measure_all()
circuits.append(circuit)
my_function = client.get("Quickstart")
job = my_function.run(circuits=circuits)
Step 3: monitor job status
job.status()
job.logs()
Step 4: get results
job.result()