classiq 0.45.0__py3-none-any.whl → 0.46.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.
- classiq/__init__.py +0 -1
- classiq/_internals/__init__.py +20 -0
- classiq/_internals/authentication/authentication.py +11 -0
- classiq/analyzer/analyzer.py +12 -10
- classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +1 -1
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_utils.py +1 -1
- classiq/applications/combinatorial_optimization/combinatorial_optimization_model_constructor.py +1 -1
- classiq/applications/libraries/qmci_library.py +4 -9
- classiq/execution/execution_session.py +68 -7
- classiq/executor.py +14 -2
- classiq/interface/_version.py +1 -1
- classiq/interface/backend/backend_preferences.py +189 -0
- classiq/interface/backend/quantum_backend_providers.py +38 -0
- classiq/interface/debug_info/debug_info.py +22 -2
- classiq/interface/exceptions.py +16 -1
- classiq/interface/executor/execution_preferences.py +18 -0
- classiq/interface/generator/application_apis/chemistry_declarations.py +1 -177
- classiq/interface/generator/application_apis/combinatorial_optimization_declarations.py +0 -12
- classiq/interface/generator/application_apis/finance_declarations.py +8 -43
- classiq/interface/generator/application_apis/qsvm_declarations.py +0 -78
- classiq/interface/generator/builtin_api_builder.py +0 -3
- classiq/interface/generator/functions/__init__.py +0 -2
- classiq/interface/generator/functions/builtins/__init__.py +0 -15
- classiq/interface/generator/generated_circuit_data.py +2 -0
- classiq/interface/generator/hardware/hardware_data.py +37 -0
- classiq/interface/generator/model/constraints.py +18 -1
- classiq/interface/generator/model/preferences/preferences.py +53 -1
- classiq/interface/generator/model/quantum_register.py +1 -1
- classiq/interface/generator/quantum_program.py +10 -2
- classiq/interface/generator/transpiler_basis_gates.py +4 -0
- classiq/interface/generator/types/builtin_enum_declarations.py +136 -21
- classiq/interface/generator/types/enum_declaration.py +1 -3
- classiq/interface/generator/types/struct_declaration.py +1 -3
- classiq/interface/hardware.py +5 -0
- classiq/interface/ide/visual_model.py +1 -1
- classiq/interface/model/classical_parameter_declaration.py +6 -0
- classiq/interface/model/inplace_binary_operation.py +0 -14
- classiq/interface/model/model.py +1 -18
- classiq/interface/model/port_declaration.py +4 -2
- classiq/interface/model/quantum_function_declaration.py +19 -6
- classiq/interface/model/quantum_lambda_function.py +11 -1
- classiq/interface/model/quantum_variable_declaration.py +1 -1
- classiq/model_expansions/__init__.py +0 -0
- classiq/model_expansions/atomic_expression_functions_defs.py +250 -0
- classiq/model_expansions/capturing/__init__.py +0 -0
- classiq/model_expansions/capturing/captured_var_manager.py +50 -0
- classiq/model_expansions/capturing/mangling_utils.py +17 -0
- classiq/model_expansions/capturing/propagated_var_stack.py +180 -0
- classiq/model_expansions/closure.py +160 -0
- classiq/model_expansions/debug_flag.py +3 -0
- classiq/model_expansions/evaluators/__init__.py +0 -0
- classiq/model_expansions/evaluators/arg_type_match.py +160 -0
- classiq/model_expansions/evaluators/argument_types.py +42 -0
- classiq/model_expansions/evaluators/classical_expression.py +36 -0
- classiq/model_expansions/evaluators/control.py +144 -0
- classiq/model_expansions/evaluators/parameter_types.py +227 -0
- classiq/model_expansions/evaluators/quantum_type_utils.py +235 -0
- classiq/model_expansions/evaluators/type_type_match.py +90 -0
- classiq/model_expansions/expression_evaluator.py +125 -0
- classiq/model_expansions/expression_renamer.py +76 -0
- classiq/model_expansions/function_builder.py +192 -0
- classiq/model_expansions/generative_functions.py +101 -0
- classiq/model_expansions/interpreter.py +365 -0
- classiq/model_expansions/model_tables.py +105 -0
- classiq/model_expansions/quantum_operations/__init__.py +19 -0
- classiq/model_expansions/quantum_operations/bind.py +64 -0
- classiq/model_expansions/quantum_operations/classicalif.py +39 -0
- classiq/model_expansions/quantum_operations/control.py +235 -0
- classiq/model_expansions/quantum_operations/emitter.py +215 -0
- classiq/model_expansions/quantum_operations/expression_operation.py +218 -0
- classiq/model_expansions/quantum_operations/inplace_binary_operation.py +250 -0
- classiq/model_expansions/quantum_operations/invert.py +38 -0
- classiq/model_expansions/quantum_operations/power.py +74 -0
- classiq/model_expansions/quantum_operations/quantum_assignment_operation.py +174 -0
- classiq/model_expansions/quantum_operations/quantum_function_call.py +15 -0
- classiq/model_expansions/quantum_operations/repeat.py +33 -0
- classiq/model_expansions/quantum_operations/variable_decleration.py +28 -0
- classiq/model_expansions/quantum_operations/within_apply.py +46 -0
- classiq/model_expansions/scope.py +226 -0
- classiq/model_expansions/scope_initialization.py +136 -0
- classiq/model_expansions/sympy_conversion/__init__.py +0 -0
- classiq/model_expansions/sympy_conversion/arithmetics.py +49 -0
- classiq/model_expansions/sympy_conversion/expression_to_sympy.py +150 -0
- classiq/model_expansions/sympy_conversion/sympy_to_python.py +113 -0
- classiq/model_expansions/utils/__init__.py +0 -0
- classiq/model_expansions/utils/counted_name_allocator.py +11 -0
- classiq/model_expansions/visitors/__init__.py +0 -0
- classiq/model_expansions/visitors/boolean_expression_transformers.py +214 -0
- classiq/model_expansions/visitors/variable_references.py +115 -0
- classiq/qmod/__init__.py +1 -3
- classiq/qmod/builtins/enums.py +33 -2
- classiq/qmod/builtins/functions/__init__.py +251 -0
- classiq/qmod/builtins/functions/amplitude_estimation.py +26 -0
- classiq/qmod/builtins/functions/arithmetic.py +68 -0
- classiq/qmod/builtins/functions/benchmarking.py +8 -0
- classiq/qmod/builtins/functions/chemistry.py +91 -0
- classiq/qmod/builtins/functions/discrete_sine_cosine_transform.py +105 -0
- classiq/qmod/builtins/functions/exponentiation.py +110 -0
- classiq/qmod/builtins/functions/finance.py +34 -0
- classiq/qmod/builtins/functions/grover.py +179 -0
- classiq/qmod/builtins/functions/hea.py +59 -0
- classiq/qmod/builtins/functions/linear_pauli_rotation.py +65 -0
- classiq/qmod/builtins/functions/modular_exponentiation.py +137 -0
- classiq/qmod/builtins/functions/operators.py +22 -0
- classiq/qmod/builtins/functions/qaoa_penalty.py +116 -0
- classiq/qmod/builtins/functions/qft.py +23 -0
- classiq/qmod/builtins/functions/qpe.py +39 -0
- classiq/qmod/builtins/functions/qsvm.py +24 -0
- classiq/qmod/builtins/functions/qsvt.py +136 -0
- classiq/qmod/builtins/functions/standard_gates.py +739 -0
- classiq/qmod/builtins/functions/state_preparation.py +356 -0
- classiq/qmod/builtins/functions/swap_test.py +25 -0
- classiq/qmod/builtins/structs.py +50 -28
- classiq/qmod/cparam.py +64 -0
- classiq/qmod/create_model_function.py +190 -0
- classiq/qmod/declaration_inferrer.py +52 -81
- classiq/qmod/expression_query.py +16 -0
- classiq/qmod/generative.py +48 -0
- classiq/qmod/model_state_container.py +1 -2
- classiq/qmod/native/pretty_printer.py +7 -11
- classiq/qmod/pretty_print/pretty_printer.py +7 -11
- classiq/qmod/python_classical_type.py +67 -0
- classiq/qmod/qfunc.py +19 -4
- classiq/qmod/qmod_parameter.py +15 -64
- classiq/qmod/qmod_variable.py +28 -46
- classiq/qmod/quantum_callable.py +1 -1
- classiq/qmod/quantum_expandable.py +10 -4
- classiq/qmod/quantum_function.py +22 -40
- classiq/qmod/semantics/error_manager.py +22 -10
- classiq/qmod/semantics/static_semantics_visitor.py +10 -12
- classiq/qmod/semantics/validation/types_validation.py +6 -7
- classiq/qmod/utilities.py +2 -2
- classiq/qmod/write_qmod.py +14 -0
- classiq/show.py +10 -0
- classiq/synthesis.py +46 -2
- {classiq-0.45.0.dist-info → classiq-0.46.0.dist-info}/METADATA +1 -1
- {classiq-0.45.0.dist-info → classiq-0.46.0.dist-info}/RECORD +138 -74
- classiq/interface/generator/functions/builtins/core_library/__init__.py +0 -16
- classiq/interface/generator/functions/builtins/core_library/atomic_quantum_functions.py +0 -710
- classiq/interface/generator/functions/builtins/core_library/exponentiation_functions.py +0 -105
- classiq/interface/generator/functions/builtins/open_lib_functions.py +0 -2489
- classiq/interface/generator/functions/builtins/quantum_operators.py +0 -24
- classiq/interface/generator/types/builtin_struct_declarations/__init__.py +0 -1
- classiq/interface/generator/types/builtin_struct_declarations/pauli_struct_declarations.py +0 -21
- classiq/qmod/builtins/functions.py +0 -1029
- {classiq-0.45.0.dist-info → classiq-0.46.0.dist-info}/WHEEL +0 -0
classiq/__init__.py
CHANGED
@@ -13,7 +13,6 @@ from classiq.interface.generator.functions import * # noqa: F403
|
|
13
13
|
from classiq.interface.generator.model import * # noqa: F403
|
14
14
|
from classiq.interface.generator.model import __all__ as _md_all
|
15
15
|
from classiq.interface.generator.quantum_program import QuantumProgram
|
16
|
-
from classiq.interface.generator.types.builtin_enum_declarations import * # noqa: F403
|
17
16
|
|
18
17
|
from classiq import applications, execution, synthesis
|
19
18
|
from classiq._internals import logger
|
classiq/_internals/__init__.py
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
import sys
|
2
|
+
import warnings
|
3
|
+
|
4
|
+
from classiq.interface.exceptions import ClassiqDeprecationWarning
|
5
|
+
|
6
|
+
|
7
|
+
def _check_python_version() -> None:
|
8
|
+
if sys.version_info >= (3, 9):
|
9
|
+
return
|
10
|
+
warnings.warn( # type: ignore[unreachable]
|
11
|
+
"Python version 3.8 is expected to reach its end-of-life on October 2024.\n"
|
12
|
+
"See https://devguide.python.org/versions/#supported-versions\n"
|
13
|
+
"The Classiq SDK is expected to drop support for 3.8 around the same time.\n"
|
14
|
+
"Please upgrade to a newer version of Python to avoid issues in the future.",
|
15
|
+
ClassiqDeprecationWarning,
|
16
|
+
stacklevel=2,
|
17
|
+
)
|
18
|
+
|
19
|
+
|
20
|
+
_check_python_version()
|
@@ -3,6 +3,17 @@ from classiq._internals.client import client
|
|
3
3
|
|
4
4
|
|
5
5
|
def authenticate(overwrite: bool = False) -> None:
|
6
|
+
"""
|
7
|
+
|
8
|
+
Authenticate to access the Classiq platform.
|
9
|
+
|
10
|
+
Args:
|
11
|
+
overwrite: A flag indicating whether to overwrite the existing
|
12
|
+
authentication tokens. Defaults to `False`.
|
13
|
+
|
14
|
+
If you are not registered, please visit the Classiq platform
|
15
|
+
to complete registration: https://platform.classiq.io/
|
16
|
+
"""
|
6
17
|
async_utils.run(authenticate_async(overwrite))
|
7
18
|
|
8
19
|
|
classiq/analyzer/analyzer.py
CHANGED
@@ -38,7 +38,7 @@ class Analyzer(AnalyzerUtilities):
|
|
38
38
|
"""Init self.
|
39
39
|
|
40
40
|
Args:
|
41
|
-
circuit
|
41
|
+
circuit: The circuit to be analyzed.
|
42
42
|
"""
|
43
43
|
if circuit.qasm is None:
|
44
44
|
raise ClassiqAnalyzerError(
|
@@ -86,11 +86,11 @@ class Analyzer(AnalyzerUtilities):
|
|
86
86
|
Returns dict of the available devices by the providers. only devices
|
87
87
|
with sufficient number of qubits are returns
|
88
88
|
|
89
|
-
Args: providers
|
89
|
+
Args: providers: List of providers.
|
90
90
|
if None, the table include all the available hardware.
|
91
91
|
|
92
92
|
Returns:
|
93
|
-
available devices
|
93
|
+
available devices: dict of the available devices.
|
94
94
|
"""
|
95
95
|
if providers is None:
|
96
96
|
providers = list(AnalyzerProviderVendor)
|
@@ -109,10 +109,10 @@ class Analyzer(AnalyzerUtilities):
|
|
109
109
|
analyzer_sdk extra.
|
110
110
|
|
111
111
|
Args:
|
112
|
-
provider
|
113
|
-
device
|
112
|
+
provider: provider name.
|
113
|
+
device: device name.
|
114
114
|
Returns:
|
115
|
-
hardware_connectivity_graph
|
115
|
+
hardware_connectivity_graph: interactive graph.
|
116
116
|
"""
|
117
117
|
|
118
118
|
self._validate_analyzer_extra()
|
@@ -138,11 +138,13 @@ class Analyzer(AnalyzerUtilities):
|
|
138
138
|
"""create a comparison table between the transpiled circuits result on different hardware.
|
139
139
|
The comparison table included the depth, multi qubit gates count,and total gates count of the circuits.
|
140
140
|
|
141
|
-
Args:
|
142
|
-
|
143
|
-
|
141
|
+
Args:
|
142
|
+
providers: List of providers. if None, the table include all the available hardware.
|
143
|
+
devices: List of devices. if None, the table include all the available devices of the selected
|
144
144
|
providers.
|
145
|
-
|
145
|
+
|
146
|
+
Returns:
|
147
|
+
None.
|
146
148
|
"""
|
147
149
|
if providers is None:
|
148
150
|
providers = list(AnalyzerProviderVendor)
|
@@ -21,7 +21,7 @@ from classiq.applications.combinatorial_helpers.pauli_helpers.pauli_utils import
|
|
21
21
|
from classiq.applications.combinatorial_helpers.pyomo_utils import (
|
22
22
|
convert_pyomo_to_global_presentation,
|
23
23
|
)
|
24
|
-
from classiq.qmod.builtins import PauliTerm
|
24
|
+
from classiq.qmod.builtins.structs import PauliTerm
|
25
25
|
|
26
26
|
|
27
27
|
def compute_qaoa_initial_point(
|
@@ -4,8 +4,8 @@ from classiq.interface.exceptions import ClassiqNonNumericCoefficientInPauliErro
|
|
4
4
|
from classiq.interface.generator.functions.qmod_python_interface import QmodPyStruct
|
5
5
|
from classiq.interface.helpers.custom_pydantic_types import PydanticPauliList
|
6
6
|
|
7
|
-
from classiq.qmod.builtins import PauliTerm
|
8
7
|
from classiq.qmod.builtins.enums import Pauli
|
8
|
+
from classiq.qmod.builtins.structs import PauliTerm
|
9
9
|
|
10
10
|
|
11
11
|
def pauli_operator_to_hamiltonian(pauli_list: PydanticPauliList) -> List[PauliTerm]:
|
classiq/applications/combinatorial_optimization/combinatorial_optimization_model_constructor.py
CHANGED
@@ -13,6 +13,7 @@ from classiq.interface.generator.functions.classical_type import (
|
|
13
13
|
from classiq.interface.generator.functions.port_declaration import (
|
14
14
|
PortDeclarationDirection,
|
15
15
|
)
|
16
|
+
from classiq.interface.generator.functions.type_name import Struct
|
16
17
|
from classiq.interface.model.classical_parameter_declaration import (
|
17
18
|
ClassicalParameterDeclaration,
|
18
19
|
)
|
@@ -23,7 +24,6 @@ from classiq.interface.model.port_declaration import PortDeclaration
|
|
23
24
|
from classiq.interface.model.quantum_function_call import QuantumFunctionCall
|
24
25
|
from classiq.interface.model.quantum_type import QuantumBitvector
|
25
26
|
|
26
|
-
from classiq import Struct
|
27
27
|
from classiq.applications.combinatorial_helpers.combinatorial_problem_utils import (
|
28
28
|
compute_qaoa_initial_point,
|
29
29
|
convert_pyomo_to_global_presentation,
|
@@ -2,15 +2,10 @@ from typing import cast
|
|
2
2
|
|
3
3
|
from classiq.interface.model.native_function_definition import NativeFunctionDefinition
|
4
4
|
|
5
|
-
from classiq.qmod import
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
QNum,
|
10
|
-
Z,
|
11
|
-
amplitude_estimation,
|
12
|
-
qfunc,
|
13
|
-
)
|
5
|
+
from classiq.qmod.builtins.functions import Z, amplitude_estimation
|
6
|
+
from classiq.qmod.qfunc import qfunc
|
7
|
+
from classiq.qmod.qmod_variable import QArray, QBit, QNum
|
8
|
+
from classiq.qmod.quantum_callable import QCallable
|
14
9
|
|
15
10
|
|
16
11
|
@qfunc
|
@@ -125,6 +125,15 @@ def generate_code_snippet(operation: str, **kwargs: Any) -> str:
|
|
125
125
|
|
126
126
|
|
127
127
|
class ExecutionSession:
|
128
|
+
"""
|
129
|
+
A session for executing a quantum program.
|
130
|
+
`ExecutionSession` allows to execute the quantum program with different parameters and operations without the need to re-synthesize the model.
|
131
|
+
|
132
|
+
Attributes:
|
133
|
+
quantum_program (Union[SerializedQuantumProgram, QuantumProgram]): The quantum program to execute.
|
134
|
+
execution_preferences (Optional[ExecutionPreferences]): Execution preferences for the Quantum Program.
|
135
|
+
"""
|
136
|
+
|
128
137
|
def __init__(
|
129
138
|
self,
|
130
139
|
quantum_program: Program,
|
@@ -134,35 +143,67 @@ class ExecutionSession:
|
|
134
143
|
self.update_execution_preferences(execution_preferences)
|
135
144
|
|
136
145
|
@property
|
137
|
-
def qprog(self) ->
|
146
|
+
def qprog(self) -> SerializedQuantumProgram:
|
147
|
+
"""
|
148
|
+
Returns:
|
149
|
+
SerializedQuantumProgram: The serialized quantum program (str). See `QuantumProgram`.
|
150
|
+
"""
|
138
151
|
return SerializedQuantumProgram(self.program.json(indent=2))
|
139
152
|
|
140
153
|
def update_execution_preferences(
|
141
154
|
self, execution_preferences: Optional[ExecutionPreferences]
|
142
155
|
) -> None:
|
156
|
+
"""
|
157
|
+
Update the execution preferences for the session.
|
158
|
+
|
159
|
+
Args:
|
160
|
+
execution_preferences: The execution preferences to update.
|
161
|
+
|
162
|
+
Returns:
|
163
|
+
None
|
164
|
+
"""
|
143
165
|
if execution_preferences is not None:
|
144
166
|
self.program.model.execution_preferences = execution_preferences
|
145
167
|
|
146
|
-
def
|
168
|
+
def _execute_quantum_program(
|
147
169
|
self, operation: str, **kwargs: Any
|
148
170
|
) -> ResultsCollection:
|
149
171
|
self.program.model.classical_execution_code = generate_code_snippet(
|
150
172
|
operation, **kwargs
|
151
173
|
)
|
152
|
-
return execute(self.qprog).result()
|
174
|
+
return execute(SerializedQuantumProgram(self.qprog)).result()
|
153
175
|
|
154
176
|
def sample(self, parameters: Optional[ExecutionParams] = None) -> ExecutionDetails:
|
177
|
+
"""
|
178
|
+
Samples the quantum program with the given parameters, if any.
|
179
|
+
|
180
|
+
Args:
|
181
|
+
parameters: The values to set for the parameters of the quantum program when sampling. Each key should be the name of a parameter in the quantum program (parameters of the main function), and the value should be the value to set for that parameter.
|
182
|
+
|
183
|
+
|
184
|
+
Returns:
|
185
|
+
ExecutionDetails: The result of the sampling.
|
186
|
+
"""
|
155
187
|
return cast(
|
156
188
|
ExecutionDetails,
|
157
|
-
self.
|
189
|
+
self._execute_quantum_program(
|
158
190
|
SupportedPrimitives.SAMPLE, parameters=format_parameters(parameters)
|
159
191
|
)[0].value,
|
160
192
|
)
|
161
193
|
|
162
194
|
def batch_sample(self, parameters: List[ExecutionParams]) -> List[ExecutionDetails]:
|
195
|
+
"""
|
196
|
+
Samples the quantum program multiple times with the given parameters for each iteration. The number of samples is determined by the length of the parameters list.
|
197
|
+
|
198
|
+
Args:
|
199
|
+
parameters: A list of the parameters for each iteration. Each item is a dictionary where each key should be the name of a parameter in the quantum program (parameters of the main function), and the value should be the value to set for that parameter.
|
200
|
+
|
201
|
+
Returns:
|
202
|
+
List[ExecutionDetails]: The results of all the sampling iterations.
|
203
|
+
"""
|
163
204
|
return cast(
|
164
205
|
MultipleExecutionDetails,
|
165
|
-
self.
|
206
|
+
self._execute_quantum_program(
|
166
207
|
SupportedPrimitives.BATCH_SAMPLE,
|
167
208
|
parameters=format_parameters(parameters),
|
168
209
|
)[0].value,
|
@@ -171,9 +212,19 @@ class ExecutionSession:
|
|
171
212
|
def estimate(
|
172
213
|
self, hamiltonian: Hamiltonian, parameters: Optional[ExecutionParams] = None
|
173
214
|
) -> EstimationResult:
|
215
|
+
"""
|
216
|
+
Estimates the expectation value of the given Hamiltonian using the quantum program.
|
217
|
+
|
218
|
+
Args:
|
219
|
+
hamiltonian: The Hamiltonian to estimate the expectation value of.
|
220
|
+
parameters: The values to set for the parameters of the quantum program when estimating. Each key should be the name of a parameter in the quantum program (parameters of the main function), and the value should be the value to set for that parameter.
|
221
|
+
|
222
|
+
Returns:
|
223
|
+
EstimationResult: The result of the estimation.
|
224
|
+
"""
|
174
225
|
return cast(
|
175
226
|
EstimationResult,
|
176
|
-
self.
|
227
|
+
self._execute_quantum_program(
|
177
228
|
SupportedPrimitives.ESTIMATE,
|
178
229
|
parameters=format_parameters(parameters),
|
179
230
|
hamiltonian=to_hamiltonian_str(hamiltonian),
|
@@ -183,9 +234,19 @@ class ExecutionSession:
|
|
183
234
|
def batch_estimate(
|
184
235
|
self, hamiltonian: Hamiltonian, parameters: List[ExecutionParams]
|
185
236
|
) -> List[EstimationResult]:
|
237
|
+
"""
|
238
|
+
Estimates the expectation value of the given Hamiltonian multiple times using the quantum program, with the given parameters for each iteration. The number of estimations is determined by the length of the parameters list.
|
239
|
+
|
240
|
+
Args:
|
241
|
+
hamiltonian: The Hamiltonian to estimate the expectation value of.
|
242
|
+
parameters: A list of the parameters for each iteration. Each item is a dictionary where each key should be the name of a parameter in the quantum program (parameters of the main function), and the value should be the value to set for that parameter.
|
243
|
+
|
244
|
+
Returns:
|
245
|
+
List[EstimationResult]: The results of all the estimation iterations.
|
246
|
+
"""
|
186
247
|
return cast(
|
187
248
|
EstimationResults,
|
188
|
-
self.
|
249
|
+
self._execute_quantum_program(
|
189
250
|
SupportedPrimitives.BATCH_ESTIMATE,
|
190
251
|
parameters=format_parameters(parameters),
|
191
252
|
hamiltonian=to_hamiltonian_str(hamiltonian),
|
classiq/executor.py
CHANGED
@@ -12,8 +12,8 @@ from classiq.interface.executor.quantum_instruction_set import QuantumInstructio
|
|
12
12
|
from classiq.interface.executor.result import ExecutionDetails
|
13
13
|
from classiq.interface.generator.quantum_program import QuantumProgram
|
14
14
|
|
15
|
+
from classiq._internals import async_utils
|
15
16
|
from classiq._internals.api_wrapper import ApiWrapper
|
16
|
-
from classiq._internals.async_utils import syncify_function
|
17
17
|
from classiq.execution.jobs import ExecutionJob
|
18
18
|
from classiq.synthesis import SerializedQuantumProgram
|
19
19
|
|
@@ -36,7 +36,19 @@ async def execute_async(quantum_program: SerializedQuantumProgram) -> ExecutionJ
|
|
36
36
|
return ExecutionJob(details=result)
|
37
37
|
|
38
38
|
|
39
|
-
execute
|
39
|
+
def execute(quantum_program: SerializedQuantumProgram) -> ExecutionJob:
|
40
|
+
"""
|
41
|
+
Execute a quantum program. The preferences for execution are set on the quantum program using the method `set_execution_preferences`.
|
42
|
+
|
43
|
+
Args:
|
44
|
+
quantum_program: The quantum program to execute. This is the result of the synthesize method.
|
45
|
+
|
46
|
+
Returns:
|
47
|
+
ExecutionJob: The result of the execution.
|
48
|
+
|
49
|
+
For examples please see [Execution Documentation](https://docs.classiq.io/latest/reference-manual/executor/)
|
50
|
+
"""
|
51
|
+
return async_utils.run(execute_async(quantum_program))
|
40
52
|
|
41
53
|
|
42
54
|
def set_quantum_program_execution_preferences(
|
classiq/interface/_version.py
CHANGED
@@ -24,6 +24,17 @@ from classiq.interface.helpers.pydantic_model_helpers import values_with_discrim
|
|
24
24
|
|
25
25
|
|
26
26
|
class BackendPreferences(BaseModel):
|
27
|
+
"""
|
28
|
+
Preferences for the execution of the quantum program.
|
29
|
+
|
30
|
+
For more details, refer to:
|
31
|
+
[BackendPreferences](https://docs.classiq.io/latest/reference-manual/python-sdk/?h=backend#classiq.Preferences.backend_preferences)
|
32
|
+
|
33
|
+
Attributes:
|
34
|
+
backend_service_provider (str): Provider company or cloud for the requested backend.
|
35
|
+
backend_name (str): Name of the requested backend or target.
|
36
|
+
"""
|
37
|
+
|
27
38
|
# Due to the way the field is currently implemented, i.e. it redefined with different types
|
28
39
|
# in the subclass, it shouldn't be dumped with exclude_unset. This causes this field not to appear.
|
29
40
|
# For example: don't use obj.dict(exclude_unset=True).
|
@@ -55,6 +66,49 @@ class BackendPreferences(BaseModel):
|
|
55
66
|
|
56
67
|
|
57
68
|
class AliceBobBackendPreferences(BackendPreferences):
|
69
|
+
"""
|
70
|
+
Backend preferences specific to Alice&Bob for quantum computing tasks.
|
71
|
+
|
72
|
+
This class includes configuration options for setting up a backend using Alice&Bob's quantum hardware.
|
73
|
+
It extends the base `BackendPreferences` class and provides additional parameters required for working
|
74
|
+
with Alice&Bob's cat qubits, including settings for photon dissipation rates, repetition code distance,
|
75
|
+
and the average number of photons.
|
76
|
+
|
77
|
+
Attributes:
|
78
|
+
backend_service_provider (ProviderTypeVendor.ALICE_BOB):
|
79
|
+
The service provider for the backend, which is Alice&Bob.
|
80
|
+
|
81
|
+
distance (Optional[int]):
|
82
|
+
The number of times information is duplicated in the repetition code.
|
83
|
+
- **Tooltip**: Phase-flip probability decreases exponentially with this parameter, bit-flip probability increases linearly.
|
84
|
+
- **Supported Values**: 3 to 300, though practical values are usually lower than 30.
|
85
|
+
- **Default**: None.
|
86
|
+
|
87
|
+
kappa_1 (Optional[float]):
|
88
|
+
The rate at which the cat qubit loses one photon, creating a bit-flip.
|
89
|
+
- **Tooltip**: Lower values mean lower error rates.
|
90
|
+
- **Supported Values**: 10 to 10^5. Current hardware is at ~10^3.
|
91
|
+
- **Default**: None.
|
92
|
+
|
93
|
+
kappa_2 (Optional[float]):
|
94
|
+
The rate at which the cat qubit is stabilized using two-photon dissipation.
|
95
|
+
- **Tooltip**: Higher values mean lower error rates.
|
96
|
+
- **Supported Values**: 100 to 10^9. Current hardware is at ~10^5.
|
97
|
+
- **Default**: None.
|
98
|
+
|
99
|
+
average_nb_photons (Optional[float]):
|
100
|
+
The average number of photons.
|
101
|
+
- **Tooltip**: Bit-flip probability decreases exponentially with this parameter, phase-flip probability increases linearly.
|
102
|
+
- **Supported Values**: 4 to 10^5, though practical values are usually lower than 30.
|
103
|
+
- **Default**: None.
|
104
|
+
|
105
|
+
api_key (str):
|
106
|
+
The API key required to access Alice&Bob's quantum hardware.
|
107
|
+
- **Required**: Yes.
|
108
|
+
|
109
|
+
For more details, refer to the [Alice&Bob Backend Documentation](https://docs.classiq.io/latest/reference-manual/executor/cloud-providers/alice-and-bob-backends/).
|
110
|
+
"""
|
111
|
+
|
58
112
|
backend_service_provider: ProviderTypeVendor.ALICE_BOB
|
59
113
|
distance: Optional[int] = pydantic.Field(
|
60
114
|
default=None, description="Repetition code distance"
|
@@ -90,6 +144,15 @@ class AliceBobBackendPreferences(BackendPreferences):
|
|
90
144
|
|
91
145
|
|
92
146
|
class ClassiqBackendPreferences(BackendPreferences):
|
147
|
+
"""
|
148
|
+
Represents backend preferences specific to Classiq quantum computing targets.
|
149
|
+
|
150
|
+
This class is used to configure the backend options for executing quantum circuits on Classiq's platform.
|
151
|
+
The relevant backend names for Classiq targets are specified in `ClassiqSimulatorBackendNames` & `ClassiqNvidiaBackendNames`.
|
152
|
+
|
153
|
+
For more details, refer to the [Classiq Backend Documentation](https://docs.classiq.io/latest/reference-manual/executor/cloud-providers/classiq-backends/).
|
154
|
+
"""
|
155
|
+
|
93
156
|
backend_service_provider: ProviderTypeVendor.CLASSIQ
|
94
157
|
|
95
158
|
@pydantic.root_validator(pre=True)
|
@@ -103,6 +166,36 @@ class ClassiqBackendPreferences(BackendPreferences):
|
|
103
166
|
|
104
167
|
|
105
168
|
class AwsBackendPreferences(BackendPreferences):
|
169
|
+
"""
|
170
|
+
AWS-specific backend preferences for quantum computing tasks using Amazon Braket.
|
171
|
+
|
172
|
+
This class contains configuration options specific to Amazon Braket, including the AWS role
|
173
|
+
ARN, S3 bucket details, and the folder path within the S3 bucket. It extends the base
|
174
|
+
`BackendPreferences` class to provide additional properties required for interaction with
|
175
|
+
Amazon Braket.
|
176
|
+
|
177
|
+
Attributes:
|
178
|
+
backend_service_provider (ProviderTypeVendor.AMAZON_BRAKET):
|
179
|
+
The service provider for the backend, which is Amazon Braket.
|
180
|
+
|
181
|
+
aws_role_arn (pydantic_backend.PydanticAwsRoleArn):
|
182
|
+
The Amazon Resource Name (ARN) of the role that will be assumed for execution
|
183
|
+
on your Braket account. This is a required field and should be provided to allow
|
184
|
+
secure and authorized access to AWS resources.
|
185
|
+
|
186
|
+
s3_bucket_name (str):
|
187
|
+
The name of the S3 bucket where results and other related data will be stored.
|
188
|
+
This field should contain a valid S3 bucket name under your AWS account.
|
189
|
+
|
190
|
+
s3_folder (pydantic_backend.PydanticS3BucketKey):
|
191
|
+
The folder path within the specified S3 bucket. This allows for organizing
|
192
|
+
results and data under a specific directory within the S3 bucket.
|
193
|
+
|
194
|
+
|
195
|
+
For more details, refer to:
|
196
|
+
[AwsBackendPreferences examples](https://docs.classiq.io/latest/reference-manual/executor/cloud-providers/amazon-backends/?h=awsbackend#usage)
|
197
|
+
"""
|
198
|
+
|
106
199
|
backend_service_provider: ProviderTypeVendor.AMAZON_BRAKET
|
107
200
|
aws_role_arn: pydantic_backend.PydanticAwsRoleArn = pydantic.Field(
|
108
201
|
description="ARN of the role to be assumed for execution on your Braket account."
|
@@ -129,12 +222,38 @@ class AwsBackendPreferences(BackendPreferences):
|
|
129
222
|
|
130
223
|
|
131
224
|
class IBMBackendProvider(BaseModel):
|
225
|
+
"""
|
226
|
+
|
227
|
+
Represents the provider specs for identifying an IBM Quantum backend.
|
228
|
+
|
229
|
+
Attributes:
|
230
|
+
hub (str): hub parameter of IBM Quantum provider. Defaults to `"ibm-q"`.
|
231
|
+
group (str): group parameter of IBM Quantum provider. Defaults to `"open"`.
|
232
|
+
project (str): project parameter of IBM Quantum provider. Defaults to `"main"`.
|
233
|
+
|
234
|
+
"""
|
235
|
+
|
132
236
|
hub: str = "ibm-q"
|
133
237
|
group: str = "open"
|
134
238
|
project: str = "main"
|
135
239
|
|
136
240
|
|
137
241
|
class IBMBackendPreferences(BackendPreferences):
|
242
|
+
"""
|
243
|
+
Represents the backend preferences specific to IBM Quantum services.
|
244
|
+
|
245
|
+
Inherits from `BackendPreferences` and adds additional fields and validations
|
246
|
+
specific to IBM Quantum backends.
|
247
|
+
|
248
|
+
Attributes:
|
249
|
+
backend_service_provider (ProviderTypeVendor.IBM_QUANTUM): Indicates the backend service provider as IBM Quantum.
|
250
|
+
access_token (Optional[str]): The IBM Quantum access token to be used with IBM Quantum hosted backends. Defaults to `None`.
|
251
|
+
provider (IBMBackendProvider): Specifications for identifying a single IBM Quantum provider. Defaults to a new `IBMBackendProvider`.
|
252
|
+
qctrl_api_key (Optional[str]): QCTRL API key to access QCTRL optimization abilities.
|
253
|
+
|
254
|
+
See examples in the [IBM Quantum Backend Documentation](https://docs.classiq.io/latest/reference-manual/executor/cloud-providers/ibm-backends/?h=).
|
255
|
+
"""
|
256
|
+
|
138
257
|
backend_service_provider: ProviderTypeVendor.IBM_QUANTUM
|
139
258
|
access_token: Optional[str] = pydantic.Field(
|
140
259
|
default=None,
|
@@ -158,6 +277,17 @@ class IBMBackendPreferences(BackendPreferences):
|
|
158
277
|
|
159
278
|
|
160
279
|
class AzureCredential(pydantic.BaseSettings):
|
280
|
+
"""
|
281
|
+
Represents the credentials and configuration required to authenticate with Azure services.
|
282
|
+
|
283
|
+
Attributes:
|
284
|
+
tenant_id (str): Azure Tenant ID used to identify the directory in which the application is registered.
|
285
|
+
client_id (str): Azure Client ID, also known as the application ID, which is used to authenticate the application.
|
286
|
+
client_secret (str): Azure Client Secret associated with the application, used for authentication.
|
287
|
+
resource_id (pydantic_backend.PydanticAzureResourceIDType): Azure Resource ID, including the subscription ID,
|
288
|
+
resource group, and workspace, typically used for personal resources.
|
289
|
+
"""
|
290
|
+
|
161
291
|
tenant_id: str = pydantic.Field(description="Azure Tenant ID")
|
162
292
|
client_id: str = pydantic.Field(description="Azure Client ID")
|
163
293
|
client_secret: str = pydantic.Field(description="Azure Client Secret")
|
@@ -173,6 +303,19 @@ class AzureCredential(pydantic.BaseSettings):
|
|
173
303
|
|
174
304
|
|
175
305
|
class AzureBackendPreferences(BackendPreferences):
|
306
|
+
"""
|
307
|
+
This class inherits from BackendPreferences.
|
308
|
+
This is where you specify Azure Quantum preferences.
|
309
|
+
See usage in the [Azure Backend Documentation](https://docs.classiq.io/latest/reference-manual/executor/cloud-providers/azure-backends/).
|
310
|
+
|
311
|
+
Attributes:
|
312
|
+
location (str): Azure personal resource region. Defaults to `"East US"`.
|
313
|
+
credentials (Optional[AzureCredential]): The service principal credential to access personal quantum workspace. Defaults to `None`.
|
314
|
+
ionq_error_mitigation_flag (Optional[bool]): Error mitigation configuration upon running on IonQ through Azure. Defaults to `False`.
|
315
|
+
|
316
|
+
|
317
|
+
"""
|
318
|
+
|
176
319
|
backend_service_provider: ProviderTypeVendor.AZURE_QUANTUM
|
177
320
|
|
178
321
|
location: str = pydantic.Field(
|
@@ -191,6 +334,12 @@ class AzureBackendPreferences(BackendPreferences):
|
|
191
334
|
|
192
335
|
@property
|
193
336
|
def run_through_classiq(self) -> bool:
|
337
|
+
"""
|
338
|
+
|
339
|
+
Returns: `True` if there are no Azure Credentials.
|
340
|
+
Therefore you will be running through Classiq's credentials.
|
341
|
+
|
342
|
+
"""
|
194
343
|
return self.credentials is None
|
195
344
|
|
196
345
|
@pydantic.root_validator(pre=True)
|
@@ -201,10 +350,28 @@ class AzureBackendPreferences(BackendPreferences):
|
|
201
350
|
|
202
351
|
|
203
352
|
class IonqBackendPreferences(BackendPreferences):
|
353
|
+
"""
|
354
|
+
Represents the backend preferences specific to IonQ services.
|
355
|
+
|
356
|
+
Inherits from `BackendPreferences` and adds additional fields and configurations
|
357
|
+
specific to IonQ backends
|
358
|
+
|
359
|
+
Attributes:
|
360
|
+
backend_service_provider (ProviderTypeVendor.IONQ): Indicates the backend service provider as IonQ.
|
361
|
+
api_key (PydanticIonQApiKeyType): The IonQ API key required for accessing IonQ's quantum computing services.
|
362
|
+
error_mitigation (bool): A configuration option to enable or disable error mitigation during execution. Defaults to `False`.
|
363
|
+
|
364
|
+
See examples in the [IonQ Backend Documentation](https://docs.classiq.io/latest/reference-manual/executor/cloud-providers/ionq-backends/?h=).
|
365
|
+
"""
|
366
|
+
|
204
367
|
backend_service_provider: ProviderTypeVendor.IONQ
|
205
368
|
api_key: pydantic_backend.PydanticIonQApiKeyType = pydantic.Field(
|
206
369
|
..., description="IonQ API key"
|
207
370
|
)
|
371
|
+
error_mitigation: bool = pydantic.Field(
|
372
|
+
default=False,
|
373
|
+
description="Error mitigation configuration.",
|
374
|
+
)
|
208
375
|
|
209
376
|
@pydantic.root_validator(pre=True)
|
210
377
|
def _set_backend_service_provider(cls, values: Dict[str, Any]) -> Dict[str, Any]:
|
@@ -214,6 +381,18 @@ class IonqBackendPreferences(BackendPreferences):
|
|
214
381
|
|
215
382
|
|
216
383
|
class GCPBackendPreferences(BackendPreferences):
|
384
|
+
"""
|
385
|
+
Represents the backend preferences specific to Google Cloud Platform (GCP) services.
|
386
|
+
|
387
|
+
Inherits from `BackendPreferences` and sets the backend service provider to Google.
|
388
|
+
|
389
|
+
Attributes:
|
390
|
+
backend_service_provider (ProviderTypeVendor.GOOGLE): Indicates the backend service provider as Google,
|
391
|
+
specifically for quantum computing services on Google Cloud Platform (GCP).
|
392
|
+
|
393
|
+
See examples in the [Google Cloud Backend Documentation](https://docs.classiq.io/latest/reference-manual/executor/cloud-providers/google-backends/?h=).
|
394
|
+
"""
|
395
|
+
|
217
396
|
backend_service_provider: ProviderTypeVendor.GOOGLE
|
218
397
|
|
219
398
|
@pydantic.root_validator(pre=True)
|
@@ -227,6 +406,16 @@ class GCPBackendPreferences(BackendPreferences):
|
|
227
406
|
|
228
407
|
|
229
408
|
class OQCBackendPreferences(BackendPreferences):
|
409
|
+
"""
|
410
|
+
|
411
|
+
This class inherits from `BackendPreferences`.
|
412
|
+
This is where you specify OQC preferences.
|
413
|
+
|
414
|
+
Attributes:
|
415
|
+
username (str): OQC username
|
416
|
+
password (str): OQC password
|
417
|
+
"""
|
418
|
+
|
230
419
|
backend_service_provider: ProviderTypeVendor.OQC
|
231
420
|
username: str = pydantic.Field(description="OQC username")
|
232
421
|
password: str = pydantic.Field(description="OQC password")
|