Skip to main content

Platform-agnostic quantum runtime framework.

Project description

qbraid-sdk-header

CI codecov GitHub Pages PyPI version Downloads License DOI

The qBraid-SDK is a platform-agnostic quantum runtime framework designed for both quantum software and hardware providers.

This Python-based tool streamlines the full lifecycle management of quantum jobs—from defining program specifications to job submission and through to the post-processing and visualization of results. Unlike existing runtime frameworks that focus their automation and abstractions on quantum components, qBraid adds an extra layer of abstractions that considers the ultimate IR needed to encode the quantum program and securely submit it to a remote API. Notably, the qBraid-SDK does not adhere to a fixed circuit-building library, or quantum program representation. Instead, it empowers providers to dynamically register any desired input program type as the target based on their specific needs. This flexibility is extended by the framework’s modular pipeline, which facilitates any number of additional program validation, transpilation, and compilation steps.

By addressing the full scope of client-side software requirements necessary for secure submission and management of quantum jobs, the qBraid-SDK vastly reduces the overhead and redundancy typically associated with the development of internal pipelines and cross-platform integrations in quantum computing.


Runtime Diagram

Resources

Installation & Setup

For the best experience, install the qBraid-SDK environment on lab.qbraid.com. Login (or create an account) and follow the steps to install an environment. Using the SDK on qBraid Lab means direct, pre-configured access to QPUs from IonQ, AQT, QuEra, Rigetti, Pasqal, and IQM, as well as on-demand simulators from qBraid, AWS, IonQ, QuEra, Quantinuum, Rigetti, and Pasqal. See qBraid Quantum Jobs and pricing for more.

Local install

The qBraid-SDK, and all of its dependencies, can be installed using pip:

pip install qbraid

Warning: qbraid versions <0.11 are not compatible with qBraid API V2. See migration guide.

To ensure compatibility with the new platform, use qbraid>=0.11.0.

You can also install from source by cloning this repository and running a pip install command in the root directory of the repository:

git clone https://github.com/qBraid/qBraid.git
cd qBraid
pip install .

Note: The qBraid-SDK requires Python 3.10 or greater.

To use qBraid Runtime locally, you must also install the necessary extras and configure your account credentials according to the device(s) that you are targeting. Follow the linked, provider-specific, instructions for the QbraidProvider, BraketProvider, QiskitRuntimeProvider, IonQProvider, OQCProvider, and AzureQuantumProvider, as applicable.

Quickstart

Check version

You can view the version of the qBraid-SDK you have installed and get detailed information about the installation within Python using the following commands:

In [1]: import qbraid

In [2]: qbraid.__version__

In [3]: qbraid.about()

Transpiler

Graph-based approach to quantum program type conversions.

Below, QPROGRAM_REGISTRY maps shorthand identifiers for supported quantum programs, each corresponding to a type in the typed QPROGRAM Union. For example, 'qiskit' maps to qiskit.QuantumCircuit in QPROGRAM. Notably, 'qasm2' and 'qasm3' both represent raw OpenQASM strings. This arrangement simplifies targeting and transpiling between different quantum programming frameworks.

>>> from qbraid import QPROGRAM_REGISTRY
>>> QPROGRAM_REGISTRY
{'cirq': cirq.circuits.circuit.Circuit,
 'qiskit': qiskit.circuit.quantumcircuit.QuantumCircuit,
 'pennylane': pennylane.tape.tape.QuantumTape,
 'pyquil': pyquil.quil.Program,
 'pytket': pytket._tket.circuit.Circuit,
 'braket': braket.circuits.circuit.Circuit,
 'braket_ahs': braket.ahs.analog_hamiltonian_simulation.AnalogHamiltonianSimulation,
 'openqasm3': openqasm3.ast.Program,
 'pyqir': pyqir.Module,
 'cpp_pyqubo': cpp_pyqubo.Model,
 'qasm2': str,
 'qasm3': str,
 'qasm2_kirin': str,
 'ionq': qbraid.programs.typer.IonQDict,
 'qubo': qbraid.programs.typer.QuboCoefficientsDict,
 'bloqade': bloqade.analog.builder.assign.BatchAssign,
 'cudaq': cudaq.kernel.kernel_builder.PyKernel,
 'qibo': qibo.models.circuit.Circuit,
 'stim': stim._stim_sse2.Circuit,
 'pulser': pulser.sequence.sequence.Sequence,
 'pyqpanda3': pyqpanda3.core.QProg,
 'autoqasm': autoqasm.program.program.Program}

