classiq 0.93.0__py3-none-any.whl → 0.94.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.
Potentially problematic release.
This version of classiq might be problematic. Click here for more details.
- classiq/__init__.py +6 -19
- classiq/_analyzer_extras/_ipywidgets_async_extension.py +7 -7
- classiq/_analyzer_extras/interactive_hardware.py +19 -12
- classiq/_internals/api_wrapper.py +38 -52
- classiq/_internals/async_utils.py +4 -7
- classiq/_internals/authentication/auth0.py +3 -3
- classiq/_internals/authentication/device.py +4 -4
- classiq/_internals/authentication/password_manager.py +13 -13
- classiq/_internals/authentication/token_manager.py +4 -5
- classiq/_internals/client.py +17 -44
- classiq/_internals/config.py +1 -2
- 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/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 +8 -8
- classiq/applications/qnn/datasets/dataset_base_classes.py +6 -6
- classiq/applications/qnn/datasets/dataset_parity.py +6 -6
- classiq/applications/qnn/qlayer.py +8 -7
- classiq/applications/qnn/torch_utils.py +3 -4
- classiq/applications/qnn/types.py +2 -1
- classiq/applications/qsp/qsp.py +5 -4
- classiq/applications/qsvm/qsvm_data_generation.py +1 -2
- classiq/evaluators/classical_expression.py +0 -4
- classiq/evaluators/parameter_types.py +7 -8
- classiq/evaluators/qmod_annotated_expression.py +24 -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/classical_function_evaluation.py +4 -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/execution_session.py +18 -19
- classiq/execution/jobs.py +26 -26
- classiq/execution/qnn.py +1 -2
- classiq/execution/user_budgets.py +52 -7
- 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/applications/qsvm.py +5 -8
- classiq/interface/ast_node.py +3 -3
- classiq/interface/backend/backend_preferences.py +16 -16
- classiq/interface/backend/ionq/ionq_quantum_program.py +5 -5
- 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 +7 -7
- classiq/interface/exceptions.py +2 -3
- classiq/interface/execution/iqcc.py +1 -3
- 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 +2 -3
- classiq/interface/executor/vqe_result.py +5 -6
- classiq/interface/generator/ansatz_library.py +6 -8
- classiq/interface/generator/application_apis/__init__.py +0 -2
- 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 +7 -36
- 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 +2 -2
- 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 -20
- 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 -14
- classiq/interface/generator/functions/type_name.py +2 -2
- classiq/interface/generator/generated_circuit_data.py +12 -13
- 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 +8 -8
- 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/qsvm.py +2 -2
- classiq/interface/generator/quantum_function_call.py +8 -11
- classiq/interface/generator/quantum_program.py +12 -15
- 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/state_preparation/state_preparation.py +6 -8
- classiq/interface/generator/synthesis_execution_parameter.py +1 -3
- classiq/interface/generator/synthesis_metadata/synthesis_execution_data.py +2 -3
- classiq/interface/generator/transpiler_basis_gates.py +2 -4
- classiq/interface/generator/types/builtin_enum_declarations.py +0 -136
- 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 -2
- 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 +5 -5
- classiq/interface/jobs.py +3 -3
- classiq/interface/model/allocate.py +4 -4
- classiq/interface/model/block.py +2 -2
- classiq/interface/model/bounds.py +3 -3
- classiq/interface/model/control.py +1 -1
- classiq/interface/model/inplace_binary_operation.py +2 -2
- classiq/interface/model/model.py +4 -4
- classiq/interface/model/parameter.py +1 -3
- classiq/interface/model/port_declaration.py +1 -1
- 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 +4 -4
- classiq/interface/model/quantum_type.py +14 -14
- classiq/interface/model/validation_handle.py +2 -3
- classiq/interface/model/variable_declaration_statement.py +2 -2
- classiq/interface/pretty_print/expression_to_qmod.py +3 -4
- classiq/interface/server/routes.py +0 -4
- classiq/interface/source_reference.py +3 -4
- classiq/model_expansions/arithmetic.py +6 -7
- classiq/model_expansions/arithmetic_compute_result_attrs.py +4 -5
- 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 +1 -4
- classiq/model_expansions/interpreters/base_interpreter.py +2 -6
- 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 +3 -3
- classiq/model_expansions/visitors/uncomputation_signature_inference.py +317 -0
- classiq/model_expansions/visitors/variable_references.py +15 -14
- classiq/open_library/functions/__init__.py +6 -0
- classiq/open_library/functions/discrete_sine_cosine_transform.py +5 -5
- classiq/open_library/functions/grover.py +8 -10
- classiq/open_library/functions/modular_exponentiation.py +96 -8
- classiq/qmod/__init__.py +5 -2
- classiq/qmod/builtins/classical_execution_primitives.py +4 -11
- classiq/qmod/builtins/classical_functions.py +1 -42
- classiq/qmod/builtins/enums.py +0 -136
- classiq/qmod/builtins/functions/__init__.py +0 -13
- classiq/qmod/builtins/functions/allocation.py +4 -4
- classiq/qmod/builtins/functions/arithmetic.py +22 -27
- classiq/qmod/builtins/functions/standard_gates.py +27 -27
- classiq/qmod/builtins/operations.py +35 -58
- classiq/qmod/builtins/structs.py +2 -58
- 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/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 +139 -16
- classiq/qmod/qmod_constant.py +2 -2
- classiq/qmod/qmod_parameter.py +5 -2
- classiq/qmod/qmod_variable.py +47 -43
- classiq/qmod/quantum_callable.py +18 -13
- classiq/qmod/quantum_expandable.py +31 -26
- classiq/qmod/quantum_function.py +51 -32
- classiq/qmod/semantics/annotation/call_annotation.py +2 -2
- classiq/qmod/semantics/error_manager.py +5 -6
- 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 -10
- 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.94.0.dist-info}/METADATA +2 -3
- {classiq-0.93.0.dist-info → classiq-0.94.0.dist-info}/RECORD +238 -260
- 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/evaluators/qmod_expression_visitors/qmod_expression_bwc.py +0 -129
- 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/generator/application_apis/chemistry_declarations.py +0 -69
- classiq/interface/generator/application_apis/entangler_declarations.py +0 -29
- 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/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/ucc.py +0 -74
- classiq/interface/helpers/backward_compatibility.py +0 -9
- classiq/model_expansions/transformers/type_modifier_inference.py +0 -392
- classiq/qmod/builtins/functions/chemistry.py +0 -123
- {classiq-0.93.0.dist-info → classiq-0.94.0.dist-info}/WHEEL +0 -0
- {classiq-0.93.0.dist-info → classiq-0.94.0.dist-info}/licenses/LICENSE.txt +0 -0
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import dataclasses
|
|
2
|
-
from typing import Union
|
|
3
|
-
|
|
4
|
-
from classiq.interface.generator.excitations import EXCITATIONS_TYPE_EXACT
|
|
5
|
-
from classiq.interface.generator.ucc import default_excitation_factory
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
@dataclasses.dataclass
|
|
9
|
-
class UCCParameters:
|
|
10
|
-
excitations: EXCITATIONS_TYPE_EXACT = dataclasses.field(
|
|
11
|
-
default_factory=default_excitation_factory
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
@dataclasses.dataclass
|
|
16
|
-
class HVAParameters:
|
|
17
|
-
reps: int
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
@dataclasses.dataclass
|
|
21
|
-
class HEAParameters:
|
|
22
|
-
reps: int
|
|
23
|
-
num_qubits: int
|
|
24
|
-
connectivity_map: list[tuple[int, int]]
|
|
25
|
-
one_qubit_gates: list[str]
|
|
26
|
-
two_qubit_gates: list[str]
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
AnsatzParameters = Union[UCCParameters, HVAParameters, HEAParameters]
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import dataclasses
|
|
2
|
-
from typing import Optional
|
|
3
|
-
|
|
4
|
-
import numpy as np
|
|
5
|
-
|
|
6
|
-
from classiq.interface.executor.optimizer_preferences import OptimizerType
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
@dataclasses.dataclass
|
|
10
|
-
class ChemistryExecutionParameters:
|
|
11
|
-
optimizer: OptimizerType
|
|
12
|
-
max_iteration: int
|
|
13
|
-
initial_point: Optional[np.ndarray] = dataclasses.field(default=None)
|
|
14
|
-
tolerance: float = dataclasses.field(default=0.0)
|
|
15
|
-
step_size: float = dataclasses.field(default=0.0)
|
|
16
|
-
skip_compute_variance: bool = dataclasses.field(default=False)
|
|
@@ -1,532 +0,0 @@
|
|
|
1
|
-
import warnings
|
|
2
|
-
from collections.abc import Mapping
|
|
3
|
-
from typing import Optional, cast
|
|
4
|
-
|
|
5
|
-
from classiq.interface.chemistry.fermionic_operator import (
|
|
6
|
-
FermionicOperator,
|
|
7
|
-
SummedFermionicOperator,
|
|
8
|
-
)
|
|
9
|
-
from classiq.interface.chemistry.ground_state_problem import (
|
|
10
|
-
CHEMISTRY_PROBLEMS_TYPE,
|
|
11
|
-
HamiltonianProblem,
|
|
12
|
-
MoleculeProblem,
|
|
13
|
-
)
|
|
14
|
-
from classiq.interface.chemistry.molecule import Atom
|
|
15
|
-
from classiq.interface.exceptions import ClassiqDeprecationWarning, ClassiqError
|
|
16
|
-
from classiq.interface.generator.expressions.expression import Expression
|
|
17
|
-
from classiq.interface.generator.function_params import IOName
|
|
18
|
-
from classiq.interface.generator.functions.classical_type import (
|
|
19
|
-
ClassicalArray,
|
|
20
|
-
Real,
|
|
21
|
-
)
|
|
22
|
-
from classiq.interface.generator.functions.port_declaration import (
|
|
23
|
-
PortDeclarationDirection,
|
|
24
|
-
)
|
|
25
|
-
from classiq.interface.generator.functions.type_modifier import TypeModifier
|
|
26
|
-
from classiq.interface.model.allocate import Allocate
|
|
27
|
-
from classiq.interface.model.classical_parameter_declaration import (
|
|
28
|
-
ClassicalParameterDeclaration,
|
|
29
|
-
)
|
|
30
|
-
from classiq.interface.model.handle_binding import HandleBinding
|
|
31
|
-
from classiq.interface.model.model import Model, SerializedModel
|
|
32
|
-
from classiq.interface.model.native_function_definition import NativeFunctionDefinition
|
|
33
|
-
from classiq.interface.model.port_declaration import PortDeclaration
|
|
34
|
-
from classiq.interface.model.quantum_function_call import QuantumFunctionCall
|
|
35
|
-
from classiq.interface.model.quantum_lambda_function import QuantumLambdaFunction
|
|
36
|
-
from classiq.interface.model.quantum_statement import QuantumStatement
|
|
37
|
-
|
|
38
|
-
from classiq.applications.chemistry.ansatz_parameters import (
|
|
39
|
-
AnsatzParameters,
|
|
40
|
-
HEAParameters,
|
|
41
|
-
HVAParameters,
|
|
42
|
-
UCCParameters,
|
|
43
|
-
)
|
|
44
|
-
from classiq.applications.chemistry.chemistry_execution_parameters import (
|
|
45
|
-
ChemistryExecutionParameters,
|
|
46
|
-
)
|
|
47
|
-
from classiq.qmod.builtins.enums import (
|
|
48
|
-
Element,
|
|
49
|
-
FermionMapping,
|
|
50
|
-
)
|
|
51
|
-
from classiq.qmod.builtins.structs import (
|
|
52
|
-
ChemistryAtom as QmodChemistryAtom,
|
|
53
|
-
Molecule as QmodMolecule,
|
|
54
|
-
MoleculeProblem as QmodMoleculeProblem,
|
|
55
|
-
Position as QmodPosition,
|
|
56
|
-
)
|
|
57
|
-
from classiq.qmod.global_declarative_switch import set_global_declarative_switch
|
|
58
|
-
from classiq.qmod.utilities import qmod_val_to_expr_str
|
|
59
|
-
|
|
60
|
-
# isort: split
|
|
61
|
-
|
|
62
|
-
# This import causes a circular import if done earlier. We use isort: split to avoid it
|
|
63
|
-
from classiq.open_library.functions.hea import full_hea
|
|
64
|
-
|
|
65
|
-
with set_global_declarative_switch():
|
|
66
|
-
_FULL_HEA = cast(
|
|
67
|
-
NativeFunctionDefinition, full_hea.create_model().function_dict["full_hea"]
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
_LADDER_OPERATOR_TYPE_INDICATOR_TO_QMOD_MAPPING: dict[str, str] = {
|
|
71
|
-
"+": "PLUS",
|
|
72
|
-
"-": "MINUS",
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
_CHEMISTRY_PROBLEM_PREFIX_MAPPING: dict[type[CHEMISTRY_PROBLEMS_TYPE], str] = {
|
|
76
|
-
MoleculeProblem: "molecule",
|
|
77
|
-
HamiltonianProblem: "fock_hamiltonian",
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
_ANSATZ_PARAMETERS_FUNCTION_NAME_MAPPING: dict[type[AnsatzParameters], str] = {
|
|
81
|
-
UCCParameters: "ucc",
|
|
82
|
-
HVAParameters: "hva",
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
_EXECUTION_RESULT = "vqe_result"
|
|
86
|
-
_MOLECULE_PROBLEM_RESULT = "molecule_result"
|
|
87
|
-
|
|
88
|
-
_HAE_GATE_MAPPING: dict[str, QuantumFunctionCall] = {
|
|
89
|
-
"h": QuantumFunctionCall(
|
|
90
|
-
function="H",
|
|
91
|
-
positional_args=[HandleBinding(name="q")],
|
|
92
|
-
),
|
|
93
|
-
"x": QuantumFunctionCall(
|
|
94
|
-
function="X",
|
|
95
|
-
positional_args=[HandleBinding(name="q")],
|
|
96
|
-
),
|
|
97
|
-
"y": QuantumFunctionCall(
|
|
98
|
-
function="Y",
|
|
99
|
-
positional_args=[HandleBinding(name="q")],
|
|
100
|
-
),
|
|
101
|
-
"z": QuantumFunctionCall(
|
|
102
|
-
function="Z",
|
|
103
|
-
positional_args=[HandleBinding(name="q")],
|
|
104
|
-
),
|
|
105
|
-
"i": QuantumFunctionCall(
|
|
106
|
-
function="I",
|
|
107
|
-
positional_args=[HandleBinding(name="q")],
|
|
108
|
-
),
|
|
109
|
-
"s": QuantumFunctionCall(
|
|
110
|
-
function="S",
|
|
111
|
-
positional_args=[HandleBinding(name="q")],
|
|
112
|
-
),
|
|
113
|
-
"t": QuantumFunctionCall(
|
|
114
|
-
function="T",
|
|
115
|
-
positional_args=[HandleBinding(name="q")],
|
|
116
|
-
),
|
|
117
|
-
"sdg": QuantumFunctionCall(
|
|
118
|
-
function="SDG",
|
|
119
|
-
positional_args=[HandleBinding(name="q")],
|
|
120
|
-
),
|
|
121
|
-
"tdg": QuantumFunctionCall(
|
|
122
|
-
function="TDG",
|
|
123
|
-
positional_args=[HandleBinding(name="q")],
|
|
124
|
-
),
|
|
125
|
-
"p": QuantumFunctionCall(
|
|
126
|
-
function="PHASE",
|
|
127
|
-
positional_args=[HandleBinding(name="q")],
|
|
128
|
-
),
|
|
129
|
-
"rx": QuantumFunctionCall(
|
|
130
|
-
function="RX",
|
|
131
|
-
positional_args=[Expression(expr="angle"), HandleBinding(name="q")],
|
|
132
|
-
),
|
|
133
|
-
"ry": QuantumFunctionCall(
|
|
134
|
-
function="RY",
|
|
135
|
-
positional_args=[Expression(expr="angle"), HandleBinding(name="q")],
|
|
136
|
-
),
|
|
137
|
-
"rz": QuantumFunctionCall(
|
|
138
|
-
function="RZ",
|
|
139
|
-
positional_args=[Expression(expr="angle"), HandleBinding(name="q")],
|
|
140
|
-
),
|
|
141
|
-
"rxx": QuantumFunctionCall(
|
|
142
|
-
function="RXX",
|
|
143
|
-
positional_args=[Expression(expr="angle"), HandleBinding(name="q")],
|
|
144
|
-
),
|
|
145
|
-
"ryy": QuantumFunctionCall(
|
|
146
|
-
function="RYY",
|
|
147
|
-
positional_args=[Expression(expr="angle"), HandleBinding(name="q")],
|
|
148
|
-
),
|
|
149
|
-
"rzz": QuantumFunctionCall(
|
|
150
|
-
function="RZZ",
|
|
151
|
-
positional_args=[Expression(expr="angle"), HandleBinding(name="q")],
|
|
152
|
-
),
|
|
153
|
-
"ch": QuantumFunctionCall(
|
|
154
|
-
function="CH",
|
|
155
|
-
positional_args=[HandleBinding(name="q1"), HandleBinding(name="q2")],
|
|
156
|
-
),
|
|
157
|
-
"cx": QuantumFunctionCall(
|
|
158
|
-
function="CX",
|
|
159
|
-
positional_args=[HandleBinding(name="q1"), HandleBinding(name="q2")],
|
|
160
|
-
),
|
|
161
|
-
"cy": QuantumFunctionCall(
|
|
162
|
-
function="CY",
|
|
163
|
-
positional_args=[HandleBinding(name="q1"), HandleBinding(name="q2")],
|
|
164
|
-
),
|
|
165
|
-
"cz": QuantumFunctionCall(
|
|
166
|
-
function="CZ",
|
|
167
|
-
positional_args=[HandleBinding(name="q1"), HandleBinding(name="q2")],
|
|
168
|
-
),
|
|
169
|
-
"crx": QuantumFunctionCall(
|
|
170
|
-
function="CRX",
|
|
171
|
-
positional_args=[
|
|
172
|
-
Expression(expr="angle"),
|
|
173
|
-
HandleBinding(name="q1"),
|
|
174
|
-
HandleBinding(name="q2"),
|
|
175
|
-
],
|
|
176
|
-
),
|
|
177
|
-
"cry": QuantumFunctionCall(
|
|
178
|
-
function="CRY",
|
|
179
|
-
positional_args=[
|
|
180
|
-
Expression(expr="angle"),
|
|
181
|
-
HandleBinding(name="q1"),
|
|
182
|
-
HandleBinding(name="q2"),
|
|
183
|
-
],
|
|
184
|
-
),
|
|
185
|
-
"crz": QuantumFunctionCall(
|
|
186
|
-
function="CRZ",
|
|
187
|
-
positional_args=[
|
|
188
|
-
Expression(expr="angle"),
|
|
189
|
-
HandleBinding(name="q1"),
|
|
190
|
-
HandleBinding(name="q2"),
|
|
191
|
-
],
|
|
192
|
-
),
|
|
193
|
-
"cp": QuantumFunctionCall(
|
|
194
|
-
function="CPHASE",
|
|
195
|
-
positional_args=[
|
|
196
|
-
Expression(expr="angle"),
|
|
197
|
-
HandleBinding(name="q1"),
|
|
198
|
-
HandleBinding(name="q2"),
|
|
199
|
-
],
|
|
200
|
-
),
|
|
201
|
-
"swap": QuantumFunctionCall(
|
|
202
|
-
function="SWAP",
|
|
203
|
-
positional_args=[HandleBinding(name="q1"), HandleBinding(name="q2")],
|
|
204
|
-
),
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
def _atoms_to_qmod_atoms(atoms: list[Atom]) -> list[QmodChemistryAtom]:
|
|
209
|
-
return [
|
|
210
|
-
QmodChemistryAtom(
|
|
211
|
-
element=Element[atom.symbol], # type:ignore[arg-type]
|
|
212
|
-
position=QmodPosition(
|
|
213
|
-
x=atom.x, # type:ignore[arg-type]
|
|
214
|
-
y=atom.y, # type:ignore[arg-type]
|
|
215
|
-
z=atom.z, # type:ignore[arg-type]
|
|
216
|
-
),
|
|
217
|
-
)
|
|
218
|
-
for atom in atoms
|
|
219
|
-
]
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
def molecule_problem_to_qmod(
|
|
223
|
-
molecule_problem: MoleculeProblem,
|
|
224
|
-
) -> QmodMoleculeProblem:
|
|
225
|
-
return QmodMoleculeProblem(
|
|
226
|
-
mapping=FermionMapping[ # type:ignore[arg-type]
|
|
227
|
-
molecule_problem.mapping.value.upper()
|
|
228
|
-
],
|
|
229
|
-
z2_symmetries=molecule_problem.z2_symmetries, # type:ignore[arg-type]
|
|
230
|
-
molecule=QmodMolecule(
|
|
231
|
-
atoms=_atoms_to_qmod_atoms(
|
|
232
|
-
molecule_problem.molecule.atoms
|
|
233
|
-
), # type:ignore[arg-type]
|
|
234
|
-
spin=molecule_problem.molecule.spin, # type:ignore[arg-type]
|
|
235
|
-
charge=molecule_problem.molecule.charge, # type:ignore[arg-type]
|
|
236
|
-
),
|
|
237
|
-
freeze_core=molecule_problem.freeze_core, # type:ignore[arg-type]
|
|
238
|
-
remove_orbitals=molecule_problem.remove_orbitals, # type:ignore[arg-type]
|
|
239
|
-
)
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
def _fermionic_operator_to_qmod_ladder_ops(
|
|
243
|
-
fermionic_operator: FermionicOperator,
|
|
244
|
-
) -> str:
|
|
245
|
-
return "\n\t\t\t\t\t".join(
|
|
246
|
-
[
|
|
247
|
-
f"struct_literal(LadderOp, op=LadderOperator.{_LADDER_OPERATOR_TYPE_INDICATOR_TO_QMOD_MAPPING[ladder_op[0]]}, index={ladder_op[1]}),"
|
|
248
|
-
for ladder_op in fermionic_operator.op_list
|
|
249
|
-
]
|
|
250
|
-
)[:-1]
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
def _summed_fermionic_operator_to_qmod_lader_terms(
|
|
254
|
-
hamiltonian: SummedFermionicOperator,
|
|
255
|
-
) -> str:
|
|
256
|
-
return "\t\t".join(
|
|
257
|
-
[
|
|
258
|
-
f"""
|
|
259
|
-
struct_literal(LadderTerm,
|
|
260
|
-
coefficient={fermionic_operator[1]},
|
|
261
|
-
ops=[
|
|
262
|
-
{_fermionic_operator_to_qmod_ladder_ops(fermionic_operator[0])}
|
|
263
|
-
]
|
|
264
|
-
),"""
|
|
265
|
-
for fermionic_operator in hamiltonian.op_list
|
|
266
|
-
]
|
|
267
|
-
)[:-1]
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
def _hamiltonian_problem_to_qmod_fock_hamiltonian_problem(
|
|
271
|
-
hamiltonian_problem: HamiltonianProblem,
|
|
272
|
-
) -> str:
|
|
273
|
-
mapping = FermionMapping[hamiltonian_problem.mapping.value.upper()]
|
|
274
|
-
return (
|
|
275
|
-
# fmt: off
|
|
276
|
-
"struct_literal("
|
|
277
|
-
"FockHamiltonianProblem,"
|
|
278
|
-
f"mapping={qmod_val_to_expr_str(mapping)},"
|
|
279
|
-
f"z2_symmetries={hamiltonian_problem.z2_symmetries},"
|
|
280
|
-
f"terms=[{_summed_fermionic_operator_to_qmod_lader_terms(hamiltonian_problem.hamiltonian)}],"
|
|
281
|
-
f"num_particles={hamiltonian_problem.num_particles}"
|
|
282
|
-
")"
|
|
283
|
-
# fmt: on
|
|
284
|
-
)
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
def _convert_library_problem_to_qmod_problem(problem: CHEMISTRY_PROBLEMS_TYPE) -> str:
|
|
288
|
-
if isinstance(problem, MoleculeProblem):
|
|
289
|
-
return qmod_val_to_expr_str(molecule_problem_to_qmod(problem))
|
|
290
|
-
elif isinstance(problem, HamiltonianProblem):
|
|
291
|
-
return _hamiltonian_problem_to_qmod_fock_hamiltonian_problem(problem)
|
|
292
|
-
else:
|
|
293
|
-
raise ClassiqError(f"Invalid problem type: {problem}")
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
def _get_chemistry_function(
|
|
297
|
-
chemistry_problem: CHEMISTRY_PROBLEMS_TYPE,
|
|
298
|
-
chemistry_function_name: str,
|
|
299
|
-
inouts: Mapping[IOName, HandleBinding],
|
|
300
|
-
ansatz_parameters_expressions: Optional[list[Expression]] = None,
|
|
301
|
-
) -> QuantumFunctionCall:
|
|
302
|
-
problem_prefix = _CHEMISTRY_PROBLEM_PREFIX_MAPPING[type(chemistry_problem)]
|
|
303
|
-
return QuantumFunctionCall(
|
|
304
|
-
function=f"{problem_prefix}_{chemistry_function_name}",
|
|
305
|
-
positional_args=[
|
|
306
|
-
Expression(
|
|
307
|
-
expr=_convert_library_problem_to_qmod_problem(chemistry_problem)
|
|
308
|
-
),
|
|
309
|
-
*(ansatz_parameters_expressions or []),
|
|
310
|
-
*inouts.values(),
|
|
311
|
-
],
|
|
312
|
-
)
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
def _get_hartree_fock(
|
|
316
|
-
chemistry_problem: CHEMISTRY_PROBLEMS_TYPE,
|
|
317
|
-
) -> QuantumFunctionCall:
|
|
318
|
-
return _get_chemistry_function(
|
|
319
|
-
chemistry_problem,
|
|
320
|
-
"hartree_fock",
|
|
321
|
-
{"qbv": HandleBinding(name="qbv")},
|
|
322
|
-
)
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
def _get_hea_function(hea_parameters: HEAParameters) -> QuantumFunctionCall:
|
|
326
|
-
return QuantumFunctionCall(
|
|
327
|
-
function="full_hea",
|
|
328
|
-
positional_args=[
|
|
329
|
-
Expression(expr=f"{hea_parameters.num_qubits}"),
|
|
330
|
-
Expression(
|
|
331
|
-
expr=f"{[int(_is_parametric_gate(_HAE_GATE_MAPPING[gate])) for gate in hea_parameters.one_qubit_gates+hea_parameters.two_qubit_gates]}"
|
|
332
|
-
),
|
|
333
|
-
Expression(expr="t"),
|
|
334
|
-
Expression(
|
|
335
|
-
expr=f"{[list(connectivity_pair) for connectivity_pair in hea_parameters.connectivity_map]}"
|
|
336
|
-
),
|
|
337
|
-
Expression(expr=f"{hea_parameters.reps}"),
|
|
338
|
-
[
|
|
339
|
-
QuantumLambdaFunction(
|
|
340
|
-
pos_rename_params=["angle", "q"],
|
|
341
|
-
body=[_HAE_GATE_MAPPING[gate]],
|
|
342
|
-
)
|
|
343
|
-
for gate in hea_parameters.one_qubit_gates
|
|
344
|
-
],
|
|
345
|
-
[
|
|
346
|
-
QuantumLambdaFunction(
|
|
347
|
-
pos_rename_params=["angle", "q1", "q2"],
|
|
348
|
-
body=[_HAE_GATE_MAPPING[gate]],
|
|
349
|
-
)
|
|
350
|
-
for gate in hea_parameters.two_qubit_gates
|
|
351
|
-
],
|
|
352
|
-
HandleBinding(name="qbv"),
|
|
353
|
-
],
|
|
354
|
-
)
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
def _get_ansatz(
|
|
358
|
-
chemistry_problem: CHEMISTRY_PROBLEMS_TYPE,
|
|
359
|
-
ansatz_parameters: AnsatzParameters,
|
|
360
|
-
) -> QuantumFunctionCall:
|
|
361
|
-
if isinstance(ansatz_parameters, HEAParameters):
|
|
362
|
-
return _get_hea_function(ansatz_parameters)
|
|
363
|
-
return _get_chemistry_function(
|
|
364
|
-
chemistry_problem,
|
|
365
|
-
_ANSATZ_PARAMETERS_FUNCTION_NAME_MAPPING[type(ansatz_parameters)],
|
|
366
|
-
{"qbv": HandleBinding(name="qbv")},
|
|
367
|
-
[
|
|
368
|
-
Expression(expr=str(param_value))
|
|
369
|
-
for param_name, param_value in ansatz_parameters.__dict__.items()
|
|
370
|
-
],
|
|
371
|
-
)
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
def _get_chemistry_vqe_additional_params(
|
|
375
|
-
execution_parameters: ChemistryExecutionParameters,
|
|
376
|
-
) -> str:
|
|
377
|
-
return f"""maximize=False,
|
|
378
|
-
initial_point={execution_parameters.initial_point or list()},
|
|
379
|
-
optimizer=Optimizer.{execution_parameters.optimizer.value},
|
|
380
|
-
max_iteration={execution_parameters.max_iteration},
|
|
381
|
-
tolerance={execution_parameters.tolerance or 0},
|
|
382
|
-
step_size={execution_parameters.step_size or 0},
|
|
383
|
-
skip_compute_variance={execution_parameters.skip_compute_variance},
|
|
384
|
-
alpha_cvar=1.0,
|
|
385
|
-
"""
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
def _get_molecule_problem_execution_post_processing(
|
|
389
|
-
molecule_problem: MoleculeProblem,
|
|
390
|
-
) -> str:
|
|
391
|
-
return f"""
|
|
392
|
-
{_MOLECULE_PROBLEM_RESULT} = molecule_ground_state_solution_post_process({qmod_val_to_expr_str(molecule_problem_to_qmod(molecule_problem))},{_EXECUTION_RESULT})
|
|
393
|
-
save({{{_MOLECULE_PROBLEM_RESULT!r}: {_MOLECULE_PROBLEM_RESULT}}})
|
|
394
|
-
"""
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
def _is_parametric_gate(call: QuantumFunctionCall) -> bool:
|
|
398
|
-
# FIXME: call call.params instead (CAD-21568)
|
|
399
|
-
return any(
|
|
400
|
-
arg for arg in call.positional_args if isinstance(arg, Expression)
|
|
401
|
-
) or any(isinstance(arg, Expression) for arg in call.positional_args)
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
def _get_execution_result_post_processing_statements(
|
|
405
|
-
problem: CHEMISTRY_PROBLEMS_TYPE,
|
|
406
|
-
) -> str:
|
|
407
|
-
if isinstance(problem, MoleculeProblem):
|
|
408
|
-
return _get_molecule_problem_execution_post_processing(problem)
|
|
409
|
-
elif isinstance(problem, HamiltonianProblem):
|
|
410
|
-
return ""
|
|
411
|
-
else:
|
|
412
|
-
raise ClassiqError(f"Invalid problem type: {problem}")
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
def _count_parametric_gates(gates: list[str]) -> int:
|
|
416
|
-
return sum(_is_parametric_gate(_HAE_GATE_MAPPING[gate]) for gate in gates)
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
def _get_hea_port_size(hea_parameters: HEAParameters) -> int:
|
|
420
|
-
return hea_parameters.reps * (
|
|
421
|
-
hea_parameters.num_qubits
|
|
422
|
-
* _count_parametric_gates(hea_parameters.one_qubit_gates)
|
|
423
|
-
+ len(hea_parameters.connectivity_map)
|
|
424
|
-
* _count_parametric_gates(hea_parameters.two_qubit_gates)
|
|
425
|
-
)
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
def _get_chemistry_quantum_main_params(
|
|
429
|
-
ansatz_parameters: AnsatzParameters,
|
|
430
|
-
) -> list[ClassicalParameterDeclaration]:
|
|
431
|
-
if not isinstance(ansatz_parameters, HEAParameters):
|
|
432
|
-
return []
|
|
433
|
-
return [
|
|
434
|
-
ClassicalParameterDeclaration(
|
|
435
|
-
name="t",
|
|
436
|
-
classical_type=ClassicalArray(
|
|
437
|
-
element_type=Real(),
|
|
438
|
-
length=Expression(expr=str(_get_hea_port_size(ansatz_parameters))),
|
|
439
|
-
),
|
|
440
|
-
),
|
|
441
|
-
]
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
def _get_problem_to_hamiltonian_name(chemistry_problem: CHEMISTRY_PROBLEMS_TYPE) -> str:
|
|
445
|
-
problem_prefix = _CHEMISTRY_PROBLEM_PREFIX_MAPPING[type(chemistry_problem)]
|
|
446
|
-
return f"{problem_prefix}_problem_to_hamiltonian"
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
def _get_chemistry_quantum_main(
|
|
450
|
-
chemistry_problem: CHEMISTRY_PROBLEMS_TYPE,
|
|
451
|
-
use_hartree_fock: bool,
|
|
452
|
-
ansatz_parameters: AnsatzParameters,
|
|
453
|
-
) -> NativeFunctionDefinition:
|
|
454
|
-
body: list[QuantumStatement] = []
|
|
455
|
-
body.append(
|
|
456
|
-
Allocate(
|
|
457
|
-
size=Expression(
|
|
458
|
-
expr=f"{_get_problem_to_hamiltonian_name(chemistry_problem)}({_convert_library_problem_to_qmod_problem(chemistry_problem)})[0].pauli.len"
|
|
459
|
-
),
|
|
460
|
-
target=HandleBinding(name="qbv"),
|
|
461
|
-
),
|
|
462
|
-
)
|
|
463
|
-
if use_hartree_fock:
|
|
464
|
-
body.append(_get_hartree_fock(chemistry_problem))
|
|
465
|
-
|
|
466
|
-
body.append(_get_ansatz(chemistry_problem, ansatz_parameters))
|
|
467
|
-
|
|
468
|
-
return NativeFunctionDefinition(
|
|
469
|
-
name="main",
|
|
470
|
-
positional_arg_declarations=_get_chemistry_quantum_main_params(
|
|
471
|
-
ansatz_parameters
|
|
472
|
-
)
|
|
473
|
-
+ [
|
|
474
|
-
PortDeclaration(
|
|
475
|
-
name="qbv",
|
|
476
|
-
direction=PortDeclarationDirection.Output,
|
|
477
|
-
type_modifier=TypeModifier.Mutable,
|
|
478
|
-
)
|
|
479
|
-
],
|
|
480
|
-
body=body,
|
|
481
|
-
)
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
def _get_chemistry_classical_code(
|
|
485
|
-
chemistry_problem: CHEMISTRY_PROBLEMS_TYPE,
|
|
486
|
-
execution_parameters: ChemistryExecutionParameters,
|
|
487
|
-
) -> str:
|
|
488
|
-
qmod_problem = _convert_library_problem_to_qmod_problem(chemistry_problem)
|
|
489
|
-
return (
|
|
490
|
-
f"""
|
|
491
|
-
{_EXECUTION_RESULT} = vqe(
|
|
492
|
-
hamiltonian={_get_problem_to_hamiltonian_name(chemistry_problem)}({qmod_problem}), {_get_chemistry_vqe_additional_params(execution_parameters)}
|
|
493
|
-
)
|
|
494
|
-
save({{{_EXECUTION_RESULT!r}: {_EXECUTION_RESULT}}})
|
|
495
|
-
"""
|
|
496
|
-
+ _get_execution_result_post_processing_statements(chemistry_problem)
|
|
497
|
-
).strip()
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
def construct_chemistry_model(
|
|
501
|
-
chemistry_problem: CHEMISTRY_PROBLEMS_TYPE,
|
|
502
|
-
use_hartree_fock: bool,
|
|
503
|
-
ansatz_parameters: AnsatzParameters,
|
|
504
|
-
execution_parameters: ChemistryExecutionParameters,
|
|
505
|
-
) -> SerializedModel:
|
|
506
|
-
warnings.warn(
|
|
507
|
-
(
|
|
508
|
-
"The function `construct_chemistry_model` is deprecated and will no "
|
|
509
|
-
"longer be supported starting on 2025-09-18 at the earliest. "
|
|
510
|
-
"For more information on Classiq's chemistry application, see "
|
|
511
|
-
"https://docs.classiq.io/latest/explore/applications/chemistry/classiq_chemistry_application/classiq_chemistry_application/."
|
|
512
|
-
),
|
|
513
|
-
category=ClassiqDeprecationWarning,
|
|
514
|
-
stacklevel=2,
|
|
515
|
-
)
|
|
516
|
-
|
|
517
|
-
chemistry_functions = [
|
|
518
|
-
_get_chemistry_quantum_main(
|
|
519
|
-
chemistry_problem,
|
|
520
|
-
use_hartree_fock,
|
|
521
|
-
ansatz_parameters,
|
|
522
|
-
)
|
|
523
|
-
]
|
|
524
|
-
if isinstance(ansatz_parameters, HEAParameters):
|
|
525
|
-
chemistry_functions.append(_FULL_HEA)
|
|
526
|
-
model = Model(
|
|
527
|
-
functions=chemistry_functions,
|
|
528
|
-
classical_execution_code=_get_chemistry_classical_code(
|
|
529
|
-
chemistry_problem, execution_parameters
|
|
530
|
-
),
|
|
531
|
-
)
|
|
532
|
-
return model.get_model()
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
from typing import Optional
|
|
2
|
-
|
|
3
|
-
from classiq.interface.chemistry import ground_state_problem
|
|
4
|
-
from classiq.interface.chemistry.ground_state_problem import (
|
|
5
|
-
CHEMISTRY_PROBLEMS_TYPE,
|
|
6
|
-
HamiltonianProblem,
|
|
7
|
-
)
|
|
8
|
-
from classiq.interface.chemistry.operator import PauliOperator
|
|
9
|
-
|
|
10
|
-
from classiq._internals import async_utils
|
|
11
|
-
from classiq._internals.api_wrapper import ApiWrapper
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
async def generate_hamiltonian_async(
|
|
15
|
-
problem: CHEMISTRY_PROBLEMS_TYPE,
|
|
16
|
-
) -> PauliOperator:
|
|
17
|
-
return await ApiWrapper.call_generate_hamiltonian_task(problem)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
ground_state_problem.GroundStateProblem.generate_hamiltonian = async_utils.syncify_function(generate_hamiltonian_async) # type: ignore[attr-defined]
|
|
21
|
-
ground_state_problem.GroundStateProblem.generate_hamiltonian_async = generate_hamiltonian_async # type: ignore[attr-defined]
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
async def _get_num_qubits(problem: CHEMISTRY_PROBLEMS_TYPE) -> int:
|
|
25
|
-
if isinstance(problem, HamiltonianProblem) and not problem.z2_symmetries:
|
|
26
|
-
return problem.hamiltonian.num_qubits
|
|
27
|
-
hamiltonian = await generate_hamiltonian_async(problem)
|
|
28
|
-
return hamiltonian.num_qubits
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
async def update_problem_async(
|
|
32
|
-
problem: CHEMISTRY_PROBLEMS_TYPE, num_qubits: Optional[int] = None
|
|
33
|
-
) -> CHEMISTRY_PROBLEMS_TYPE:
|
|
34
|
-
if num_qubits is None:
|
|
35
|
-
num_qubits = await _get_num_qubits(problem)
|
|
36
|
-
return problem.model_copy(update={"num_qubits": num_qubits})
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
ground_state_problem.GroundStateProblem.update_problem = async_utils.syncify_function( # type: ignore[attr-defined]
|
|
40
|
-
update_problem_async
|
|
41
|
-
)
|
|
42
|
-
ground_state_problem.GroundStateProblem.update_problem_async = update_problem_async # type: ignore[attr-defined]
|