classiq 0.92.0__py3-none-any.whl → 0.99.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 +11 -19
- classiq/_analyzer_extras/_ipywidgets_async_extension.py +7 -7
- classiq/_analyzer_extras/interactive_hardware.py +19 -12
- classiq/_internals/api_wrapper.py +31 -142
- classiq/_internals/async_utils.py +4 -7
- classiq/_internals/authentication/auth0.py +41 -15
- classiq/_internals/authentication/authorization_code.py +9 -0
- classiq/_internals/authentication/authorization_flow.py +41 -0
- classiq/_internals/authentication/device.py +33 -52
- classiq/_internals/authentication/hybrid_flow.py +19 -0
- classiq/_internals/authentication/password_manager.py +13 -13
- classiq/_internals/authentication/token_manager.py +9 -9
- classiq/_internals/client.py +17 -44
- classiq/_internals/config.py +19 -5
- classiq/_internals/help.py +1 -2
- classiq/_internals/host_checker.py +3 -3
- classiq/_internals/jobs.py +14 -14
- classiq/_internals/type_validation.py +3 -3
- classiq/analyzer/analyzer.py +18 -18
- classiq/analyzer/rb.py +17 -8
- classiq/analyzer/show_interactive_hack.py +1 -1
- classiq/applications/__init__.py +2 -2
- classiq/applications/chemistry/__init__.py +0 -30
- classiq/applications/chemistry/op_utils.py +4 -4
- classiq/applications/chemistry/problems.py +3 -3
- classiq/applications/chemistry/ucc.py +1 -2
- classiq/applications/chemistry/z2_symmetries.py +4 -4
- classiq/applications/combinatorial_helpers/allowed_constraints.py +1 -3
- classiq/applications/combinatorial_helpers/arithmetic/arithmetic_expression.py +2 -1
- classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +2 -2
- classiq/applications/combinatorial_helpers/encoding_mapping.py +2 -3
- classiq/applications/combinatorial_helpers/encoding_utils.py +2 -2
- classiq/applications/combinatorial_helpers/optimization_model.py +3 -4
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_sparsing.py +2 -2
- classiq/applications/combinatorial_helpers/pyomo_utils.py +8 -8
- classiq/applications/combinatorial_helpers/sympy_utils.py +1 -3
- classiq/applications/combinatorial_helpers/transformations/encoding.py +3 -3
- classiq/applications/combinatorial_helpers/transformations/fixed_variables.py +1 -2
- classiq/applications/combinatorial_optimization/combinatorial_optimization_config.py +2 -3
- classiq/applications/combinatorial_optimization/combinatorial_optimization_model_constructor.py +4 -6
- classiq/applications/combinatorial_optimization/combinatorial_problem.py +15 -10
- classiq/applications/hamiltonian/pauli_decomposition.py +6 -4
- classiq/applications/iqae/iqae.py +14 -11
- classiq/applications/qnn/datasets/dataset_base_classes.py +6 -6
- classiq/applications/qnn/datasets/dataset_parity.py +6 -6
- classiq/applications/qnn/gradients/simple_quantum_gradient.py +1 -1
- classiq/applications/qnn/qlayer.py +9 -8
- classiq/applications/qnn/torch_utils.py +5 -6
- classiq/applications/qnn/types.py +2 -1
- classiq/applications/qsp/__init__.py +20 -2
- classiq/applications/qsp/qsp.py +239 -11
- classiq/applications/qsvm/qsvm_data_generation.py +1 -2
- classiq/evaluators/classical_expression.py +0 -4
- classiq/evaluators/parameter_types.py +20 -12
- classiq/evaluators/qmod_annotated_expression.py +31 -26
- classiq/evaluators/qmod_expression_visitors/qmod_expression_evaluator.py +14 -14
- classiq/evaluators/qmod_expression_visitors/qmod_expression_simplifier.py +2 -1
- classiq/evaluators/qmod_expression_visitors/sympy_wrappers.py +8 -8
- classiq/evaluators/qmod_node_evaluators/binary_op_evaluation.py +4 -4
- classiq/evaluators/qmod_node_evaluators/classical_function_evaluation.py +14 -4
- classiq/evaluators/qmod_node_evaluators/list_evaluation.py +2 -2
- classiq/evaluators/qmod_node_evaluators/numeric_attrs_utils.py +3 -3
- classiq/evaluators/qmod_node_evaluators/subscript_evaluation.py +9 -9
- classiq/evaluators/qmod_node_evaluators/utils.py +6 -6
- classiq/evaluators/qmod_type_inference/classical_type_inference.py +9 -10
- classiq/evaluators/qmod_type_inference/quantum_type_inference.py +5 -5
- classiq/execution/__init__.py +0 -3
- classiq/execution/execution_session.py +28 -21
- classiq/execution/jobs.py +26 -26
- classiq/execution/qnn.py +1 -2
- classiq/execution/user_budgets.py +71 -37
- classiq/executor.py +1 -3
- classiq/interface/_version.py +1 -1
- classiq/interface/analyzer/analysis_params.py +4 -4
- classiq/interface/analyzer/cytoscape_graph.py +3 -3
- classiq/interface/analyzer/result.py +4 -4
- classiq/interface/ast_node.py +3 -3
- classiq/interface/backend/backend_preferences.py +26 -50
- classiq/interface/backend/ionq/ionq_quantum_program.py +5 -5
- classiq/interface/backend/provider_config/__init__.py +0 -0
- classiq/interface/backend/provider_config/provider_config.py +8 -0
- classiq/interface/backend/provider_config/providers/__init__.py +0 -0
- classiq/interface/backend/provider_config/providers/alice_bob.py +47 -0
- classiq/interface/backend/provider_config/providers/aqt.py +16 -0
- classiq/interface/backend/provider_config/providers/azure.py +37 -0
- classiq/interface/backend/provider_config/providers/braket.py +39 -0
- classiq/interface/backend/provider_config/providers/ibm.py +26 -0
- classiq/interface/backend/provider_config/providers/ionq.py +22 -0
- classiq/interface/backend/quantum_backend_providers.py +20 -2
- classiq/interface/chemistry/ansatz_library.py +3 -5
- classiq/interface/chemistry/operator.py +3 -3
- classiq/interface/combinatorial_optimization/examples/knapsack.py +2 -4
- classiq/interface/combinatorial_optimization/examples/tsp_digraph.py +1 -2
- classiq/interface/compression_utils.py +2 -3
- classiq/interface/debug_info/debug_info.py +8 -7
- classiq/interface/exceptions.py +10 -7
- classiq/interface/execution/primitives.py +6 -6
- classiq/interface/executor/estimate_cost.py +1 -1
- classiq/interface/executor/execution_preferences.py +3 -5
- classiq/interface/executor/execution_request.py +10 -10
- classiq/interface/executor/execution_result.py +1 -2
- classiq/interface/executor/quantum_code.py +8 -8
- classiq/interface/executor/result.py +28 -18
- classiq/interface/executor/user_budget.py +25 -17
- classiq/interface/executor/vqe_result.py +5 -6
- classiq/interface/generator/ansatz_library.py +6 -8
- classiq/interface/generator/application_apis/__init__.py +0 -3
- classiq/interface/generator/arith/arithmetic.py +2 -2
- classiq/interface/generator/arith/arithmetic_arg_type_validator.py +2 -3
- classiq/interface/generator/arith/arithmetic_expression_abc.py +4 -5
- classiq/interface/generator/arith/arithmetic_expression_parser.py +11 -4
- classiq/interface/generator/arith/arithmetic_expression_validator.py +12 -15
- classiq/interface/generator/arith/arithmetic_operations.py +4 -6
- classiq/interface/generator/arith/arithmetic_param_getters.py +70 -107
- classiq/interface/generator/arith/arithmetic_result_builder.py +4 -4
- classiq/interface/generator/arith/ast_node_rewrite.py +8 -4
- classiq/interface/generator/arith/binary_ops.py +15 -40
- classiq/interface/generator/arith/logical_ops.py +2 -3
- classiq/interface/generator/arith/number_utils.py +2 -2
- classiq/interface/generator/arith/register_user_input.py +3 -3
- classiq/interface/generator/arith/unary_ops.py +2 -2
- classiq/interface/generator/circuit_code/circuit_code.py +8 -10
- classiq/interface/generator/circuit_code/types_and_constants.py +1 -1
- classiq/interface/generator/complex_type.py +2 -2
- classiq/interface/generator/copy.py +1 -3
- classiq/interface/generator/expressions/atomic_expression_functions.py +0 -5
- classiq/interface/generator/expressions/evaluated_expression.py +2 -3
- classiq/interface/generator/expressions/expression.py +2 -2
- classiq/interface/generator/expressions/proxies/classical/classical_array_proxy.py +4 -7
- classiq/interface/generator/function_param_list.py +0 -40
- classiq/interface/generator/function_params.py +5 -6
- classiq/interface/generator/functions/classical_function_declaration.py +2 -2
- classiq/interface/generator/functions/classical_type.py +3 -3
- classiq/interface/generator/functions/type_modifier.py +0 -15
- classiq/interface/generator/functions/type_name.py +2 -2
- classiq/interface/generator/generated_circuit_data.py +14 -18
- classiq/interface/generator/hamiltonian_evolution/exponentiation.py +2 -4
- classiq/interface/generator/hardware/hardware_data.py +8 -8
- classiq/interface/generator/hardware_efficient_ansatz.py +9 -9
- classiq/interface/generator/mcu.py +3 -3
- classiq/interface/generator/mcx.py +3 -3
- classiq/interface/generator/model/constraints.py +34 -5
- classiq/interface/generator/model/preferences/preferences.py +15 -21
- classiq/interface/generator/model/quantum_register.py +7 -10
- classiq/interface/generator/noise_properties.py +3 -7
- classiq/interface/generator/parameters.py +1 -1
- classiq/interface/generator/partitioned_register.py +1 -2
- classiq/interface/generator/preferences/qasm_to_qmod_params.py +11 -0
- classiq/interface/generator/quantum_function_call.py +9 -12
- classiq/interface/generator/quantum_program.py +10 -23
- classiq/interface/generator/range_types.py +3 -3
- classiq/interface/generator/slice_parsing_utils.py +4 -5
- classiq/interface/generator/standard_gates/standard_gates.py +2 -4
- classiq/interface/generator/synthesis_execution_parameter.py +1 -3
- classiq/interface/generator/synthesis_metadata/synthesis_duration.py +9 -0
- classiq/interface/generator/synthesis_metadata/synthesis_execution_data.py +2 -3
- classiq/interface/generator/transpiler_basis_gates.py +12 -4
- classiq/interface/generator/types/builtin_enum_declarations.py +0 -145
- classiq/interface/generator/types/compilation_metadata.py +12 -1
- classiq/interface/generator/types/enum_declaration.py +2 -1
- classiq/interface/generator/validations/flow_graph.py +3 -3
- classiq/interface/generator/visitor.py +10 -12
- classiq/interface/hardware.py +2 -3
- classiq/interface/helpers/classproperty.py +2 -2
- classiq/interface/helpers/custom_encoders.py +2 -1
- classiq/interface/helpers/custom_pydantic_types.py +1 -1
- classiq/interface/helpers/text_utils.py +1 -4
- classiq/interface/ide/visual_model.py +6 -5
- classiq/interface/interface_version.py +1 -1
- classiq/interface/jobs.py +3 -3
- classiq/interface/model/allocate.py +4 -4
- classiq/interface/model/block.py +6 -2
- classiq/interface/model/bounds.py +3 -3
- classiq/interface/model/classical_if.py +4 -0
- classiq/interface/model/control.py +8 -1
- classiq/interface/model/inplace_binary_operation.py +2 -2
- classiq/interface/model/invert.py +4 -0
- classiq/interface/model/model.py +4 -4
- classiq/interface/model/model_visitor.py +40 -1
- classiq/interface/model/parameter.py +1 -3
- classiq/interface/model/port_declaration.py +1 -1
- classiq/interface/model/power.py +4 -0
- classiq/interface/model/quantum_expressions/quantum_expression.py +1 -2
- classiq/interface/model/quantum_function_call.py +3 -6
- classiq/interface/model/quantum_function_declaration.py +1 -0
- classiq/interface/model/quantum_lambda_function.py +4 -4
- classiq/interface/model/quantum_statement.py +11 -4
- classiq/interface/model/quantum_type.py +14 -14
- classiq/interface/model/repeat.py +4 -0
- classiq/interface/model/skip_control.py +4 -0
- classiq/interface/model/validation_handle.py +2 -3
- classiq/interface/model/variable_declaration_statement.py +2 -2
- classiq/interface/model/within_apply_operation.py +4 -0
- classiq/interface/pretty_print/expression_to_qmod.py +3 -4
- classiq/interface/server/routes.py +0 -16
- classiq/interface/source_reference.py +3 -4
- classiq/model_expansions/arithmetic.py +11 -7
- classiq/model_expansions/arithmetic_compute_result_attrs.py +30 -27
- classiq/model_expansions/capturing/captured_vars.py +3 -3
- classiq/model_expansions/capturing/mangling_utils.py +1 -2
- classiq/model_expansions/closure.py +12 -11
- classiq/model_expansions/function_builder.py +14 -6
- classiq/model_expansions/generative_functions.py +7 -12
- classiq/model_expansions/interpreters/base_interpreter.py +3 -7
- classiq/model_expansions/interpreters/frontend_generative_interpreter.py +2 -1
- classiq/model_expansions/interpreters/generative_interpreter.py +8 -4
- classiq/model_expansions/quantum_operations/allocate.py +4 -4
- classiq/model_expansions/quantum_operations/assignment_result_processor.py +8 -4
- classiq/model_expansions/quantum_operations/call_emitter.py +31 -37
- classiq/model_expansions/quantum_operations/declarative_call_emitter.py +2 -2
- classiq/model_expansions/quantum_operations/emitter.py +3 -5
- classiq/model_expansions/quantum_operations/expression_evaluator.py +3 -3
- classiq/model_expansions/quantum_operations/skip_control_verifier.py +1 -2
- classiq/model_expansions/quantum_operations/variable_decleration.py +61 -29
- classiq/model_expansions/scope.py +7 -7
- classiq/model_expansions/scope_initialization.py +4 -0
- classiq/model_expansions/visitors/symbolic_param_inference.py +6 -6
- classiq/model_expansions/visitors/uncomputation_signature_inference.py +328 -0
- classiq/model_expansions/visitors/variable_references.py +15 -14
- classiq/open_library/functions/__init__.py +28 -11
- classiq/open_library/functions/amplitude_loading.py +81 -0
- classiq/open_library/functions/discrete_sine_cosine_transform.py +19 -14
- classiq/open_library/functions/grover.py +8 -10
- classiq/open_library/functions/lcu.py +47 -18
- classiq/open_library/functions/modular_exponentiation.py +93 -8
- classiq/open_library/functions/qsvt.py +66 -79
- classiq/open_library/functions/qsvt_temp.py +536 -0
- classiq/open_library/functions/state_preparation.py +130 -27
- classiq/qmod/__init__.py +6 -4
- classiq/qmod/builtins/classical_execution_primitives.py +4 -23
- classiq/qmod/builtins/classical_functions.py +1 -42
- classiq/qmod/builtins/enums.py +15 -153
- classiq/qmod/builtins/functions/__init__.py +9 -18
- classiq/qmod/builtins/functions/allocation.py +25 -4
- classiq/qmod/builtins/functions/arithmetic.py +22 -27
- classiq/qmod/builtins/functions/exponentiation.py +51 -2
- classiq/qmod/builtins/functions/mcx_func.py +7 -0
- classiq/qmod/builtins/functions/standard_gates.py +46 -27
- classiq/qmod/builtins/operations.py +173 -79
- classiq/qmod/builtins/structs.py +24 -91
- classiq/qmod/cfunc.py +3 -2
- classiq/qmod/classical_function.py +2 -1
- classiq/qmod/classical_variable.py +4 -2
- classiq/qmod/cparam.py +2 -8
- classiq/qmod/create_model_function.py +7 -7
- classiq/qmod/declaration_inferrer.py +33 -30
- classiq/qmod/expression_query.py +7 -4
- classiq/qmod/model_state_container.py +2 -2
- classiq/qmod/native/pretty_printer.py +25 -14
- classiq/qmod/pretty_print/expression_to_python.py +5 -3
- classiq/qmod/pretty_print/pretty_printer.py +39 -17
- classiq/qmod/python_classical_type.py +40 -13
- classiq/qmod/qfunc.py +124 -19
- classiq/qmod/qmod_constant.py +2 -2
- classiq/qmod/qmod_parameter.py +5 -2
- classiq/qmod/qmod_variable.py +47 -46
- classiq/qmod/quantum_callable.py +18 -13
- classiq/qmod/quantum_expandable.py +33 -26
- classiq/qmod/quantum_function.py +84 -36
- classiq/qmod/semantics/annotation/call_annotation.py +5 -5
- classiq/qmod/semantics/error_manager.py +12 -14
- classiq/qmod/semantics/lambdas.py +1 -2
- classiq/qmod/semantics/validation/types_validation.py +1 -2
- classiq/qmod/symbolic.py +2 -4
- classiq/qmod/symbolic_expr.py +12 -4
- classiq/qmod/utilities.py +13 -20
- classiq/qmod/write_qmod.py +3 -4
- classiq/quantum_program.py +1 -3
- classiq/synthesis.py +11 -7
- {classiq-0.92.0.dist-info → classiq-0.99.0.dist-info}/METADATA +38 -37
- {classiq-0.92.0.dist-info → classiq-0.99.0.dist-info}/RECORD +273 -300
- classiq-0.99.0.dist-info/WHEEL +4 -0
- classiq-0.99.0.dist-info/licenses/LICENSE.txt +27 -0
- classiq/applications/chemistry/ansatz_parameters.py +0 -29
- classiq/applications/chemistry/chemistry_execution_parameters.py +0 -16
- classiq/applications/chemistry/chemistry_model_constructor.py +0 -532
- classiq/applications/chemistry/ground_state_problem.py +0 -42
- classiq/applications/qsvm/__init__.py +0 -8
- classiq/applications/qsvm/qsvm.py +0 -11
- classiq/evaluators/qmod_expression_visitors/qmod_expression_bwc.py +0 -129
- classiq/execution/iqcc.py +0 -128
- classiq/interface/applications/qsvm.py +0 -117
- classiq/interface/chemistry/elements.py +0 -120
- classiq/interface/chemistry/fermionic_operator.py +0 -208
- classiq/interface/chemistry/ground_state_problem.py +0 -132
- classiq/interface/chemistry/ground_state_result.py +0 -8
- classiq/interface/chemistry/molecule.py +0 -71
- classiq/interface/execution/iqcc.py +0 -44
- classiq/interface/generator/application_apis/chemistry_declarations.py +0 -69
- classiq/interface/generator/application_apis/entangler_declarations.py +0 -29
- classiq/interface/generator/application_apis/qsvm_declarations.py +0 -6
- classiq/interface/generator/chemistry_function_params.py +0 -50
- classiq/interface/generator/entangler_params.py +0 -72
- classiq/interface/generator/entanglers.py +0 -14
- classiq/interface/generator/hamiltonian_evolution/qdrift.py +0 -27
- classiq/interface/generator/hartree_fock.py +0 -26
- classiq/interface/generator/hva.py +0 -22
- classiq/interface/generator/linear_pauli_rotations.py +0 -92
- classiq/interface/generator/qft.py +0 -37
- classiq/interface/generator/qsvm.py +0 -96
- classiq/interface/generator/state_preparation/__init__.py +0 -14
- classiq/interface/generator/state_preparation/bell_state_preparation.py +0 -27
- classiq/interface/generator/state_preparation/computational_basis_state_preparation.py +0 -28
- classiq/interface/generator/state_preparation/distributions.py +0 -53
- classiq/interface/generator/state_preparation/exponential_state_preparation.py +0 -14
- classiq/interface/generator/state_preparation/ghz_state_preparation.py +0 -14
- classiq/interface/generator/state_preparation/metrics.py +0 -41
- classiq/interface/generator/state_preparation/state_preparation.py +0 -113
- classiq/interface/generator/state_preparation/state_preparation_abc.py +0 -24
- classiq/interface/generator/state_preparation/uniform_distibution_state_preparation.py +0 -13
- classiq/interface/generator/state_preparation/w_state_preparation.py +0 -13
- classiq/interface/generator/ucc.py +0 -74
- classiq/interface/helpers/backward_compatibility.py +0 -9
- classiq/model_expansions/transformers/type_modifier_inference.py +0 -392
- classiq/open_library/functions/lookup_table.py +0 -58
- classiq/qmod/builtins/functions/chemistry.py +0 -123
- classiq/qmod/builtins/functions/qsvm.py +0 -24
- classiq-0.92.0.dist-info/WHEEL +0 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Any
|
|
1
|
+
from typing import Any
|
|
2
2
|
|
|
3
3
|
from sympy import Function, Integer
|
|
4
4
|
from sympy.logic.boolalg import BooleanFunction
|
|
@@ -6,7 +6,7 @@ from sympy.logic.boolalg import BooleanFunction
|
|
|
6
6
|
|
|
7
7
|
class BitwiseAnd(Function):
|
|
8
8
|
@classmethod
|
|
9
|
-
def eval(cls, a: Any, b: Any) ->
|
|
9
|
+
def eval(cls, a: Any, b: Any) -> int | None:
|
|
10
10
|
if isinstance(a, Integer) and isinstance(b, Integer):
|
|
11
11
|
return a & b
|
|
12
12
|
|
|
@@ -15,7 +15,7 @@ class BitwiseAnd(Function):
|
|
|
15
15
|
|
|
16
16
|
class BitwiseXor(Function):
|
|
17
17
|
@classmethod
|
|
18
|
-
def eval(cls, a: Any, b: Any) ->
|
|
18
|
+
def eval(cls, a: Any, b: Any) -> int | None:
|
|
19
19
|
if isinstance(a, Integer) and isinstance(b, Integer):
|
|
20
20
|
return a ^ b
|
|
21
21
|
|
|
@@ -24,7 +24,7 @@ class BitwiseXor(Function):
|
|
|
24
24
|
|
|
25
25
|
class LogicalXor(BooleanFunction):
|
|
26
26
|
@classmethod
|
|
27
|
-
def eval(cls, a: Any, b: Any) ->
|
|
27
|
+
def eval(cls, a: Any, b: Any) -> bool | None:
|
|
28
28
|
if isinstance(a, bool) and isinstance(b, bool):
|
|
29
29
|
return a ^ b
|
|
30
30
|
|
|
@@ -33,7 +33,7 @@ class LogicalXor(BooleanFunction):
|
|
|
33
33
|
|
|
34
34
|
class BitwiseOr(Function):
|
|
35
35
|
@classmethod
|
|
36
|
-
def eval(cls, a: Any, b: Any) ->
|
|
36
|
+
def eval(cls, a: Any, b: Any) -> int | None:
|
|
37
37
|
if isinstance(a, Integer) and isinstance(b, Integer):
|
|
38
38
|
return a | b
|
|
39
39
|
|
|
@@ -42,7 +42,7 @@ class BitwiseOr(Function):
|
|
|
42
42
|
|
|
43
43
|
class BitwiseNot(Function):
|
|
44
44
|
@classmethod
|
|
45
|
-
def eval(cls, a: Any) ->
|
|
45
|
+
def eval(cls, a: Any) -> int | None:
|
|
46
46
|
if isinstance(a, Integer):
|
|
47
47
|
return ~a
|
|
48
48
|
|
|
@@ -51,7 +51,7 @@ class BitwiseNot(Function):
|
|
|
51
51
|
|
|
52
52
|
class RShift(Function):
|
|
53
53
|
@classmethod
|
|
54
|
-
def eval(cls, a: Any, b: Any) ->
|
|
54
|
+
def eval(cls, a: Any, b: Any) -> int | None:
|
|
55
55
|
if isinstance(a, Integer) and isinstance(b, Integer):
|
|
56
56
|
return a >> b
|
|
57
57
|
|
|
@@ -60,7 +60,7 @@ class RShift(Function):
|
|
|
60
60
|
|
|
61
61
|
class LShift(Function):
|
|
62
62
|
@classmethod
|
|
63
|
-
def eval(cls, a: Any, b: Any) ->
|
|
63
|
+
def eval(cls, a: Any, b: Any) -> int | None:
|
|
64
64
|
if isinstance(a, Integer) and isinstance(b, Integer):
|
|
65
65
|
return a << b
|
|
66
66
|
|
|
@@ -160,28 +160,28 @@ def _infer_binary_op_type(
|
|
|
160
160
|
if right_value is None or treat_qnum_as_float:
|
|
161
161
|
return QuantumNumeric()
|
|
162
162
|
result_attrs = compute_result_attrs_modulo(
|
|
163
|
-
left_attrs,
|
|
163
|
+
left_attrs, right_attrs, machine_precision
|
|
164
164
|
)
|
|
165
165
|
|
|
166
166
|
elif isinstance(op, ast.Pow):
|
|
167
167
|
if right_value is None or treat_qnum_as_float:
|
|
168
168
|
return QuantumNumeric()
|
|
169
169
|
result_attrs = compute_result_attrs_power(
|
|
170
|
-
left_attrs,
|
|
170
|
+
left_attrs, right_attrs, machine_precision
|
|
171
171
|
)
|
|
172
172
|
|
|
173
173
|
elif isinstance(op, ast.LShift):
|
|
174
174
|
if right_value is None:
|
|
175
175
|
return QuantumNumeric()
|
|
176
176
|
result_attrs = compute_result_attrs_lshift(
|
|
177
|
-
left_attrs,
|
|
177
|
+
left_attrs, right_attrs, machine_precision
|
|
178
178
|
)
|
|
179
179
|
|
|
180
180
|
elif isinstance(op, ast.RShift):
|
|
181
181
|
if right_value is None:
|
|
182
182
|
return QuantumNumeric()
|
|
183
183
|
result_attrs = compute_result_attrs_rshift(
|
|
184
|
-
left_attrs,
|
|
184
|
+
left_attrs, right_attrs, machine_precision
|
|
185
185
|
)
|
|
186
186
|
|
|
187
187
|
elif isinstance(op, ast.BitAnd):
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import ast
|
|
2
|
-
from
|
|
2
|
+
from collections.abc import Callable
|
|
3
|
+
from typing import cast
|
|
3
4
|
|
|
4
5
|
import sympy
|
|
5
6
|
|
|
6
7
|
from classiq.interface.exceptions import (
|
|
7
8
|
ClassiqExpansionError,
|
|
8
9
|
ClassiqInternalExpansionError,
|
|
10
|
+
ClassiqValueError,
|
|
9
11
|
)
|
|
10
12
|
from classiq.interface.generator.functions.classical_function_declaration import (
|
|
11
13
|
ClassicalFunctionDeclaration,
|
|
@@ -19,7 +21,6 @@ from classiq.interface.generator.functions.classical_type import (
|
|
|
19
21
|
Real,
|
|
20
22
|
)
|
|
21
23
|
from classiq.interface.generator.functions.type_name import TypeName
|
|
22
|
-
from classiq.interface.helpers.backward_compatibility import zip_strict
|
|
23
24
|
from classiq.interface.helpers.pydantic_model_helpers import nameables_to_dict
|
|
24
25
|
|
|
25
26
|
from classiq.evaluators.qmod_annotated_expression import QmodAnnotatedExpression
|
|
@@ -39,7 +40,7 @@ INTEGER_FUNCTION_OVERRIDE = {"floor", "ceiling"}
|
|
|
39
40
|
|
|
40
41
|
|
|
41
42
|
def _check_classical_array_arg_type(
|
|
42
|
-
param_type:
|
|
43
|
+
param_type: ClassicalArray | ClassicalTuple, arg_type: ClassicalType
|
|
43
44
|
) -> bool:
|
|
44
45
|
if not isinstance(arg_type, (ClassicalArray, ClassicalTuple)):
|
|
45
46
|
return False
|
|
@@ -63,7 +64,7 @@ def _check_classical_array_arg_type(
|
|
|
63
64
|
)
|
|
64
65
|
return all(
|
|
65
66
|
check_classical_arg_type(param_element_type, arg_element_type)
|
|
66
|
-
for param_element_type, arg_element_type in
|
|
67
|
+
for param_element_type, arg_element_type in zip(
|
|
67
68
|
param_type.element_types, arg_type.element_types, strict=True
|
|
68
69
|
)
|
|
69
70
|
)
|
|
@@ -208,6 +209,15 @@ def try_eval_sympy_function(
|
|
|
208
209
|
|
|
209
210
|
def try_eval_builtin_function(
|
|
210
211
|
expr_val: QmodAnnotatedExpression, node: ast.Call, func_name: str
|
|
212
|
+
) -> bool:
|
|
213
|
+
try:
|
|
214
|
+
return _try_eval_builtin_function(expr_val, node, func_name)
|
|
215
|
+
except ValueError as e:
|
|
216
|
+
raise ClassiqValueError(str(e)) from e
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def _try_eval_builtin_function(
|
|
220
|
+
expr_val: QmodAnnotatedExpression, node: ast.Call, func_name: str
|
|
211
221
|
) -> bool:
|
|
212
222
|
args_are_int = all(isinstance(expr_val.get_type(arg), Integer) for arg in node.args)
|
|
213
223
|
args_are_real = all(
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ast
|
|
2
|
-
from typing import
|
|
2
|
+
from typing import cast
|
|
3
3
|
|
|
4
4
|
from classiq.interface.exceptions import (
|
|
5
5
|
ClassiqExpansionError,
|
|
@@ -57,7 +57,7 @@ def list_allowed(classical_types: list[ClassicalType]) -> bool:
|
|
|
57
57
|
if len(classical_types) < 2:
|
|
58
58
|
return True
|
|
59
59
|
|
|
60
|
-
element_without_empty_tuple:
|
|
60
|
+
element_without_empty_tuple: ClassicalType | None = None
|
|
61
61
|
for classical_type in classical_types:
|
|
62
62
|
if not _has_empty_tuple(classical_type):
|
|
63
63
|
element_without_empty_tuple = classical_type
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ast
|
|
2
|
-
from typing import TYPE_CHECKING
|
|
2
|
+
from typing import TYPE_CHECKING
|
|
3
3
|
|
|
4
4
|
import sympy
|
|
5
5
|
|
|
@@ -22,7 +22,7 @@ def get_numeric_attrs(
|
|
|
22
22
|
qmod_type: QmodType,
|
|
23
23
|
machine_precision: int,
|
|
24
24
|
treat_qnum_as_float: bool,
|
|
25
|
-
) ->
|
|
25
|
+
) -> NumericAttributes | None:
|
|
26
26
|
if isinstance(qmod_type, Bool):
|
|
27
27
|
return NumericAttributes.from_bounds(0, 1, 0, machine_precision)
|
|
28
28
|
if is_classical_type(qmod_type):
|
|
@@ -45,7 +45,7 @@ def get_classical_value_for_arithmetic(
|
|
|
45
45
|
node: ast.AST,
|
|
46
46
|
qmod_type: QmodType,
|
|
47
47
|
treat_qnum_as_float: bool,
|
|
48
|
-
) ->
|
|
48
|
+
) -> float | None:
|
|
49
49
|
if not is_classical_type(qmod_type):
|
|
50
50
|
return None
|
|
51
51
|
if not expr_val.has_value(node):
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ast
|
|
2
|
-
from typing import
|
|
2
|
+
from typing import cast
|
|
3
3
|
|
|
4
4
|
from classiq.interface.exceptions import (
|
|
5
5
|
ClassiqExpansionError,
|
|
@@ -53,12 +53,12 @@ def _eval_slice(expr_val: QmodAnnotatedExpression, node: ast.Subscript) -> None:
|
|
|
53
53
|
f"Slice indices must be integers, not {index_type.raw_qmod_type_name}"
|
|
54
54
|
)
|
|
55
55
|
|
|
56
|
-
start_val:
|
|
56
|
+
start_val: int | None = None
|
|
57
57
|
if expr_val.has_value(start):
|
|
58
58
|
start_val = cast(int, expr_val.get_value(start))
|
|
59
59
|
if start_val < 0:
|
|
60
60
|
raise ClassiqExpansionError("Slice indices must be positive integers")
|
|
61
|
-
stop_val:
|
|
61
|
+
stop_val: int | None = None
|
|
62
62
|
if expr_val.has_value(stop):
|
|
63
63
|
stop_val = cast(int, expr_val.get_value(stop))
|
|
64
64
|
if start_val is not None and stop_val < start_val:
|
|
@@ -74,7 +74,7 @@ def _eval_slice(expr_val: QmodAnnotatedExpression, node: ast.Subscript) -> None:
|
|
|
74
74
|
or (stop_val is not None and stop_val > subject_type.length_value)
|
|
75
75
|
):
|
|
76
76
|
raise ClassiqExpansionError("Array index out of range")
|
|
77
|
-
length_expr:
|
|
77
|
+
length_expr: Expression | None = None
|
|
78
78
|
if start_val is not None and stop_val is not None:
|
|
79
79
|
length_expr = Expression(expr=str(stop_val - start_val))
|
|
80
80
|
slice_type = ClassicalArray(
|
|
@@ -139,7 +139,7 @@ def _eval_subscript(expr_val: QmodAnnotatedExpression, node: ast.Subscript) -> N
|
|
|
139
139
|
f"{index_type.raw_qmod_type_name}"
|
|
140
140
|
)
|
|
141
141
|
|
|
142
|
-
sub_val:
|
|
142
|
+
sub_val: int | None = None
|
|
143
143
|
if expr_val.has_value(subscript):
|
|
144
144
|
sub_val = cast(int, expr_val.get_value(subscript))
|
|
145
145
|
if sub_val < 0:
|
|
@@ -195,10 +195,10 @@ def eval_subscript(expr_val: QmodAnnotatedExpression, node: ast.Subscript) -> No
|
|
|
195
195
|
|
|
196
196
|
|
|
197
197
|
def validate_quantum_subscript_index_properties(
|
|
198
|
-
index_size:
|
|
199
|
-
index_sign:
|
|
200
|
-
index_fraction_digits:
|
|
201
|
-
array_len:
|
|
198
|
+
index_size: int | None,
|
|
199
|
+
index_sign: bool | None,
|
|
200
|
+
index_fraction_digits: int | None,
|
|
201
|
+
array_len: int | None,
|
|
202
202
|
) -> None:
|
|
203
203
|
if index_sign or (index_fraction_digits is not None and index_fraction_digits > 0):
|
|
204
204
|
raise ClassiqValueError("Quantum index must be an unsigned integer")
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import
|
|
1
|
+
from typing import Union, cast
|
|
2
2
|
|
|
3
3
|
import sympy
|
|
4
4
|
|
|
@@ -42,7 +42,7 @@ def qnum_is_qbit(qmod_type: QuantumNumeric) -> bool:
|
|
|
42
42
|
|
|
43
43
|
def get_numeric_properties(
|
|
44
44
|
qmod_type: QuantumScalar,
|
|
45
|
-
) -> tuple[
|
|
45
|
+
) -> tuple[int | None, bool | None, int | None]:
|
|
46
46
|
if isinstance(qmod_type, QuantumBit):
|
|
47
47
|
return 1, False, 0
|
|
48
48
|
if not isinstance(qmod_type, QuantumNumeric):
|
|
@@ -66,7 +66,7 @@ def get_numeric_properties(
|
|
|
66
66
|
|
|
67
67
|
|
|
68
68
|
def element_types(
|
|
69
|
-
classical_type:
|
|
69
|
+
classical_type: ClassicalArray | ClassicalTuple,
|
|
70
70
|
) -> list[ClassicalType]:
|
|
71
71
|
if isinstance(classical_type, ClassicalArray):
|
|
72
72
|
return [classical_type.element_type]
|
|
@@ -74,8 +74,8 @@ def element_types(
|
|
|
74
74
|
|
|
75
75
|
|
|
76
76
|
def array_len(
|
|
77
|
-
classical_type:
|
|
78
|
-
) ->
|
|
77
|
+
classical_type: ClassicalArray | ClassicalTuple,
|
|
78
|
+
) -> int | None:
|
|
79
79
|
if isinstance(classical_type, ClassicalTuple):
|
|
80
80
|
return len(classical_type.element_types)
|
|
81
81
|
if classical_type.has_constant_length:
|
|
@@ -95,7 +95,7 @@ def is_classical_integer(qmod_type: QmodType) -> bool:
|
|
|
95
95
|
)
|
|
96
96
|
|
|
97
97
|
|
|
98
|
-
def get_sympy_val(val: sympy.Basic) ->
|
|
98
|
+
def get_sympy_val(val: sympy.Basic) -> bool | int | float | complex:
|
|
99
99
|
if hasattr(val, "is_Boolean") and val.is_Boolean:
|
|
100
100
|
return bool(val)
|
|
101
101
|
if (hasattr(val, "is_integer") and val.is_integer) or (
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from enum import IntEnum
|
|
2
|
-
from typing import Any
|
|
2
|
+
from typing import Any
|
|
3
3
|
|
|
4
4
|
import sympy
|
|
5
5
|
|
|
@@ -18,14 +18,13 @@ from classiq.interface.generator.functions.classical_type import (
|
|
|
18
18
|
)
|
|
19
19
|
from classiq.interface.generator.functions.type_name import Enum, Struct, TypeName
|
|
20
20
|
from classiq.interface.generator.types.struct_declaration import StructDeclaration
|
|
21
|
-
from classiq.interface.helpers.backward_compatibility import zip_strict
|
|
22
21
|
|
|
23
22
|
from classiq.evaluators.qmod_node_evaluators.utils import get_sympy_type
|
|
24
23
|
|
|
25
24
|
|
|
26
25
|
def _copy_generative_flag(
|
|
27
|
-
from_type: ClassicalType, to_type:
|
|
28
|
-
) ->
|
|
26
|
+
from_type: ClassicalType, to_type: ClassicalType | None
|
|
27
|
+
) -> ClassicalType | None:
|
|
29
28
|
if to_type is None:
|
|
30
29
|
return None
|
|
31
30
|
if from_type.is_generative:
|
|
@@ -65,11 +64,11 @@ def infer_classical_type(value: Any) -> ClassicalType:
|
|
|
65
64
|
|
|
66
65
|
|
|
67
66
|
def _inject_classical_array_attributes(
|
|
68
|
-
from_type: ClassicalType, to_type:
|
|
69
|
-
) ->
|
|
67
|
+
from_type: ClassicalType, to_type: ClassicalArray | ClassicalTuple
|
|
68
|
+
) -> ClassicalType | None:
|
|
70
69
|
if isinstance(to_type, ClassicalArray):
|
|
71
70
|
if isinstance(from_type, ClassicalArray):
|
|
72
|
-
length:
|
|
71
|
+
length: Expression | None
|
|
73
72
|
if from_type.has_constant_length:
|
|
74
73
|
if (
|
|
75
74
|
to_type.has_constant_length
|
|
@@ -116,7 +115,7 @@ def _inject_classical_array_attributes(
|
|
|
116
115
|
return None
|
|
117
116
|
element_types = [
|
|
118
117
|
inject_classical_type_attributes(from_element_type, to_element_type)
|
|
119
|
-
for from_element_type, to_element_type in
|
|
118
|
+
for from_element_type, to_element_type in zip(
|
|
120
119
|
from_type.element_types, to_type.element_types, strict=True
|
|
121
120
|
)
|
|
122
121
|
]
|
|
@@ -128,7 +127,7 @@ def _inject_classical_array_attributes(
|
|
|
128
127
|
|
|
129
128
|
def _inject_classical_type_name_attributes(
|
|
130
129
|
from_type: ClassicalType, to_type: TypeName
|
|
131
|
-
) ->
|
|
130
|
+
) -> ClassicalType | None:
|
|
132
131
|
if to_type.is_enum:
|
|
133
132
|
if isinstance(from_type, Integer) or (
|
|
134
133
|
isinstance(from_type, TypeName) and from_type.name == to_type.name
|
|
@@ -157,7 +156,7 @@ def _inject_classical_type_name_attributes(
|
|
|
157
156
|
|
|
158
157
|
def inject_classical_type_attributes(
|
|
159
158
|
from_type: ClassicalType, to_type: ClassicalType
|
|
160
|
-
) ->
|
|
159
|
+
) -> ClassicalType | None:
|
|
161
160
|
if isinstance(to_type, Bool):
|
|
162
161
|
if isinstance(from_type, Bool):
|
|
163
162
|
return _copy_generative_flag(to_type, Bool())
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import TYPE_CHECKING
|
|
1
|
+
from typing import TYPE_CHECKING
|
|
2
2
|
|
|
3
3
|
from classiq.interface.exceptions import (
|
|
4
4
|
ClassiqExpansionError,
|
|
@@ -80,7 +80,7 @@ def _same_shape(quantum_type_1: QuantumType, quantum_type_2: QuantumType) -> boo
|
|
|
80
80
|
def _inject_qnum_type_attributes(
|
|
81
81
|
from_type: QuantumType, to_type: QuantumNumeric
|
|
82
82
|
) -> QuantumNumeric:
|
|
83
|
-
size:
|
|
83
|
+
size: Expression | None
|
|
84
84
|
if from_type.has_size_in_bits:
|
|
85
85
|
size = Expression(expr=str(from_type.size_in_bits))
|
|
86
86
|
else:
|
|
@@ -126,7 +126,7 @@ def _inject_qnum_type_attributes(
|
|
|
126
126
|
|
|
127
127
|
def _inject_qarray_type_attributes(
|
|
128
128
|
from_type: QuantumType, to_type: QuantumBitvector
|
|
129
|
-
) ->
|
|
129
|
+
) -> QuantumBitvector | None:
|
|
130
130
|
if _same_shape(from_type, to_type):
|
|
131
131
|
if TYPE_CHECKING:
|
|
132
132
|
assert isinstance(from_type, QuantumBitvector)
|
|
@@ -182,7 +182,7 @@ def _inject_qarray_type_attributes(
|
|
|
182
182
|
|
|
183
183
|
def _inject_qstruct_type_attributes(
|
|
184
184
|
from_type: QuantumType, to_type: TypeName
|
|
185
|
-
) ->
|
|
185
|
+
) -> TypeName | None:
|
|
186
186
|
if isinstance(from_type, TypeName) and from_type.name == to_type.name:
|
|
187
187
|
fields = {
|
|
188
188
|
field_name: inject_quantum_type_attributes(
|
|
@@ -241,7 +241,7 @@ def _inject_qstruct_type_attributes(
|
|
|
241
241
|
|
|
242
242
|
def inject_quantum_type_attributes(
|
|
243
243
|
from_type: QuantumType, to_type: QuantumType
|
|
244
|
-
) ->
|
|
244
|
+
) -> QuantumType | None:
|
|
245
245
|
for qmod_type in (from_type, to_type):
|
|
246
246
|
if isinstance(qmod_type, TypeName) and not qmod_type.has_fields:
|
|
247
247
|
raise ClassiqInternalExpansionError
|
classiq/execution/__init__.py
CHANGED
|
@@ -8,7 +8,6 @@ from ..interface.executor.execution_preferences import __all__ as _ep_all
|
|
|
8
8
|
from ..interface.executor.result import ExecutionDetails
|
|
9
9
|
from ..interface.executor.vqe_result import VQESolverResult
|
|
10
10
|
from .execution_session import ExecutionSession
|
|
11
|
-
from .iqcc import generate_iqcc_token, generate_iqcc_token_async
|
|
12
11
|
from .jobs import ExecutionJob, get_execution_jobs, get_execution_jobs_async
|
|
13
12
|
from .qnn import execute_qnn
|
|
14
13
|
from .user_budgets import (
|
|
@@ -33,8 +32,6 @@ __all__ = (
|
|
|
33
32
|
"get_execution_jobs_async",
|
|
34
33
|
"ExecutionSession",
|
|
35
34
|
"execute_qnn",
|
|
36
|
-
"generate_iqcc_token",
|
|
37
|
-
"generate_iqcc_token_async",
|
|
38
35
|
"get_budget",
|
|
39
36
|
"get_budget_async",
|
|
40
37
|
"set_budget_limit",
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import inspect
|
|
2
2
|
import random
|
|
3
3
|
import warnings
|
|
4
|
+
from collections.abc import Callable
|
|
4
5
|
from types import TracebackType
|
|
5
|
-
from typing import Any,
|
|
6
|
+
from typing import Any, Optional, Union, cast
|
|
6
7
|
|
|
7
8
|
from classiq.interface.chemistry.operator import PauliOperator, pauli_integers_to_str
|
|
8
9
|
from classiq.interface.exceptions import (
|
|
@@ -104,7 +105,7 @@ class ExecutionSession:
|
|
|
104
105
|
def __init__(
|
|
105
106
|
self,
|
|
106
107
|
quantum_program: QuantumProgram,
|
|
107
|
-
execution_preferences:
|
|
108
|
+
execution_preferences: ExecutionPreferences | None = None,
|
|
108
109
|
):
|
|
109
110
|
self.program: QuantumProgram = quantum_program
|
|
110
111
|
self.update_execution_preferences(execution_preferences)
|
|
@@ -124,9 +125,9 @@ class ExecutionSession:
|
|
|
124
125
|
|
|
125
126
|
def __exit__(
|
|
126
127
|
self,
|
|
127
|
-
exc_type:
|
|
128
|
-
exc_val:
|
|
129
|
-
exc_tb:
|
|
128
|
+
exc_type: type[BaseException] | None,
|
|
129
|
+
exc_val: BaseException | None,
|
|
130
|
+
exc_tb: TracebackType | None,
|
|
130
131
|
) -> None:
|
|
131
132
|
self.close()
|
|
132
133
|
|
|
@@ -156,7 +157,7 @@ class ExecutionSession:
|
|
|
156
157
|
return ExecutionJob(details=result)
|
|
157
158
|
|
|
158
159
|
def update_execution_preferences(
|
|
159
|
-
self, execution_preferences:
|
|
160
|
+
self, execution_preferences: ExecutionPreferences | None
|
|
160
161
|
) -> None:
|
|
161
162
|
"""
|
|
162
163
|
Update the execution preferences for the session.
|
|
@@ -170,7 +171,7 @@ class ExecutionSession:
|
|
|
170
171
|
if execution_preferences is not None:
|
|
171
172
|
self.program.model.execution_preferences = execution_preferences
|
|
172
173
|
|
|
173
|
-
def sample(self, parameters:
|
|
174
|
+
def sample(self, parameters: ExecutionParams | None = None) -> ExecutionDetails:
|
|
174
175
|
"""
|
|
175
176
|
Samples the quantum program with the given parameters, if any.
|
|
176
177
|
|
|
@@ -183,9 +184,7 @@ class ExecutionSession:
|
|
|
183
184
|
job = self.submit_sample(parameters=parameters)
|
|
184
185
|
return job.get_sample_result(_http_client=self._async_client)
|
|
185
186
|
|
|
186
|
-
def submit_sample(
|
|
187
|
-
self, parameters: Optional[ExecutionParams] = None
|
|
188
|
-
) -> ExecutionJob:
|
|
187
|
+
def submit_sample(self, parameters: ExecutionParams | None = None) -> ExecutionJob:
|
|
189
188
|
"""
|
|
190
189
|
Initiates an execution job with the `sample` primitive.
|
|
191
190
|
|
|
@@ -235,7 +234,7 @@ class ExecutionSession:
|
|
|
235
234
|
return self._execute(execution_primitives_input)
|
|
236
235
|
|
|
237
236
|
def estimate(
|
|
238
|
-
self, hamiltonian: Hamiltonian, parameters:
|
|
237
|
+
self, hamiltonian: Hamiltonian, parameters: ExecutionParams | None = None
|
|
239
238
|
) -> EstimationResult:
|
|
240
239
|
"""
|
|
241
240
|
Estimates the expectation value of the given Hamiltonian using the quantum program.
|
|
@@ -246,6 +245,9 @@ class ExecutionSession:
|
|
|
246
245
|
|
|
247
246
|
Returns:
|
|
248
247
|
EstimationResult: The result of the estimation.
|
|
248
|
+
|
|
249
|
+
See Also:
|
|
250
|
+
More information about [Hamiltonians](https://docs.classiq.io/latest/qmod-reference/language-reference/classical-types/#hamiltonians).
|
|
249
251
|
"""
|
|
250
252
|
_hamiltonian_deprecation_warning(hamiltonian)
|
|
251
253
|
job = self.submit_estimate(
|
|
@@ -256,7 +258,7 @@ class ExecutionSession:
|
|
|
256
258
|
def submit_estimate(
|
|
257
259
|
self,
|
|
258
260
|
hamiltonian: Hamiltonian,
|
|
259
|
-
parameters:
|
|
261
|
+
parameters: ExecutionParams | None = None,
|
|
260
262
|
*,
|
|
261
263
|
_check_deprecation: bool = True,
|
|
262
264
|
) -> ExecutionJob:
|
|
@@ -336,14 +338,15 @@ class ExecutionSession:
|
|
|
336
338
|
|
|
337
339
|
def minimize(
|
|
338
340
|
self,
|
|
339
|
-
cost_function:
|
|
341
|
+
cost_function: Hamiltonian | QmodExpressionCreator,
|
|
340
342
|
initial_params: ExecutionParams,
|
|
341
343
|
max_iteration: int,
|
|
342
344
|
quantile: float = 1.0,
|
|
343
|
-
tolerance:
|
|
345
|
+
tolerance: float | None = None,
|
|
344
346
|
) -> list[tuple[float, ExecutionParams]]:
|
|
345
347
|
"""
|
|
346
348
|
Minimizes the given cost function using the quantum program.
|
|
349
|
+
|
|
347
350
|
Args:
|
|
348
351
|
cost_function: The cost function to minimize. It can be one of the following:
|
|
349
352
|
- A quantum cost function defined by a Hamiltonian.
|
|
@@ -357,9 +360,13 @@ class ExecutionSession:
|
|
|
357
360
|
max_iteration: The maximum number of iterations for the minimization.
|
|
358
361
|
quantile: The quantile to use for cost estimation.
|
|
359
362
|
tolerance: The tolerance for the minimization.
|
|
363
|
+
|
|
360
364
|
Returns:
|
|
361
|
-
|
|
362
|
-
|
|
365
|
+
A list of tuples, each containing the estimated cost and the corresponding parameters for that iteration. `cost` is a float, and `parameters` is a dictionary matching the execution parameter format.
|
|
366
|
+
|
|
367
|
+
See Also:
|
|
368
|
+
The [Classiq Tutorial](https://docs.classiq.io/latest/getting-started/classiq_tutorial/execution_tutorial_part2/) has examples on using this method in variational quantum algorithms.
|
|
369
|
+
More information about [Hamiltonians](https://docs.classiq.io/latest/qmod-reference/language-reference/classical-types/#hamiltonians).
|
|
363
370
|
"""
|
|
364
371
|
_hamiltonian_deprecation_warning(cost_function)
|
|
365
372
|
job = self.submit_minimize(
|
|
@@ -378,11 +385,11 @@ class ExecutionSession:
|
|
|
378
385
|
|
|
379
386
|
def submit_minimize(
|
|
380
387
|
self,
|
|
381
|
-
cost_function:
|
|
388
|
+
cost_function: Hamiltonian | QmodExpressionCreator,
|
|
382
389
|
initial_params: ExecutionParams,
|
|
383
390
|
max_iteration: int,
|
|
384
391
|
quantile: float = 1.0,
|
|
385
|
-
tolerance:
|
|
392
|
+
tolerance: float | None = None,
|
|
386
393
|
*,
|
|
387
394
|
_check_deprecation: bool = True,
|
|
388
395
|
) -> ExecutionJob:
|
|
@@ -416,9 +423,9 @@ class ExecutionSession:
|
|
|
416
423
|
"The initial parameters must be a dictionary with a single key-value pair."
|
|
417
424
|
)
|
|
418
425
|
|
|
419
|
-
_cost_function:
|
|
426
|
+
_cost_function: PauliOperator | Expression
|
|
420
427
|
_initial_params = parse_params(initial_params)
|
|
421
|
-
minimize:
|
|
428
|
+
minimize: MinimizeQuantumCostInput | MinimizeClassicalCostInput
|
|
422
429
|
if callable(cost_function):
|
|
423
430
|
circuit_output_types = self.program.model.circuit_output_types
|
|
424
431
|
_cost_function = self._create_qmod_expression(
|
|
@@ -447,7 +454,7 @@ class ExecutionSession:
|
|
|
447
454
|
def estimate_cost(
|
|
448
455
|
self,
|
|
449
456
|
cost_func: Callable[[ParsedState], float],
|
|
450
|
-
parameters:
|
|
457
|
+
parameters: ExecutionParams | None = None,
|
|
451
458
|
quantile: float = 1.0,
|
|
452
459
|
) -> float:
|
|
453
460
|
"""
|