From 1bd8eaf9b052a56923495b0a1a7770cef9cc2579 Mon Sep 17 00:00:00 2001 From: AkiDoesntCode Date: Tue, 30 Jun 2026 20:50:35 -0500 Subject: [PATCH 1/3] Batch Jobs Added a batch jobs --- .../qbraid_runtime_batch_jobs.ipynb | 131 ++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 qBraid-Runtime/qbraid_runtime_batch_jobs.ipynb diff --git a/qBraid-Runtime/qbraid_runtime_batch_jobs.ipynb b/qBraid-Runtime/qbraid_runtime_batch_jobs.ipynb new file mode 100644 index 0000000..59b90de --- /dev/null +++ b/qBraid-Runtime/qbraid_runtime_batch_jobs.ipynb @@ -0,0 +1,131 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Submitting Batch Jobs with the qBraid Runtime\n", + "\n", + "The [qBraid-SDK](https://github.com/qBraid/qBraid) can submit a list of circuits as a single batch job. Passing `as_batch=True` to `QbraidDevice.run()` sends the circuits in one API call and returns a single `BatchResult` instead of a separate job per circuit. This was added in [qBraid-SDK v0.12.1](https://github.com/qBraid/qBraid/releases/tag/v0.12.1).\n", + "\n", + "> **Note:** Batch submission requires a device whose profile reports `batch_job_support = True`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%%capture\n", + "\n", + "%pip install 'qbraid[qiskit,visualization]'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from qiskit import QuantumCircuit\n", + "from qbraid.runtime import QbraidProvider\n", + "from qbraid.visualization import plot_histogram\n", + "\n", + "provider = QbraidProvider()\n", + "device = provider.get_device(\"qbraid:equal1:sim:bell-1\")\n", + "\n", + "assert device.profile.batch_job_support is True" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Build the circuits\n", + "\n", + "A batch needs more than one circuit, so we build two with Qiskit. `bell` is a two-qubit circuit and `ghz` is a three-qubit circuit — both are standard entangled states. Calling `measure_all()` adds a measurement on every qubit so the device returns counts." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "bell = QuantumCircuit(2)\n", + "bell.h(0)\n", + "bell.cx(0, 1)\n", + "bell.measure_all()\n", + "\n", + "ghz = QuantumCircuit(3)\n", + "ghz.h(0)\n", + "ghz.cx(0, 1)\n", + "ghz.cx(1, 2)\n", + "ghz.measure_all()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Submit as a single batch\n", + "\n", + "We pass the two circuits as a list with `as_batch=True`, so they run as one job instead of two separate submissions. `job.result()` returns a `BatchResult`: `result.num_circuits` is how many circuits ran, `result.results` holds each circuit's counts on its own, and `result.data.get_counts()` combines them, which we then plot as a histogram." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "job = device.run([bell, ghz], as_batch=True, shots=100)\n", + "\n", + "result = job.result() # BatchResult\n", + "print(result.num_circuits) # 2\n", + "\n", + "for i, circuit_result in enumerate(result.results):\n", + " print(f\"Circuit {i}: {circuit_result.data.get_counts()}\")\n", + "\n", + "batch_counts = result.data.get_counts()\n", + "\n", + "plot_histogram(batch_counts)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + "Copyright Notice: \n", + " All rights reserved © [2026] qBraid. This notebook is part of the qBraid-Lab-Demo repository.\n", + "The qBraid-Lab-Demo is licensed under the Apache License, Version 2.0.\n", + "You may obtain a copy of the License at .\n", + "Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n", + "
" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".demo", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.0" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} From 19b4d15d9f838589b55f045f732d63548320b352 Mon Sep 17 00:00:00 2001 From: AkiDoesntCode Date: Tue, 30 Jun 2026 22:52:45 -0500 Subject: [PATCH 2/3] Fixed Copilot Suggestions --- qBraid-Runtime/qbraid_runtime_batch_jobs.ipynb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/qBraid-Runtime/qbraid_runtime_batch_jobs.ipynb b/qBraid-Runtime/qbraid_runtime_batch_jobs.ipynb index 59b90de..a0a7daf 100644 --- a/qBraid-Runtime/qbraid_runtime_batch_jobs.ipynb +++ b/qBraid-Runtime/qbraid_runtime_batch_jobs.ipynb @@ -19,7 +19,7 @@ "source": [ "%%capture\n", "\n", - "%pip install 'qbraid[qiskit,visualization]'" + "%pip install --upgrade 'qbraid[qiskit,visualization]'" ] }, { @@ -35,7 +35,8 @@ "provider = QbraidProvider()\n", "device = provider.get_device(\"qbraid:equal1:sim:bell-1\")\n", "\n", - "assert device.profile.batch_job_support is True" + "if not device.profile.batch_job_support:\n", + " raise RuntimeError(f\"Device {device.id} does not support batch jobs.\")" ] }, { @@ -71,7 +72,7 @@ "source": [ "## Submit as a single batch\n", "\n", - "We pass the two circuits as a list with `as_batch=True`, so they run as one job instead of two separate submissions. `job.result()` returns a `BatchResult`: `result.num_circuits` is how many circuits ran, `result.results` holds each circuit's counts on its own, and `result.data.get_counts()` combines them, which we then plot as a histogram." + "We pass the two circuits as a list with `as_batch=True`, so they run as one job instead of two separate submissions. `job.result()` returns a `BatchResult`: `result.num_circuits` is how many circuits ran, and `result.results` holds each circuit's result on its own. Because the two circuits have different numbers of qubits, we print and plot each circuit's counts separately rather than combining them." ] }, { @@ -86,11 +87,9 @@ "print(result.num_circuits) # 2\n", "\n", "for i, circuit_result in enumerate(result.results):\n", - " print(f\"Circuit {i}: {circuit_result.data.get_counts()}\")\n", - "\n", - "batch_counts = result.data.get_counts()\n", - "\n", - "plot_histogram(batch_counts)" + " counts = circuit_result.data.get_counts()\n", + " print(f\"Circuit {i}: {counts}\")\n", + " display(plot_histogram(counts))" ] }, { From e8ef8f83521d23a98a8873f2f8d9112f6a597e23 Mon Sep 17 00:00:00 2001 From: AkiDoesntCode Date: Thu, 2 Jul 2026 09:24:59 -0500 Subject: [PATCH 3/3] Added qBraid version --- qBraid-Runtime/qbraid_runtime_batch_jobs.ipynb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/qBraid-Runtime/qbraid_runtime_batch_jobs.ipynb b/qBraid-Runtime/qbraid_runtime_batch_jobs.ipynb index a0a7daf..00a2de9 100644 --- a/qBraid-Runtime/qbraid_runtime_batch_jobs.ipynb +++ b/qBraid-Runtime/qbraid_runtime_batch_jobs.ipynb @@ -22,6 +22,17 @@ "%pip install --upgrade 'qbraid[qiskit,visualization]'" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import qbraid\n", + "\n", + "qbraid.__version__" + ] + }, { "cell_type": "code", "execution_count": null,