Pass any registered quantum program along with a target package from QPROGRAM_REGISTRY to "transpile" your circuit to a new program type:

>>> from qbraid import random_circuit, transpile
>>> qiskit_circuit = random_circuit("qiskit")
>>> cirq_circuit = transpile(qiskit_circuit, "cirq")
>>> print(qiskit_circuit)
          ┌────────────┐
q_0: ──■──┤ Rx(3.0353) 
     ┌─┴─┐└───┬────┬───┘
q_1:  H ├────┤ X ├────
     └───┘    └────┘
>>> print(cirq_circuit)
0: ───@───Rx(0.966π)───
      
1: ───H───X^0.5────────

Behind the scenes, the qBraid-SDK uses rustworkx to create a directional graph that maps all possible conversions between supported program types:

from qbraid import ConversionGraph

# Loads native conversions from QPROGRAM_REGISTRY
graph = ConversionGraph()

graph.plot(legend=True)

You can use the native conversions supported by qBraid, or define your own. For example:

from unittest.mock import Mock

from qbraid import Conversion, register_program_type

# replace with any program type
register_program_type(Mock, alias="mock")

# replace with your custom conversion function
example_qasm3_to_mock_func = lambda x: x

conversion = Conversion("qasm3", "mock", example_qasm3_to_mock_func)

graph.add_conversion(conversion)

# using a seed is helpful to ensure reproducibility
graph.plot(seed=20, k=3, legend=True)

QbraidProvider

Run experiments using on-demand simulators provided by qBraid. Retrieve a list of available devices:

from qbraid import QbraidProvider

provider = QbraidProvider()
devices = provider.get_devices()

Or, instantiate a known device by ID and submit quantum jobs from any supported program type:

device = provider.get_device("qbraid:qbraid:sim:qir-sv")
jobs = device.run([qiskit_circuit, braket_circuit, cirq_circuit, qasm3_str], shots=1000)

results = [job.result() for job in jobs]
batch_counts = [result.data.get_counts() for result in results]

print(batch_counts[0])
# {'00': 483, '01': 14, '10': 486, '11': 17}

And visualize the results:

from qbraid.visualization import plot_distribution, plot_histogram

plot_distribution(batch_counts)

plot_histogram(batch_counts)

Get Involved

Community GitHub Issues Stack Exchange Discord

License

Apache-2.0 License

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

qbraid-0.11.1.tar.gz (549.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qbraid-0.11.1-py3-none-any.whl (276.0 kB view details)

Uploaded Python 3

File details

Details for the file qbraid-0.11.1.tar.gz.

File metadata

  • Download URL: qbraid-0.11.1.tar.gz
  • Upload date:
  • Size: 549.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for qbraid-0.11.1.tar.gz
Algorithm Hash digest
SHA256 bbdabd181b400f146437552cadb923d38062cc06f9b174927807ed37d922bccf
MD5 aa5ece2804e7ffe4e7c4fffa0f8a8de3
BLAKE2b-256 3c1ef9c56e1ea3bedae952279c19f8d4b8bd4d2fb35532c4fb88af4617f1fba3

See more details on using hashes here.

File details

Details for the file qbraid-0.11.1-py3-none-any.whl.

File metadata

  • Download URL: qbraid-0.11.1-py3-none-any.whl
  • Upload date:
  • Size: 276.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for qbraid-0.11.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f459c6bc261117b64530c064ca27d3c92af7427fbed543bd118d2db84f0b5180
MD5 2743ddb0573840b593121dca04e32ac1
BLAKE2b-256 8eab2e4ef35e5f014420f71282aefd1c80d631fbde6d6a1c992338130eee3b54

See more details on using hashes here.

Supported by

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