classiq 0.93.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 +238 -10
- classiq/applications/qsvm/qsvm_data_generation.py +1 -2
- classiq/evaluators/classical_expression.py +0 -4
- classiq/evaluators/parameter_types.py +10 -8
- 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 +6 -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 +5 -3
- classiq/model_expansions/quantum_operations/allocate.py +4 -4
- classiq/model_expansions/quantum_operations/assignment_result_processor.py +2 -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 +2 -2
- 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 +5 -5
- 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 +165 -79
- classiq/qmod/builtins/structs.py +24 -91
- classiq/qmod/cfunc.py +3 -2
- classiq/qmod/classical_function.py +2 -1
- 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 +31 -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/utilities.py +13 -20
- classiq/qmod/write_qmod.py +3 -4
- classiq/quantum_program.py +1 -3
- classiq/synthesis.py +11 -7
- {classiq-0.93.0.dist-info → classiq-0.99.0.dist-info}/METADATA +2 -3
- {classiq-0.93.0.dist-info → classiq-0.99.0.dist-info}/RECORD +271 -299
- {classiq-0.93.0.dist-info → classiq-0.99.0.dist-info}/WHEEL +1 -1
- 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.93.0.dist-info → classiq-0.99.0.dist-info}/licenses/LICENSE.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import copy
|
|
2
|
+
from collections.abc import Callable
|
|
2
3
|
from itertools import chain, product
|
|
3
|
-
from typing import Callable, Union
|
|
4
4
|
|
|
5
5
|
import pyomo.environ as pyo
|
|
6
6
|
from pyomo.core.base.var import VarData
|
|
@@ -25,7 +25,7 @@ def _make_invalid_encoding_type_error(
|
|
|
25
25
|
)
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
def encoding_length(var: VarData, encoding_type:
|
|
28
|
+
def encoding_length(var: VarData, encoding_type: EncodingType | None) -> int:
|
|
29
29
|
if encoding_type is None:
|
|
30
30
|
return 1
|
|
31
31
|
|
|
@@ -172,7 +172,7 @@ class ModelEncoder:
|
|
|
172
172
|
def encode_expr(
|
|
173
173
|
self,
|
|
174
174
|
expr: pyo.Expression,
|
|
175
|
-
substitution_dict:
|
|
175
|
+
substitution_dict: dict[int, pyo.Expression] | None = None,
|
|
176
176
|
) -> pyo.Expression:
|
|
177
177
|
if substitution_dict is None:
|
|
178
178
|
substitution_dict = self.vars_encoding_mapping.substitution_dict
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import copy
|
|
2
|
-
from typing import Union
|
|
3
2
|
|
|
4
3
|
from pyomo.core import ConcreteModel, Var
|
|
5
4
|
from pyomo.core.base.constraint import _GeneralConstraintData
|
|
@@ -125,7 +124,7 @@ def add_fixed_variables_to_solution(
|
|
|
125
124
|
return solution_with_fixed
|
|
126
125
|
|
|
127
126
|
|
|
128
|
-
def _get_value_if_exists(var: VarData) ->
|
|
127
|
+
def _get_value_if_exists(var: VarData) -> int | VarData:
|
|
129
128
|
return var.value if var.value is not None else var
|
|
130
129
|
|
|
131
130
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import dataclasses
|
|
2
2
|
from dataclasses import dataclass
|
|
3
|
-
from typing import Optional
|
|
4
3
|
|
|
5
4
|
from classiq.interface.executor.optimizer_preferences import CostType, OptimizerType
|
|
6
5
|
|
|
@@ -14,10 +13,10 @@ class QAOAConfig:
|
|
|
14
13
|
@dataclass
|
|
15
14
|
class OptimizerConfig:
|
|
16
15
|
opt_type: OptimizerType = OptimizerType.COBYLA
|
|
17
|
-
max_iteration:
|
|
16
|
+
max_iteration: int | None = None
|
|
18
17
|
tolerance: float = 0.0
|
|
19
18
|
step_size: float = 0.0
|
|
20
19
|
skip_compute_variance: bool = False
|
|
21
20
|
cost_type: CostType = CostType.CVAR
|
|
22
21
|
alpha_cvar: float = 1.0
|
|
23
|
-
initial_point:
|
|
22
|
+
initial_point: list[float] | None = dataclasses.field(default=None)
|
classiq/applications/combinatorial_optimization/combinatorial_optimization_model_constructor.py
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
from typing import Optional
|
|
2
|
-
|
|
3
1
|
from pyomo import environ as pyo
|
|
4
2
|
from pyomo.core import Objective, maximize
|
|
5
3
|
|
|
@@ -47,8 +45,8 @@ with set_global_declarative_switch():
|
|
|
47
45
|
|
|
48
46
|
def construct_combi_opt_py_model(
|
|
49
47
|
pyo_model: pyo.ConcreteModel,
|
|
50
|
-
qaoa_config:
|
|
51
|
-
optimizer_config:
|
|
48
|
+
qaoa_config: QAOAConfig | None = None,
|
|
49
|
+
optimizer_config: OptimizerConfig | None = None,
|
|
52
50
|
) -> Model:
|
|
53
51
|
if qaoa_config is None:
|
|
54
52
|
qaoa_config = QAOAConfig()
|
|
@@ -137,8 +135,8 @@ save({{"vqe_result": vqe_result, "hamiltonian": hamiltonian}})
|
|
|
137
135
|
|
|
138
136
|
def construct_combinatorial_optimization_model(
|
|
139
137
|
pyo_model: pyo.ConcreteModel,
|
|
140
|
-
qaoa_config:
|
|
141
|
-
optimizer_config:
|
|
138
|
+
qaoa_config: QAOAConfig | None = None,
|
|
139
|
+
optimizer_config: OptimizerConfig | None = None,
|
|
142
140
|
) -> SerializedModel:
|
|
143
141
|
converted_pyo_model = convert_pyomo_to_global_presentation(pyo_model)
|
|
144
142
|
model = construct_combi_opt_py_model(
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import math
|
|
2
2
|
import re
|
|
3
|
-
from
|
|
3
|
+
from collections.abc import Callable
|
|
4
|
+
from typing import TYPE_CHECKING, cast
|
|
4
5
|
|
|
5
6
|
import numpy as np
|
|
6
|
-
import pandas as pd
|
|
7
7
|
import pyomo.core as pyo
|
|
8
|
-
import scipy
|
|
9
8
|
|
|
10
9
|
from classiq.interface.executor.execution_preferences import ExecutionPreferences
|
|
11
10
|
from classiq.interface.executor.result import ExecutionDetails
|
|
@@ -29,6 +28,9 @@ from classiq.qmod.qmod_parameter import CArray
|
|
|
29
28
|
from classiq.qmod.qmod_variable import Output, QVar
|
|
30
29
|
from classiq.synthesis import synthesize
|
|
31
30
|
|
|
31
|
+
if TYPE_CHECKING:
|
|
32
|
+
import pandas as pd
|
|
33
|
+
|
|
32
34
|
|
|
33
35
|
class CombinatorialProblem:
|
|
34
36
|
def __init__(
|
|
@@ -62,8 +64,8 @@ class CombinatorialProblem:
|
|
|
62
64
|
|
|
63
65
|
def get_model(
|
|
64
66
|
self,
|
|
65
|
-
constraints:
|
|
66
|
-
preferences:
|
|
67
|
+
constraints: Constraints | None = None,
|
|
68
|
+
preferences: Preferences | None = None,
|
|
67
69
|
) -> SerializedModel:
|
|
68
70
|
@qfunc
|
|
69
71
|
def main(
|
|
@@ -93,10 +95,10 @@ class CombinatorialProblem:
|
|
|
93
95
|
|
|
94
96
|
def optimize(
|
|
95
97
|
self,
|
|
96
|
-
execution_preferences:
|
|
98
|
+
execution_preferences: ExecutionPreferences | None = None,
|
|
97
99
|
maxiter: int = 20,
|
|
98
100
|
quantile: float = 1.0,
|
|
99
|
-
initial_params:
|
|
101
|
+
initial_params: list[float] | None = None,
|
|
100
102
|
) -> list[float]:
|
|
101
103
|
if self.qprog_ is None:
|
|
102
104
|
self.get_qprog()
|
|
@@ -131,10 +133,12 @@ class CombinatorialProblem:
|
|
|
131
133
|
self._es = _es
|
|
132
134
|
return _optimized_params
|
|
133
135
|
|
|
134
|
-
def sample_uniform(self) -> pd.DataFrame:
|
|
136
|
+
def sample_uniform(self) -> "pd.DataFrame":
|
|
135
137
|
return self.sample([0] * self.num_layers_ * 2)
|
|
136
138
|
|
|
137
|
-
def sample(self, params: list) -> pd.DataFrame:
|
|
139
|
+
def sample(self, params: list) -> "pd.DataFrame":
|
|
140
|
+
import pandas as pd
|
|
141
|
+
|
|
138
142
|
assert self._es is not None
|
|
139
143
|
res = self._es.sample({"params": params})
|
|
140
144
|
parsed_result = [
|
|
@@ -161,7 +165,7 @@ def execute_qaoa(
|
|
|
161
165
|
cost_func: Callable,
|
|
162
166
|
num_layers: int,
|
|
163
167
|
maxiter: int,
|
|
164
|
-
execution_preferences:
|
|
168
|
+
execution_preferences: ExecutionPreferences | None = None,
|
|
165
169
|
) -> tuple[SerializedModel, QuantumProgram, ExecutionDetails]:
|
|
166
170
|
"""
|
|
167
171
|
Implements a simple QAOA algorithm, including the creation and synthesis of the QAOA
|
|
@@ -178,6 +182,7 @@ def execute_qaoa(
|
|
|
178
182
|
a tuple containing the model of the QAOA ansatz, the corresponding synthesized quantum program,
|
|
179
183
|
and the result of the execution with the optimized parameters
|
|
180
184
|
"""
|
|
185
|
+
import scipy
|
|
181
186
|
|
|
182
187
|
@qfunc
|
|
183
188
|
def main(
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
from typing import Union
|
|
2
|
-
|
|
3
1
|
import numpy as np
|
|
4
2
|
from sympy import fwht
|
|
5
3
|
|
|
@@ -56,7 +54,7 @@ def _coefficents_for_set(mat: np.ndarray, set_index: int) -> list:
|
|
|
56
54
|
|
|
57
55
|
def _get_signed_coefficient(
|
|
58
56
|
c: complex, k: int, i: int, is_hermitian: bool
|
|
59
|
-
) ->
|
|
57
|
+
) -> complex | float:
|
|
60
58
|
# correct from iY to Y
|
|
61
59
|
coef = complex((1j) ** ((i & k).bit_count()) * c)
|
|
62
60
|
if is_hermitian:
|
|
@@ -131,7 +129,7 @@ def _sparse_pauli_to_list(operator: SparsePauliOp) -> list[PauliTerm]:
|
|
|
131
129
|
|
|
132
130
|
# return matrix from hamiltonian
|
|
133
131
|
def hamiltonian_to_matrix(
|
|
134
|
-
hamiltonian:
|
|
132
|
+
hamiltonian: list[PauliTerm] | SparsePauliOp,
|
|
135
133
|
) -> np.ndarray:
|
|
136
134
|
if isinstance(hamiltonian, SparsePauliOp):
|
|
137
135
|
hamiltonian = _sparse_pauli_to_list(hamiltonian)
|
|
@@ -143,3 +141,7 @@ def hamiltonian_to_matrix(
|
|
|
143
141
|
matrix += p.coefficient * pauli_string_to_mat(p.pauli)
|
|
144
142
|
|
|
145
143
|
return matrix
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def pauli_operator_to_matrix(pauli_op: SparsePauliOp) -> np.ndarray:
|
|
147
|
+
return hamiltonian_to_matrix(_sparse_pauli_to_list(pauli_op))
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Literal,
|
|
1
|
+
from typing import Literal, cast
|
|
2
2
|
|
|
3
3
|
from classiq.interface.applications.iqae.generic_iqae import GenericIQAE
|
|
4
4
|
from classiq.interface.applications.iqae.iqae_result import (
|
|
@@ -20,8 +20,10 @@ from classiq.qmod import (
|
|
|
20
20
|
QCallable,
|
|
21
21
|
)
|
|
22
22
|
from classiq.qmod.builtins import Z, allocate, bind, within_apply
|
|
23
|
+
from classiq.qmod.builtins.functions.allocation import drop
|
|
23
24
|
from classiq.qmod.create_model_function import create_model
|
|
24
|
-
from classiq.qmod.qfunc import qfunc
|
|
25
|
+
from classiq.qmod.qfunc import qfunc, qperm
|
|
26
|
+
from classiq.qmod.qmod_variable import Const
|
|
25
27
|
from classiq.synthesis import synthesize
|
|
26
28
|
|
|
27
29
|
|
|
@@ -46,15 +48,15 @@ class IQAE:
|
|
|
46
48
|
self,
|
|
47
49
|
state_prep_op: QCallable[QArray[QBit, Literal["problem_vars_size"]], QBit],
|
|
48
50
|
problem_vars_size: int,
|
|
49
|
-
constraints:
|
|
50
|
-
preferences:
|
|
51
|
+
constraints: Constraints | None = None,
|
|
52
|
+
preferences: Preferences | None = None,
|
|
51
53
|
) -> None:
|
|
52
54
|
self._state_prep_op = state_prep_op
|
|
53
55
|
self._problem_vars_size: int = problem_vars_size
|
|
54
|
-
self._constraints:
|
|
55
|
-
self._preferences:
|
|
56
|
-
self._model:
|
|
57
|
-
self._qprog:
|
|
56
|
+
self._constraints: Constraints | None = constraints
|
|
57
|
+
self._preferences: Preferences | None = preferences
|
|
58
|
+
self._model: SerializedModel | None = None
|
|
59
|
+
self._qprog: QuantumProgram | None = None
|
|
58
60
|
|
|
59
61
|
"""
|
|
60
62
|
Args:
|
|
@@ -83,8 +85,8 @@ class IQAE:
|
|
|
83
85
|
def space_transform(est_reg: QArray) -> None:
|
|
84
86
|
state_prep_op(est_reg[0 : est_reg.len - 1], est_reg[est_reg.len - 1])
|
|
85
87
|
|
|
86
|
-
@
|
|
87
|
-
def oracle(est_reg: QArray) -> None:
|
|
88
|
+
@qperm
|
|
89
|
+
def oracle(est_reg: Const[QArray]) -> None:
|
|
88
90
|
Z(est_reg[est_reg.len - 1])
|
|
89
91
|
|
|
90
92
|
@qfunc
|
|
@@ -105,6 +107,7 @@ class IQAE:
|
|
|
105
107
|
est_reg,
|
|
106
108
|
),
|
|
107
109
|
)
|
|
110
|
+
drop(problem_vars)
|
|
108
111
|
|
|
109
112
|
if self._model is None:
|
|
110
113
|
self._model = create_model(
|
|
@@ -133,7 +136,7 @@ class IQAE:
|
|
|
133
136
|
self,
|
|
134
137
|
epsilon: float,
|
|
135
138
|
alpha: float,
|
|
136
|
-
execution_preferences:
|
|
139
|
+
execution_preferences: ExecutionPreferences | None = None,
|
|
137
140
|
) -> IQAEResult:
|
|
138
141
|
"""
|
|
139
142
|
Executes IQAE's quantum program with the provided epsilon, alpha, and execution
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from abc import ABC, abstractmethod
|
|
2
2
|
from collections.abc import Sequence
|
|
3
|
-
from typing import Literal,
|
|
3
|
+
from typing import Literal, TypeVar
|
|
4
4
|
|
|
5
5
|
from torch import Tensor, tensor
|
|
6
6
|
from torch.utils.data import Dataset
|
|
@@ -16,8 +16,8 @@ class MyDataset(Dataset, ABC):
|
|
|
16
16
|
def __init__(
|
|
17
17
|
self,
|
|
18
18
|
n: int = 2,
|
|
19
|
-
transform:
|
|
20
|
-
target_transform:
|
|
19
|
+
transform: Transform | None = None,
|
|
20
|
+
target_transform: Transform | None = None,
|
|
21
21
|
) -> None:
|
|
22
22
|
self._n = n
|
|
23
23
|
self.transform = transform
|
|
@@ -55,9 +55,9 @@ class MySubsetDataset(MyDataset, ABC):
|
|
|
55
55
|
def __init__(
|
|
56
56
|
self,
|
|
57
57
|
n: int = 2,
|
|
58
|
-
subset:
|
|
59
|
-
transform:
|
|
60
|
-
target_transform:
|
|
58
|
+
subset: list[int] | Literal["all"] = "all",
|
|
59
|
+
transform: Transform | None = None,
|
|
60
|
+
target_transform: Transform | None = None,
|
|
61
61
|
) -> None:
|
|
62
62
|
super().__init__(n, transform, target_transform)
|
|
63
63
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Literal
|
|
1
|
+
from typing import Literal
|
|
2
2
|
|
|
3
3
|
from classiq.applications.qnn.datasets.dataset_base_classes import MySubsetDataset
|
|
4
4
|
from classiq.applications.qnn.types import DataAndLabel, Transform
|
|
@@ -8,10 +8,10 @@ class DatasetSubsetParity(MySubsetDataset):
|
|
|
8
8
|
def __init__(
|
|
9
9
|
self,
|
|
10
10
|
n: int = 2,
|
|
11
|
-
subset:
|
|
11
|
+
subset: list[int] | Literal["all"] = "all",
|
|
12
12
|
add_readout_qubit: bool = True,
|
|
13
|
-
transform:
|
|
14
|
-
target_transform:
|
|
13
|
+
transform: Transform | None = None,
|
|
14
|
+
target_transform: Transform | None = None,
|
|
15
15
|
) -> None:
|
|
16
16
|
super().__init__(n, subset, transform, target_transform)
|
|
17
17
|
|
|
@@ -35,7 +35,7 @@ class DatasetParity(DatasetSubsetParity):
|
|
|
35
35
|
self,
|
|
36
36
|
n: int = 2,
|
|
37
37
|
add_readout_qubit: bool = True,
|
|
38
|
-
transform:
|
|
39
|
-
target_transform:
|
|
38
|
+
transform: Transform | None = None,
|
|
39
|
+
target_transform: Transform | None = None,
|
|
40
40
|
) -> None:
|
|
41
41
|
super().__init__(n, "all", add_readout_qubit, transform, target_transform)
|
|
@@ -59,7 +59,7 @@ def _differentiate_tensor(
|
|
|
59
59
|
# The minus comes from the way pytorch defines diff
|
|
60
60
|
# it diffs the second object minus the first
|
|
61
61
|
# where we want the first minus the second
|
|
62
|
-
diff = -tensor.diff(axis=axis).squeeze(axis)
|
|
62
|
+
diff = -tensor.diff(axis=axis).squeeze(axis)
|
|
63
63
|
return diff / (2 * epsilon)
|
|
64
64
|
|
|
65
65
|
|
|
@@ -2,7 +2,8 @@ import functools
|
|
|
2
2
|
import inspect
|
|
3
3
|
import os
|
|
4
4
|
import typing
|
|
5
|
-
from
|
|
5
|
+
from collections.abc import Callable
|
|
6
|
+
from typing import Any, overload
|
|
6
7
|
|
|
7
8
|
import more_itertools
|
|
8
9
|
import torch
|
|
@@ -41,14 +42,14 @@ from classiq.execution.qnn import _MAX_ARGUMENTS_SIZE, _execute_qnn_sample
|
|
|
41
42
|
|
|
42
43
|
class QLayerFunction(torch.autograd.Function):
|
|
43
44
|
@staticmethod
|
|
44
|
-
def forward(
|
|
45
|
+
def forward(
|
|
45
46
|
ctx: Any,
|
|
46
47
|
inputs: Tensor,
|
|
47
48
|
weights: Tensor,
|
|
48
49
|
quantum_program: QuantumProgram,
|
|
49
50
|
execute: ExecuteFunction,
|
|
50
51
|
post_process: PostProcessFunction,
|
|
51
|
-
epsilon:
|
|
52
|
+
epsilon: float | None = EPSILON,
|
|
52
53
|
) -> Tensor:
|
|
53
54
|
"""
|
|
54
55
|
This function receives:
|
|
@@ -103,9 +104,9 @@ class QLayerFunction(torch.autograd.Function):
|
|
|
103
104
|
)
|
|
104
105
|
|
|
105
106
|
@staticmethod
|
|
106
|
-
def backward(
|
|
107
|
+
def backward(
|
|
107
108
|
ctx: Any, grad_output: Tensor
|
|
108
|
-
) -> tuple[
|
|
109
|
+
) -> tuple[Tensor | None, Tensor | None, None, None, None, None]:
|
|
109
110
|
"""
|
|
110
111
|
grad_output: Tensor
|
|
111
112
|
is of shape (ctx.batch_size, ctx.num_out_features)
|
|
@@ -159,7 +160,7 @@ class QLayer(nn.Module):
|
|
|
159
160
|
execute: ExecuteFunction,
|
|
160
161
|
post_process: PostProcessFunction,
|
|
161
162
|
# Optional parameters:
|
|
162
|
-
head_start:
|
|
163
|
+
head_start: float | Tensor | None = None,
|
|
163
164
|
# Experimental parameters:
|
|
164
165
|
calc_num_out_features: CalcNumOutFeatures = calc_num_out_features_single_output,
|
|
165
166
|
epsilon: float = EPSILON,
|
|
@@ -172,7 +173,7 @@ class QLayer(nn.Module):
|
|
|
172
173
|
post_process: PostProcessFunction,
|
|
173
174
|
/,
|
|
174
175
|
# Optional parameters:
|
|
175
|
-
head_start:
|
|
176
|
+
head_start: float | Tensor | None = None,
|
|
176
177
|
# Experimental parameters:
|
|
177
178
|
calc_num_out_features: CalcNumOutFeatures = calc_num_out_features_single_output,
|
|
178
179
|
epsilon: float = EPSILON,
|
|
@@ -207,7 +208,7 @@ class QLayer(nn.Module):
|
|
|
207
208
|
circuit: Circuit,
|
|
208
209
|
execute: ExecuteFunction,
|
|
209
210
|
post_process: PostProcessFunction,
|
|
210
|
-
head_start:
|
|
211
|
+
head_start: float | Tensor | None = None,
|
|
211
212
|
calc_num_out_features: CalcNumOutFeatures = calc_num_out_features_single_output,
|
|
212
213
|
epsilon: float = EPSILON,
|
|
213
214
|
) -> None:
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
from collections.abc import Sized
|
|
2
2
|
from functools import reduce
|
|
3
|
-
from typing import Optional
|
|
4
3
|
|
|
5
4
|
import torch
|
|
6
5
|
import torch.nn as nn
|
|
@@ -24,7 +23,7 @@ def get_shape_second_dimension(shape: torch.Size) -> int:
|
|
|
24
23
|
if len(shape) == 1:
|
|
25
24
|
return 1
|
|
26
25
|
elif len(shape) == 2:
|
|
27
|
-
return shape[1]
|
|
26
|
+
return shape[1] # type: ignore[index]
|
|
28
27
|
else:
|
|
29
28
|
raise ClassiqValueError("Invalid shape dimension - must be 1D or 2D")
|
|
30
29
|
|
|
@@ -34,7 +33,7 @@ def get_shape_first_dimension(shape: torch.Size) -> int:
|
|
|
34
33
|
raise ClassiqValueError("Invalid shape type - must have `__len__`")
|
|
35
34
|
|
|
36
35
|
if len(shape) in (1, 2):
|
|
37
|
-
return shape[0]
|
|
36
|
+
return shape[0] # type: ignore[index]
|
|
38
37
|
else:
|
|
39
38
|
raise ClassiqValueError("Invalid shape dimension - must be 1D or 2D")
|
|
40
39
|
|
|
@@ -52,8 +51,8 @@ def _result_to_tensor(
|
|
|
52
51
|
all_results: list,
|
|
53
52
|
inputs: Tensor,
|
|
54
53
|
weights: Tensor,
|
|
55
|
-
expected_shape:
|
|
56
|
-
requires_grad:
|
|
54
|
+
expected_shape: Shape | None = None,
|
|
55
|
+
requires_grad: bool | None = None,
|
|
57
56
|
) -> Tensor:
|
|
58
57
|
default_shape = (
|
|
59
58
|
torch.Size([inputs.shape[0]])
|
|
@@ -94,7 +93,7 @@ def iter_inputs_weights(
|
|
|
94
93
|
post_process: PostProcessFunction,
|
|
95
94
|
*,
|
|
96
95
|
expected_shape: Shape = (),
|
|
97
|
-
requires_grad:
|
|
96
|
+
requires_grad: bool | None = None,
|
|
98
97
|
) -> Tensor:
|
|
99
98
|
if is_single_layer_circuit(weights):
|
|
100
99
|
iter_weights = torch.reshape(weights, (1, weights.shape[0]))
|
|
@@ -1,6 +1,24 @@
|
|
|
1
|
-
from .qsp import
|
|
1
|
+
from .qsp import (
|
|
2
|
+
gqsp_phases,
|
|
3
|
+
poly_inversion,
|
|
4
|
+
poly_jacobi_anger_cos,
|
|
5
|
+
poly_jacobi_anger_exp_cos,
|
|
6
|
+
poly_jacobi_anger_exp_sin,
|
|
7
|
+
poly_jacobi_anger_sin,
|
|
8
|
+
qsp_approximate,
|
|
9
|
+
qsvt_phases,
|
|
10
|
+
)
|
|
2
11
|
|
|
3
|
-
__all__ = [
|
|
12
|
+
__all__ = [
|
|
13
|
+
"gqsp_phases",
|
|
14
|
+
"poly_inversion",
|
|
15
|
+
"poly_jacobi_anger_cos",
|
|
16
|
+
"poly_jacobi_anger_exp_cos",
|
|
17
|
+
"poly_jacobi_anger_exp_sin",
|
|
18
|
+
"poly_jacobi_anger_sin",
|
|
19
|
+
"qsp_approximate",
|
|
20
|
+
"qsvt_phases",
|
|
21
|
+
]
|
|
4
22
|
|
|
5
23
|
|
|
6
24
|
def __dir__() -> list[str]:
|