Skip to content

Commit 43e3ee1

Browse files
authored
qbraid qir batch jobs example (#35)
* qir sim notebook * qbraid_qir sim * Update qbraid_qir_sim_batch_jobs.ipynb * Update qbraid_qir_sim_batch_jobs.ipynb
1 parent 8374a08 commit 43e3ee1

File tree

1 file changed

+222
-0
lines changed

1 file changed

+222
-0
lines changed
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "a3266f3c-cde6-416c-a440-82157c045254",
6+
"metadata": {},
7+
"source": [
8+
"# qBraid QIR simulator batch job submission"
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": null,
14+
"id": "d86abb05-b5e2-4098-9248-df4eb56c5a6e",
15+
"metadata": {
16+
"tags": []
17+
},
18+
"outputs": [],
19+
"source": [
20+
"from qbraid.runtime import QbraidProvider\n",
21+
"from qbraid.visualization import plot_histogram\n",
22+
"from qbraid.programs import QPROGRAM_REGISTRY"
23+
]
24+
},
25+
{
26+
"cell_type": "code",
27+
"execution_count": null,
28+
"id": "cd6e2abc-0ed9-4162-90e7-87ea0b134c7f",
29+
"metadata": {
30+
"tags": []
31+
},
32+
"outputs": [],
33+
"source": [
34+
"provider = QbraidProvider()"
35+
]
36+
},
37+
{
38+
"cell_type": "code",
39+
"execution_count": null,
40+
"id": "cd3ff1ba-8ef9-4e26-acc0-fc3e6702a83b",
41+
"metadata": {
42+
"tags": []
43+
},
44+
"outputs": [],
45+
"source": [
46+
"device = provider.get_device(\"qbraid_qir_simulator\")\n",
47+
"\n",
48+
"device.status()"
49+
]
50+
},
51+
{
52+
"cell_type": "code",
53+
"execution_count": null,
54+
"id": "2a338a0c-2a38-4606-8d4a-bbaeedec6f94",
55+
"metadata": {
56+
"tags": []
57+
},
58+
"outputs": [],
59+
"source": [
60+
"target_spec = device.profile.get(\"program_spec\")\n",
61+
"\n",
62+
"target_spec"
63+
]
64+
},
65+
{
66+
"cell_type": "code",
67+
"execution_count": null,
68+
"id": "20373871-5eae-4340-be68-21699222e285",
69+
"metadata": {
70+
"tags": []
71+
},
72+
"outputs": [],
73+
"source": [
74+
"QPROGRAM_REGISTRY"
75+
]
76+
},
77+
{
78+
"cell_type": "code",
79+
"execution_count": null,
80+
"id": "409a018a-7924-413b-b831-9e659c4d2c51",
81+
"metadata": {
82+
"tags": []
83+
},
84+
"outputs": [],
85+
"source": [
86+
"graph = device.scheme.conversion_graph\n",
87+
"\n",
88+
"graph.plot(legend=True)"
89+
]
90+
},
91+
{
92+
"cell_type": "markdown",
93+
"id": "f5c98c5e-f74a-40be-9051-5b5a510bcfd2",
94+
"metadata": {},
95+
"source": [
96+
"Create batch of GHZ state circuits using OpenQASM 3 and Cirq"
97+
]
98+
},
99+
{
100+
"cell_type": "code",
101+
"execution_count": null,
102+
"id": "3c530aa7-d1c5-4966-bb87-9c56e7c9a224",
103+
"metadata": {
104+
"tags": []
105+
},
106+
"outputs": [],
107+
"source": [
108+
"import cirq\n",
109+
"import qiskit\n",
110+
"\n",
111+
"from qbraid.visualization import circuit_drawer\n",
112+
"\n",
113+
"\n",
114+
"def qasm3_ghz() -> str:\n",
115+
" return \"\"\"\n",
116+
"OPENQASM 3.0;\n",
117+
"bit[3] b;\n",
118+
"qubit[3] q;\n",
119+
"h q[0];\n",
120+
"cx q[0], q[1];\n",
121+
"cx q[1], q[2];\n",
122+
"b[0] = measure q[0];\n",
123+
"b[1] = measure q[1];\n",
124+
"b[2] = measure q[2];\n",
125+
" \"\"\"\n",
126+
"\n",
127+
"\n",
128+
"def cirq_ghz() -> cirq.Circuit:\n",
129+
" \"\"\"Returns Cirq GHZ circuit\"\"\"\n",
130+
" q0, q1, q2 = cirq.LineQubit.range(3)\n",
131+
" circuit = cirq.Circuit(\n",
132+
" cirq.ops.H(q0),\n",
133+
" cirq.ops.CNOT(q0, q1),\n",
134+
" cirq.ops.CNOT(q1, q2),\n",
135+
" cirq.measure((q0, q1, q2), key=\"result\"),\n",
136+
" )\n",
137+
" return circuit\n",
138+
"\n",
139+
"\n",
140+
"circuits = [qasm3_ghz(), cirq_ghz()]\n",
141+
"\n",
142+
"circuit_drawer(circuits[0])"
143+
]
144+
},
145+
{
146+
"cell_type": "markdown",
147+
"id": "a224e3a1-5d1e-4c80-8fe8-2dd9744b602e",
148+
"metadata": {},
149+
"source": [
150+
"Submit quantum jobs to remote qBraid QIR simulator and plot results"
151+
]
152+
},
153+
{
154+
"cell_type": "code",
155+
"execution_count": null,
156+
"id": "27400989-57c3-4b81-884d-a8de9d830089",
157+
"metadata": {},
158+
"outputs": [],
159+
"source": [
160+
"batch_jobs = device.run(circuits, shots=100)"
161+
]
162+
},
163+
{
164+
"cell_type": "code",
165+
"execution_count": null,
166+
"id": "0d3e36bc-0909-47d5-830a-7abec30a7f77",
167+
"metadata": {
168+
"tags": []
169+
},
170+
"outputs": [],
171+
"source": [
172+
"for job in batch_jobs:\n",
173+
" print(job.status())"
174+
]
175+
},
176+
{
177+
"cell_type": "code",
178+
"execution_count": null,
179+
"id": "b8f93ae4-1505-47b8-abe5-8ce7547f7d78",
180+
"metadata": {},
181+
"outputs": [],
182+
"source": [
183+
"batch_results = [job.result() for job in batch_jobs]\n",
184+
"\n",
185+
"batch_counts = [result.measurement_counts() for result in batch_results]"
186+
]
187+
},
188+
{
189+
"cell_type": "code",
190+
"execution_count": null,
191+
"id": "132eb338-fe98-46b6-a590-8025df4087c0",
192+
"metadata": {
193+
"tags": []
194+
},
195+
"outputs": [],
196+
"source": [
197+
"plot_histogram(batch_counts)"
198+
]
199+
}
200+
],
201+
"metadata": {
202+
"kernelspec": {
203+
"display_name": "Python 3 [qBraid]",
204+
"language": "python",
205+
"name": "python3_qbraid_sdk_9j9sjy"
206+
},
207+
"language_info": {
208+
"codemirror_mode": {
209+
"name": "ipython",
210+
"version": 3
211+
},
212+
"file_extension": ".py",
213+
"mimetype": "text/x-python",
214+
"name": "python",
215+
"nbconvert_exporter": "python",
216+
"pygments_lexer": "ipython3",
217+
"version": "3.10.14"
218+
}
219+
},
220+
"nbformat": 4,
221+
"nbformat_minor": 5
222+
}

0 commit comments

Comments
 (0)