classiq 0.55.0__py3-none-any.whl → 0.56.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. classiq/interface/_version.py +1 -1
  2. classiq/interface/debug_info/debug_info.py +11 -0
  3. classiq/interface/executor/result.py +0 -3
  4. classiq/interface/generator/visitor.py +13 -1
  5. classiq/interface/ide/visual_model.py +2 -0
  6. classiq/interface/interface_version.py +1 -1
  7. classiq/interface/model/handle_binding.py +28 -0
  8. classiq/interface/model/quantum_statement.py +3 -0
  9. classiq/model_expansions/capturing/mangling_utils.py +22 -0
  10. classiq/model_expansions/capturing/propagated_var_stack.py +36 -25
  11. classiq/model_expansions/closure.py +3 -1
  12. classiq/model_expansions/function_builder.py +9 -4
  13. classiq/model_expansions/interpreter.py +7 -1
  14. classiq/model_expansions/quantum_operations/control.py +35 -9
  15. classiq/model_expansions/quantum_operations/emitter.py +13 -3
  16. classiq/model_expansions/quantum_operations/expression_operation.py +55 -17
  17. classiq/model_expansions/quantum_operations/power.py +5 -0
  18. classiq/model_expansions/quantum_operations/quantum_assignment_operation.py +4 -11
  19. classiq/model_expansions/quantum_operations/repeat.py +5 -0
  20. classiq/model_expansions/scope_initialization.py +2 -2
  21. classiq/qmod/builtins/functions/arithmetic.py +0 -2
  22. classiq/qmod/builtins/functions/discrete_sine_cosine_transform.py +0 -12
  23. classiq/qmod/builtins/functions/exponentiation.py +0 -6
  24. classiq/qmod/builtins/functions/grover.py +0 -17
  25. classiq/qmod/builtins/functions/linear_pauli_rotation.py +0 -5
  26. classiq/qmod/builtins/functions/modular_exponentiation.py +0 -3
  27. classiq/qmod/builtins/functions/qaoa_penalty.py +0 -8
  28. classiq/qmod/builtins/functions/qft_functions.py +0 -3
  29. classiq/qmod/builtins/functions/qpe.py +0 -6
  30. classiq/qmod/builtins/functions/qsvt.py +0 -12
  31. classiq/qmod/builtins/functions/standard_gates.py +0 -88
  32. classiq/qmod/builtins/functions/state_preparation.py +7 -15
  33. classiq/qmod/builtins/functions/swap_test.py +0 -3
  34. classiq/qmod/builtins/operations.py +39 -0
  35. classiq/qmod/qmod_constant.py +31 -3
  36. {classiq-0.55.0.dist-info → classiq-0.56.0.dist-info}/METADATA +2 -3
  37. {classiq-0.55.0.dist-info → classiq-0.56.0.dist-info}/RECORD +38 -38
  38. {classiq-0.55.0.dist-info → classiq-0.56.0.dist-info}/WHEEL +0 -0
@@ -18,12 +18,8 @@ def H(target: QBit) -> None:
18
18
  H = \\frac{1}{\\sqrt{2}} \\begin{bmatrix} 1 & 1 \\\\ 1 & -1 \\end{bmatrix}
19
19
  $$
20
20
 
