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,5 +1,5 @@
|
|
1
1
|
from datetime import timedelta
|
2
|
-
from typing import Any, Dict,
|
2
|
+
from typing import Any, Dict, Optional, TypeVar
|
3
3
|
|
4
4
|
import pydantic
|
5
5
|
|
@@ -23,6 +23,7 @@ from classiq.interface.generator.model.preferences.randomness import create_rand
|
|
23
23
|
from classiq.interface.generator.noise_properties import NoiseProperties
|
24
24
|
|
25
25
|
from classiq._internals.enum_utils import ReprEnum
|
26
|
+
from classiq.exceptions import ClassiqValueError
|
26
27
|
|
27
28
|
DIFFERENT_TIMEOUT_MSG = (
|
28
29
|
"Timeout is defined differently in the execution preferences and the "
|
@@ -40,41 +41,12 @@ class QaeWithQpeEstimationMethod(int, ReprEnum):
|
|
40
41
|
BEST_FIT = 1
|
41
42
|
|
42
43
|
|
43
|
-
class AmplitudeAmplification(pydantic.BaseModel):
|
44
|
-
iterations: List[int] = pydantic.Field(
|
45
|
-
default_factory=list,
|
46
|
-
description="Number or list of numbers of iteration to use",
|
47
|
-
)
|
48
|
-
growth_rate: float = pydantic.Field(
|
49
|
-
default=1.25,
|
50
|
-
description="Number of iteration used is set to round(growth_rate**iterations)",
|
51
|
-
)
|
52
|
-
sample_from_iterations: bool = pydantic.Field(
|
53
|
-
default=False,
|
54
|
-
description="If True, number of iterations used is picked randomly from "
|
55
|
-
"[1, iteration] range",
|
56
|
-
)
|
57
|
-
num_of_highest_probability_states_to_check: pydantic.PositiveInt = pydantic.Field(
|
58
|
-
default=1, description="Then number of highest probability states to check"
|
59
|
-
)
|
60
|
-
|
61
|
-
@pydantic.validator("iterations")
|
62
|
-
def _validate_iterations(cls, iterations: Union[List[int], int]) -> List[int]:
|
63
|
-
if isinstance(iterations, int):
|
64
|
-
return [iterations]
|
65
|
-
return iterations
|
66
|
-
|
67
|
-
|
68
44
|
class ExecutionPreferences(pydantic.BaseModel):
|
69
45
|
timeout_sec: Optional[pydantic.PositiveInt] = pydantic.Field(
|
70
46
|
default=None,
|
71
47
|
description="If set, limits the execution runtime. Value is in seconds. "
|
72
48
|
"Not supported on all platforms.",
|
73
49
|
)
|
74
|
-
amplitude_amplification: AmplitudeAmplification = pydantic.Field(
|
75
|
-
default_factory=AmplitudeAmplification,
|
76
|
-
description="Settings related to amplitude amplification execution, used during the grover execution.",
|
77
|
-
)
|
78
50
|
optimizer_preferences: Optional[OptimizerPreferences] = pydantic.Field(
|
79
51
|
default_factory=None,
|
80
52
|
description="Settings related to VQE execution.",
|
@@ -130,9 +102,9 @@ class ExecutionPreferences(pydantic.BaseModel):
|
|
130
102
|
timeout != backend_preferences.job_timeout
|
131
103
|
and backend_preferences.job_timeout != AWS_DEFAULT_JOB_TIMEOUT_SECONDS
|
132
104
|
):
|
133
|
-
raise
|
105
|
+
raise ClassiqValueError(DIFFERENT_TIMEOUT_MSG)
|
134
106
|
if timeout > MAX_EXECUTION_TIMEOUT_SECONDS:
|
135
|
-
raise
|
107
|
+
raise ClassiqValueError(TIMEOUT_LARGE_FOR_AWS_MSG)
|
136
108
|
|
137
109
|
backend_preferences.job_timeout = timeout
|
138
110
|
return backend_preferences
|
@@ -169,7 +141,7 @@ def _choose_original_or_optimizer_attribute(
|
|
169
141
|
return optimizer_attribute
|
170
142
|
|
171
143
|
elif original_attribute != optimizer_attribute:
|
172
|
-
raise
|
144
|
+
raise ClassiqValueError(
|
173
145
|
f"Different {attribure_name} were given for ExecutionPreferences and OptimizerPreferences."
|
174
146
|
)
|
175
147
|
|
@@ -179,7 +151,6 @@ def _choose_original_or_optimizer_attribute(
|
|
179
151
|
|
180
152
|
__all__ = [
|
181
153
|
"ExecutionPreferences",
|
182
|
-
"AmplitudeAmplification",
|
183
154
|
"ErrorMitigationMethod",
|
184
155
|
"NoiseProperties",
|
185
156
|
"OptimizerPreferences",
|
@@ -1,80 +1,47 @@
|
|
1
1
|
from datetime import datetime
|
2
|
-
from typing import
|
2
|
+
from typing import List, Literal, Optional, Union
|
3
3
|
|
4
4
|
import pydantic
|
5
|
-
from pydantic import BaseModel
|
5
|
+
from pydantic import BaseModel, Field
|
6
|
+
from typing_extensions import Annotated
|
6
7
|
|
7
|
-
from classiq.interface.backend.backend_preferences import IonqBackendPreferences
|
8
8
|
from classiq.interface.executor.estimation import OperatorsEstimation
|
9
9
|
from classiq.interface.executor.execution_preferences import ExecutionPreferences
|
10
|
-
from classiq.interface.executor.
|
11
|
-
|
12
|
-
|
13
|
-
)
|
14
|
-
from classiq.interface.generator.generated_circuit import GeneratedCircuit
|
10
|
+
from classiq.interface.executor.quantum_code import QuantumCode
|
11
|
+
from classiq.interface.generator.quantum_program import QuantumProgram
|
12
|
+
from classiq.interface.helpers.custom_encoders import CUSTOM_ENCODERS
|
15
13
|
from classiq.interface.helpers.versioned_model import VersionedModel
|
16
14
|
from classiq.interface.jobs import JobStatus
|
17
15
|
|
18
16
|
|
19
|
-
class
|
20
|
-
execution_type: Literal["
|
17
|
+
class QuantumProgramExecution(QuantumProgram):
|
18
|
+
execution_type: Literal["quantum_program2"] = "quantum_program2"
|
21
19
|
|
22
20
|
|
23
|
-
class
|
24
|
-
execution_type: Literal["
|
21
|
+
class QuantumCodeExecution(QuantumCode):
|
22
|
+
execution_type: Literal["quantum_code"] = "quantum_code"
|
25
23
|
|
26
24
|
|
27
25
|
class EstimateOperatorsExecution(OperatorsEstimation):
|
28
26
|
execution_type: Literal["estimate_operators"] = "estimate_operators"
|
29
27
|
|
30
28
|
|
31
|
-
ExecutionPayloads =
|
32
|
-
|
29
|
+
ExecutionPayloads = Annotated[
|
30
|
+
Union[QuantumProgramExecution, QuantumCodeExecution, EstimateOperatorsExecution],
|
31
|
+
Field(discriminator="execution_type"),
|
33
32
|
]
|
34
33
|
|
35
34
|
|
36
|
-
class ExecutionRequest(BaseModel):
|
35
|
+
class ExecutionRequest(BaseModel, json_encoders=CUSTOM_ENCODERS):
|
37
36
|
execution_payload: ExecutionPayloads
|
38
37
|
preferences: ExecutionPreferences = pydantic.Field(
|
39
38
|
default_factory=ExecutionPreferences,
|
40
39
|
description="preferences for the execution",
|
41
40
|
)
|
42
41
|
|
43
|
-
@pydantic.validator("preferences")
|
44
|
-
def validate_ionq_backend(
|
45
|
-
cls, preferences: ExecutionPreferences, values: Dict[str, Any]
|
46
|
-
) -> ExecutionPreferences:
|
47
|
-
"""
|
48
|
-
This function implement the following check:
|
49
|
-
BE \\ payload | IonQ program | Qasm program | Other
|
50
|
-
--------------|--------------|--------------|------
|
51
|
-
IonQ backend | V | V | X
|
52
|
-
Other backend | X | V | V
|
53
|
-
Since:
|
54
|
-
- We can't execute non-programs on the IonQ backends
|
55
|
-
- We can't execute IonQ programs on non-IonQ backends
|
56
|
-
"""
|
57
|
-
quantum_program = values.get("execution_payload")
|
58
|
-
is_ionq_backend = isinstance(
|
59
|
-
preferences.backend_preferences, IonqBackendPreferences
|
60
|
-
)
|
61
|
-
if isinstance(quantum_program, QuantumProgram):
|
62
|
-
if (
|
63
|
-
quantum_program.syntax == QuantumInstructionSet.IONQ
|
64
|
-
and not is_ionq_backend
|
65
|
-
):
|
66
|
-
raise ValueError("Can only execute IonQ code on IonQ backend.")
|
67
|
-
else:
|
68
|
-
# If we handle anything other than a program.
|
69
|
-
if is_ionq_backend:
|
70
|
-
raise ValueError(
|
71
|
-
"IonQ backend supports only execution of QuantumPrograms"
|
72
|
-
)
|
73
|
-
return preferences
|
74
|
-
|
75
42
|
|
76
43
|
class QuantumProgramExecutionRequest(ExecutionRequest):
|
77
|
-
execution_payload:
|
44
|
+
execution_payload: QuantumCodeExecution
|
78
45
|
|
79
46
|
|
80
47
|
class ExecutionJobDetails(VersionedModel):
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import List, Optional
|
1
|
+
from typing import Any, Dict, List, Optional
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
from pydantic import BaseModel
|
@@ -6,6 +6,7 @@ from pydantic import BaseModel
|
|
6
6
|
from classiq.interface.helpers.custom_pydantic_types import PydanticAlphaParamCVAR
|
7
7
|
|
8
8
|
from classiq._internals.enum_utils import StrEnum
|
9
|
+
from classiq.exceptions import ClassiqValueError
|
9
10
|
|
10
11
|
|
11
12
|
class CostType(StrEnum):
|
@@ -33,10 +34,10 @@ class OptimizerPreferences(BaseModel):
|
|
33
34
|
max_iteration: pydantic.PositiveInt = pydantic.Field(
|
34
35
|
default=100, description="Maximal number of optimizer iterations"
|
35
36
|
)
|
36
|
-
tolerance: pydantic.PositiveFloat = pydantic.Field(
|
37
|
+
tolerance: Optional[pydantic.PositiveFloat] = pydantic.Field(
|
37
38
|
default=None, description="Final accuracy in the optimization"
|
38
39
|
)
|
39
|
-
step_size: pydantic.PositiveFloat = pydantic.Field(
|
40
|
+
step_size: Optional[pydantic.PositiveFloat] = pydantic.Field(
|
40
41
|
default=None,
|
41
42
|
description="step size for numerically " "calculating the gradient",
|
42
43
|
)
|
@@ -54,30 +55,36 @@ class OptimizerPreferences(BaseModel):
|
|
54
55
|
)
|
55
56
|
|
56
57
|
@pydantic.validator("tolerance", pre=True, always=True)
|
57
|
-
def check_tolerance(
|
58
|
+
def check_tolerance(
|
59
|
+
cls, tolerance: Optional[pydantic.PositiveFloat], values: Dict[str, Any]
|
60
|
+
) -> Optional[pydantic.PositiveFloat]:
|
58
61
|
optimizer_type = values.get("type")
|
59
62
|
if tolerance is not None and optimizer_type == OptimizerType.SPSA:
|
60
|
-
raise
|
63
|
+
raise ClassiqValueError("No tolerance param for SPSA optimizer")
|
61
64
|
|
62
65
|
if tolerance is None and optimizer_type != OptimizerType.SPSA:
|
63
|
-
tolerance = 0.001
|
66
|
+
tolerance = pydantic.PositiveFloat(0.001)
|
64
67
|
|
65
68
|
return tolerance
|
66
69
|
|
67
70
|
@pydantic.validator("step_size", pre=True, always=True)
|
68
|
-
def check_step_size(
|
71
|
+
def check_step_size(
|
72
|
+
cls, step_size: Optional[pydantic.PositiveFloat], values: Dict[str, Any]
|
73
|
+
) -> Optional[pydantic.PositiveFloat]:
|
69
74
|
optimizer_type = values.get("name")
|
70
75
|
if step_size is not None and optimizer_type not in (
|
71
76
|
OptimizerType.L_BFGS_B,
|
72
77
|
OptimizerType.ADAM,
|
73
78
|
):
|
74
|
-
raise
|
79
|
+
raise ClassiqValueError(
|
80
|
+
"Use step_size only for L_BFGS_B or ADAM optimizers."
|
81
|
+
)
|
75
82
|
|
76
83
|
if step_size is None and optimizer_type in (
|
77
84
|
OptimizerType.L_BFGS_B,
|
78
85
|
OptimizerType.ADAM,
|
79
86
|
):
|
80
|
-
step_size = 0.05
|
87
|
+
step_size = pydantic.PositiveFloat(0.05)
|
81
88
|
|
82
89
|
return step_size
|
83
90
|
|
@@ -91,7 +98,7 @@ class CombinatorialOptimizer(OptimizerPreferences):
|
|
91
98
|
default=CostType.CVAR,
|
92
99
|
description="Summarizing method of the measured bit strings",
|
93
100
|
)
|
94
|
-
alpha_cvar: PydanticAlphaParamCVAR = pydantic.Field(
|
101
|
+
alpha_cvar: Optional[PydanticAlphaParamCVAR] = pydantic.Field(
|
95
102
|
default=None, description="Parameter for the CVAR summarizing method"
|
96
103
|
)
|
97
104
|
is_maximization: bool = pydantic.Field(
|
@@ -104,12 +111,14 @@ class CombinatorialOptimizer(OptimizerPreferences):
|
|
104
111
|
)
|
105
112
|
|
106
113
|
@pydantic.validator("alpha_cvar", pre=True, always=True)
|
107
|
-
def check_alpha_cvar(
|
114
|
+
def check_alpha_cvar(
|
115
|
+
cls, alpha_cvar: Optional[PydanticAlphaParamCVAR], values: Dict[str, Any]
|
116
|
+
) -> Optional[PydanticAlphaParamCVAR]:
|
108
117
|
cost_type = values.get("cost_type")
|
109
118
|
if alpha_cvar is not None and cost_type != CostType.CVAR:
|
110
|
-
raise
|
119
|
+
raise ClassiqValueError("Use CVAR params only for CostType.CVAR.")
|
111
120
|
|
112
121
|
if alpha_cvar is None and cost_type == CostType.CVAR:
|
113
|
-
alpha_cvar = 0.2
|
122
|
+
alpha_cvar = PydanticAlphaParamCVAR(0.2)
|
114
123
|
|
115
124
|
return alpha_cvar
|
@@ -6,7 +6,7 @@ from typing import Any, Dict, Optional, Tuple, Union
|
|
6
6
|
import pydantic
|
7
7
|
from pydantic import BaseModel
|
8
8
|
|
9
|
-
from classiq.interface.backend.ionq import
|
9
|
+
from classiq.interface.backend.ionq.ionq_quantum_program import IonqQuantumCircuit
|
10
10
|
from classiq.interface.backend.pydantic_backend import PydanticArgumentNameType
|
11
11
|
from classiq.interface.executor.quantum_instruction_set import QuantumInstructionSet
|
12
12
|
from classiq.interface.executor.register_initialization import RegisterInitialization
|
@@ -14,15 +14,17 @@ from classiq.interface.generator.synthesis_metadata.synthesis_execution_data imp
|
|
14
14
|
ExecutionData,
|
15
15
|
)
|
16
16
|
|
17
|
+
from classiq.exceptions import ClassiqValueError
|
18
|
+
|
17
19
|
Arguments = Dict[PydanticArgumentNameType, Any]
|
18
20
|
MultipleArguments = Tuple[Arguments, ...]
|
19
|
-
CodeType =
|
21
|
+
CodeType = str
|
20
22
|
RegistersInitialization = Dict[str, RegisterInitialization]
|
21
23
|
Qubits = Tuple[int, ...]
|
22
24
|
OutputQubitsMap = Dict[str, Qubits]
|
23
25
|
|
24
26
|
|
25
|
-
class
|
27
|
+
class QuantumBaseCode(BaseModel):
|
26
28
|
syntax: QuantumInstructionSet = pydantic.Field(
|
27
29
|
default=QuantumInstructionSet.QASM, description="The syntax of the program."
|
28
30
|
)
|
@@ -31,17 +33,21 @@ class QuantumBaseProgram(BaseModel):
|
|
31
33
|
)
|
32
34
|
|
33
35
|
@pydantic.validator("code")
|
34
|
-
def load_quantum_program(
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
def load_quantum_program(
|
37
|
+
cls, code: Union[CodeType, IonqQuantumCircuit], values: Dict[str, Any]
|
38
|
+
) -> CodeType:
|
38
39
|
syntax = values.get("syntax")
|
39
|
-
if
|
40
|
-
|
40
|
+
if isinstance(code, IonqQuantumCircuit):
|
41
|
+
if syntax != QuantumInstructionSet.IONQ:
|
42
|
+
raise ClassiqValueError(
|
43
|
+
f"Invalid code type {type(code)} for syntax: {syntax}"
|
44
|
+
)
|
45
|
+
return code.json()
|
46
|
+
|
41
47
|
return code
|
42
48
|
|
43
49
|
|
44
|
-
class
|
50
|
+
class QuantumCode(QuantumBaseCode):
|
45
51
|
arguments: MultipleArguments = pydantic.Field(
|
46
52
|
default=(),
|
47
53
|
description="The parameters dictionary for a parametrized quantum program.",
|
@@ -68,10 +74,10 @@ class QuantumProgram(QuantumBaseProgram):
|
|
68
74
|
QuantumInstructionSet.QSHARP,
|
69
75
|
QuantumInstructionSet.QASM,
|
70
76
|
):
|
71
|
-
raise
|
77
|
+
raise ClassiqValueError("Only QASM or Q# programs support arguments")
|
72
78
|
|
73
79
|
if values.get("syntax") == QuantumInstructionSet.QSHARP and len(arguments) > 1:
|
74
|
-
raise
|
80
|
+
raise ClassiqValueError(
|
75
81
|
f"Q# programs supports only one group of arguments. {len(arguments)} given"
|
76
82
|
)
|
77
83
|
|
@@ -87,7 +93,7 @@ class QuantumProgram(QuantumBaseProgram):
|
|
87
93
|
synthesis_execution_data is not None
|
88
94
|
and values.get("syntax") is not QuantumInstructionSet.QASM
|
89
95
|
):
|
90
|
-
raise
|
96
|
+
raise ClassiqValueError("Only QASM supports the requested configuration")
|
91
97
|
|
92
98
|
return synthesis_execution_data
|
93
99
|
|
@@ -96,9 +102,9 @@ class QuantumProgram(QuantumBaseProgram):
|
|
96
102
|
file_path: Union[str, Path],
|
97
103
|
syntax: Optional[Union[str, QuantumInstructionSet]] = None,
|
98
104
|
arguments: MultipleArguments = (),
|
99
|
-
) ->
|
105
|
+
) -> QuantumCode:
|
100
106
|
path = Path(file_path)
|
101
107
|
code = path.read_text()
|
102
108
|
if syntax is None:
|
103
109
|
syntax = QuantumInstructionSet.from_suffix(path.suffix.lstrip("."))
|
104
|
-
return
|
110
|
+
return QuantumCode(syntax=syntax, code=code, arguments=arguments)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
from classiq._internals.enum_utils import StrEnum
|
2
|
+
from classiq.exceptions import ClassiqValueError
|
2
3
|
|
3
4
|
|
4
5
|
class QuantumInstructionSet(StrEnum):
|
@@ -14,4 +15,4 @@ class QuantumInstructionSet(StrEnum):
|
|
14
15
|
return QuantumInstructionSet.QSHARP
|
15
16
|
if suffix == "ionq":
|
16
17
|
return QuantumInstructionSet.IONQ
|
17
|
-
raise
|
18
|
+
raise ClassiqValueError("Illegal suffix")
|
@@ -30,9 +30,7 @@ class RegisterInitialization(pydantic.BaseModel):
|
|
30
30
|
initial_condition: int = values.get("initial_condition", 0)
|
31
31
|
name: str = values.get("name", "")
|
32
32
|
|
33
|
-
initial_condition_length = number_utils.size(
|
34
|
-
initial_condition, machine_precision=number_utils.MAX_FRACTION_PLACES
|
35
|
-
)
|
33
|
+
initial_condition_length = number_utils.size(initial_condition)
|
36
34
|
register_length = len(qubits)
|
37
35
|
if initial_condition_length > register_length:
|
38
36
|
raise ClassiqStateInitializationError(
|
@@ -17,7 +17,7 @@ import pydantic
|
|
17
17
|
from pydantic import BaseModel
|
18
18
|
from typing_extensions import TypeAlias
|
19
19
|
|
20
|
-
from classiq.interface.executor.
|
20
|
+
from classiq.interface.executor.quantum_code import OutputQubitsMap, Qubits
|
21
21
|
from classiq.interface.generator.arith import number_utils
|
22
22
|
from classiq.interface.generator.complex_type import Complex
|
23
23
|
from classiq.interface.generator.functions.classical_type import QmodPyObject
|
@@ -44,6 +44,9 @@ class SampledState(BaseModel):
|
|
44
44
|
state: ParsedState
|
45
45
|
shots: MeasuredShots
|
46
46
|
|
47
|
+
def __repr__(self) -> str:
|
48
|
+
return f"{self.state}: {self.shots}"
|
49
|
+
|
47
50
|
|
48
51
|
ParsedCounts: TypeAlias = List[SampledState]
|
49
52
|
|
@@ -97,6 +100,28 @@ def get_sampled_state(
|
|
97
100
|
return None
|
98
101
|
|
99
102
|
|
103
|
+
def reduce_parsed_states(
|
104
|
+
parsed_states: ParsedStates, outputs: Tuple[Name, ...]
|
105
|
+
) -> ParsedStates:
|
106
|
+
return {
|
107
|
+
state: {
|
108
|
+
output: value for output, value in parsed_state.items() if output in outputs
|
109
|
+
}
|
110
|
+
for state, parsed_state in parsed_states.items()
|
111
|
+
}
|
112
|
+
|
113
|
+
|
114
|
+
def get_parsed_counts(counts: Counts, parsed_states: ParsedStates) -> ParsedCounts:
|
115
|
+
parsed_counts: ParsedCounts = []
|
116
|
+
for bitstring, count in counts.items():
|
117
|
+
parsed_state = parsed_states[bitstring]
|
118
|
+
if sampled_state := get_sampled_state(parsed_counts, parsed_state):
|
119
|
+
sampled_state.shots += count
|
120
|
+
else:
|
121
|
+
parsed_counts.append(SampledState(state=parsed_state, shots=count))
|
122
|
+
return sorted(parsed_counts, key=lambda k: k.shots, reverse=True)
|
123
|
+
|
124
|
+
|
100
125
|
class ExecutionDetails(BaseModel, QmodPyObject):
|
101
126
|
vendor_format_result: Dict[str, Any] = pydantic.Field(
|
102
127
|
..., description="Result in proprietary vendor format"
|
@@ -155,14 +180,7 @@ class ExecutionDetails(BaseModel, QmodPyObject):
|
|
155
180
|
|
156
181
|
@property
|
157
182
|
def parsed_counts(self) -> ParsedCounts:
|
158
|
-
|
159
|
-
for bitstring, count in self.counts.items():
|
160
|
-
parsed_state = self.parsed_states[bitstring]
|
161
|
-
if sampled_state := get_sampled_state(parsed_counts, parsed_state):
|
162
|
-
sampled_state.shots += count
|
163
|
-
else:
|
164
|
-
parsed_counts.append(SampledState(state=parsed_state, shots=count))
|
165
|
-
return sorted(parsed_counts, key=lambda k: k.shots, reverse=True)
|
183
|
+
return get_parsed_counts(self.counts, self.parsed_states)
|
166
184
|
|
167
185
|
@property
|
168
186
|
def parsed_state_vector(self) -> Optional[ParsedStateVector]:
|
@@ -223,6 +241,17 @@ class ExecutionDetails(BaseModel, QmodPyObject):
|
|
223
241
|
reduced_counts[reduced_strs] += state_count
|
224
242
|
return dict(reduced_counts)
|
225
243
|
|
244
|
+
def parsed_counts_of_outputs(
|
245
|
+
self, output_names: Union[Name, Tuple[Name, ...]]
|
246
|
+
) -> ParsedCounts:
|
247
|
+
if isinstance(output_names, Name):
|
248
|
+
output_names = (output_names,)
|
249
|
+
if any(name not in self.output_qubits_map for name in output_names):
|
250
|
+
raise ClassiqError(_UNAVAILABLE_OUTPUT_ERROR_MSG)
|
251
|
+
|
252
|
+
reduced_parsed_states = reduce_parsed_states(self.parsed_states, output_names)
|
253
|
+
return get_parsed_counts(self.counts, reduced_parsed_states)
|
254
|
+
|
226
255
|
def register_output_from_qubits(self, qubits: Tuple[int, ...]) -> Dict[float, int]:
|
227
256
|
register_output: Dict[float, int] = {}
|
228
257
|
value_from_str_bin = functools.partial(
|
@@ -273,7 +302,9 @@ class EstimationResults(VersionedModel):
|
|
273
302
|
def __len__(self) -> int:
|
274
303
|
return len(self.results)
|
275
304
|
|
276
|
-
def __iter__(self) -> Iterator[EstimationResult]: # type: ignore
|
305
|
+
def __iter__(self) -> Iterator[EstimationResult]: # type: ignore[override]
|
306
|
+
# TODO This is a bug waiting to happen. We change the meaning of
|
307
|
+
# __iter__ in a derived class.
|
277
308
|
return iter(self.results)
|
278
309
|
|
279
310
|
def __getitem__(self, index: int) -> EstimationResult:
|
@@ -18,7 +18,7 @@ Solution = Tuple[int, ...]
|
|
18
18
|
class SolverResult(BaseModel):
|
19
19
|
energy: float
|
20
20
|
# TODO: add time units (like seconds)
|
21
|
-
time: Optional[float]
|
21
|
+
time: Optional[float] = None
|
22
22
|
solution: Optional[Solution]
|
23
23
|
|
24
24
|
|
@@ -63,7 +63,7 @@ class VQESolverResult(SolverResult, QmodPyObject):
|
|
63
63
|
self.convergence_graph.show()
|
64
64
|
|
65
65
|
@property
|
66
|
-
def convergence_graph(self):
|
66
|
+
def convergence_graph(self) -> Image.Image:
|
67
67
|
return Image.open(io.BytesIO(base64.b64decode(self.convergence_graph_str)))
|
68
68
|
|
69
69
|
@property
|
@@ -3,12 +3,15 @@ from typing import Any, Dict, Optional, Union
|
|
3
3
|
import pydantic
|
4
4
|
|
5
5
|
from classiq.interface.generator.expressions.enums.finance_functions import (
|
6
|
+
FINANCE_FUNCTION_STRING,
|
6
7
|
FinanceFunctionType,
|
7
8
|
)
|
8
9
|
from classiq.interface.helpers.custom_pydantic_types import (
|
9
10
|
PydanticNonZeroProbabilityFloat,
|
10
11
|
)
|
11
12
|
|
13
|
+
from classiq.exceptions import ClassiqValueError
|
14
|
+
|
12
15
|
|
13
16
|
class FunctionCondition(pydantic.BaseModel):
|
14
17
|
threshold: float
|
@@ -22,8 +25,9 @@ class FunctionCondition(pydantic.BaseModel):
|
|
22
25
|
|
23
26
|
|
24
27
|
class FinanceFunctionInput(pydantic.BaseModel):
|
25
|
-
f:
|
26
|
-
description="
|
28
|
+
f: FinanceFunctionType = pydantic.Field(
|
29
|
+
description="An enumeration of the wanted financial function: VaR, expected "
|
30
|
+
"shortfall, European call options or x^2"
|
27
31
|
)
|
28
32
|
variable: str = pydantic.Field(
|
29
33
|
default="x", description="Variable/s of the function"
|
@@ -45,13 +49,20 @@ class FinanceFunctionInput(pydantic.BaseModel):
|
|
45
49
|
description="The required probability on the tail of the distribution (1 - percentile)",
|
46
50
|
)
|
47
51
|
|
52
|
+
@pydantic.validator("f", pre=True)
|
53
|
+
def _convert_f_if_str(cls, f: Any) -> FinanceFunctionType:
|
54
|
+
# Keep this for backwards-compatible string support
|
55
|
+
if f in FINANCE_FUNCTION_STRING:
|
56
|
+
return FINANCE_FUNCTION_STRING[f]
|
57
|
+
return f
|
58
|
+
|
48
59
|
@pydantic.validator("use_chebyshev_polynomial_approximation")
|
49
60
|
def _validate_polynomial_flag(
|
50
61
|
cls, use_chebyshev_flag: bool, values: Dict[str, Any]
|
51
62
|
) -> bool:
|
52
63
|
if use_chebyshev_flag ^ (values.get("polynomial_degree") is None):
|
53
64
|
return use_chebyshev_flag
|
54
|
-
raise
|
65
|
+
raise ClassiqValueError(
|
55
66
|
"Degree must be positive and use_chebyshev_polynomial_approximation set to True"
|
56
67
|
)
|
57
68
|
|
@@ -72,7 +83,9 @@ class FinanceFunctionInput(pydantic.BaseModel):
|
|
72
83
|
values: Dict[str, Any],
|
73
84
|
) -> Optional[PydanticNonZeroProbabilityFloat]:
|
74
85
|
if values.get("f") == FinanceFunctionType.SHORTFALL and not tail_probability:
|
75
|
-
raise
|
86
|
+
raise ClassiqValueError(
|
87
|
+
"Tail probability must be set for expected shortfall"
|
88
|
+
)
|
76
89
|
return tail_probability
|
77
90
|
|
78
91
|
class Config:
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import math
|
2
|
-
from typing import List, Optional, Tuple
|
2
|
+
from typing import List, Literal, Optional, Tuple
|
3
3
|
|
4
4
|
import pydantic
|
5
5
|
|
@@ -8,6 +8,8 @@ from classiq.interface.helpers.custom_pydantic_types import PydanticProbabilityF
|
|
8
8
|
|
9
9
|
|
10
10
|
class GaussianModelInput(FinanceModelInput):
|
11
|
+
kind: Literal["gaussian"] = pydantic.Field(default="gaussian")
|
12
|
+
|
11
13
|
num_qubits: pydantic.PositiveInt = pydantic.Field(
|
12
14
|
description="The number of qubits represent"
|
13
15
|
"the latent normal random variable Z (Resolution of "
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import Tuple
|
1
|
+
from typing import Literal, Tuple
|
2
2
|
|
3
3
|
import numpy as np
|
4
4
|
import pydantic
|
@@ -7,6 +7,8 @@ from classiq.interface.finance.model_input import FinanceModelInput
|
|
7
7
|
|
8
8
|
|
9
9
|
class LogNormalModelInput(FinanceModelInput):
|
10
|
+
kind: Literal["log_normal"] = pydantic.Field(default="log_normal")
|
11
|
+
|
10
12
|
num_qubits: pydantic.PositiveInt = pydantic.Field(
|
11
13
|
description="Number of qubits to represent the probability."
|
12
14
|
)
|
@@ -20,6 +20,7 @@ from classiq.interface.generator.function_params import (
|
|
20
20
|
from classiq.interface.helpers.custom_pydantic_types import PydanticExpressionStr
|
21
21
|
|
22
22
|
from classiq._internals.enum_utils import StrEnum
|
23
|
+
from classiq.exceptions import ClassiqValueError
|
23
24
|
|
24
25
|
AMPLITUDE_IO_NAME = "AMPLITUDE"
|
25
26
|
TARGET_OUTPUT_NAME = "TARGET"
|
@@ -66,14 +67,17 @@ class AmplitudeLoading(FunctionParams):
|
|
66
67
|
not_allowed = literals.intersection(FORBIDDEN_LITERALS)
|
67
68
|
variables = literals.difference(SUPPORTED_FUNC_NAMES)
|
68
69
|
if not_allowed:
|
69
|
-
raise
|
70
|
+
raise ClassiqValueError(
|
71
|
+
f"The following names: {not_allowed} are not allowed"
|
72
|
+
)
|
70
73
|
|
71
74
|
if len(variables) != 1:
|
72
|
-
raise
|
75
|
+
raise ClassiqValueError(f"{variables} must contain exactly single variable")
|
73
76
|
return values
|
74
77
|
|
75
78
|
def _create_ios(self) -> None:
|
76
79
|
self._inputs = {
|
80
|
+
TARGET_OUTPUT_NAME: RegisterUserInput(name=TARGET_OUTPUT_NAME, size=1),
|
77
81
|
AMPLITUDE_IO_NAME: RegisterUserInput(
|
78
82
|
name=AMPLITUDE_IO_NAME, size=self.size
|
79
83
|
),
|
@@ -82,7 +86,6 @@ class AmplitudeLoading(FunctionParams):
|
|
82
86
|
TARGET_OUTPUT_NAME: RegisterUserInput(name=TARGET_OUTPUT_NAME, size=1),
|
83
87
|
**self._inputs,
|
84
88
|
}
|
85
|
-
self._create_zero_input_registers({TARGET_OUTPUT_NAME: 1})
|
86
89
|
|
87
90
|
@property
|
88
91
|
def variable(self) -> str:
|
@@ -2,6 +2,7 @@ from classiq.interface.generator.builtin_api_builder import (
|
|
2
2
|
populate_builtin_declarations,
|
3
3
|
)
|
4
4
|
|
5
|
+
from .arithmetic_declarations import * # noqa: F403
|
5
6
|
from .chemistry_declarations import * # noqa: F403
|
6
7
|
from .combinatorial_optimization_declarations import * # noqa: F403
|
7
8
|
from .entangler_declarations import * # noqa: F403
|
@@ -0,0 +1,14 @@
|
|
1
|
+
from classiq.interface.generator.functions.classical_function_declaration import (
|
2
|
+
ClassicalFunctionDeclaration,
|
3
|
+
)
|
4
|
+
from classiq.interface.generator.functions.classical_type import Integer, Real
|
5
|
+
|
6
|
+
qft_const_adder_phase = ClassicalFunctionDeclaration(
|
7
|
+
name="qft_const_adder_phase",
|
8
|
+
param_decls={
|
9
|
+
"bit_index": Integer(),
|
10
|
+
"value": Integer(),
|
11
|
+
"reg_len": Integer(),
|
12
|
+
},
|
13
|
+
return_type=Real(),
|
14
|
+
)
|