Git Product home page Git Product logo

qbraid / qbraid-lab-demo Goto Github PK

View Code? Open in Web Editor NEW
30.0 30.0 10.0 2.78 MB

Notebooks demonstrating how to use qBraid Lab to streamline quantum workflows, connect to quantum hardware, and leverage GPU-enabled scalable compute for hybrid algorithms.

Home Page: https://www.qbraid.com

License: Apache License 2.0

Jupyter Notebook 99.16% Python 0.84%
ipython quantum quantum-algorithms quantum-circuit quantum-computing

qbraid-lab-demo's Introduction

qbraid-sdk-header

CI codecov Documentation Status 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, Oxford Quantum Circuits, QuEra, Rigetti, and IQM, as well as on-demand simulators from qBraid and AWS. See qBraid Quantum Jobs for more.

Local install

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

pip install qbraid

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.9 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, and OQCProvider, 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.programs 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,
 'openqasm3': openqasm3.ast.Program,
 'pyqir': pyqir.Module,
 'qasm2': str,
 'qasm3': str}

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

>>> from qbraid.interface import random_circuit
>>> from qbraid.transpiler import 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.transpiler 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.programs import register_program_type
from qbraid.transpiler import Conversion

# 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 experiements using on-demand simulators provided by qBraid. Retrieve a list of available devices:

from qbraid.runtime 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_qir_simulator")
jobs = device.run([qiskit_circuit, braket_circuit, cirq_circuit, qasm3_str], shots=1000)

results = [job.result() for job in jobs]
batch_counts = [result.measurement_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

Launch on qBraid

The "Launch on qBraid" button (top) can be added to any public GitHub repository. Clicking on it automaically opens qBraid Lab, and performs a git clone of the project repo into your account's home directory. Copy the code below, and replace YOUR-USERNAME and YOUR-REPOSITORY with your GitHub info.

Use the badge in your project's README.md:

[<img src="https://qbraid-static.s3.amazonaws.com/logos/Launch_on_qBraid_white.png" width="150">](https://account.qbraid.com?gitHubUrl=https://github.com/YOUR-USERNAME/YOUR-REPOSITORY.git)

Use the badge in your project's README.rst:

.. image:: https://qbraid-static.s3.amazonaws.com/logos/Launch_on_qBraid_white.png
    :target: https://account.qbraid.com?gitHubUrl=https://github.com/YOUR-USERNAME/YOUR-REPOSITORY.git
    :width: 150px

License

GNU General Public License v3.0

qbraid-lab-demo's People

Contributors

0sophy1 avatar kanavsetia avatar kenny-heitritter avatar pranavkakhandiki avatar rryoung98 avatar ryanhill1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

qbraid-lab-demo's Issues

SDK IBM batch jobs + qBraid Lab integration

@pranavkakhandiki

From Unitary Hack PR qBraid/qBraid#246 from issue qBraid/qBraid#231, SDK now supports submitting batch jobs (multiple circuits at once) to IBM devices, see qbraid.IBMBackendWrapper.run_batch()

Will want to create demo notebook that shows an example of doing this, and also that highlights the batch jobs integration with a picture or gif of the qBraid devices sidebar (see circuitBatch field at bottom of image on right).

qBraid Lab does not currently support IBM quantum jobs, so will need to use your own IBM credentials to submit to these devices.

SDK / quantum jobs show submitting to IonQ Harmony

@pranavkakhandiki

Unitary Hack PR qBraid/qBraid#257 from issue qBraid/qBraid#233 added ability to compile a Braket / Pytket circuit to run on IonQ Harmony device through qbraid.devices.AwsDeviceWrapper.run method via _compat_run_input via braket_ionq_compilation.

Want to create demo notebook that shows a useful example of doing this. Should use qbraid.get_devices to get device ID, and show qbraid.get_jobs` at the end, and how to retrieve and print results.

Added bonus to include qBraid Lab features as part of workflow e.g. :

Feel free to use anything from amazon braket examples or docs as reference if useful

qBraid-SDK Qiskit algo--> AWS device demo

@pranavkakhandiki

We would like to create a new demo notebook that shows how you can write an algorithm in Qiskit and execute it on an AWS device using the qBraid-SDK.

The qiskit-braket-provider tutorials directory contains some notebooks that are of a similar idea. I would say you could work directly off of one of these, but a key factor in this issue is that many of the built-in qiskit.algorithms libraries use custom gates which are not supported by the qBraid-SDK transpiler. So the best approach could be to find an algorithm that is of a small enough size / scope that it can re-written using qiskit standard gates.

Once you have a qiskit algorithm written, the first litmus test is to attempt to transpile it to braket (see sdk transpiler docs), e.g.

from qbraid import circuit_wrapper
from qiskit import QuantumCircuit()

qiskit_circuit = QuantumCircuit(...)
braket_circuit = circuit_wrapper(qiskit_circuit).transpile.("braket")

if that works, then you are almost done. The last step is to use the device wrapper to submit the algo circuit as a quantum job to an AWS device e.g. Braket SV1 (see sdk devices docs). If you have your own AWS credentials, you can do this all locally. If not, you can use the qBraid-SDK environment on qBraid Lab with Quantum Jobs enabled. See install environment docs and quantum jobs docs / sdk quantum jobs demo notebook

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.