Skip to main content

No project description provided

Project description

Stability Client verify process License Code style: Black Python Qiskit

Quantum Serverless client

diagram

Installation

pip install quantum_serverless

Documentation

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

Usage

Step 1: write program

  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 program

   from quantum_serverless import QuantumServerless, GatewayProvider
   from qiskit.circuit.random import random_circuit

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

   # create program
   program = Program(
       title="Quickstart",
       entrypoint="program.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()
   # <JobStatus.SUCCEEDED: 'SUCCEEDED'>
    
   # 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


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.4.0.tar.gz (31.3 kB view details)

Uploaded Source

Built Distribution

quantum_serverless-0.4.0-py3-none-any.whl (48.9 kB view details)

Uploaded Python 3

File details

Details for the file quantum_serverless-0.4.0.tar.gz.

File metadata

  • Download URL: quantum_serverless-0.4.0.tar.gz
  • Upload date:
  • Size: 31.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for quantum_serverless-0.4.0.tar.gz
Algorithm Hash digest
SHA256 b0492fe48bd57bb0ca6afc5de8478e1c6f51e4f108baa060054ae7cbb5e2ef46
MD5 689be4fd8966adc658e0d65f861a6822
BLAKE2b-256 0aadd16061aecc5363d4436b950de9a391e99bf7a047527f1b5935ac6abed2a5

See more details on using hashes here.

File details

Details for the file quantum_serverless-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for quantum_serverless-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0c938b3560e70a8379e17c026ad1741cdcb25fca0944ad44c54c7a0db7f4678
MD5 1a7c475d27a37ce72a5e30d6cadbf162
BLAKE2b-256 233be93db54e2846d1f6b5fdcb1823cb7ea9ca0956299467da25a0332241423e

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