Skip to content

Commit

Permalink
qbraid qir batch jobs example (#35)
Browse files Browse the repository at this point in the history
* qir sim notebook

* qbraid_qir sim

* Update qbraid_qir_sim_batch_jobs.ipynb

* Update qbraid_qir_sim_batch_jobs.ipynb
  • Loading branch information
ryanhill1 authored Jul 2, 2024
1 parent 8374a08 commit 43e3ee1
Showing 1 changed file with 222 additions and 0 deletions.
222 changes: 222 additions & 0 deletions qbraid_sdk/qbraid_qir_sim_batch_jobs.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "a3266f3c-cde6-416c-a440-82157c045254",
"metadata": {},
"source": [
"# qBraid QIR simulator batch job submission"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d86abb05-b5e2-4098-9248-df4eb56c5a6e",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from qbraid.runtime import QbraidProvider\n",
"from qbraid.visualization import plot_histogram\n",
"from qbraid.programs import QPROGRAM_REGISTRY"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cd6e2abc-0ed9-4162-90e7-87ea0b134c7f",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"provider = QbraidProvider()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cd3ff1ba-8ef9-4e26-acc0-fc3e6702a83b",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"device = provider.get_device(\"qbraid_qir_simulator\")\n",
"\n",
"device.status()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2a338a0c-2a38-4606-8d4a-bbaeedec6f94",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"target_spec = device.profile.get(\"program_spec\")\n",
"\n",
"target_spec"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "20373871-5eae-4340-be68-21699222e285",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"QPROGRAM_REGISTRY"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "409a018a-7924-413b-b831-9e659c4d2c51",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"graph = device.scheme.conversion_graph\n",
"\n",
"graph.plot(legend=True)"
]
},
{
"cell_type": "markdown",
"id": "f5c98c5e-f74a-40be-9051-5b5a510bcfd2",
"metadata": {},
"source": [
"Create batch of GHZ state circuits using OpenQASM 3 and Cirq"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3c530aa7-d1c5-4966-bb87-9c56e7c9a224",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import cirq\n",
"import qiskit\n",
"\n",
"from qbraid.visualization import circuit_drawer\n",
"\n",
"\n",
"def qasm3_ghz() -> str:\n",
" return \"\"\"\n",
"OPENQASM 3.0;\n",
"bit[3] b;\n",
"qubit[3] q;\n",
"h q[0];\n",
"cx q[0], q[1];\n",
"cx q[1], q[2];\n",
"b[0] = measure q[0];\n",
"b[1] = measure q[1];\n",
"b[2] = measure q[2];\n",
" \"\"\"\n",
"\n",
"\n",
"def cirq_ghz() -> cirq.Circuit:\n",
" \"\"\"Returns Cirq GHZ circuit\"\"\"\n",
" q0, q1, q2 = cirq.LineQubit.range(3)\n",
" circuit = cirq.Circuit(\n",
" cirq.ops.H(q0),\n",
" cirq.ops.CNOT(q0, q1),\n",
" cirq.ops.CNOT(q1, q2),\n",
" cirq.measure((q0, q1, q2), key=\"result\"),\n",
" )\n",
" return circuit\n",
"\n",
"\n",
"circuits = [qasm3_ghz(), cirq_ghz()]\n",
"\n",
"circuit_drawer(circuits[0])"
]
},
{
"cell_type": "markdown",
"id": "a224e3a1-5d1e-4c80-8fe8-2dd9744b602e",
"metadata": {},
"source": [
"Submit quantum jobs to remote qBraid QIR simulator and plot results"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "27400989-57c3-4b81-884d-a8de9d830089",
"metadata": {},
"outputs": [],
"source": [
"batch_jobs = device.run(circuits, shots=100)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0d3e36bc-0909-47d5-830a-7abec30a7f77",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"for job in batch_jobs:\n",
" print(job.status())"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b8f93ae4-1505-47b8-abe5-8ce7547f7d78",
"metadata": {},
"outputs": [],
"source": [
"batch_results = [job.result() for job in batch_jobs]\n",
"\n",
"batch_counts = [result.measurement_counts() for result in batch_results]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "132eb338-fe98-46b6-a590-8025df4087c0",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"plot_histogram(batch_counts)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 [qBraid]",
"language": "python",
"name": "python3_qbraid_sdk_9j9sjy"
},
"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.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit 43e3ee1

Please sign in to comment.