classiq 0.45.1__py3-none-any.whl → 0.46.1__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 (146) hide show
  1. classiq/__init__.py +0 -1
  2. classiq/_internals/__init__.py +20 -0
  3. classiq/_internals/authentication/authentication.py +11 -0
  4. classiq/analyzer/analyzer.py +12 -10
  5. classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +1 -1
  6. classiq/applications/combinatorial_helpers/pauli_helpers/pauli_utils.py +1 -1
  7. classiq/applications/combinatorial_optimization/combinatorial_optimization_model_constructor.py +1 -1
  8. classiq/applications/libraries/qmci_library.py +4 -9
  9. classiq/execution/execution_session.py +68 -7
  10. classiq/executor.py +14 -2
  11. classiq/interface/_version.py +1 -1
  12. classiq/interface/backend/backend_preferences.py +189 -0
  13. classiq/interface/backend/quantum_backend_providers.py +38 -0
  14. classiq/interface/debug_info/debug_info.py +22 -2
  15. classiq/interface/exceptions.py +16 -1
  16. classiq/interface/executor/execution_preferences.py +18 -0
  17. classiq/interface/generator/application_apis/chemistry_declarations.py +1 -177
  18. classiq/interface/generator/application_apis/combinatorial_optimization_declarations.py +0 -12
  19. classiq/interface/generator/application_apis/finance_declarations.py +8 -43
  20. classiq/interface/generator/application_apis/qsvm_declarations.py +0 -78
  21. classiq/interface/generator/builtin_api_builder.py +0 -3
  22. classiq/interface/generator/functions/__init__.py +0 -2
  23. classiq/interface/generator/functions/builtins/__init__.py +0 -15
  24. classiq/interface/generator/generated_circuit_data.py +2 -0
  25. classiq/interface/generator/hardware/hardware_data.py +37 -0
  26. classiq/interface/generator/model/constraints.py +18 -1
  27. classiq/interface/generator/model/preferences/preferences.py +53 -1
  28. classiq/interface/generator/model/quantum_register.py +1 -1
  29. classiq/interface/generator/quantum_program.py +10 -2
  30. classiq/interface/generator/transpiler_basis_gates.py +4 -0
  31. classiq/interface/generator/types/builtin_enum_declarations.py +136 -21
  32. classiq/interface/generator/types/enum_declaration.py +1 -3
  33. classiq/interface/generator/types/struct_declaration.py +1 -3
  34. classiq/interface/hardware.py +5 -0
  35. classiq/interface/ide/visual_model.py +1 -1
  36. classiq/interface/model/classical_parameter_declaration.py +6 -0
  37. classiq/interface/model/inplace_binary_operation.py +0 -14
  38. classiq/interface/model/model.py +1 -18
  39. classiq/interface/model/port_declaration.py +4 -2
  40. classiq/interface/model/quantum_function_declaration.py +19 -6
  41. classiq/interface/model/quantum_lambda_function.py +11 -1
  42. classiq/interface/model/quantum_variable_declaration.py +1 -1
  43. classiq/model_expansions/__init__.py +0 -0
  44. classiq/model_expansions/atomic_expression_functions_defs.py +250 -0
  45. classiq/model_expansions/capturing/__init__.py +0 -0
  46. classiq/model_expansions/capturing/captured_var_manager.py +50 -0
  47. classiq/model_expansions/capturing/mangling_utils.py +17 -0
  48. classiq/model_expansions/capturing/propagated_var_stack.py +180 -0
  49. classiq/model_expansions/closure.py +160 -0
  50. classiq/model_expansions/debug_flag.py +3 -0
  51. classiq/model_expansions/evaluators/__init__.py +0 -0
  52. classiq/model_expansions/evaluators/arg_type_match.py +160 -0
  53. classiq/model_expansions/evaluators/argument_types.py +42 -0
  54. classiq/model_expansions/evaluators/classical_expression.py +36 -0
  55. classiq/model_expansions/evaluators/control.py +144 -0
  56. classiq/model_expansions/evaluators/parameter_types.py +227 -0
  57. classiq/model_expansions/evaluators/quantum_type_utils.py +235 -0
  58. classiq/model_expansions/evaluators/type_type_match.py +90 -0
  59. classiq/model_expansions/expression_evaluator.py +125 -0
  60. classiq/model_expansions/expression_renamer.py +76 -0
  61. classiq/model_expansions/function_builder.py +192 -0
  62. classiq/model_expansions/generative_functions.py +101 -0
  63. classiq/model_expansions/interpreter.py +365 -0
  64. classiq/model_expansions/model_tables.py +105 -0
  65. classiq/model_expansions/quantum_operations/__init__.py +19 -0
  66. classiq/model_expansions/quantum_operations/bind.py +64 -0
  67. classiq/model_expansions/quantum_operations/classicalif.py +39 -0
  68. classiq/model_expansions/quantum_operations/control.py +235 -0
  69. classiq/model_expansions/quantum_operations/emitter.py +215 -0
  70. classiq/model_expansions/quantum_operations/expression_operation.py +218 -0
  71. classiq/model_expansions/quantum_operations/inplace_binary_operation.py +250 -0
  72. classiq/model_expansions/quantum_operations/invert.py +38 -0
  73. classiq/model_expansions/quantum_operations/power.py +74 -0
  74. classiq/model_expansions/quantum_operations/quantum_assignment_operation.py +174 -0
  75. classiq/model_expansions/quantum_operations/quantum_function_call.py +15 -0
  76. classiq/model_expansions/quantum_operations/repeat.py +33 -0
  77. classiq/model_expansions/quantum_operations/variable_decleration.py +28 -0
  78. classiq/model_expansions/quantum_operations/within_apply.py +46 -0
  79. classiq/model_expansions/scope.py +226 -0
  80. classiq/model_expansions/scope_initialization.py +136 -0
  81. classiq/model_expansions/sympy_conversion/__init__.py +0 -0
  82. classiq/model_expansions/sympy_conversion/arithmetics.py +49 -0
  83. classiq/model_expansions/sympy_conversion/expression_to_sympy.py +150 -0
  84. classiq/model_expansions/sympy_conversion/sympy_to_python.py +113 -0
  85. classiq/model_expansions/utils/__init__.py +0 -0
  86. classiq/model_expansions/utils/counted_name_allocator.py +11 -0
  87. classiq/model_expansions/visitors/__init__.py +0 -0
  88. classiq/model_expansions/visitors/boolean_expression_transformers.py +214 -0
  89. classiq/model_expansions/visitors/variable_references.py +115 -0
  90. classiq/qmod/__init__.py +1 -3
  91. classiq/qmod/builtins/enums.py +33 -2
  92. classiq/qmod/builtins/functions/__init__.py +251 -0
  93. classiq/qmod/builtins/functions/amplitude_estimation.py +27 -0
  94. classiq/qmod/builtins/functions/arithmetic.py +68 -0
  95. classiq/qmod/builtins/functions/benchmarking.py +8 -0
  96. classiq/qmod/builtins/functions/chemistry.py +91 -0
  97. classiq/qmod/builtins/functions/discrete_sine_cosine_transform.py +105 -0
  98. classiq/qmod/builtins/functions/exponentiation.py +111 -0
  99. classiq/qmod/builtins/functions/finance.py +34 -0
  100. classiq/qmod/builtins/functions/grover.py +178 -0
  101. classiq/qmod/builtins/functions/hea.py +59 -0
  102. classiq/qmod/builtins/functions/linear_pauli_rotation.py +65 -0
  103. classiq/qmod/builtins/functions/modular_exponentiation.py +137 -0
  104. classiq/qmod/builtins/functions/operators.py +22 -0
  105. classiq/qmod/builtins/functions/qaoa_penalty.py +116 -0
  106. classiq/qmod/builtins/functions/qft.py +23 -0
  107. classiq/qmod/builtins/functions/qpe.py +39 -0
  108. classiq/qmod/builtins/functions/qsvm.py +24 -0
  109. classiq/qmod/builtins/functions/qsvt.py +136 -0
  110. classiq/qmod/builtins/functions/standard_gates.py +739 -0
  111. classiq/qmod/builtins/functions/state_preparation.py +357 -0
  112. classiq/qmod/builtins/functions/swap_test.py +25 -0
  113. classiq/qmod/builtins/structs.py +50 -28
  114. classiq/qmod/cparam.py +64 -0
  115. classiq/qmod/create_model_function.py +190 -0
  116. classiq/qmod/declaration_inferrer.py +52 -81
  117. classiq/qmod/expression_query.py +16 -0
  118. classiq/qmod/generative.py +48 -0
  119. classiq/qmod/model_state_container.py +1 -2
  120. classiq/qmod/native/pretty_printer.py +7 -11
  121. classiq/qmod/pretty_print/pretty_printer.py +7 -11
  122. classiq/qmod/python_classical_type.py +67 -0
  123. classiq/qmod/qfunc.py +19 -4
  124. classiq/qmod/qmod_parameter.py +15 -64
  125. classiq/qmod/qmod_variable.py +27 -45
  126. classiq/qmod/quantum_callable.py +1 -1
  127. classiq/qmod/quantum_expandable.py +10 -4
  128. classiq/qmod/quantum_function.py +22 -40
  129. classiq/qmod/semantics/error_manager.py +22 -10
  130. classiq/qmod/semantics/static_semantics_visitor.py +10 -12
  131. classiq/qmod/semantics/validation/types_validation.py +6 -7
  132. classiq/qmod/utilities.py +2 -2
  133. classiq/qmod/write_qmod.py +14 -0
  134. classiq/show.py +10 -0
  135. classiq/synthesis.py +46 -2
  136. {classiq-0.45.1.dist-info → classiq-0.46.1.dist-info}/METADATA +1 -1
  137. {classiq-0.45.1.dist-info → classiq-0.46.1.dist-info}/RECORD +138 -74
  138. classiq/interface/generator/functions/builtins/core_library/__init__.py +0 -16
  139. classiq/interface/generator/functions/builtins/core_library/atomic_quantum_functions.py +0 -710
  140. classiq/interface/generator/functions/builtins/core_library/exponentiation_functions.py +0 -105
  141. classiq/interface/generator/functions/builtins/open_lib_functions.py +0 -2489
  142. classiq/interface/generator/functions/builtins/quantum_operators.py +0 -24
  143. classiq/interface/generator/types/builtin_struct_declarations/__init__.py +0 -1
  144. classiq/interface/generator/types/builtin_struct_declarations/pauli_struct_declarations.py +0 -21
  145. classiq/qmod/builtins/functions.py +0 -1029
  146. {classiq-0.45.1.dist-info → classiq-0.46.1.dist-info}/WHEEL +0 -0
