classiq 0.37.1__py3-none-any.whl → 0.39.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 +23 -24
- classiq/_analyzer_extras/_ipywidgets_async_extension.py +1 -1
- classiq/_analyzer_extras/interactive_hardware.py +3 -3
- classiq/_internals/api_wrapper.py +37 -17
- classiq/_internals/async_utils.py +1 -74
- classiq/_internals/authentication/device.py +9 -4
- classiq/_internals/authentication/password_manager.py +25 -10
- classiq/_internals/authentication/token_manager.py +2 -2
- classiq/_internals/client.py +24 -6
- classiq/_internals/jobs.py +10 -7
- classiq/analyzer/analyzer.py +29 -29
- classiq/analyzer/analyzer_utilities.py +5 -5
- classiq/analyzer/rb.py +4 -5
- classiq/analyzer/show_interactive_hack.py +6 -6
- classiq/applications/__init__.py +1 -8
- classiq/applications/chemistry/__init__.py +6 -0
- classiq/{applications_model_constructors → applications/chemistry}/chemistry_model_constructor.py +9 -16
- classiq/applications/combinatorial_helpers/allowed_constraints.py +20 -0
- classiq/applications/combinatorial_helpers/arithmetic/arithmetic_expression.py +35 -0
- classiq/applications/combinatorial_helpers/arithmetic/isolation.py +42 -0
- classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +150 -0
- classiq/applications/combinatorial_helpers/encoding_mapping.py +107 -0
- classiq/applications/combinatorial_helpers/encoding_utils.py +122 -0
- classiq/applications/combinatorial_helpers/memory.py +77 -0
- classiq/applications/combinatorial_helpers/optimization_model.py +162 -0
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_sparsing.py +31 -0
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_utils.py +75 -0
- classiq/applications/combinatorial_helpers/py.typed +0 -0
- classiq/applications/combinatorial_helpers/pyomo_utils.py +245 -0
- classiq/applications/combinatorial_helpers/solvers/__init__.py +0 -0
- classiq/applications/combinatorial_helpers/sympy_utils.py +22 -0
- classiq/applications/combinatorial_helpers/transformations/__init__.py +0 -0
- classiq/applications/combinatorial_helpers/transformations/encoding.py +187 -0
- classiq/applications/combinatorial_helpers/transformations/fixed_variables.py +142 -0
- classiq/applications/combinatorial_helpers/transformations/ising_converter.py +122 -0
- classiq/applications/combinatorial_helpers/transformations/penalty.py +32 -0
- classiq/applications/combinatorial_helpers/transformations/penalty_support.py +37 -0
- classiq/applications/combinatorial_helpers/transformations/sign_seperation.py +75 -0
- classiq/applications/combinatorial_helpers/transformations/slack_variables.py +88 -0
- classiq/applications/combinatorial_optimization/__init__.py +13 -2
- classiq/applications/combinatorial_optimization/combinatorial_optimization_model_constructor.py +134 -0
- classiq/applications/finance/__init__.py +3 -2
- classiq/{applications_model_constructors → applications/finance}/finance_model_constructor.py +27 -30
- classiq/applications/grover/__init__.py +11 -0
- classiq/{applications_model_constructors → applications/grover}/grover_model_constructor.py +20 -91
- classiq/applications/libraries/__init__.py +0 -0
- classiq/applications/libraries/qmci_library.py +35 -0
- classiq/applications/qnn/circuit_utils.py +2 -2
- classiq/applications/qnn/gradients/quantum_gradient.py +2 -2
- classiq/applications/qnn/types.py +2 -2
- classiq/applications/qsvm/__init__.py +5 -1
- classiq/applications/qsvm/qsvm.py +4 -7
- classiq/applications/qsvm/qsvm_data_generation.py +2 -5
- classiq/exceptions.py +43 -1
- classiq/execution/all_hardware_devices.py +13 -0
- classiq/executor.py +12 -10
- classiq/interface/_version.py +1 -1
- classiq/interface/analyzer/analysis_params.py +6 -3
- classiq/interface/analyzer/result.py +12 -8
- classiq/interface/applications/qsvm.py +17 -3
- classiq/interface/ast_node.py +23 -0
- classiq/interface/backend/backend_preferences.py +4 -2
- classiq/interface/backend/pydantic_backend.py +3 -1
- classiq/interface/backend/quantum_backend_providers.py +1 -0
- classiq/interface/chemistry/fermionic_operator.py +15 -13
- classiq/interface/chemistry/ground_state_problem.py +18 -3
- classiq/interface/chemistry/molecule.py +8 -6
- classiq/interface/chemistry/operator.py +20 -14
- classiq/interface/combinatorial_optimization/examples/ascending_sequence.py +1 -1
- classiq/interface/combinatorial_optimization/examples/greater_than_ilp.py +1 -1
- classiq/interface/combinatorial_optimization/examples/ilp.py +2 -1
- classiq/interface/combinatorial_optimization/examples/integer_portfolio_optimization.py +2 -2
- classiq/interface/combinatorial_optimization/examples/mds.py +2 -1
- classiq/interface/combinatorial_optimization/examples/mht.py +8 -3
- classiq/interface/combinatorial_optimization/examples/mis.py +4 -1
- classiq/interface/combinatorial_optimization/examples/mvc.py +2 -1
- classiq/interface/combinatorial_optimization/examples/set_cover.py +2 -1
- classiq/interface/combinatorial_optimization/examples/tsp.py +4 -3
- classiq/interface/combinatorial_optimization/examples/tsp_digraph.py +6 -2
- classiq/interface/combinatorial_optimization/mht_qaoa_input.py +9 -3
- classiq/interface/executor/aws_execution_cost.py +4 -3
- classiq/interface/executor/estimation.py +2 -2
- classiq/interface/executor/execution_preferences.py +5 -34
- classiq/interface/executor/execution_request.py +15 -48
- classiq/interface/executor/optimizer_preferences.py +22 -13
- classiq/interface/executor/{quantum_program.py → quantum_code.py} +21 -15
- classiq/interface/executor/quantum_instruction_set.py +2 -1
- classiq/interface/executor/register_initialization.py +1 -3
- classiq/interface/executor/result.py +41 -10
- classiq/interface/executor/vqe_result.py +2 -2
- classiq/interface/finance/function_input.py +17 -4
- classiq/interface/finance/gaussian_model_input.py +3 -1
- classiq/interface/finance/log_normal_model_input.py +3 -1
- classiq/interface/finance/model_input.py +2 -0
- classiq/interface/generator/amplitude_loading.py +6 -3
- classiq/interface/generator/application_apis/__init__.py +1 -0
- classiq/interface/generator/application_apis/arithmetic_declarations.py +14 -0
- classiq/interface/generator/arith/argument_utils.py +14 -4
- classiq/interface/generator/arith/arithmetic.py +3 -1
- classiq/interface/generator/arith/arithmetic_arg_type_validator.py +12 -13
- classiq/interface/generator/arith/arithmetic_expression_abc.py +4 -1
- classiq/interface/generator/arith/arithmetic_expression_parser.py +8 -2
- classiq/interface/generator/arith/arithmetic_expression_validator.py +16 -2
- classiq/interface/generator/arith/arithmetic_operations.py +5 -10
- classiq/interface/generator/arith/ast_node_rewrite.py +1 -1
- classiq/interface/generator/arith/binary_ops.py +202 -54
- classiq/interface/generator/arith/extremum_operations.py +5 -3
- classiq/interface/generator/arith/logical_ops.py +4 -2
- classiq/interface/generator/arith/machine_precision.py +3 -0
- classiq/interface/generator/arith/number_utils.py +34 -44
- classiq/interface/generator/arith/register_user_input.py +21 -1
- classiq/interface/generator/arith/unary_ops.py +16 -25
- classiq/interface/generator/builtin_api_builder.py +0 -5
- classiq/interface/generator/chemistry_function_params.py +4 -4
- classiq/interface/generator/commuting_pauli_exponentiation.py +3 -1
- classiq/interface/generator/compiler_keywords.py +4 -0
- classiq/interface/generator/complex_type.py +3 -10
- classiq/interface/generator/constant.py +2 -3
- classiq/interface/generator/control_state.py +5 -3
- classiq/interface/generator/credit_risk_example/linear_gci.py +10 -3
- classiq/interface/generator/credit_risk_example/weighted_adder.py +14 -4
- classiq/interface/generator/expressions/atomic_expression_functions.py +5 -3
- classiq/interface/generator/expressions/evaluated_expression.py +18 -4
- classiq/interface/generator/expressions/expression.py +3 -5
- classiq/interface/generator/expressions/qmod_qscalar_proxy.py +33 -0
- classiq/interface/generator/expressions/sympy_supported_expressions.py +2 -1
- classiq/interface/generator/finance.py +1 -1
- classiq/interface/generator/function_params.py +7 -6
- classiq/interface/generator/functions/__init__.py +2 -2
- classiq/interface/generator/functions/builtins/__init__.py +15 -0
- classiq/interface/generator/functions/builtins/core_library/__init__.py +14 -0
- classiq/interface/generator/functions/builtins/core_library/chemistry_functions.py +0 -0
- classiq/interface/generator/functions/builtins/internal_operators.py +62 -0
- classiq/interface/generator/functions/{core_lib_declarations/quantum_functions/std_lib_functions.py → builtins/open_lib_functions.py} +612 -219
- classiq/interface/generator/functions/builtins/quantum_operators.py +37 -0
- classiq/interface/generator/functions/classical_type.py +2 -4
- classiq/interface/generator/functions/foreign_function_definition.py +12 -4
- classiq/interface/generator/functions/function_declaration.py +2 -2
- classiq/interface/generator/functions/function_implementation.py +8 -4
- classiq/interface/generator/functions/native_function_definition.py +4 -2
- classiq/interface/generator/functions/register.py +4 -2
- classiq/interface/generator/functions/register_mapping_data.py +14 -10
- classiq/interface/generator/generated_circuit_data.py +2 -2
- classiq/interface/generator/grover_operator.py +5 -3
- classiq/interface/generator/hamiltonian_evolution/suzuki_trotter.py +5 -1
- classiq/interface/generator/hardware/hardware_data.py +6 -4
- classiq/interface/generator/hardware_efficient_ansatz.py +25 -8
- classiq/interface/generator/hartree_fock.py +13 -3
- classiq/interface/generator/linear_pauli_rotations.py +3 -1
- classiq/interface/generator/mcu.py +5 -3
- classiq/interface/generator/mcx.py +7 -5
- classiq/interface/generator/model/classical_main_validator.py +1 -1
- classiq/interface/generator/model/constraints.py +2 -1
- classiq/interface/generator/model/model.py +12 -20
- classiq/interface/generator/model/preferences/preferences.py +4 -3
- classiq/interface/generator/oracles/custom_oracle.py +4 -2
- classiq/interface/generator/oracles/oracle_abc.py +2 -2
- classiq/interface/generator/qpe.py +6 -4
- classiq/interface/generator/qsvm.py +5 -8
- classiq/interface/generator/quantum_function_call.py +21 -16
- classiq/interface/generator/{generated_circuit.py → quantum_program.py} +10 -14
- classiq/interface/generator/range_types.py +3 -1
- classiq/interface/generator/slice_parsing_utils.py +8 -3
- classiq/interface/generator/standard_gates/controlled_standard_gates.py +4 -2
- classiq/interface/generator/state_preparation/metrics.py +2 -1
- classiq/interface/generator/state_preparation/state_preparation.py +7 -5
- classiq/interface/generator/state_propagator.py +16 -5
- classiq/interface/generator/types/builtin_struct_declarations/__init__.py +0 -1
- classiq/interface/generator/types/struct_declaration.py +10 -7
- classiq/interface/generator/ucc.py +6 -4
- classiq/interface/generator/unitary_gate.py +7 -3
- classiq/interface/generator/validations/flow_graph.py +6 -4
- classiq/interface/generator/validations/validator_functions.py +6 -4
- classiq/interface/hardware.py +2 -2
- classiq/interface/helpers/custom_encoders.py +3 -0
- classiq/interface/helpers/pydantic_model_helpers.py +0 -6
- classiq/interface/helpers/validation_helpers.py +1 -1
- classiq/interface/helpers/versioned_model.py +4 -1
- classiq/interface/ide/show.py +2 -2
- classiq/interface/jobs.py +72 -3
- classiq/interface/model/bind_operation.py +18 -11
- classiq/interface/model/call_synthesis_data.py +68 -0
- classiq/interface/model/classical_if.py +13 -0
- classiq/interface/model/classical_parameter_declaration.py +2 -3
- classiq/interface/model/control.py +16 -0
- classiq/interface/model/handle_binding.py +3 -2
- classiq/interface/model/inplace_binary_operation.py +2 -2
- classiq/interface/model/invert.py +10 -0
- classiq/interface/model/model.py +29 -22
- classiq/interface/model/native_function_definition.py +3 -5
- classiq/interface/model/power.py +12 -0
- classiq/interface/model/quantum_expressions/amplitude_loading_operation.py +9 -4
- classiq/interface/model/quantum_expressions/control_state.py +2 -2
- classiq/interface/model/quantum_function_call.py +33 -142
- classiq/interface/model/quantum_function_declaration.py +8 -0
- classiq/interface/model/quantum_if_operation.py +4 -5
- classiq/interface/model/quantum_lambda_function.py +58 -0
- classiq/{quantum_register.py → interface/model/quantum_register.py} +17 -9
- classiq/interface/model/quantum_statement.py +3 -2
- classiq/interface/model/quantum_type.py +58 -59
- classiq/interface/model/quantum_variable_declaration.py +3 -3
- classiq/interface/model/repeat.py +13 -0
- classiq/interface/model/resolvers/function_call_resolver.py +26 -0
- classiq/interface/model/statement_block.py +49 -0
- classiq/interface/model/validations/handles_validator.py +16 -18
- classiq/interface/model/within_apply_operation.py +11 -0
- classiq/interface/pyomo_extension/pyomo_sympy_bimap.py +4 -1
- classiq/interface/server/routes.py +5 -4
- classiq/qmod/__init__.py +13 -6
- classiq/qmod/builtins/classical_execution_primitives.py +27 -36
- classiq/qmod/builtins/classical_functions.py +22 -12
- classiq/qmod/builtins/functions.py +272 -328
- classiq/qmod/builtins/operations.py +171 -35
- classiq/qmod/builtins/structs.py +15 -15
- classiq/qmod/cfunc.py +42 -0
- classiq/qmod/classical_function.py +6 -14
- classiq/qmod/declaration_inferrer.py +12 -21
- classiq/qmod/expression_query.py +23 -0
- classiq/qmod/model_state_container.py +2 -0
- classiq/qmod/native/__init__.py +0 -0
- classiq/qmod/native/expression_to_qmod.py +189 -0
- classiq/qmod/native/pretty_printer.py +340 -0
- classiq/qmod/qfunc.py +27 -0
- classiq/qmod/qmod_constant.py +100 -0
- classiq/qmod/qmod_parameter.py +36 -13
- classiq/qmod/qmod_struct.py +3 -3
- classiq/qmod/qmod_variable.py +148 -31
- classiq/qmod/quantum_callable.py +1 -0
- classiq/qmod/quantum_expandable.py +18 -19
- classiq/qmod/quantum_function.py +41 -8
- classiq/qmod/symbolic.py +48 -5
- classiq/qmod/symbolic_expr.py +9 -0
- classiq/qmod/utilities.py +13 -0
- classiq/qmod/write_qmod.py +39 -0
- {classiq-0.37.1.dist-info → classiq-0.39.0.dist-info}/METADATA +2 -1
- {classiq-0.37.1.dist-info → classiq-0.39.0.dist-info}/RECORD +244 -225
- {classiq-0.37.1.dist-info → classiq-0.39.0.dist-info}/WHEEL +1 -1
- classiq/applications/benchmarking/__init__.py +0 -9
- classiq/applications/benchmarking/mirror_benchmarking.py +0 -67
- classiq/applications/numpy_utils.py +0 -37
- classiq/applications_model_constructors/__init__.py +0 -17
- classiq/applications_model_constructors/combinatorial_optimization_model_constructor.py +0 -178
- classiq/applications_model_constructors/libraries/qmci_library.py +0 -109
- classiq/builtin_functions/__init__.py +0 -43
- classiq/builtin_functions/amplitude_loading.py +0 -3
- classiq/builtin_functions/binary_ops.py +0 -1
- classiq/builtin_functions/exponentiation.py +0 -5
- classiq/builtin_functions/qpe.py +0 -4
- classiq/builtin_functions/qsvm.py +0 -7
- classiq/builtin_functions/range_types.py +0 -5
- classiq/builtin_functions/standard_gates.py +0 -1
- classiq/builtin_functions/state_preparation.py +0 -6
- classiq/builtin_functions/suzuki_trotter.py +0 -3
- classiq/interface/generator/expressions/qmod_qnum_proxy.py +0 -22
- classiq/interface/generator/functions/core_lib_declarations/quantum_functions/__init__.py +0 -18
- classiq/interface/generator/functions/core_lib_declarations/quantum_operators.py +0 -169
- classiq/interface/generator/types/builtin_struct_declarations/qaoa_declarations.py +0 -23
- classiq/interface/generator/types/combinatorial_problem.py +0 -26
- classiq/interface/model/numeric_reinterpretation.py +0 -25
- classiq/interface/model/operator_synthesis_data.py +0 -48
- classiq/model/__init__.py +0 -14
- classiq/model/composite_function_generator.py +0 -33
- classiq/model/function_handler.py +0 -466
- classiq/model/function_handler.pyi +0 -152
- classiq/model/logic_flow.py +0 -149
- classiq/model/logic_flow_change_handler.py +0 -71
- classiq/model/model.py +0 -246
- classiq/quantum_functions/__init__.py +0 -17
- classiq/quantum_functions/annotation_parser.py +0 -207
- classiq/quantum_functions/decorators.py +0 -22
- classiq/quantum_functions/function_library.py +0 -181
- classiq/quantum_functions/function_parser.py +0 -74
- classiq/quantum_functions/quantum_function.py +0 -236
- /classiq/{applications_model_constructors/libraries → applications/combinatorial_helpers}/__init__.py +0 -0
- /classiq/{interface/generator/functions/core_lib_declarations → applications/combinatorial_helpers/arithmetic}/__init__.py +0 -0
- /classiq/{interface/generator/functions/core_lib_declarations/quantum_functions/chemistry_functions.py → applications/combinatorial_helpers/pauli_helpers/__init__.py} +0 -0
- /classiq/{applications_model_constructors → applications}/libraries/ampltitude_estimation_library.py +0 -0
- /classiq/{applications_model_constructors → applications/qsvm}/qsvm_model_constructor.py +0 -0
- /classiq/interface/generator/functions/{core_lib_declarations/quantum_functions → builtins/core_library}/atomic_quantum_functions.py +0 -0
- /classiq/interface/generator/functions/{core_lib_declarations/quantum_functions → builtins/core_library}/exponentiation_functions.py +0 -0
@@ -1,17 +1,16 @@
|
|
1
|
-
from
|
2
|
-
|
3
|
-
import abc
|
4
|
-
from typing import Iterable, Optional
|
1
|
+
from typing import TYPE_CHECKING, Iterable, Optional
|
5
2
|
|
6
3
|
import pydantic
|
7
4
|
|
8
|
-
from classiq.interface.generator.arith import number_utils
|
5
|
+
from classiq.interface.generator.arith import argument_utils, number_utils
|
9
6
|
from classiq.interface.generator.arith.arithmetic_operations import (
|
10
7
|
ArithmeticOperationParams,
|
11
8
|
)
|
12
9
|
from classiq.interface.generator.arith.register_user_input import RegisterArithmeticInfo
|
13
10
|
from classiq.interface.generator.function_params import get_zero_input_name
|
14
11
|
|
12
|
+
from classiq.exceptions import ClassiqValueError
|
13
|
+
|
15
14
|
UNARY_ARG_NAME: str = "arg"
|
16
15
|
|
17
16
|
|
@@ -19,16 +18,9 @@ class UnaryOpParams(ArithmeticOperationParams):
|
|
19
18
|
arg: RegisterArithmeticInfo
|
20
19
|
inplace: bool = False
|
21
20
|
|
22
|
-
@abc.abstractmethod
|
23
|
-
def _expected_result_size(self) -> pydantic.PositiveInt:
|
24
|
-
pass
|
25
|
-
|
26
|
-
def actual_result_size(self) -> int:
|
27
|
-
return self.output_size or self._expected_result_size()
|
28
|
-
|
29
21
|
def garbage_output_size(self) -> pydantic.NonNegativeInt:
|
30
22
|
return int(self.is_inplaced()) * max(
|
31
|
-
self.arg.size - self.
|
23
|
+
self.arg.size - self.result_register.size, 0
|
32
24
|
)
|
33
25
|
|
34
26
|
def should_add_zero_inputs(self) -> bool:
|
@@ -60,7 +52,7 @@ class UnaryOpParams(ArithmeticOperationParams):
|
|
60
52
|
def is_inplaced(self) -> bool:
|
61
53
|
return self.inplace
|
62
54
|
|
63
|
-
def get_params_inplace_options(self) -> Iterable[UnaryOpParams]:
|
55
|
+
def get_params_inplace_options(self) -> Iterable["UnaryOpParams"]:
|
64
56
|
params_kwargs = self.copy().__dict__
|
65
57
|
params_kwargs["inplace"] = True
|
66
58
|
yield self.__class__(**params_kwargs)
|
@@ -72,14 +64,16 @@ class UnaryOpParams(ArithmeticOperationParams):
|
|
72
64
|
class BitwiseInvert(UnaryOpParams):
|
73
65
|
output_name = "inverted"
|
74
66
|
|
75
|
-
def _expected_result_size(self) -> pydantic.PositiveInt:
|
76
|
-
return self.arg.size
|
77
|
-
|
78
67
|
def _get_result_register(self) -> RegisterArithmeticInfo:
|
68
|
+
eff_arg = argument_utils.limit_fraction_places(
|
69
|
+
self.arg, machine_precision=self.machine_precision
|
70
|
+
)
|
71
|
+
if TYPE_CHECKING:
|
72
|
+
assert isinstance(eff_arg, RegisterArithmeticInfo)
|
79
73
|
return RegisterArithmeticInfo(
|
80
|
-
size=self.
|
81
|
-
fraction_places=
|
82
|
-
is_signed=
|
74
|
+
size=self.output_size or eff_arg.size,
|
75
|
+
fraction_places=eff_arg.fraction_places,
|
76
|
+
is_signed=eff_arg.is_signed and self._include_sign,
|
83
77
|
)
|
84
78
|
|
85
79
|
|
@@ -97,7 +91,7 @@ class Negation(UnaryOpParams):
|
|
97
91
|
is_signed = max(self.arg.bounds) > 0 and self._include_sign
|
98
92
|
bounds = (-max(self.arg.bounds), -min(self.arg.bounds))
|
99
93
|
return RegisterArithmeticInfo(
|
100
|
-
size=self.
|
94
|
+
size=self.output_size or self._expected_result_size(),
|
101
95
|
fraction_places=self.arg.fraction_places,
|
102
96
|
is_signed=is_signed,
|
103
97
|
bounds=bounds if (is_signed or min(bounds) >= 0) else None,
|
@@ -112,10 +106,7 @@ class Sign(UnaryOpParams):
|
|
112
106
|
cls, output_size: Optional[pydantic.PositiveInt]
|
113
107
|
) -> pydantic.PositiveInt:
|
114
108
|
if output_size is not None and output_size != 1:
|
115
|
-
raise
|
116
|
-
return 1
|
117
|
-
|
118
|
-
def _expected_result_size(self) -> pydantic.PositiveInt:
|
109
|
+
raise ClassiqValueError("Sign output size must be 1")
|
119
110
|
return 1
|
120
111
|
|
121
112
|
def _get_result_register(self) -> RegisterArithmeticInfo:
|
@@ -4,15 +4,10 @@ from classiq.interface.generator.functions.classical_function_declaration import
|
|
4
4
|
ClassicalFunctionDeclaration,
|
5
5
|
)
|
6
6
|
from classiq.interface.generator.types.struct_declaration import StructDeclaration
|
7
|
-
from classiq.interface.model.quantum_function_declaration import (
|
8
|
-
QuantumFunctionDeclaration,
|
9
|
-
)
|
10
7
|
|
11
8
|
|
12
9
|
def populate_builtin_declarations(decls: Iterable[Any]) -> None:
|
13
10
|
for decl in decls:
|
14
|
-
if isinstance(decl, QuantumFunctionDeclaration):
|
15
|
-
QuantumFunctionDeclaration.BUILTIN_FUNCTION_DECLARATIONS[decl.name] = decl
|
16
11
|
if isinstance(decl, ClassicalFunctionDeclaration):
|
17
12
|
ClassicalFunctionDeclaration.FOREIGN_FUNCTION_DECLARATIONS[decl.name] = decl
|
18
13
|
if isinstance(decl, StructDeclaration):
|
@@ -11,18 +11,18 @@ from classiq.interface.generator.function_params import (
|
|
11
11
|
FunctionParams,
|
12
12
|
)
|
13
13
|
|
14
|
+
from classiq.exceptions import ClassiqValueError
|
15
|
+
|
14
16
|
|
15
17
|
class ChemistryFunctionParams(FunctionParams):
|
16
|
-
gs_problem: CHEMISTRY_PROBLEMS_TYPE
|
17
|
-
description="Ground state problem object describing the system."
|
18
|
-
)
|
18
|
+
gs_problem: CHEMISTRY_PROBLEMS_TYPE
|
19
19
|
|
20
20
|
@pydantic.validator("gs_problem")
|
21
21
|
def validate_gs_problem_contains_num_qubits(
|
22
22
|
cls, gs_problem: CHEMISTRY_PROBLEMS_TYPE
|
23
23
|
) -> CHEMISTRY_PROBLEMS_TYPE:
|
24
24
|
if not gs_problem.num_qubits:
|
25
|
-
raise
|
25
|
+
raise ClassiqValueError(
|
26
26
|
"Ground state problem doesn't contain num_qubits. "
|
27
27
|
"Use update_problem method."
|
28
28
|
)
|
@@ -10,6 +10,8 @@ from classiq.interface.generator.function_params import (
|
|
10
10
|
)
|
11
11
|
from classiq.interface.generator.parameters import ParameterFloatType
|
12
12
|
|
13
|
+
from classiq.exceptions import ClassiqValueError
|
14
|
+
|
13
15
|
|
14
16
|
class CommutingPauliExponentiation(FunctionParams):
|
15
17
|
"""
|
@@ -32,7 +34,7 @@ class CommutingPauliExponentiation(FunctionParams):
|
|
32
34
|
@pydantic.validator("pauli_operator")
|
33
35
|
def _validate_paulis_commute(cls, pauli_operator: PauliOperator) -> PauliOperator:
|
34
36
|
if not pauli_operator.is_commutative:
|
35
|
-
raise
|
37
|
+
raise ClassiqValueError("Pauli strings are not commutative")
|
36
38
|
return pauli_operator
|
37
39
|
|
38
40
|
def _create_ios(self) -> None:
|
@@ -1,17 +1,16 @@
|
|
1
|
-
from typing import Any
|
1
|
+
from typing import Any, Callable, Dict, Iterator
|
2
2
|
|
3
|
-
import pydantic.json
|
4
3
|
from typing_extensions import Self
|
5
4
|
|
6
5
|
|
7
6
|
# Use this class as a type for complex data from the json, e.g., in the state_propagator function.
|
8
7
|
class Complex(complex):
|
9
8
|
@classmethod
|
10
|
-
def __get_validators__(cls):
|
9
|
+
def __get_validators__(cls) -> Iterator[Callable]:
|
11
10
|
yield cls.validate
|
12
11
|
|
13
12
|
@classmethod
|
14
|
-
def __modify_schema__(cls, field_schema):
|
13
|
+
def __modify_schema__(cls, field_schema: Dict[str, Any]) -> None:
|
15
14
|
field_schema.update(
|
16
15
|
pattern=r"[+-]?\d+\.?\d* *[+-] *\d+\.?\d*j",
|
17
16
|
)
|
@@ -22,9 +21,3 @@ class Complex(complex):
|
|
22
21
|
v = "".join(v.split())
|
23
22
|
|
24
23
|
return cls(v)
|
25
|
-
|
26
|
-
|
27
|
-
assert (
|
28
|
-
complex not in pydantic.json.ENCODERS_BY_TYPE
|
29
|
-
), "Is complex type supported on newer version of pydantic?"
|
30
|
-
pydantic.json.ENCODERS_BY_TYPE[complex] = str
|
@@ -1,10 +1,9 @@
|
|
1
|
-
import
|
2
|
-
|
1
|
+
from classiq.interface.ast_node import ASTNode
|
3
2
|
from classiq.interface.generator.expressions.expression import Expression
|
4
3
|
from classiq.interface.generator.functions.classical_type import ConcreteClassicalType
|
5
4
|
|
6
5
|
|
7
|
-
class Constant(
|
6
|
+
class Constant(ASTNode):
|
8
7
|
name: str
|
9
8
|
const_type: ConcreteClassicalType
|
10
9
|
value: Expression
|
@@ -7,6 +7,8 @@ from pydantic import BaseModel
|
|
7
7
|
|
8
8
|
from classiq.interface.generator.arith.register_user_input import RegisterUserInput
|
9
9
|
|
10
|
+
from classiq.exceptions import ClassiqValueError
|
11
|
+
|
10
12
|
_DEFAULT_CONTROL_NAME: str = "ctrl"
|
11
13
|
_DEFAULT_NUM_CONTROL_QUBITS = 1
|
12
14
|
_INVALID_CONTROL_STATE = "invalid_control_state"
|
@@ -39,7 +41,7 @@ class ControlState(BaseModel):
|
|
39
41
|
values["num_ctrl_qubits"] = num_ctrl_qubits
|
40
42
|
|
41
43
|
if len(ctrl_state) != num_ctrl_qubits:
|
42
|
-
raise
|
44
|
+
raise ClassiqValueError(
|
43
45
|
"Control state length should be equal to the number of control qubits"
|
44
46
|
)
|
45
47
|
|
@@ -51,11 +53,11 @@ class ControlState(BaseModel):
|
|
51
53
|
@staticmethod
|
52
54
|
def validate_control_string(ctrl_state: str) -> None:
|
53
55
|
if not set(ctrl_state) <= {"1", "0"}:
|
54
|
-
raise
|
56
|
+
raise ClassiqValueError(
|
55
57
|
f"Control state can only be constructed from 0 and 1, received: {ctrl_state}"
|
56
58
|
)
|
57
59
|
if not ctrl_state:
|
58
|
-
raise
|
60
|
+
raise ClassiqValueError("Control state cannot be empty")
|
59
61
|
|
60
62
|
def __str__(self) -> str:
|
61
63
|
return self.ctrl_state
|
@@ -1,5 +1,5 @@
|
|
1
1
|
from statistics import NormalDist
|
2
|
-
from typing import List, Tuple
|
2
|
+
from typing import Any, Dict, List, Tuple
|
3
3
|
|
4
4
|
import numpy as np
|
5
5
|
import pydantic
|
@@ -11,6 +11,8 @@ from classiq.interface.helpers.custom_pydantic_types import (
|
|
11
11
|
PydanticProbabilityFloat,
|
12
12
|
)
|
13
13
|
|
14
|
+
from classiq.exceptions import ClassiqValueError
|
15
|
+
|
14
16
|
RHOS_PZEROS_LENGTH_ERROR_MSG = "rhos and p_zeros must have the same length"
|
15
17
|
|
16
18
|
|
@@ -42,10 +44,15 @@ class LinearGCI(function_params.FunctionParams):
|
|
42
44
|
)
|
43
45
|
|
44
46
|
@pydantic.validator("rhos")
|
45
|
-
def validate_rhos(
|
47
|
+
def validate_rhos(
|
48
|
+
cls, rhos: List[PydanticNonOneProbabilityFloat], values: Dict[str, Any]
|
49
|
+
) -> List[PydanticNonOneProbabilityFloat]:
|
46
50
|
p_zeros = values.get("p_zeros")
|
51
|
+
if p_zeros is None:
|
52
|
+
raise ClassiqValueError("Cannot validate rhos, p_zeros is missing")
|
53
|
+
|
47
54
|
if len(p_zeros) != len(rhos):
|
48
|
-
raise
|
55
|
+
raise ClassiqValueError(RHOS_PZEROS_LENGTH_ERROR_MSG)
|
49
56
|
return rhos
|
50
57
|
|
51
58
|
@property
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import List
|
1
|
+
from typing import Any, Dict, List, Optional
|
2
2
|
|
3
3
|
import numpy as np
|
4
4
|
import pydantic
|
@@ -7,6 +7,8 @@ from classiq.interface.generator import function_params
|
|
7
7
|
from classiq.interface.generator.arith.register_user_input import RegisterUserInput
|
8
8
|
from classiq.interface.generator.function_params import get_zero_input_name
|
9
9
|
|
10
|
+
from classiq.exceptions import ClassiqValueError
|
11
|
+
|
10
12
|
LENGTH_ERROR_MESSAGE = "Input length error: Length of weights vector has to be identical to the number of input qubits"
|
11
13
|
STATE = "state"
|
12
14
|
SUM = "sum"
|
@@ -33,12 +35,20 @@ class WeightedAdder(function_params.FunctionParams):
|
|
33
35
|
)
|
34
36
|
|
35
37
|
@pydantic.validator("weights", always=True, pre=True)
|
36
|
-
def validate_weights(
|
38
|
+
def validate_weights(
|
39
|
+
cls,
|
40
|
+
weights: Optional[List[PydanticStrictNonNegativeInteger]],
|
41
|
+
values: Dict[str, Any],
|
42
|
+
) -> List[PydanticStrictNonNegativeInteger]:
|
37
43
|
num_state_qubits = values.get("num_state_qubits")
|
44
|
+
if num_state_qubits is None:
|
45
|
+
raise ClassiqValueError(
|
46
|
+
"Missing num_state_qubits and weights, either must be provided"
|
47
|
+
)
|
38
48
|
if weights is None:
|
39
|
-
return [1] * num_state_qubits
|
49
|
+
return [PydanticStrictNonNegativeInteger(1)] * num_state_qubits
|
40
50
|
if len(weights) != num_state_qubits:
|
41
|
-
raise
|
51
|
+
raise ClassiqValueError(LENGTH_ERROR_MESSAGE)
|
42
52
|
return weights
|
43
53
|
|
44
54
|
def num_sum_qubits(self) -> int:
|
@@ -3,9 +3,7 @@ SUPPORTED_BUILTIN_FUNCTIONS = {"len", "sum", "print"}
|
|
3
3
|
SUPPORTED_ATOMIC_EXPRESSION_FUNCTIONS = {
|
4
4
|
"hypercube_entangler_graph",
|
5
5
|
"grid_entangler_graph",
|
6
|
-
"
|
7
|
-
"compute_qaoa_initial_point",
|
8
|
-
"get_optimization_solution",
|
6
|
+
"qft_const_adder_phase",
|
9
7
|
"log_normal_finance_post_process",
|
10
8
|
"gaussian_finance_post_process",
|
11
9
|
"get_type",
|
@@ -16,5 +14,9 @@ SUPPORTED_ATOMIC_EXPRESSION_FUNCTIONS = {
|
|
16
14
|
"molecule_problem_to_hamiltonian",
|
17
15
|
"fock_hamiltonian_problem_to_hamiltonian",
|
18
16
|
"molecule_ground_state_solution_post_process",
|
17
|
+
"BitwiseAnd",
|
18
|
+
"BitwiseXor",
|
19
|
+
"BitwiseNot",
|
20
|
+
"BitwiseOr",
|
19
21
|
*SUPPORTED_BUILTIN_FUNCTIONS,
|
20
22
|
}
|
@@ -1,8 +1,11 @@
|
|
1
|
+
import re
|
1
2
|
from dataclasses import dataclass
|
2
|
-
from typing import Any, Mapping, Type
|
3
|
+
from typing import Any, Mapping, Optional, Type
|
3
4
|
|
5
|
+
from sympy import Expr
|
4
6
|
from typing_extensions import get_args
|
5
7
|
|
8
|
+
from classiq.interface.backend.pydantic_backend import EXECUTION_PARAMETER_PATTERN
|
6
9
|
from classiq.interface.generator.expressions.expression_types import (
|
7
10
|
ExpressionValue,
|
8
11
|
QmodStructInstance,
|
@@ -17,15 +20,20 @@ from classiq.exceptions import ClassiqValueError
|
|
17
20
|
class EvaluatedExpression:
|
18
21
|
value: ExpressionValue
|
19
22
|
|
20
|
-
def is_constant(self) -> bool:
|
23
|
+
def is_constant(self, constant_type: Optional[Type] = None) -> bool:
|
21
24
|
if self.value is None:
|
22
25
|
return False
|
23
26
|
|
24
|
-
return isinstance(
|
27
|
+
return isinstance(
|
28
|
+
self.value,
|
29
|
+
get_args(RuntimeConstant) if constant_type is None else constant_type,
|
30
|
+
)
|
25
31
|
|
26
32
|
def as_constant_type(self, constant_type: Type) -> Any:
|
27
33
|
if not self.is_constant():
|
28
|
-
raise ClassiqValueError(
|
34
|
+
raise ClassiqValueError(
|
35
|
+
f"Invalid access to expression {self.value!r} as {constant_type}"
|
36
|
+
)
|
29
37
|
|
30
38
|
return constant_type(self.value)
|
31
39
|
|
@@ -62,3 +70,9 @@ class EvaluatedExpression:
|
|
62
70
|
raise ClassiqValueError("Invalid access to unevaluated expression")
|
63
71
|
|
64
72
|
return str(self.value)
|
73
|
+
|
74
|
+
def is_identifier(self) -> bool:
|
75
|
+
return (
|
76
|
+
isinstance(self.value, Expr)
|
77
|
+
and re.fullmatch(EXECUTION_PARAMETER_PATTERN, str(self.value)) is not None
|
78
|
+
)
|
@@ -4,6 +4,7 @@ from typing import Any, Mapping, Optional, Type
|
|
4
4
|
import pydantic
|
5
5
|
from pydantic import PrivateAttr
|
6
6
|
|
7
|
+
from classiq.interface.ast_node import HashableASTNode
|
7
8
|
from classiq.interface.generator.arith.arithmetic_expression_validator import (
|
8
9
|
DEFAULT_SUPPORTED_FUNC_NAMES,
|
9
10
|
)
|
@@ -17,14 +18,11 @@ from classiq.interface.generator.expressions.sympy_supported_expressions import
|
|
17
18
|
SYMPY_SUPPORTED_EXPRESSIONS,
|
18
19
|
)
|
19
20
|
from classiq.interface.generator.function_params import validate_expression_str
|
20
|
-
from classiq.interface.helpers.hashable_pydantic_base_model import (
|
21
|
-
HashablePydanticBaseModel,
|
22
|
-
)
|
23
21
|
|
24
22
|
from classiq.exceptions import ClassiqError
|
25
23
|
|
26
24
|
|
27
|
-
class Expression(
|
25
|
+
class Expression(HashableASTNode):
|
28
26
|
expr: str
|
29
27
|
_evaluated_expr: Optional[EvaluatedExpression] = PrivateAttr(default=None)
|
30
28
|
|
@@ -69,7 +67,7 @@ class Expression(HashablePydanticBaseModel):
|
|
69
67
|
result = ast.literal_eval(self.expr)
|
70
68
|
if isinstance(result, (int, float, bool)):
|
71
69
|
self._evaluated_expr = EvaluatedExpression(value=result)
|
72
|
-
except Exception: #
|
70
|
+
except Exception: # noqa: S110
|
73
71
|
pass
|
74
72
|
|
75
73
|
@property
|
@@ -0,0 +1,33 @@
|
|
1
|
+
from sympy import Symbol
|
2
|
+
|
3
|
+
from classiq.interface.generator.expressions.qmod_sized_proxy import QmodSizedProxy
|
4
|
+
|
5
|
+
|
6
|
+
class QmodQScalarProxy(Symbol, QmodSizedProxy):
|
7
|
+
def __new__(cls, name: str, **assumptions: bool) -> "QmodQScalarProxy":
|
8
|
+
return super().__new__(cls, name, **assumptions)
|
9
|
+
|
10
|
+
def __init__(self, name: str, size: int) -> None:
|
11
|
+
super().__init__(size)
|
12
|
+
|
13
|
+
|
14
|
+
class QmodQBitProxy(QmodQScalarProxy):
|
15
|
+
pass
|
16
|
+
|
17
|
+
|
18
|
+
class QmodQNumProxy(QmodQScalarProxy):
|
19
|
+
|
20
|
+
def __init__(
|
21
|
+
self, name: str, size: int, fraction_digits: int, is_signed: bool
|
22
|
+
) -> None:
|
23
|
+
super().__init__(name, size)
|
24
|
+
self._fraction_digits = fraction_digits
|
25
|
+
self._is_signed = is_signed
|
26
|
+
|
27
|
+
@property
|
28
|
+
def fraction_digits(self) -> int:
|
29
|
+
return self._fraction_digits
|
30
|
+
|
31
|
+
@property
|
32
|
+
def is_signed(self) -> bool:
|
33
|
+
return self._is_signed
|
@@ -34,6 +34,7 @@ MATHEMATICAL_FUNCTIONS: List[str] = [
|
|
34
34
|
"ceiling",
|
35
35
|
"Max",
|
36
36
|
"Min",
|
37
|
+
"mod_inverse",
|
37
38
|
]
|
38
39
|
SPECIAL_FUNCTIONS: List[str] = [
|
39
40
|
"erf",
|
@@ -69,7 +70,7 @@ LOGIC_OPERATORS: List[str] = [
|
|
69
70
|
"Nand",
|
70
71
|
"Nor",
|
71
72
|
]
|
72
|
-
RELATIONAL_OPERATORS: List[str] = ["<", "<=", ">", ">=", "!=", "<>", "Eq"]
|
73
|
+
RELATIONAL_OPERATORS: List[str] = ["<", "<=", ">", ">=", "!=", "<>", "Eq", "Ne"]
|
73
74
|
|
74
75
|
SYMPY_SUPPORTED_EXPRESSIONS: List[str] = (
|
75
76
|
BASIC_ARITHMETIC_OPERATORS
|
@@ -20,7 +20,7 @@ DEFAULT_POST_INPUT_NAME = "post_function_input"
|
|
20
20
|
|
21
21
|
class Finance(function_params.FunctionParams):
|
22
22
|
model: Union[GaussianModelInput, LogNormalModelInput] = pydantic.Field(
|
23
|
-
description="Load a financial model"
|
23
|
+
description="Load a financial model", discriminator="kind"
|
24
24
|
)
|
25
25
|
finance_function: FinanceFunctionInput = pydantic.Field(
|
26
26
|
description="The finance function to solve the model"
|
@@ -30,6 +30,7 @@ from classiq.interface.helpers.hashable_pydantic_base_model import (
|
|
30
30
|
)
|
31
31
|
|
32
32
|
from classiq._internals.enum_utils import StrEnum
|
33
|
+
from classiq.exceptions import ClassiqValueError
|
33
34
|
|
34
35
|
FunctionParamsDiscriminator = str
|
35
36
|
|
@@ -84,7 +85,6 @@ ExecutionExpressionSupportedNodeTypes = Union[
|
|
84
85
|
]
|
85
86
|
|
86
87
|
GenerationOnlyExpressionSupportedNodeTypes = Union[
|
87
|
-
ast.FloorDiv,
|
88
88
|
ast.Pow,
|
89
89
|
ast.List,
|
90
90
|
ast.Subscript,
|
@@ -96,6 +96,7 @@ GenerationOnlyExpressionSupportedNodeTypes = Union[
|
|
96
96
|
ast.Lt,
|
97
97
|
ast.LtE,
|
98
98
|
ast.Eq,
|
99
|
+
ast.NotEq,
|
99
100
|
ast.Call,
|
100
101
|
ast.Dict,
|
101
102
|
ast.Slice,
|
@@ -243,7 +244,7 @@ class FunctionParams(HashablePydanticBaseModel):
|
|
243
244
|
error_msg += self._get_error_msg(self._outputs, BAD_OUTPUT_REGISTER_ERROR_MSG)
|
244
245
|
if error_msg:
|
245
246
|
error_msg += [END_BAD_REGISTER_ERROR_MSG]
|
246
|
-
raise
|
247
|
+
raise ClassiqValueError("\n".join(error_msg))
|
247
248
|
|
248
249
|
@staticmethod
|
249
250
|
def _sum_registers_sizes(registers: Iterable[RegisterArithmeticInfo]) -> int:
|
@@ -255,7 +256,7 @@ class FunctionParams(HashablePydanticBaseModel):
|
|
255
256
|
)
|
256
257
|
total_outputs_size = self._sum_registers_sizes(self._outputs.values())
|
257
258
|
if total_inputs_size != total_outputs_size:
|
258
|
-
raise
|
259
|
+
raise ClassiqValueError(REGISTER_SIZES_MISMATCH_ERROR_MSG)
|
259
260
|
|
260
261
|
def _get_error_msg(self, names: Iterable[IOName], msg: str) -> List[str]:
|
261
262
|
bad_names = [name for name in names if re.fullmatch(NAME_REGEX, name) is None]
|
@@ -312,7 +313,7 @@ def parse_function_params(
|
|
312
313
|
try:
|
313
314
|
return default_parser_class.parse_obj(params)
|
314
315
|
except Exception:
|
315
|
-
raise bad_function_error
|
316
|
+
raise bad_function_error from None
|
316
317
|
raise bad_function_error
|
317
318
|
|
318
319
|
return matching_classes[0].parse_obj(params)
|
@@ -335,10 +336,10 @@ def parse_function_params_values(
|
|
335
336
|
params=params,
|
336
337
|
discriminator=discriminator,
|
337
338
|
param_classes=param_classes,
|
338
|
-
no_discriminator_error=
|
339
|
+
no_discriminator_error=ClassiqValueError(
|
339
340
|
f"The {discriminator_key} {NO_DISCRIMINATOR_ERROR_MSG} {params_key} type."
|
340
341
|
),
|
341
|
-
bad_function_error=
|
342
|
+
bad_function_error=ClassiqValueError(
|
342
343
|
f"{BAD_FUNCTION_ERROR_MSG} {discriminator_key}: {discriminator}"
|
343
344
|
),
|
344
345
|
default_parser_class=default_parser_class,
|
@@ -1,7 +1,7 @@
|
|
1
1
|
from typing import List
|
2
2
|
|
3
|
-
import classiq.interface.generator.functions.
|
4
|
-
import classiq.interface.generator.functions.
|
3
|
+
import classiq.interface.generator.functions.builtins.core_library
|
4
|
+
import classiq.interface.generator.functions.builtins.quantum_operators
|
5
5
|
from classiq.interface.generator.functions.foreign_function_definition import *
|
6
6
|
from classiq.interface.generator.functions.foreign_function_definition import (
|
7
7
|
SynthesisForeignFunctionDefinition as ForeignFunctionDefinition,
|
@@ -0,0 +1,15 @@
|
|
1
|
+
from classiq.interface.generator.functions.builtins.core_library import CORE_LIB_DECLS
|
2
|
+
from classiq.interface.generator.functions.builtins.open_lib_functions import (
|
3
|
+
OPEN_LIB_DECLS,
|
4
|
+
)
|
5
|
+
from classiq.interface.generator.functions.builtins.quantum_operators import (
|
6
|
+
STD_QMOD_OPERATORS,
|
7
|
+
)
|
8
|
+
from classiq.interface.helpers.pydantic_model_helpers import nameables_to_dict
|
9
|
+
from classiq.interface.model.quantum_function_declaration import (
|
10
|
+
QuantumFunctionDeclaration,
|
11
|
+
)
|
12
|
+
|
13
|
+
QuantumFunctionDeclaration.BUILTIN_FUNCTION_DECLARATIONS.update(
|
14
|
+
nameables_to_dict(STD_QMOD_OPERATORS + CORE_LIB_DECLS + OPEN_LIB_DECLS)
|
15
|
+
)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
from classiq.interface.generator.application_apis.chemistry_declarations import * # noqa: F403
|
2
|
+
from classiq.interface.generator.application_apis.combinatorial_optimization_declarations import * # noqa: F403
|
3
|
+
from classiq.interface.generator.application_apis.finance_declarations import * # noqa: F403
|
4
|
+
from classiq.interface.generator.application_apis.qsvm_declarations import * # noqa: F403
|
5
|
+
from classiq.interface.model.quantum_function_declaration import (
|
6
|
+
QuantumFunctionDeclaration,
|
7
|
+
)
|
8
|
+
|
9
|
+
from .atomic_quantum_functions import * # noqa: F403
|
10
|
+
from .exponentiation_functions import * # noqa: F403
|
11
|
+
|
12
|
+
CORE_LIB_DECLS = [
|
13
|
+
func for func in vars().values() if isinstance(func, QuantumFunctionDeclaration)
|
14
|
+
]
|
File without changes
|
@@ -0,0 +1,62 @@
|
|
1
|
+
from classiq.interface.generator.functions.builtins.quantum_operators import (
|
2
|
+
get_single_empty_operand_operator,
|
3
|
+
)
|
4
|
+
from classiq.interface.generator.functions.classical_type import Bool, Integer
|
5
|
+
from classiq.interface.generator.functions.port_declaration import (
|
6
|
+
PortDeclarationDirection,
|
7
|
+
)
|
8
|
+
from classiq.interface.helpers.pydantic_model_helpers import nameables_to_dict
|
9
|
+
from classiq.interface.model.port_declaration import PortDeclaration
|
10
|
+
from classiq.interface.model.quantum_function_declaration import (
|
11
|
+
QuantumFunctionDeclaration,
|
12
|
+
QuantumOperandDeclaration,
|
13
|
+
)
|
14
|
+
|
15
|
+
_CTRL_FIELD_NAME = "ctrl"
|
16
|
+
CONTROL_OPERATOR = get_single_empty_operand_operator(
|
17
|
+
operator_name="control",
|
18
|
+
port_declarations={
|
19
|
+
_CTRL_FIELD_NAME: PortDeclaration(
|
20
|
+
name=_CTRL_FIELD_NAME,
|
21
|
+
direction=PortDeclarationDirection.Inout,
|
22
|
+
)
|
23
|
+
},
|
24
|
+
)
|
25
|
+
|
26
|
+
REPEAT_OPERATOR = QuantumFunctionDeclaration(
|
27
|
+
name="repeat",
|
28
|
+
param_decls={"count": Integer()},
|
29
|
+
operand_declarations={
|
30
|
+
"iteration": QuantumOperandDeclaration(
|
31
|
+
name="iteration", param_decls={"index": Integer()}
|
32
|
+
)
|
33
|
+
},
|
34
|
+
)
|
35
|
+
POWER_OPERATOR = get_single_empty_operand_operator(
|
36
|
+
operator_name="power", param_decls={"power": Integer()}
|
37
|
+
)
|
38
|
+
INVERT_OPERATOR = get_single_empty_operand_operator(operator_name="invert")
|
39
|
+
|
40
|
+
IF_OPERATOR = QuantumFunctionDeclaration(
|
41
|
+
name="if",
|
42
|
+
param_decls={"condition": Bool()},
|
43
|
+
operand_declarations={
|
44
|
+
"then": QuantumOperandDeclaration(name="then"),
|
45
|
+
"else": QuantumOperandDeclaration(name="else"),
|
46
|
+
},
|
47
|
+
)
|
48
|
+
COMPUTE = get_single_empty_operand_operator(operator_name="compute")
|
49
|
+
UNCOMPUTE = get_single_empty_operand_operator(operator_name="uncompute")
|
50
|
+
|
51
|
+
|
52
|
+
INTERNAL_OPERATORS = nameables_to_dict(
|
53
|
+
[
|
54
|
+
CONTROL_OPERATOR,
|
55
|
+
REPEAT_OPERATOR,
|
56
|
+
POWER_OPERATOR,
|
57
|
+
INVERT_OPERATOR,
|
58
|
+
IF_OPERATOR,
|
59
|
+
COMPUTE,
|
60
|
+
UNCOMPUTE,
|
61
|
+
]
|
62
|
+
)
|