Skip to content

Commit 16dc6ef

Browse files
committed
Updates for 0.51.0
1 parent 78df43a commit 16dc6ef

File tree

17 files changed

+875
-415
lines changed

17 files changed

+875
-415
lines changed

algorithms/algebraic/discrete_log/discrete_log.ipynb

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@
8585
" x2: QArray[QBit],\n",
8686
" func_res: Output[QArray[QBit]],\n",
8787
") -> None:\n",
88-
"\n",
8988
" allocate(ceiling(log(N_modulus, 2)), func_res)\n",
9089
"\n",
9190
" inplace_prepare_int(1, func_res)\n",
@@ -215,9 +214,7 @@
215214
{
216215
"name": "stdout",
217216
"output_type": "stream",
218-
"text": [
219-
""
220-
]
217+
"text": []
221218
}
222219
],
223220
"source": [
@@ -401,9 +398,7 @@
401398
{
402399
"name": "stdout",
403400
"output_type": "stream",
404-
"text": [
405-
""
406-
]
401+
"text": []
407402
}
408403
],
409404
"source": [
@@ -550,8 +545,6 @@
550545
}
551546
],
552547
"source": [
553-
"import math\n",
554-
"\n",
555548
"logarithm = None\n",
556549
"for sample in parsed:\n",
557550
" try:\n",

algorithms/algebraic/shor/shor_modular_exponentiation.ipynb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,7 @@
302302
{
303303
"name": "stdout",
304304
"output_type": "stream",
305-
"text": [
306-
""
307-
]
305+
"text": []
308306
}
309307
],
310308
"source": [
@@ -571,16 +569,12 @@
571569
"cell_type": "code",
572570
"execution_count": 10,
573571
"id": "8e9d0b08-f3f8-4e95-a468-bfeec010d97c",
574-
"metadata": {
575-
"scrolled": true
576-
},
572+
"metadata": {},
577573
"outputs": [
578574
{
579575
"name": "stdout",
580576
"output_type": "stream",
581-
"text": [
582-
""
583-
]
577+
"text": []
584578
}
585579
],
586580
"source": [

algorithms/amplitude_estimation/quantum_counting/quantum_counting.ipynb

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,7 @@
288288
{
289289
"name": "stdout",
290290
"output_type": "stream",
291-
"text": [
292-
""
293-
]
291+
"text": []
294292
}
295293
],
296294
"source": [
@@ -561,16 +559,12 @@
561559
"cell_type": "code",
562560
"execution_count": 14,
563561
"id": "b127fa25-1285-49f4-9fe3-43a57f984d2d",
564-
"metadata": {
565-
"scrolled": true
566-
},
562+
"metadata": {},
567563
"outputs": [
568564
{
569565
"name": "stdout",
570566
"output_type": "stream",
571-
"text": [
572-
""
573-
]
567+
"text": []
574568
}
575569
],
576570
"source": [
@@ -597,9 +591,7 @@
597591
"cell_type": "code",
598592
"execution_count": 15,
599593
"id": "c1110098-1af8-4c2a-9ca7-14b8d36e75f3",
600-
"metadata": {
601-
"scrolled": true
602-
},
594+
"metadata": {},
603595
"outputs": [
604596
{
605597
"name": "stdout",

algorithms/grover/grover_max_cut/grover_max_cut.ipynb

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@
207207
" )\n",
208208
"\n",
209209
"\n",
210-
"qmod = create_model(main)"
210+
"qmod = create_model(main)\n",
211+
"qmod = set_constraints(qmod, max_width=22)\n",
212+
"write_qmod(qmod, \"grover_max_cut\")"
211213
]
212214
},
213215
{
@@ -224,28 +226,6 @@
224226
"We proceed by synthesizing the circuit using Classiq's synthesis engine. The synthesis should take approximately several seconds:"
225227
]
226228
},
227-
{
228-
"cell_type": "code",
229-
"execution_count": 6,
230-
"id": "542b41be-c61c-42cf-a6ea-062a9c8abc01",
231-
"metadata": {
232-
"tags": []
233-
},
234-
"outputs": [],
235-
"source": [
236-
"qmod = set_constraints(qmod, Constraints(max_width=22))"
237-
]
238-
},
239-
{
240-
"cell_type": "code",
241-
"execution_count": 7,
242-
"id": "e400ac31-f38f-4855-a00b-c3b599ce299c",
243-
"metadata": {},
244-
"outputs": [],
245-
"source": [
246-
"write_qmod(qmod, \"grover_max_cut\")"
247-
]
248-
},
249229
{
250230
"cell_type": "code",
251231
"execution_count": 8,
@@ -284,9 +264,7 @@
284264
{
285265
"name": "stdout",
286266
"output_type": "stream",
287-
"text": [
288-
""
289-
]
267+
"text": []
290268
}
291269
],
292270
"source": [
@@ -342,19 +320,7 @@
342320
},
343321
"outputs": [],
344322
"source": [
345-
"optimization_result = execute(qprog).result()"
346-
]
347-
},
348-
{
349-
"cell_type": "code",
350-
"execution_count": 12,
351-
"id": "9ccbd6e5-c1ce-4818-bebe-78294e0690fe",
352-
"metadata": {
353-
"tags": []
354-
},
355-
"outputs": [],
356-
"source": [
357-
"res = optimization_result[0].value"
323+
"optimization_result = execute(qprog).result_value()"
358324
]
359325
},
360326
{
@@ -420,7 +386,7 @@
420386
}
421387
],
422388
"source": [
423-
"res.parsed_counts"
389+
"optimization_result.parsed_counts"
424390
]
425391
},
426392
{
@@ -440,7 +406,7 @@
440406
},
441407
"outputs": [],
442408
"source": [
443-
"most_probable_result = res.parsed_counts[0]"
409+
"most_probable_result = optimization_result.parsed_counts[0]"
444410
]
445411
},
446412
{

algorithms/hhl/hhl/hhl.ipynb

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198
}
199199
],
200200
"source": [
201-
"from classiq import matrix_to_hamiltonian\n",
201+
"from classiq import *\n",
202202
"\n",
203203
"hamiltonian = matrix_to_hamiltonian(A)\n",
204204
"n = len(hamiltonian[0].pauli)\n",
@@ -256,19 +256,6 @@
256256
},
257257
"outputs": [],
258258
"source": [
259-
"from classiq import (\n",
260-
" CArray,\n",
261-
" CInt,\n",
262-
" CReal,\n",
263-
" Output,\n",
264-
" QArray,\n",
265-
" QBit,\n",
266-
" QCallable,\n",
267-
" prepare_amplitudes,\n",
268-
" qfunc,\n",
269-
")\n",
270-
"\n",
271-
"\n",
272259
"@qfunc\n",
273260
"def load_b(\n",
274261
" amplitudes: CArray[CReal], state: Output[QArray[QBit]], bound: CReal\n",
@@ -323,22 +310,6 @@
323310
},
324311
"outputs": [],
325312
"source": [
326-
"from classiq import (\n",
327-
" CInt,\n",
328-
" Output,\n",
329-
" PauliTerm,\n",
330-
" QArray,\n",
331-
" QBit,\n",
332-
" QCallable,\n",
333-
" QNum,\n",
334-
" allocate,\n",
335-
" allocate_num,\n",
336-
" create_model,\n",
337-
" qfunc,\n",
338-
" qpe_flexible,\n",
339-
" synthesize,\n",
340-
" within_apply,\n",
341-
")\n",
342313
"from classiq.qmod.symbolic import floor, log\n",
343314
"\n",
344315
"# Parameters for the initial state preparation\n",
@@ -365,7 +336,6 @@
365336
" phase: Output[QNum],\n",
366337
" indicator: Output[QBit],\n",
367338
"):\n",
368-
"\n",
369339
" # Allocate a quantum number for the phase with given precision\n",
370340
" allocate_num(precision, False, precision, phase)\n",
371341
"\n",
@@ -410,7 +380,6 @@
410380
" ClassiqSimulatorBackendNames,\n",
411381
" ExecutionPreferences,\n",
412382
")\n",
413-
"from classiq.synthesis import set_execution_preferences\n",
414383
"\n",
415384
"backend_preferences = ClassiqBackendPreferences(\n",
416385
" backend_name=ClassiqSimulatorBackendNames.SIMULATOR_STATEVECTOR\n",
@@ -463,7 +432,6 @@
463432
"outputs": [],
464433
"source": [
465434
"def read_positions(circuit_hhl, res_hhl):\n",
466-
"\n",
467435
" # positions of control qubit\n",
468436
" target_pos = res_hhl.physical_qubits_map[\"indicator\"][0]\n",
469437
"\n",
@@ -520,7 +488,6 @@
520488
"outputs": [],
521489
"source": [
522490
"def quantum_solution(circuit_hhl, res_hhl, precision):\n",
523-
"\n",
524491
" target_pos, sol_pos, phase_pos = read_positions(circuit_hhl, res_hhl)\n",
525492
"\n",
526493
" # Read Quantum solution from the entries of `res` registers, where the target register `indicator` is 1 and the `phase` register is in state |0>^m\n",
@@ -561,7 +528,6 @@
561528
"\n",
562529
"\n",
563530
"def quantum_solution_preprocessed(A, b, circuit_hhl, res_hhl, precision, disp=True):\n",
564-
"\n",
565531
" # Classical solution\n",
566532
" sol_classical = np.linalg.solve(A, b)\n",
567533
" if disp:\n",
@@ -587,7 +553,6 @@
587553
"\n",
588554
"\n",
589555
"def show_solutions(A, b, circuit_hhl, res_hhl, precision, check=True, disp=True):\n",
590-
"\n",
591556
" # Classical solution and preprocessed quantum solution\n",
592557
" sol_classical, qsol_corrected = quantum_solution_preprocessed(\n",
593558
" A, b, circuit_hhl, res_hhl, QPE_SIZE, disp=disp\n",
@@ -747,15 +712,12 @@
747712
"name": "stdout",
748713
"output_type": "stream",
749714
"text": [
750-
"",
751715
"Circuit depth = 461\n",
752716
"Circuit CX count = 288\n"
753717
]
754718
}
755719
],
756720
"source": [
757-
"from classiq import QuantumProgram, show, synthesize\n",
758-
"\n",
759721
"qprog_hhl_exact = synthesize(qmod_hhl_exact)\n",
760722
"show(qprog_hhl_exact)\n",
761723
"\n",
@@ -798,10 +760,9 @@
798760
},
799761
"outputs": [],
800762
"source": [
801-
"from classiq import execute\n",
802763
"from classiq.execution import ExecutionDetails\n",
803764
"\n",
804-
"res_hhl_exact = execute(qprog_hhl_exact).result()[0].value"
765+
"res_hhl_exact = execute(qprog_hhl_exact).result_value()"
805766
]
806767
},
807768
{
@@ -920,7 +881,6 @@
920881
},
921882
"outputs": [],
922883
"source": [
923-
"from classiq import CArray, CReal, suzuki_trotter\n",
924884
"from classiq.qmod.symbolic import ceiling, log\n",
925885
"\n",
926886
"\n",
@@ -961,7 +921,6 @@
961921
},
962922
"outputs": [],
963923
"source": [
964-
"from classiq import Output, create_model, prepare_amplitudes, synthesize\n",
965924
"from classiq.qmod.symbolic import floor\n",
966925
"\n",
967926
"# parameters for the amplitude preparation\n",
@@ -1033,7 +992,6 @@
1033992
"name": "stdout",
1034993
"output_type": "stream",
1035994
"text": [
1036-
"",
1037995
"Circuit depth = 5074\n",
1038996
"Circuit CX count = 2968\n",
1039997
"\n",
@@ -1067,7 +1025,7 @@
10671025
"print()\n",
10681026
"\n",
10691027
"# Show results\n",
1070-
"res_hhl_trotter = execute(qprog_hhl_trotter).result()[0].value\n",
1028+
"res_hhl_trotter = execute(qprog_hhl_trotter).result_value()\n",
10711029
"show_solutions(A, b, circuit_hhl_trotter, res_hhl_trotter, precision)"
10721030
]
10731031
},

0 commit comments

Comments
 (0)