21
- More information on quantum logic gates can be found on [Wikipedia](https://en.wikipedia.org/wiki/Quantum_logic_gate).
22
-
23
21
  Args:
24
22
  target: The qubit to apply the Hadamard gate to.
25
-
26
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
27
23
  """
28
24
  pass
29
25
 
@@ -41,12 +37,8 @@ def X(target: QBit) -> None:
41
37
  X = \\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}
42
38
  $$
43
39
 
44
- More information on quantum logic gates can be found on [Wikipedia](https://en.wikipedia.org/wiki/Quantum_logic_gate).
45
-
46
40
  Args:
47
41
  target: The qubit to apply the Pauli-X gate to.
48
-
49
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
50
42
  """
51
43
  pass
52
44
 
@@ -64,12 +56,8 @@ def Y(target: QBit) -> None:
64
56
  Y = \\begin{bmatrix} 0 & -i \\\\ i & 0 \\end{bmatrix}
65
57
  $$
66
58
 
67
- More information on quantum logic gates can be found on [Wikipedia](https://en.wikipedia.org/wiki/Quantum_logic_gate).
68
-
69
59
  Args:
70
60
  target: The qubit to apply the Pauli-Y gate to.
71
-
72
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
73
61
  """
74
62
  pass
75
63
 
@@ -87,12 +75,8 @@ def Z(target: QBit) -> None:
87
75
  Z = \\begin{bmatrix} 1 & 0 \\\\ 0 & -1 \\end{bmatrix}
88
76
  $$
89
77
 
90
- More information on quantum logic gates can be found on [Wikipedia](https://en.wikipedia.org/wiki/Quantum_logic_gate).
91
-
92
78
  Args:
93
79
  target: The qubit to apply the Pauli-Z gate to.
94
-
95
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
96
80
  """
97
81
  pass
98
82
 
@@ -110,12 +94,8 @@ def I(target: QBit) -> None:
110
94
  I = \\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix}
111
95
  $$
112
96
 
113
- More information on quantum logic gates can be found on [Wikipedia](https://en.wikipedia.org/wiki/Quantum_logic_gate).
114
-
115
97
  Args:
116
98
  target: The qubit to apply the identity gate to.
117
-
118
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
119
99
  """
120
100
  pass
121
101
 
@@ -135,8 +115,6 @@ def S(target: QBit) -> None:
135
115
 
136
116
  Args:
137
117
  target: The qubit to apply the S gate to.
138
-
139
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
140
118
  """
141
119
  pass
142
120
 
@@ -156,8 +134,6 @@ def T(target: QBit) -> None:
156
134
 
157
135
  Args:
158
136
  target: The qubit to apply the T gate to.
159
-
160
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
161
137
  """
162
138
  pass
163
139
 
@@ -177,8 +153,6 @@ def SDG(target: QBit) -> None:
177
153
 
178
154
  Args:
179
155
  target: The qubit to apply the S-dagger gate to.
180
-
181
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
182
156
  """
183
157
  pass
184
158
 
@@ -198,8 +172,6 @@ def TDG(target: QBit) -> None:
198
172
 
199
173
  Args:
200
174
  target: The qubit to apply the T-dagger gate to.
201
-
202
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
203
175
  """
204
176
  pass
205
177
 
@@ -217,13 +189,9 @@ def PHASE(theta: CReal, target: QBit) -> None:
217
189
  PHASE(\\theta) = \\begin{bmatrix} 1 & 0 \\\\ 0 & e^{i\\theta} \\end{bmatrix}
218
190
  $$
219
191
 
220
- More information on quantum logic gates can be found on [Wikipedia](https://en.wikipedia.org/wiki/List_of_quantum_logic_gates#Relative_phase_gates).
221
-
222
192
  Args:
223
193
  theta: The phase angle in radians.
224
194
  target: The qubit to apply the phase gate to.
225
-
226
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
227
195
  """
228
196
  pass
229
197
 
@@ -242,13 +210,9 @@ def RX(theta: CReal, target: QBit) -> None:
242
210
  = \\begin{bmatrix} cos(\\frac{\\theta}{2}) & -i sin(\\frac{\\theta}{2}) \\\\ -i sin(\\frac{\\theta}{2}) & cos(\\frac{\\theta}{2}) \\end{bmatrix}
243
211
  $$
244
212
 
245
- More information on quantum logic gates can be found on [Wikipedia](https://en.wikipedia.org/wiki/List_of_quantum_logic_gates#Rotation_operator_gates).
246
-
247
213
  Args:
248
214
  theta: The rotation angle in radians.
249
215
  target: The qubit to apply the Pauli-X rotation gate to.
250
-
251
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
252
216
  """
253
217
  pass
254
218
 
@@ -267,13 +231,9 @@ def RY(theta: CReal, target: QBit) -> None:
267
231
  = \\begin{bmatrix} cos(\\frac{\\theta}{2}) & -sin(\\frac{\\theta}{2}) \\\\ -sin(\\frac{\\theta}{2}) & cos(\\frac{\\theta}{2}) \\end{bmatrix}
268
232
  $$
269
233
 
270
- More information on quantum logic gates can be found on [Wikipedia](https://en.wikipedia.org/wiki/List_of_quantum_logic_gates#Rotation_operator_gates).
271
-
272
234
  Args:
273
235
  theta: The rotation angle in radians.
274
236
  target: The qubit to apply the Pauli-Y rotation gate to.
275
-
276
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
277
237
  """
278
238
  pass
279
239
 
@@ -292,13 +252,9 @@ def RZ(theta: CReal, target: QBit) -> None:
292
252
  = \\begin{bmatrix} e^{-i\\frac{\\theta}{2}} & 0 \\\\ 0 & e^{i\\frac{\\theta}{2}} \\end{bmatrix}
293
253
  $$
294
254
 
295
- More information on quantum logic gates can be found on [Wikipedia](https://en.wikipedia.org/wiki/List_of_quantum_logic_gates#Rotation_operator_gates).
296
-
297
255
  Args:
298
256
  theta: The rotation angle in radians.
299
257
  target: The qubit to apply the Pauli-Z rotation gate to.
300
-
301
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
302
258
  """
303
259
  pass
304
260
 
@@ -317,14 +273,10 @@ def R(theta: CReal, phi: CReal, target: QBit) -> None:
317
273
  = \\begin{bmatrix} cos(\\frac{\\theta}{2}) & -i e^{-i\\phi} sin(\\frac{\\theta}{2}) \\\\ -i e^{i\\phi} sin(\\frac{\\theta}{2}) & cos(\\frac{\\theta}{2}) \\end{bmatrix}
318
274
  $$
319
275
 
320
- More information on this gate can be found in the [Qiskit documentation](https://docs.quantum.ibm.com/api/qiskit/qiskit.circuit.library.RGate).
321
-
322
276
  Args:
323
277
  theta: The rotation angle in radians.
324
278
  phi: The phase angle in radians.
325
279
  target: The qubit to apply the general single-qubit rotation gate to.
326
-
327
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
328
280
  """
329
281
  pass
330
282
 
@@ -343,13 +295,9 @@ def RXX(theta: CReal, target: QArray[QBit, Literal[2]]) -> None:
343
295
  = \\begin{bmatrix} cos(\\frac{\\theta}{2}) & 0 & 0 & -i sin(\\frac{\\theta}{2}) \\\\ 0 & cos(\\frac{\\theta}{2}) & -i sin(\\frac{\\theta}{2}) & 0 \\\\ 0 & -i sin(\\frac{\\theta}{2}) & cos(\\frac{\\theta}{2}) & 0 \\\\ -i sin(\\frac{\\theta}{2}) & 0 & 0 & cos(\\frac{\\theta}{2}) \\end{bmatrix}
344
296
  $$
345
297
 
346
- For more information on quantum logic gates, see [Wikipedia](https://en.wikipedia.org/wiki/List_of_quantum_logic_gates#Two-qubit_interaction_gates).
347
-
348
298
  Args:
349
299
  theta: The rotation angle in radians.
350
300
  target: The pair of qubits to apply the XX rotation gate to.
351
-
352
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
353
301
  """
354
302
  pass
355
303
 
@@ -368,13 +316,9 @@ def RYY(theta: CReal, target: QArray[QBit, Literal[2]]) -> None:
368
316
  = \\begin{bmatrix} cos(\\frac{\\theta}{2}) & 0 & 0 & -sin(\\frac{\\theta}{2}) \\\\ 0 & cos(\\frac{\\theta}{2}) & sin(\\frac{\\theta}{2}) & 0 \\\\ 0 & sin(\\frac{\\theta}{2}) & cos(\\frac{\\theta}{2}) & 0 \\\\ -sin(\\frac{\\theta}{2}) & 0 & 0 & cos(\\frac{\\theta}{2}) \\end{bmatrix}
369
317
  $$
370
318
 
371
- For more information on quantum logic gates, see [Wikipedia](https://en.wikipedia.org/wiki/List_of_quantum_logic_gates#Two-qubit_interaction_gates).
372
-
373
319
  Args:
374
320
  theta: The rotation angle in radians.
375
321
  target: The pair of qubits to apply the YY rotation gate to.
376
-
377
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
378
322
  """
379
323
  pass
380
324
 
@@ -393,13 +337,9 @@ def RZZ(theta: CReal, target: QArray[QBit, Literal[2]]) -> None:
393
337
  = \\begin{bmatrix} e^{-i\\frac{\\theta}{2}} & 0 & 0 & 0 \\\\ 0 & e^{i\\frac{\\theta}{2}} & 0 & 0 \\\\ 0 & 0 & e^{i\\frac{\\theta}{2}} & 0 \\\\ 0 & 0 & 0 & e^{-i\\frac{\\theta}{2}} \\end{bmatrix}
394
338
  $$
395
339
 
396
- For more information on quantum logic gates, see [Wikipedia](https://en.wikipedia.org/wiki/List_of_quantum_logic_gates#Two-qubit_interaction_gates).
397
-
398
340
  Args:
399
341
  theta: The rotation angle in radians.
400
342
  target: The pair of qubits to apply the ZZ rotation gate to.
401
-
402
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
403
343
  """
404
344
  pass
405
345
 
@@ -425,8 +365,6 @@ def CH(ctrl: QBit, target: QBit) -> None:
425
365
  Args:
426
366
  ctrl: The control qubit.
427
367
  target: The qubit to apply the Hadamard gate on.
428
-
429
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
430
368
  """
431
369
  pass
432
370
 
@@ -452,8 +390,6 @@ def CX(ctrl: QBit, target: QBit) -> None:
452
390
  Args:
453
391
  ctrl: The control qubit.
454
392
  target: The qubit to apply the Pauli-X gate on.
455
-
456
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
457
393
  """
458
394
  pass
459
395
 
@@ -479,8 +415,6 @@ def CY(ctrl: QBit, target: QBit) -> None:
479
415
  Args:
480
416
  ctrl: The control qubit.
481
417
  target: The qubit to apply the Pauli-Y gate on.
482
-
483
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
484
418
  """
485
419
  pass
486
420
 
@@ -506,8 +440,6 @@ def CZ(ctrl: QBit, target: QBit) -> None:
506
440
  Args:
507
441
  ctrl: The control qubit.
508
442
  target: The qubit to apply the Pauli-Z gate on.
509
-
510
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
511
443
  """
512
444
  pass
513
445
 
@@ -534,8 +466,6 @@ def CRX(theta: CReal, ctrl: QBit, target: QBit) -> None:
534
466
  theta: The rotation angle in radians.
535
467
  ctrl: The control qubit.
536
468
  target: The qubit to apply the RX gate on.
537
-
538
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
539
469
  """
540
470
  pass
541
471
 
@@ -562,8 +492,6 @@ def CRY(theta: CReal, ctrl: QBit, target: QBit) -> None:
562
492
  theta (CReal): The rotation angle in radians.
563
493
  ctrl (QBit): The control qubit.
564
494
  target (QBit): The qubit to apply the RY gate on.
565
-
566
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
567
495
  """
568
496
  pass
569
497
 
@@ -590,8 +518,6 @@ def CRZ(theta: CReal, ctrl: QBit, target: QBit) -> None:
590
518
  theta (CReal): The rotation angle in radians.
591
519
  ctrl (QBit): The control qubit.
592
520
  target (QBit): The qubit to apply the RZ gate on.
593
-
594
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
595
521
  """
596
522
  pass
597
523
 
@@ -618,8 +544,6 @@ def CPHASE(theta: CReal, ctrl: QBit, target: QBit) -> None:
618
544
  theta (CReal): The rotation angle in radians.
619
545
  ctrl (QBit): The control qubit.
620
546
  target (QBit): The qubit to apply the PHASE gate on.
621
-
622
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
623
547
  """
624
548
  pass
625
549
 
@@ -645,8 +569,6 @@ def SWAP(qbit0: QBit, qbit1: QBit) -> None:
645
569
  Args:
646
570
  qbit0 (QBit): The first qubit.
647
571
  qbit1 (QBit): The second qubit.
648
-
649
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
650
572
  """
651
573
  pass
652
574
 
@@ -669,8 +591,6 @@ def IDENTITY(target: QArray[QBit]) -> None:
669
591
 
670
592
  Args:
671
593
  target (QArray[QBit]): The qubits to apply the IDENTITY gate on.
672
-
673
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
674
594
  """
675
595
  pass
676
596
 
@@ -692,16 +612,12 @@ def U(theta: CReal, phi: CReal, lam: CReal, gam: CReal, target: QBit) -> None:
692
612
  \\end{bmatrix}
693
613
  $$
694
614
 
695
- More information on this gate can be found on [Wikipedia](https://en.wikipedia.org/wiki/List_of_quantum_logic_gates#Other_named_gates).
696
-
697
615
  Args:
698
616
  theta (CReal): The first Euler angle in radians.
699
617
  phi (CReal): The second Euler angle in radians.
700
618
  lam (CReal): The third Euler angle in radians.
701
619
  gam (CReal): The global phase angle in radians.
702
620
  target (QBit): The qubit to apply the general single-qubit unitary gate to.
703
-
704
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
705
621
  """
706
622
  pass
707
623
 
@@ -728,12 +644,8 @@ def CCX(ctrl: QArray[QBit, Literal[2]], target: QBit) -> None:
728
644
  \\end{bmatrix}
729
645
  $$
730
646
 
731
- More information can be found on [Wikipedia](https://en.wikipedia.org/wiki/Toffoli_gate).
732
-
733
647
  Args:
734
648
  ctrl (QArray[QBit, Literal[2]]): The control qubits.
735
649
  target (QBit): The qubit to apply the conditioned Pauli-X gate on.
736
-
737
- Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
738
650
  """
739
651
  pass
@@ -37,12 +37,11 @@ def allocate(
37
37
 
38
38
  Args:
39
39
  num_qubits: The number of qubits to allocate. Must be a positive integer.
40
- out: The quantum variable that will receive the allocated qubits. Must be uninitialized before allocation. For more information on quantum variable initialization, see [here](https://docs.classiq.io/latest/reference-manual/qmod/language-reference/quantum-variables/).
40
+ out: The quantum variable that will receive the allocated qubits. Must be uninitialized before allocation.
41
41
 
42
42
  Notes:
43
43
  1. If the output variable has been declared with a specific number of qubits, the number of qubits allocated must match the declared number.
44
44
  2. The synthesis engine automatically handles the allocation, either by drawing new qubits from the available pool or by reusing existing ones.
45
-
46
45
  """
47
46
  pass
48
47
 
@@ -65,9 +64,6 @@ def allocate_num(
65
64
  num_qubits: The number of qubits to allocate.
66
65
  is_signed: Whether the number is signed or unsigned.
67
66
  fraction_digits: The number of fractional digits.
68
-
69
- Further reading is available on the [reference manual](https://docs.classiq.io/latest/reference-manual/qmod/language-reference/quantum-types#allocate-num)
70
-
71
67
  """
72
68
  allocate(num_qubits, out)
73
69
 
@@ -80,7 +76,7 @@ def free(in_: Input[QArray[QBit]]) -> None:
80
76
  Releases the qubits allocated to a quantum variable, allowing them to be reused.
81
77
 
82
78
  Args:
83
- in_: The quantum variable that will be freed. Must be initialized before. For more information on quantum variable initialization, see [here](https://docs.classiq.io/latest/reference-manual/qmod/language-reference/quantum-variables/).
79
+ in_: The quantum variable that will be freed. Must be initialized before.
84
80
 
85
81
  Note:
86
82
  This operation does not uncompute the qubits. It is the responsibility of the user to ensure that the qubits are at the zero state before freeing them.
@@ -108,12 +104,11 @@ def prepare_state(
108
104
  Args:
109
105
  probabilities: The probability distribution to initialize the quantum variable. Must be a valid probability distribution, i.e., a list of non-negative real numbers that sum to 1. Must have a valid length (a power of 2).
110
106
  bound: An error bound, expressed as the $L^{2}$ norm between the expected and actual distributions. A larger bound can reduce the circuit size at the expense of accuracy. Must be a positive real number.
111
- out: The quantum variable that will receive the initialized state. Must be uninitialized. For more information on quantum variable initialization, see [here](https://docs.classiq.io/latest/reference-manual/qmod/language-reference/quantum-variables/).
107
+ out: The quantum variable that will receive the initialized state. Must be uninitialized.
112
108
 
113
109
  Notes:
114
110
  1. If the output variable has been declared with a specific number of qubits, the number of qubits formed by the distribution must match the declared number.
115
111
  2. The synthesis engine automatically handles the allocation, either by drawing new qubits from the available pool or by reusing existing ones.
116
-
117
112
  """
118
113
  pass
119
114
 
@@ -138,12 +133,11 @@ def prepare_amplitudes(
138
133
  Args:
139
134
  amplitudes: The amplitudes to initialize the quantum variable. Must be a valid real quantum state vector, i.e., the sum of squares should be 1. Must have a valid length (a power of 2).
140
135
  bound: An error bound, expressed as the $L^{2}$ norm between the expected and actual distributions. A larger bound can reduce the circuit size at the expense of accuracy. Must be a positive real number.
141
- out: The quantum variable that will receive the initialized state. Must be uninitialized. For more information on quantum variable initialization, see [here](https://docs.classiq.io/latest/reference-manual/qmod/language-reference/quantum-variables/).
136
+ out: The quantum variable that will receive the initialized state. Must be uninitialized.
142
137
 
143
138
  Notes:
144
139
  1. If the output variable has been declared with a specific number of qubits, the number of qubits formed by the distribution must match the declared number.
145
140
  2. The synthesis engine automatically handles the allocation, either by drawing new qubits from the available pool or by reusing existing ones.
146
-
147
141
  """
148
142
  pass
149
143
 
@@ -237,7 +231,7 @@ def prepare_uniform_trimmed_state(m: CInt, q: QArray[QBit]) -> None:
237
231
 
238
232
  Args:
239
233
  m: The number of states to load in the superposition.
240
- q: The quantum variable that will receive the initialized state. Must be uninitialized. For more information on quantum variable initialization, see [here](https://docs.classiq.io/latest/reference-manual/qmod/language-reference/quantum-variables/).
234
+ q: The quantum variable that will receive the initialized state. Must be uninitialized.
241
235
 
242
236
  Notes:
243
237
  1. If the output variable has been declared with a specific number of qubits, it must match the number of allocated qubits.
@@ -283,7 +277,7 @@ def prepare_uniform_interval_state(start: CInt, end: CInt, q: QArray[QBit]) -> N
283
277
  Args:
284
278
  start: The lower bound of the interval to load (inclusive).
285
279
  end: The upper bound of the interval to load (exclusive).
286
- q: The quantum variable that will receive the initialized state. Must be uninitialized. For more information on quantum variable initialization, see [here](https://docs.classiq.io/latest/reference-manual/qmod/language-reference/quantum-variables/).
280
+ q: The quantum variable that will receive the initialized state. Must be uninitialized.
287
281
 
288
282
  Notes:
289
283
  1. If the output variable has been declared with a specific number of qubits, it must match the number of allocated qubits.
@@ -340,8 +334,6 @@ def prepare_exponential_state(rate: CInt, q: QArray[QBit]) -> None:
340
334
  Args:
341
335
  rate: The rate of the exponential decay.
342
336
  q: The quantum register to prepare.
343
-
344
- Further reading is available on the [reference manual](https://docs.classiq.io/latest/explore/functions/qmod_library_reference/classiq_open_library/special_state_preparations/prepare_exponential_state)
345
337
  """
346
338
  repeat(q.len, lambda i: RY(2.0 * atan(exp((-rate * 2.0**i) / 2.0)), q[i]))
347
339
 
@@ -433,7 +425,7 @@ def prepare_int(
433
425
 
434
426
  Args:
435
427
  value: The value to assign to the quantum variable.
436
- out: The allocated quantum variable. Must be uninitialized. For more information on quantum variable initialization, see [here](https://docs.classiq.io/latest/reference-manual/qmod/language-reference/quantum-variables/).
428
+ out: The allocated quantum variable. Must be uninitialized.
437
429
 
438
430
  Note:
439
431
  If the output variable has been declared with a specific number of qubits, it must match the number of allocated qubits.
@@ -21,9 +21,6 @@ def swap_test(state1: QArray[QBit], state2: QArray[QBit], test: Output[QBit]) ->
21
21
  state1: A quantum state to check its overlap with state2.
22
22
  state2: A quantum state to check its overlap with state1.
23
23
  test: A qubit for which the probability of measuring 0 is $0.5*(|\\langle state1 | state2 \\rangle |^2+1)$
24
-
25
- Example:
26
- Further reading in the Classiq library is found [here](https://docs.classiq.io/latest/explore/algorithms/swap_test/swap_test/).
27
24
  """
28
25
  allocate(1, test)
29
26
  H(test)
@@ -116,6 +116,17 @@ def control(
116
116
 
117
117
 
118
118
  def assign(expression: SymbolicExpr, target_var: QScalar) -> None:
119
+ """
120
+ Initialize a scalar quantum variable using an arithmetic expression.
121
+ If specified, the variable numeric properties (size, signedness, and fraction
122
+ digits) must match the expression properties.
123
+
124
+ Equivalent to `<target_var> |= <expression>`.
125
+
126
+ Args:
127
+ expression: A classical or quantum arithmetic expression
128
+ target_var: An uninitialized scalar quantum variable
129
+ """
119
130
  assert QCallable.CURRENT_EXPANDABLE is not None
120
131
  source_ref = get_source_ref(sys._getframe(1))
121
132
  QCallable.CURRENT_EXPANDABLE.append_statement_to_body(
@@ -129,6 +140,16 @@ def assign(expression: SymbolicExpr, target_var: QScalar) -> None:
129
140
 
130
141
 
131
142
  def assign_amplitude(expression: SymbolicExpr, target_var: QScalar) -> None:
143
+ """
144
+ Perform an amplitude-encoding assignment operation on a quantum variable and a
145
+ quantum expression.
146
+
147
+ Equivalent to `<target_var> *= <expression>`.
148
+
149
+ Args:
150
+ expression: A quantum arithmetic expression
151
+ target_var: A scalar quantum variable
152
+ """
132
153
  assert QCallable.CURRENT_EXPANDABLE is not None
133
154
  source_ref = get_source_ref(sys._getframe(1))
134
155
  QCallable.CURRENT_EXPANDABLE.append_statement_to_body(
@@ -156,6 +177,15 @@ def inplace_add(
156
177
  value: Optional[QNum] = None,
157
178
  target: Optional[QNum] = None,
158
179
  ) -> None:
180
+ """
181
+ Add an arithmetic expression to a quantum variable.
182
+
183
+ Equivalent to `<target_var> += <expression>`.
184
+
185
+ Args:
186
+ expression: A classical or quantum arithmetic expression
187
+ target_var: A scalar quantum variable
188
+ """
159
189
  assert QCallable.CURRENT_EXPANDABLE is not None
160
190
  if value is not None or target is not None:
161
191
  warnings.warn(
@@ -201,6 +231,15 @@ def inplace_xor(
201
231
  value: Optional[QNum] = None,
202
232
  target: Optional[QNum] = None,
203
233
  ) -> None:
234
+ """
235
+ Bitwise-XOR a quantum variable with an arithmetic expression.
236
+
237
+ Equivalent to `<target_var> ^= <expression>`.
238
+
239
+ Args:
240
+ expression: A classical or quantum arithmetic expression
241
+ target_var: A scalar quantum variable
242
+ """
204
243
  assert QCallable.CURRENT_EXPANDABLE is not None
205
244
  if value is not None or target is not None:
206
245
  warnings.warn(
@@ -1,8 +1,8 @@
1
1
  import inspect
2
2
  from dataclasses import is_dataclass
3
- from typing import Any, Optional
3
+ from typing import Any, Optional, cast, get_origin
4
4
 
5
- from classiq.interface.exceptions import ClassiqError
5
+ from classiq.interface.exceptions import ClassiqError, ClassiqValueError
6
6
  from classiq.interface.generator.constant import Constant
7
7
  from classiq.interface.generator.expressions.expression import Expression
8
8
  from classiq.interface.generator.functions.classical_type import (
@@ -10,7 +10,13 @@ from classiq.interface.generator.functions.classical_type import (
10
10
  ClassicalList,
11
11
  )
12
12
 
13
+ from classiq.qmod.cparam import CArray, CParamScalar
13
14
  from classiq.qmod.declaration_inferrer import python_type_to_qmod
15
+ from classiq.qmod.generative import (
16
+ get_frontend_interpreter,
17
+ interpret_expression,
18
+ is_generative_mode,
19
+ )
14
20
  from classiq.qmod.model_state_container import ModelStateContainer
15
21
  from classiq.qmod.qmod_parameter import CParam, CParamList, CParamStruct
16
22
  from classiq.qmod.symbolic_expr import SymbolicExpr
@@ -49,7 +55,10 @@ class QConstant(SymbolicExpr):
49
55
  ):
50
56
  raise ClassiqError(f"Constant {self.name} is already defined in the model")
51
57
 
52
- QConstant.CURRENT_QMODULE.constants[self.name] = self._get_constant_node()
58
+ constant = self._get_constant_node()
59
+ QConstant.CURRENT_QMODULE.constants[self.name] = constant
60
+ if is_generative_mode():
61
+ get_frontend_interpreter().add_constant(constant)
53
62
 
54
63
  def _get_constant_node(self) -> Constant:
55
64
  if isinstance(self._value, QConstant):
@@ -113,3 +122,22 @@ class QConstant(SymbolicExpr):
113
122
  qmod_type,
114
123
  QConstant.CURRENT_QMODULE,
115
124
  )[item]
125
+
126
+ def __len__(self) -> int:
127
+ raise ClassiqValueError(
128
+ "len(<const>) is not supported for classical constants - use <const>.len "
129
+ "instead"
130
+ )
131
+
132
+ @property
133
+ def len(self) -> int:
134
+ self.add_to_model()
135
+ if get_origin(self._py_type) != CArray:
136
+ raise ClassiqValueError(
137
+ f"Constant {self.name!r} of type {self._py_type.__name__!r} does not "
138
+ f"have a 'len' property"
139
+ )
140
+ len_expr = f"get_field({self.name}, 'len')"
141
+ if is_generative_mode():
142
+ return interpret_expression(len_expr)
143
+ return cast(int, CParamScalar(len_expr))
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: classiq
3
- Version: 0.55.0
3
+ Version: 0.56.0
4
4
  Summary: Classiq's Python SDK for quantum computing
5
5
  Home-page: https://classiq.io
6
6
  License: Proprietary
7
7
  Keywords: quantum computing,quantum circuits,quantum algorithms,QAD,QDL
8
8
  Author: Classiq Technologies
9
9
  Author-email: support@classiq.io
10
- Requires-Python: >=3.8,<3.13
10
+ Requires-Python: >=3.9,<3.13
11
11
  Classifier: Development Status :: 4 - Beta
12
12
  Classifier: Intended Audience :: Developers
13
13
  Classifier: Intended Audience :: Education
@@ -16,7 +16,6 @@ Classifier: License :: Other/Proprietary License
16
16
  Classifier: Natural Language :: English
17
17
  Classifier: Operating System :: OS Independent
18
18
  Classifier: Programming Language :: Python :: 3
19
- Classifier: Programming Language :: Python :: 3.8
20
19
  Classifier: Programming Language :: Python :: 3.9
21
20
  Classifier: Programming Language :: Python :: 3.10
22
21
  Classifier: Programming Language :: Python :: 3.11