@@ -22,6 +22,24 @@ BACKEND_VALIDATION_ERROR_MESSAGE = (
22
22
 
23
23
 
24
24
  class HardwareData(pydantic.BaseModel):
25
+ """
26
+ Hardware-specific settings used in quantum circuit synthesis,
27
+ including basis gates, connectivity map, and connectivity symmetry.
28
+
29
+ Attributes:
30
+ basis_gates (List[str]):
31
+ The basis gates of the hardware, used during model optimization.
32
+ If not provided, default values are used based on the connectivity map's symmetry.
33
+
34
+ connectivity_map(Optional[ConnectivityMap]):
35
+ The qubit connectivity map, defined as a list of qubit pairs [[q0, q1], [q1, q2],...].
36
+ If not provided, the hardware is assumed to be fully connected.
37
+
38
+ is_symmetric_connectivity(bool):
39
+ Indicates whether the coupling map forms an undirected graph, meaning
40
+ that both qubits in each pair can act as control and target. Defaults to True.
41
+ """
42
+
25
43
  basis_gates: List[str] = pydantic.Field(
26
44
  default=list(),
27
45
  description="The basis gates of the hardware. "
@@ -101,6 +119,12 @@ class HardwareData(pydantic.BaseModel):
101
119
 
102
120
 
103
121
  class CustomHardwareSettings(HardwareData):
122
+ """
123
+ Custom hardware settings for quantum circuit synthesis.
124
+ This class inherits from HardwareData (please see class for more details)
125
+
126
+ """
127
+
104
128
  _width: Optional[int] = pydantic.PrivateAttr(default=None)
105
129
 
106
130
  @pydantic.validator("basis_gates")
@@ -180,4 +204,17 @@ def _symmetrize_connectivity_map(connectivity_map: ConnectivityMap) -> Connectiv
180
204
 
181
205
 
182
206
  class SynthesisHardwareData(HardwareData):
207
+ """
208
+ Represents the synthesis-specific hardware data for a quantum circuit.
209
+
210
+ This class extends `HardwareData` and includes additional attributes that
211
+ pertain specifically to the hardware used during the synthesis of a quantum circuit.
212
+
213
+ Attributes:
214
+ backend_data (Optional[BackendPreferences]):
215
+ Preferences for the backend used during the synthesis process.
216
+ This can include specific backend configurations or settings.
217
+ Defaults to `None`.
218
+ """
219
+
183
220
  backend_data: Optional[BackendPreferences]
@@ -31,7 +31,24 @@ def optimization_parameter_type_from_string(param: str) -> OptimizationParameter
31
31
 
32
32
  class Constraints(BaseModel, extra=Extra.forbid):
33
33
  """
34
- Input constraints for the generated quantum circuit.
34
+ Constraints for the quantum circuit synthesis engine.
35
+
36
+ This class is used to specify constraints such as maximum width, depth,
37
+ gate count, and optimization parameters for the synthesis engine,
38
+ guiding the generation of quantum circuits that satisfy these constraints.
39
+
40
+ Attributes:
41
+ max_width (int):
42
+ Maximum number of qubits allowed in the generated quantum circuit.
43
+ Defaults to `None`.
44
+ max_depth (int):
45
+ Maximum depth of the generated quantum circuit. Defaults to `None`.
46
+ max_gate_count (Dict[TranspilerBasisGates, int]):
47
+ A dictionary specifying the maximum allowed count for each type of gate
48
+ in the quantum circuit. Defaults to an empty dictionary.
49
+ optimization_parameter (OptimizationParameterType):
50
+ Determines if and how the synthesis engine should optimize
51
+ the solution. Defaults to `NO_OPTIMIZATION`. See `OptimizationParameterType`
35
52
  """
36
53
 
37
54
  max_width: Optional[pydantic.PositiveInt] = pydantic.Field(
@@ -76,6 +76,55 @@ class TranspilationOption(StrEnum):
76
76
 
77
77
 
78
78
  class Preferences(pydantic.BaseModel, extra=pydantic.Extra.forbid):
79
+ """
80
+ Preferences for synthesizing a quantum circuit.
81
+
82
+ Attributes:
83
+ machine_precision (int): Specifies the precision used for quantum operations.
84
+ Defaults to `DEFAULT_MACHINE_PRECISION`.
85
+ backend_service_provider (str): The provider company or cloud service for the
86
+ requested backend. Defaults to `None`.
87
+ backend_name (str): The name of the requested backend or target. Defaults to `None`.
88
+ custom_hardware_settings (CustomHardwareSettings): Defines custom hardware
89
+ settings for optimization. This field is ignored if backend preferences are
90
+ specified.
91
+ debug_mode (bool): If `True`, debug information is added to the
92
+ synthesized result, potentially slowing down the synthesis. Useful for
93
+ executing interactive algorithms. Defaults to `True`.
94
+ output_format (List[QuantumFormat]): Lists the output format(s)
95
+ for the quantum circuit. Defaults to `[QuantumFormat.QASM]`.
96
+ `QuantumFormat` Options:
97
+ - QASM = "qasm"
98
+ - QSHARP = "qsharp"
99
+ - QIR = "qir"
100
+ - IONQ = "ionq"
101
+ - CIRQ_JSON = "cirq_json"
102
+ - QASM_CIRQ_COMPATIBLE = "qasm_cirq_compatible"
103
+ pretty_qasm (bool): If `True`, formats OpenQASM 2 outputs with line breaks
104
+ inside gate declarations, improving readability. Defaults to `True`.
105
+ qasm3 (Optional[bool]): If `True`, outputs OpenQASM 3.0 in addition to 2.0,
106
+ applicable to relevant attributes in `GeneratedCircuit`. Defaults to `None`.
107
+ transpilation_option (TranspilationOption): Sets the transpilation option to
108
+ optimize the circuit. Defaults to `AUTO_OPTIMIZE`. See `TranspilationOption`
109
+ solovay_kitaev_max_iterations (Optional[int]): Specifies the
110
+ maximum number of iterations for the Solovay-Kitaev algorithm, if used.
111
+ Defaults to `None`.
112
+ timeout_seconds (int): Timeout setting for circuit synthesis
113
+ in seconds. Defaults to `300`.
114
+ optimization_timeout_seconds (Optional[int]): Specifies the
115
+ timeout for optimization in seconds, or `None` for no optimization timeout.
116
+ This will still adhere to the overall synthesis timeout. Defaults to `None`.
117
+ random_seed (int): Random seed for circuit synthesis.
118
+
119
+ Raises:
120
+ ClassiqValueError:
121
+ - If the optimization timeout is greater than or equal to the synthesis timeout.
122
+ - If the `output_format` contains duplicate entries.
123
+ - If `backend_name` is provided without `backend_service_provider` or vice versa.
124
+ ValueError:
125
+ - If `backend_service_provider` is not valid.
126
+ """
127
+
79
128
  _backend_preferences: Optional[BackendPreferences] = pydantic.PrivateAttr(
80
129
  default=None
81
130
  )
@@ -140,7 +189,6 @@ class Preferences(pydantic.BaseModel, extra=pydantic.Extra.forbid):
140
189
  description="Optimization timeout in seconds, or None for no "
141
190
  "optimization timeout (will still timeout when the generation timeout is over)",
142
191
  )
143
-
144
192
  random_seed: int = pydantic.Field(
145
193
  default_factory=create_random_seed,
146
194
  description="The random seed used for the generation",
@@ -208,6 +256,10 @@ class Preferences(pydantic.BaseModel, extra=pydantic.Extra.forbid):
208
256
 
209
257
  @property
210
258
  def backend_preferences(self) -> Optional[BackendPreferences]:
259
+ """
260
+ Returns the backend preferences. If the backend preferences are not provided, the function sets the backend preferences according to backend name and provider.
261
+
262
+ """
211
263
  if self.backend_name is None or self.backend_service_provider is None:
212
264
  return None
213
265
  if self._backend_preferences is None:
@@ -80,7 +80,7 @@ class QReg:
80
80
  """Initializes a new QReg with the specified number of qubits.
81
81
 
82
82
  Args:
83
- size (int): The number of qubits in the QReg.
83
+ size: The number of qubits in the QReg.
84
84
  """
85
85
  if size <= 0:
86
86
  raise ClassiqQRegError(f"Cannot create {size} new qubits")
@@ -135,11 +135,10 @@ class QuantumProgram(VersionedModel, CircuitCodeInterface):
135
135
 
136
136
  def save_results(self, filename: Optional[Union[str, Path]] = None) -> None:
137
137
  """
138
- Saves quantum program results as json.
138
+ Saves quantum program results as json into a file.
139
139
  Parameters:
140
140
  filename (Union[str, Path]): Optional, path + filename of file.
141
141
  If filename supplied add `.json` suffix.
142
-
143
142
  Returns:
144
143
  None
145
144
  """
@@ -151,6 +150,15 @@ class QuantumProgram(VersionedModel, CircuitCodeInterface):
151
150
 
152
151
  @classmethod
153
152
  def from_qprog(cls, qprog: str) -> "QuantumProgram":
153
+ """
154
+ Creates a `QuantumProgram` instance from a raw quantum program string.
155
+
156
+ Args:
157
+ qprog: The raw quantum program in string format.
158
+
159
+ Returns:
160
+ QuantumProgram: The `QuantumProgram` instance.
161
+ """
154
162
  return cls.parse_raw(qprog)
155
163
 
156
164
  @property
@@ -86,6 +86,10 @@ class LowerValsEnum(StrEnum):
86
86
  if TYPE_CHECKING:
87
87
  # A subset of the gates for better type checking
88
88
  class TranspilerBasisGates(StrEnum):
89
+ """
90
+ A subset of the gates used in the transpiler.
91
+ """
92
+
89
93
  X = "x"
90
94
  CX = "cx"
91
95
  CZ = "cz"
@@ -1,20 +1,134 @@
1
+ # This file was generated automatically - do not edit manually
2
+
1
3
  from enum import IntEnum
2
4
 
3
- from classiq.interface.chemistry.elements import ELEMENTS
4
- from classiq.interface.chemistry.ground_state_problem import FermionMapping
5
- from classiq.interface.generator.types.enum_declaration import EnumDeclaration
6
5
 
7
- ELEMENT = EnumDeclaration(
8
- name="Element", members={element: idx for idx, element in enumerate(ELEMENTS)}
9
- )
6
+ class Element(IntEnum):
7
+ H = 0
8
+ He = 1
9
+ Li = 2
10
+ Be = 3
11
+ B = 4
12
+ C = 5
13
+ N = 6
14
+ O = 7 # noqa: E741
15
+ F = 8
16
+ Ne = 9
17
+ Na = 10
18
+ Mg = 11
19
+ Al = 12
20
+ Si = 13
21
+ P = 14
22
+ S = 15
23
+ Cl = 16
24
+ Ar = 17
25
+ K = 18
26
+ Ca = 19
27
+ Sc = 20
28
+ Ti = 21
29
+ V = 22
30
+ Cr = 23
31
+ Mn = 24
32
+ Fe = 25
33
+ Co = 26
34
+ Ni = 27
35
+ Cu = 28
36
+ Zn = 29
37
+ Ga = 30
38
+ Ge = 31
39
+ As = 32
40
+ Se = 33
41
+ Br = 34
42
+ Kr = 35
43
+ Rb = 36
44
+ Sr = 37
45
+ Y = 38
46
+ Zr = 39
47
+ Nb = 40
48
+ Mo = 41
49
+ Tc = 42
50
+ Ru = 43
51
+ Rh = 44
52
+ Pd = 45
53
+ Ag = 46
54
+ Cd = 47
55
+ In = 48
56
+ Sn = 49
57
+ Sb = 50
58
+ Te = 51
59
+ I = 52 # noqa: E741
60
+ Xe = 53
61
+ Cs = 54
62
+ Ba = 55
63
+ La = 56
64
+ Ce = 57
65
+ Pr = 58
66
+ Nd = 59
67
+ Pm = 60
68
+ Sm = 61
69
+ Eu = 62
70
+ Gd = 63
71
+ Tb = 64
72
+ Dy = 65
73
+ Ho = 66
74
+ Er = 67
75
+ Tm = 68
76
+ Yb = 69
77
+ Lu = 70
78
+ Hf = 71
79
+ Ta = 72
80
+ W = 73
81
+ Re = 74
82
+ Os = 75
83
+ Ir = 76
84
+ Pt = 77
85
+ Au = 78
86
+ Hg = 79
87
+ Tl = 80
88
+ Pb = 81
89
+ Bi = 82
90
+ Po = 83
91
+ At = 84
92
+ Rn = 85
93
+ Fr = 86
94
+ Ra = 87
95
+ Ac = 88
96
+ Th = 89
97
+ Pa = 90
98
+ U = 91
99
+ Np = 92
100
+ Pu = 93
101
+ Am = 94
102
+ Cm = 95
103
+ Bk = 96
104
+ Cf = 97
105
+ Es = 98
106
+ Fm = 99
107
+ Md = 100
108
+ No = 101
109
+ Lr = 102
110
+ Rf = 103
111
+ Db = 104
112
+ Sg = 105
113
+ Bh = 106
114
+ Hs = 107
115
+ Mt = 108
116
+ Ds = 109
117
+ Rg = 110
118
+ Cn = 111
119
+ Nh = 112
120
+ Fl = 113
121
+ Mc = 114
122
+ Lv = 115
123
+ Ts = 116
124
+ Og = 117
125
+
10
126
 
11
- FERMION_MAPPING = EnumDeclaration(
12
- name="FermionMapping",
13
- members={
14
- mapping.name: idx # type:ignore[attr-defined]
15
- for idx, mapping in enumerate(FermionMapping)
16
- },
17
- )
127
+ class FermionMapping(IntEnum):
128
+ JORDAN_WIGNER = 0
129
+ PARITY = 1
130
+ BRAVYI_KITAEV = 2
131
+ FAST_BRAVYI_KITAEV = 3
18
132
 
19
133
 
20
134
  class FinanceFunctionType(IntEnum):
@@ -52,11 +166,12 @@ class QSVMFeatureMapEntanglement(IntEnum):
52
166
  PAIRWISE = 4
53
167
 
54
168
 
55
- for enum_decl in list(vars().values()):
56
- if isinstance(enum_decl, EnumDeclaration):
57
- EnumDeclaration.BUILTIN_ENUM_DECLARATIONS[enum_decl.name] = enum_decl
58
- elif isinstance(enum_decl, type) and issubclass(enum_decl, IntEnum):
59
- EnumDeclaration.BUILTIN_ENUM_DECLARATIONS[enum_decl.__name__] = EnumDeclaration(
60
- name=enum_decl.__name__,
61
- members={enum_val.name: enum_val.value for enum_val in enum_decl},
62
- )
169
+ __all__ = [
170
+ "Element",
171
+ "FermionMapping",
172
+ "FinanceFunctionType",
173
+ "LadderOperator",
174
+ "Optimizer",
175
+ "Pauli",
176
+ "QSVMFeatureMapEntanglement",
177
+ ]
@@ -1,6 +1,6 @@
1
1
  from collections import Counter
2
2
  from enum import Enum, EnumMeta, IntEnum
3
- from typing import ClassVar, Dict
3
+ from typing import Dict
4
4
 
5
5
  import pydantic
6
6
 
@@ -16,8 +16,6 @@ class EnumDeclaration(HashableASTNode):
16
16
  description="Dictionary of member names and their values",
17
17
  )
18
18
 
19
- BUILTIN_ENUM_DECLARATIONS: ClassVar[Dict[str, "EnumDeclaration"]] = {}
20
-
21
19
  @pydantic.validator("members")
22
20
  def _validate_members(cls, members: Dict[str, int]) -> Dict[str, int]:
23
21
  underscore_members = [
@@ -1,4 +1,4 @@
1
- from typing import Any, ClassVar, Dict, Mapping
1
+ from typing import Any, Dict, Mapping
2
2
 
3
3
  import pydantic
4
4
 
@@ -15,8 +15,6 @@ class StructDeclaration(HashableASTNode):
15
15
  description="Dictionary of variable names and their classical types",
16
16
  )
17
17
 
18
- BUILTIN_STRUCT_DECLARATIONS: ClassVar[Dict[str, "StructDeclaration"]] = {}
19
-
20
18
  def validate_fields(self, fields: Mapping[str, Any]) -> None:
21
19
  expected_field_names = list(self.variables.keys())
22
20
  received_field_names = list(fields.keys())
@@ -7,6 +7,11 @@ from classiq.interface.enum_utils import StrEnum
7
7
 
8
8
 
9
9
  class Provider(StrEnum):
10
+ """
11
+ This class defines all Providers that Classiq supports.
12
+ This is mainly used in backend_preferences when specifying where do we want to execute the defined model.
13
+ """
14
+
10
15
  IBM_QUANTUM = "IBM Quantum"
11
16
  AZURE_QUANTUM = "Azure Quantum"
12
17
  AMAZON_BRAKET = "Amazon Braket"
@@ -33,7 +33,7 @@ class ProgramData(pydantic.BaseModel):
33
33
 
34
34
  class OperationParameter(pydantic.BaseModel):
35
35
  label: str
36
- value: Optional[float]
36
+ value: Optional[str]
37
37
 
38
38
 
39
39
  class OperationLink(pydantic.BaseModel):
@@ -2,6 +2,7 @@ from typing import Any, Dict, Literal
2
2
 
3
3
  import pydantic
4
4
 
5
+ from classiq.interface.exceptions import ClassiqInternalError
5
6
  from classiq.interface.generator.functions.concrete_types import ConcreteClassicalType
6
7
  from classiq.interface.helpers.pydantic_model_helpers import values_with_discriminator
7
8
  from classiq.interface.model.parameter import Parameter
@@ -19,6 +20,11 @@ class AnonClassicalParameterDeclaration(Parameter):
19
20
  )
20
21
 
21
22
  def rename(self, new_name: str) -> "ClassicalParameterDeclaration":
23
+ if type(self) not in (
24
+ AnonClassicalParameterDeclaration,
25
+ ClassicalParameterDeclaration,
26
+ ):
27
+ raise ClassiqInternalError
22
28
  return ClassicalParameterDeclaration(**{**self.__dict__, "name": new_name})
23
29
 
24
30
 
@@ -1,15 +1,8 @@
1
1
  from typing import Literal, Mapping, Sequence
2
2
 
3
3
  from classiq.interface.enum_utils import StrEnum
4
- from classiq.interface.generator.functions.builtins.core_library import (
5
- INTEGER_XOR_FUNCTION,
6
- MODULAR_ADD_FUNCTION,
7
- )
8
4
  from classiq.interface.helpers.pydantic_model_helpers import nameables_to_dict
9
5
  from classiq.interface.model.handle_binding import ConcreteHandleBinding, HandleBinding
10
- from classiq.interface.model.quantum_function_declaration import (
11
- NamedParamsQuantumFunctionDeclaration,
12
- )
13
6
  from classiq.interface.model.quantum_statement import HandleMetadata, QuantumOperation
14
7
 
15
8
 
@@ -17,13 +10,6 @@ class BinaryOperation(StrEnum):
17
10
  Addition = "inplace_add"
18
11
  Xor = "inplace_xor"
19
12
 
20
- @property
21
- def internal_function_declaration(self) -> NamedParamsQuantumFunctionDeclaration:
22
- return {
23
- BinaryOperation.Addition: MODULAR_ADD_FUNCTION,
24
- BinaryOperation.Xor: INTEGER_XOR_FUNCTION,
25
- }[self]
26
-
27
13
 
28
14
  class InplaceBinaryOperation(QuantumOperation):
29
15
  kind: Literal["InplaceBinaryOperation"]
@@ -1,5 +1,5 @@
1
1
  from collections import Counter
2
- from typing import List, Literal, Mapping, NewType, Set
2
+ from typing import List, Literal, Mapping, NewType
3
3
 
4
4
  import pydantic
5
5
 
@@ -54,9 +54,6 @@ class VersionedSerializedModel(VersionedModel):
54
54
 
55
55
 
56
56
  class Model(VersionedModel, ASTNode):
57
- """
58
- All the relevant data for generating quantum circuit in one place.
59
- """
60
57
 
61
58
  kind: Literal["user"] = pydantic.Field(default=USER_MODEL_MARKER)
62
59
 
@@ -133,20 +130,6 @@ class Model(VersionedModel, ASTNode):
133
130
  functions.append(_create_empty_main_function())
134
131
  return functions
135
132
 
136
- @pydantic.validator("types")
137
- def types_validator(cls, types: List[StructDeclaration]) -> List[StructDeclaration]:
138
- user_defined_types: Set[str] = set()
139
- for ctype in types:
140
- if ctype.name in StructDeclaration.BUILTIN_STRUCT_DECLARATIONS:
141
- raise ClassiqValueError(
142
- TYPE_NAME_CONFLICT_BUILTIN.format(name=ctype.name)
143
- )
144
- if ctype.name in user_defined_types:
145
- raise ClassiqValueError(TYPE_NAME_CONFLICT_USER.format(name=ctype.name))
146
- user_defined_types.add(ctype.name)
147
-
148
- return types
149
-
150
133
  def get_model(self) -> SerializedModel:
151
134
  return SerializedModel(
152
135
  self.json(exclude_defaults=True, exclude_unset=True, indent=2)
@@ -2,7 +2,7 @@ from typing import Any, Dict, Literal, Mapping, Optional
2
2
 
3
3
  import pydantic
4
4
 
5
- from classiq.interface.exceptions import ClassiqValueError
5
+ from classiq.interface.exceptions import ClassiqInternalError, ClassiqValueError
6
6
  from classiq.interface.generator.expressions.expression import Expression
7
7
  from classiq.interface.generator.functions.concrete_types import ConcreteQuantumType
8
8
  from classiq.interface.generator.functions.port_declaration import (
@@ -19,7 +19,7 @@ class AnonPortDeclaration(Parameter):
19
19
  kind: Literal["PortDeclaration"]
20
20
 
21
21
  quantum_type: ConcreteQuantumType
22
- size: Optional[Expression] = pydantic.Field(default=None)
22
+ size: Optional[Expression] = pydantic.Field(default=None, exclude=True)
23
23
  direction: PortDeclarationDirection
24
24
 
25
25
  @pydantic.root_validator(pre=True)
@@ -44,6 +44,8 @@ class AnonPortDeclaration(Parameter):
44
44
  return QuantumVariableDeclaration._propagate_size_to_type(size, values)
45
45
 
46
46
  def rename(self, new_name: str) -> "PortDeclaration":
47
+ if type(self) not in (AnonPortDeclaration, PortDeclaration):
48
+ raise ClassiqInternalError
47
49
  return PortDeclaration(**{**self.__dict__, "name": new_name})
48
50
 
49
51
 
@@ -1,6 +1,5 @@
1
1
  from typing import (
2
2
  Any,
3
- ClassVar,
4
3
  Dict,
5
4
  Literal,
6
5
  Sequence,
@@ -11,6 +10,7 @@ from typing import (
11
10
  import pydantic
12
11
  from typing_extensions import Annotated
13
12
 
13
+ from classiq.interface.exceptions import ClassiqInternalError
14
14
  from classiq.interface.generator.arith.register_user_input import RegisterUserInput
15
15
  from classiq.interface.generator.function_params import ArithmeticIODict, PortDirection
16
16
  from classiq.interface.generator.functions.function_declaration import (
@@ -132,7 +132,22 @@ class AnonQuantumFunctionDeclaration(FunctionDeclaration):
132
132
  }
133
133
 
134
134
  def rename(self, new_name: str) -> "QuantumFunctionDeclaration":
135
- return QuantumFunctionDeclaration(**{**self.__dict__, "name": new_name})
135
+ if type(self) not in (
136
+ AnonQuantumFunctionDeclaration,
137
+ QuantumFunctionDeclaration,
138
+ NamedParamsQuantumFunctionDeclaration,
139
+ ):
140
+ raise ClassiqInternalError
141
+ return QuantumFunctionDeclaration(
142
+ **{
143
+ **{
144
+ field_name: field_value
145
+ for field_name, field_value in self.__dict__.items()
146
+ if field_name in AnonQuantumFunctionDeclaration.__fields__
147
+ },
148
+ "name": new_name,
149
+ }
150
+ )
136
151
 
137
152
 
138
153
  class AnonQuantumOperandDeclaration(AnonQuantumFunctionDeclaration):
@@ -148,6 +163,8 @@ class AnonQuantumOperandDeclaration(AnonQuantumFunctionDeclaration):
148
163
  return values_with_discriminator(values, "kind", "QuantumOperandDeclaration")
149
164
 
150
165
  def rename(self, new_name: str) -> "QuantumOperandDeclaration":
166
+ if type(self) not in (AnonQuantumOperandDeclaration, QuantumOperandDeclaration):
167
+ raise ClassiqInternalError
151
168
  return QuantumOperandDeclaration(**{**self.__dict__, "name": new_name})
152
169
 
153
170
 
@@ -157,10 +174,6 @@ AnonQuantumFunctionDeclaration.update_forward_refs()
157
174
  class QuantumFunctionDeclaration(AnonQuantumFunctionDeclaration):
158
175
  name: str
159
176
 
160
- BUILTIN_FUNCTION_DECLARATIONS: ClassVar[
161
- Dict[str, "NamedParamsQuantumFunctionDeclaration"]
162
- ] = {}
163
-
164
177
 
165
178
  class QuantumOperandDeclaration(
166
179
  QuantumFunctionDeclaration, AnonQuantumOperandDeclaration
@@ -1,4 +1,4 @@
1
- from typing import TYPE_CHECKING, Dict, List, Optional, Union, cast
1
+ from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Union, cast
2
2
 
3
3
  import pydantic
4
4
 
@@ -19,6 +19,7 @@ class QuantumLambdaFunction(ASTNode):
19
19
 
20
20
  rename_params: Dict[str, str] = pydantic.Field(
21
21
  default_factory=dict,
22
+ exclude=False,
22
23
  )
23
24
 
24
25
  pos_rename_params: List[str] = pydantic.Field(
@@ -34,6 +35,15 @@ class QuantumLambdaFunction(ASTNode):
34
35
  default=None
35
36
  )
36
37
 
38
+ _py_callable: Callable = pydantic.PrivateAttr(default=None)
39
+
40
+ @property
41
+ def py_callable(self) -> Callable:
42
+ return self._py_callable
43
+
44
+ def set_py_callable(self, py_callable: Callable) -> None:
45
+ self._py_callable = py_callable
46
+
37
47
  @property
38
48
  def func_decl(self) -> AnonQuantumOperandDeclaration:
39
49
  if self._func_decl is None:
@@ -14,7 +14,7 @@ from classiq.interface.model.quantum_type import (
14
14
  class QuantumVariableDeclaration(ASTNode):
15
15
  name: str
16
16
  quantum_type: ConcreteQuantumType
17
- size: Optional[Expression] = pydantic.Field(default=None)
17
+ size: Optional[Expression] = pydantic.Field(default=None, exclude=True)
18
18
 
19
19
  @pydantic.validator("size")
20
20
  def _propagate_size_to_type(
File without changes