classiq 0.38.0__py3-none-any.whl → 0.39.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- classiq/__init__.py +21 -22
- classiq/_internals/api_wrapper.py +13 -1
- classiq/_internals/client.py +12 -2
- classiq/analyzer/analyzer.py +3 -1
- classiq/applications/__init__.py +1 -8
- classiq/applications/chemistry/__init__.py +6 -0
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/arithmetic/arithmetic_expression.py +1 -1
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/combinatorial_problem_utils.py +26 -6
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/encoding_mapping.py +1 -1
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/encoding_utils.py +1 -1
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/memory.py +2 -4
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/optimization_model.py +6 -10
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/pauli_helpers/pauli_utils.py +10 -0
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/pyomo_utils.py +4 -2
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/transformations/encoding.py +3 -10
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/transformations/fixed_variables.py +4 -6
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/transformations/ising_converter.py +3 -5
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/transformations/penalty_support.py +3 -7
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/transformations/slack_variables.py +4 -6
- classiq/applications/combinatorial_optimization/__init__.py +9 -3
- classiq/{applications_model_constructors → applications/combinatorial_optimization}/combinatorial_optimization_model_constructor.py +7 -8
- classiq/applications/finance/__init__.py +3 -2
- classiq/{applications_model_constructors → applications/finance}/finance_model_constructor.py +24 -14
- classiq/applications/grover/__init__.py +11 -0
- classiq/applications/libraries/qmci_library.py +35 -0
- classiq/applications/qsvm/__init__.py +5 -1
- classiq/execution/all_hardware_devices.py +13 -0
- classiq/executor.py +2 -1
- classiq/interface/_version.py +1 -1
- classiq/interface/analyzer/result.py +1 -5
- classiq/interface/applications/qsvm.py +4 -2
- classiq/interface/ast_node.py +23 -0
- classiq/interface/combinatorial_optimization/examples/mht.py +8 -3
- classiq/interface/executor/execution_request.py +2 -37
- classiq/interface/executor/vqe_result.py +1 -1
- classiq/interface/generator/builtin_api_builder.py +0 -5
- classiq/interface/generator/constant.py +2 -3
- classiq/interface/generator/expressions/expression.py +2 -4
- classiq/interface/generator/expressions/qmod_qscalar_proxy.py +1 -1
- classiq/interface/generator/functions/__init__.py +2 -2
- classiq/interface/generator/functions/builtins/__init__.py +15 -0
- classiq/interface/generator/functions/builtins/core_library/__init__.py +14 -0
- classiq/interface/generator/functions/builtins/internal_operators.py +62 -0
- classiq/interface/generator/functions/{core_lib_declarations/quantum_functions/std_lib_functions.py → builtins/open_lib_functions.py} +109 -83
- classiq/interface/generator/functions/builtins/quantum_operators.py +37 -0
- classiq/interface/generator/functions/classical_type.py +2 -4
- classiq/interface/generator/functions/function_declaration.py +2 -2
- classiq/interface/generator/hartree_fock.py +10 -2
- classiq/interface/generator/model/classical_main_validator.py +1 -1
- classiq/interface/generator/model/model.py +1 -1
- classiq/interface/generator/quantum_function_call.py +1 -1
- classiq/interface/generator/types/struct_declaration.py +2 -4
- classiq/interface/model/call_synthesis_data.py +3 -3
- classiq/interface/model/classical_if.py +13 -0
- classiq/interface/model/classical_parameter_declaration.py +2 -3
- classiq/interface/model/control.py +16 -0
- classiq/interface/model/handle_binding.py +3 -2
- classiq/interface/model/invert.py +10 -0
- classiq/interface/model/model.py +2 -1
- classiq/interface/model/power.py +12 -0
- classiq/interface/model/quantum_function_call.py +9 -4
- classiq/interface/model/quantum_if_operation.py +3 -3
- classiq/interface/model/quantum_lambda_function.py +3 -9
- classiq/interface/model/quantum_statement.py +3 -2
- classiq/interface/model/quantum_type.py +2 -4
- classiq/interface/model/quantum_variable_declaration.py +2 -2
- classiq/interface/model/repeat.py +13 -0
- classiq/interface/model/resolvers/function_call_resolver.py +26 -0
- classiq/interface/model/statement_block.py +21 -4
- classiq/interface/model/validations/handles_validator.py +8 -12
- classiq/interface/model/within_apply_operation.py +4 -4
- classiq/interface/server/routes.py +0 -4
- classiq/qmod/builtins/classical_functions.py +9 -9
- classiq/qmod/builtins/functions.py +153 -226
- classiq/qmod/builtins/operations.py +160 -13
- classiq/qmod/native/pretty_printer.py +49 -20
- classiq/qmod/qmod_constant.py +26 -2
- classiq/qmod/qmod_parameter.py +2 -1
- classiq/qmod/qmod_variable.py +48 -15
- classiq/qmod/quantum_callable.py +1 -0
- classiq/qmod/quantum_expandable.py +6 -7
- classiq/qmod/quantum_function.py +4 -0
- classiq/qmod/symbolic.py +2 -2
- {classiq-0.38.0.dist-info → classiq-0.39.0.dist-info}/METADATA +1 -1
- {classiq-0.38.0.dist-info → classiq-0.39.0.dist-info}/RECORD +107 -124
- classiq/applications/benchmarking/__init__.py +0 -9
- classiq/applications/benchmarking/mirror_benchmarking.py +0 -70
- classiq/applications/numpy_utils.py +0 -37
- classiq/applications_model_constructors/__init__.py +0 -25
- classiq/applications_model_constructors/combinatorial_helpers/multiple_comp_basis_sp.py +0 -34
- classiq/applications_model_constructors/libraries/qmci_library.py +0 -107
- classiq/builtin_functions/__init__.py +0 -43
- classiq/builtin_functions/amplitude_loading.py +0 -3
- classiq/builtin_functions/binary_ops.py +0 -1
- classiq/builtin_functions/exponentiation.py +0 -5
- classiq/builtin_functions/qpe.py +0 -4
- classiq/builtin_functions/qsvm.py +0 -7
- classiq/builtin_functions/range_types.py +0 -5
- classiq/builtin_functions/standard_gates.py +0 -1
- classiq/builtin_functions/state_preparation.py +0 -6
- classiq/builtin_functions/suzuki_trotter.py +0 -3
- classiq/interface/generator/functions/core_lib_declarations/quantum_functions/__init__.py +0 -18
- classiq/interface/generator/functions/core_lib_declarations/quantum_operators.py +0 -95
- classiq/model/__init__.py +0 -14
- classiq/model/composite_function_generator.py +0 -33
- classiq/model/function_handler.py +0 -462
- classiq/model/logic_flow.py +0 -149
- classiq/model/logic_flow_change_handler.py +0 -71
- classiq/model/model.py +0 -229
- classiq/quantum_functions/__init__.py +0 -17
- classiq/quantum_functions/annotation_parser.py +0 -205
- classiq/quantum_functions/decorators.py +0 -22
- classiq/quantum_functions/function_library.py +0 -181
- classiq/quantum_functions/function_parser.py +0 -74
- classiq/quantum_functions/quantum_function.py +0 -236
- /classiq/{applications_model_constructors → applications/chemistry}/chemistry_model_constructor.py +0 -0
- /classiq/{applications_model_constructors → applications}/combinatorial_helpers/__init__.py +0 -0
- /classiq/{applications_model_constructors → applications}/combinatorial_helpers/allowed_constraints.py +0 -0
- /classiq/{applications_model_constructors → applications}/combinatorial_helpers/arithmetic/__init__.py +0 -0
- /classiq/{applications_model_constructors → applications}/combinatorial_helpers/arithmetic/isolation.py +0 -0
- /classiq/{applications_model_constructors → applications}/combinatorial_helpers/pauli_helpers/__init__.py +0 -0
- /classiq/{applications_model_constructors → applications}/combinatorial_helpers/pauli_helpers/pauli_sparsing.py +0 -0
- /classiq/{applications_model_constructors → applications}/combinatorial_helpers/py.typed +0 -0
- /classiq/{applications_model_constructors/combinatorial_helpers/transformations → applications/combinatorial_helpers/solvers}/__init__.py +0 -0
- /classiq/{applications_model_constructors → applications}/combinatorial_helpers/sympy_utils.py +0 -0
- /classiq/{applications_model_constructors/libraries → applications/combinatorial_helpers/transformations}/__init__.py +0 -0
- /classiq/{applications_model_constructors → applications}/combinatorial_helpers/transformations/penalty.py +0 -0
- /classiq/{applications_model_constructors → applications}/combinatorial_helpers/transformations/sign_seperation.py +0 -0
- /classiq/{applications_model_constructors → applications/grover}/grover_model_constructor.py +0 -0
- /classiq/{interface/generator/functions/core_lib_declarations → applications/libraries}/__init__.py +0 -0
- /classiq/{applications_model_constructors → applications}/libraries/ampltitude_estimation_library.py +0 -0
- /classiq/{applications_model_constructors → applications/qsvm}/qsvm_model_constructor.py +0 -0
- /classiq/interface/generator/functions/{core_lib_declarations/quantum_functions → builtins/core_library}/atomic_quantum_functions.py +0 -0
- /classiq/interface/generator/functions/{core_lib_declarations/quantum_functions → builtins/core_library}/chemistry_functions.py +0 -0
- /classiq/interface/generator/functions/{core_lib_declarations/quantum_functions → builtins/core_library}/exponentiation_functions.py +0 -0
- /classiq/{quantum_register.py → interface/model/quantum_register.py} +0 -0
- {classiq-0.38.0.dist-info → classiq-0.39.0.dist-info}/WHEEL +0 -0
classiq/__init__.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
"""Classiq SDK."""
|
2
2
|
|
3
|
-
import sys
|
4
3
|
from typing import List
|
5
4
|
|
6
5
|
from classiq.interface._version import VERSION as _VERSION
|
@@ -13,17 +12,12 @@ from classiq.interface.generator.control_state import ControlState
|
|
13
12
|
from classiq.interface.generator.expressions.enums.pauli import Pauli
|
14
13
|
from classiq.interface.generator.functions import * # noqa: F403
|
15
14
|
from classiq.interface.generator.functions import __all__ as _ifunc_all
|
15
|
+
from classiq.interface.generator.model import * # noqa: F403
|
16
|
+
from classiq.interface.generator.model import __all__ as _md_all
|
16
17
|
from classiq.interface.generator.quantum_program import QuantumProgram
|
17
18
|
from classiq.interface.ide.show import show
|
18
19
|
|
19
|
-
from classiq import
|
20
|
-
applications,
|
21
|
-
builtin_functions,
|
22
|
-
exceptions,
|
23
|
-
execution,
|
24
|
-
model,
|
25
|
-
synthesis,
|
26
|
-
)
|
20
|
+
from classiq import applications, exceptions, execution, synthesis
|
27
21
|
from classiq._internals import _qfunc_ext, logger
|
28
22
|
from classiq._internals.async_utils import (
|
29
23
|
enable_jupyter_notebook,
|
@@ -34,23 +28,23 @@ from classiq._internals.client import configure
|
|
34
28
|
from classiq._internals.config import Configuration
|
35
29
|
from classiq._internals.help import open_help
|
36
30
|
from classiq.analyzer import Analyzer
|
37
|
-
from classiq.
|
38
|
-
|
39
|
-
|
31
|
+
from classiq.applications.chemistry import (
|
32
|
+
construct_chemistry_model,
|
33
|
+
molecule_problem_to_qmod,
|
34
|
+
)
|
35
|
+
from classiq.applications.combinatorial_optimization import (
|
36
|
+
construct_combinatorial_optimization_model,
|
40
37
|
)
|
38
|
+
from classiq.applications.finance import construct_finance_model
|
39
|
+
from classiq.applications.grover import construct_grover_model
|
40
|
+
from classiq.applications.qsvm import construct_qsvm_model
|
41
41
|
from classiq.executor import (
|
42
42
|
execute,
|
43
43
|
execute_async,
|
44
44
|
set_quantum_program_execution_preferences,
|
45
45
|
)
|
46
|
-
from classiq.model import * # noqa: F403
|
47
|
-
from classiq.model import __all__ as _md_all
|
48
46
|
from classiq.qmod import * # noqa: F403
|
49
47
|
from classiq.qmod import __all__ as _qmod_all
|
50
|
-
from classiq.quantum_functions import * # noqa: F403
|
51
|
-
from classiq.quantum_functions import __all__ as _qfuncs_all
|
52
|
-
from classiq.quantum_register import * # noqa: F403
|
53
|
-
from classiq.quantum_register import __all__ as _qregs_all
|
54
48
|
from classiq.synthesis import (
|
55
49
|
set_constraints,
|
56
50
|
set_execution_preferences,
|
@@ -59,6 +53,15 @@ from classiq.synthesis import (
|
|
59
53
|
synthesize_async,
|
60
54
|
)
|
61
55
|
|
56
|
+
_application_constructors_all = [
|
57
|
+
"construct_qsvm_model",
|
58
|
+
"construct_combinatorial_optimization_model",
|
59
|
+
"construct_chemistry_model",
|
60
|
+
"construct_finance_model",
|
61
|
+
"construct_grover_model",
|
62
|
+
"molecule_problem_to_qmod",
|
63
|
+
]
|
64
|
+
|
62
65
|
__version__ = _VERSION
|
63
66
|
|
64
67
|
if _is_notebook():
|
@@ -67,10 +70,8 @@ if _is_notebook():
|
|
67
70
|
_sub_modules = [
|
68
71
|
"analyzer",
|
69
72
|
"applications",
|
70
|
-
"builtin_functions",
|
71
73
|
"exceptions",
|
72
74
|
"execution",
|
73
|
-
"model",
|
74
75
|
"open_help",
|
75
76
|
"qmod",
|
76
77
|
"synthesis",
|
@@ -95,8 +96,6 @@ __all__ = (
|
|
95
96
|
"show",
|
96
97
|
"Pauli",
|
97
98
|
]
|
98
|
-
+ _qregs_all
|
99
|
-
+ _qfuncs_all
|
100
99
|
+ _md_all
|
101
100
|
+ _ifunc_all
|
102
101
|
+ _sub_modules
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import json
|
2
|
-
from typing import Dict, Optional, Protocol, Type, TypeVar
|
2
|
+
from typing import Dict, List, Optional, Protocol, Type, TypeVar
|
3
3
|
|
4
4
|
import pydantic
|
5
5
|
|
@@ -14,6 +14,7 @@ from classiq.interface.execution.jobs import (
|
|
14
14
|
)
|
15
15
|
from classiq.interface.executor import execution_request, result as execute_result
|
16
16
|
from classiq.interface.generator import quantum_program as generator_result
|
17
|
+
from classiq.interface.hardware import HardwareInformation
|
17
18
|
from classiq.interface.jobs import (
|
18
19
|
JobDescriptionBase,
|
19
20
|
JobDescriptionFailure,
|
@@ -297,6 +298,17 @@ class ApiWrapper:
|
|
297
298
|
)
|
298
299
|
return analysis_result.DevicesResult.parse_obj(data)
|
299
300
|
|
301
|
+
@classmethod
|
302
|
+
async def call_get_all_hardware_devices(cls) -> List[HardwareInformation]:
|
303
|
+
data = await client().call_api(
|
304
|
+
http_method=HTTPMethod.GET,
|
305
|
+
url="/hardware-catalog/v1/hardwares",
|
306
|
+
use_versioned_url=False,
|
307
|
+
)
|
308
|
+
if not isinstance(data, list):
|
309
|
+
raise ClassiqAPIError(f"Unexpected value: {data}")
|
310
|
+
return [HardwareInformation.parse_obj(info) for info in data]
|
311
|
+
|
300
312
|
@classmethod
|
301
313
|
async def call_generate_hamiltonian_task(
|
302
314
|
cls, problem: ground_state_problem.CHEMISTRY_PROBLEMS_TYPE
|
classiq/_internals/client.py
CHANGED
@@ -6,7 +6,17 @@ import os
|
|
6
6
|
import platform
|
7
7
|
import ssl
|
8
8
|
import sys
|
9
|
-
from typing import
|
9
|
+
from typing import (
|
10
|
+
Any,
|
11
|
+
Awaitable,
|
12
|
+
Callable,
|
13
|
+
Dict,
|
14
|
+
List,
|
15
|
+
NoReturn,
|
16
|
+
Optional,
|
17
|
+
TypeVar,
|
18
|
+
Union,
|
19
|
+
)
|
10
20
|
|
11
21
|
import httpx
|
12
22
|
from packaging.version import Version
|
@@ -214,7 +224,7 @@ class Client:
|
|
214
224
|
params: Optional[Dict] = None,
|
215
225
|
use_versioned_url: bool = True,
|
216
226
|
headers: Optional[Dict[str, str]] = None,
|
217
|
-
) -> Union[Dict, str]:
|
227
|
+
) -> Union[Dict, List, str]:
|
218
228
|
if use_versioned_url:
|
219
229
|
url = self.make_versioned_url(url)
|
220
230
|
async with self.async_client() as async_client:
|
classiq/analyzer/analyzer.py
CHANGED
@@ -81,7 +81,9 @@ class Analyzer(AnalyzerUtilities):
|
|
81
81
|
def get_available_devices(
|
82
82
|
self, providers: Optional[List[ProviderNameEnum]] = None
|
83
83
|
) -> Dict[ProviderNameEnum, List[DeviceName]]:
|
84
|
-
"""
|
84
|
+
"""Deprecated. Use get_all_hardware_devices instead.
|
85
|
+
|
86
|
+
Returns dict of the available devices by the providers. only devices
|
85
87
|
with sufficient number of qubits are returns
|
86
88
|
|
87
89
|
Args: providers (): List of providers (string or `AnalyzerProviderVendor`).
|
classiq/applications/__init__.py
CHANGED
@@ -1,15 +1,8 @@
|
|
1
1
|
from typing import List
|
2
2
|
|
3
|
-
from classiq.applications import
|
4
|
-
benchmarking,
|
5
|
-
chemistry,
|
6
|
-
combinatorial_optimization,
|
7
|
-
finance,
|
8
|
-
qsvm,
|
9
|
-
)
|
3
|
+
from classiq.applications import chemistry, combinatorial_optimization, finance, qsvm
|
10
4
|
|
11
5
|
__all__ = [
|
12
|
-
"benchmarking",
|
13
6
|
"combinatorial_optimization",
|
14
7
|
"chemistry",
|
15
8
|
"finance",
|
@@ -15,6 +15,10 @@ from classiq.interface.chemistry.operator import PauliOperator, PauliOperators
|
|
15
15
|
from . import ground_state_problem
|
16
16
|
from .ansatz_parameters import HEAParameters, HVAParameters, UCCParameters
|
17
17
|
from .chemistry_execution_parameters import ChemistryExecutionParameters
|
18
|
+
from .chemistry_model_constructor import (
|
19
|
+
construct_chemistry_model,
|
20
|
+
molecule_problem_to_qmod,
|
21
|
+
)
|
18
22
|
|
19
23
|
__all__ = [
|
20
24
|
"Molecule",
|
@@ -29,6 +33,8 @@ __all__ = [
|
|
29
33
|
"HVAParameters",
|
30
34
|
"HEAParameters",
|
31
35
|
"ChemistryExecutionParameters",
|
36
|
+
"construct_chemistry_model",
|
37
|
+
"molecule_problem_to_qmod",
|
32
38
|
]
|
33
39
|
|
34
40
|
|
@@ -5,7 +5,7 @@ from pyomo.core.expr.sympy_tools import PyomoSympyBimap
|
|
5
5
|
from scipy.optimize import differential_evolution
|
6
6
|
from sympy import Expr
|
7
7
|
|
8
|
-
from classiq.
|
8
|
+
from classiq.applications.combinatorial_helpers import encoding_utils
|
9
9
|
|
10
10
|
|
11
11
|
def sympy_lambdify(*args: Any, **kwargs: Any) -> Any:
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import itertools
|
2
|
-
from typing import List, Union
|
2
|
+
from typing import List, Union, cast
|
3
3
|
|
4
4
|
import numpy as np
|
5
5
|
import pyomo.environ as pyo
|
@@ -9,16 +9,19 @@ from classiq.interface.combinatorial_optimization.solver_types import QSolver
|
|
9
9
|
from classiq.interface.executor.vqe_result import VQESolverResult
|
10
10
|
from classiq.interface.generator.functions.qmod_python_interface import QmodPyStruct
|
11
11
|
|
12
|
-
from classiq.
|
12
|
+
from classiq.applications.combinatorial_helpers.optimization_model import (
|
13
13
|
OptimizationModel,
|
14
14
|
)
|
15
|
-
from classiq.
|
15
|
+
from classiq.applications.combinatorial_helpers.pauli_helpers.pauli_sparsing import (
|
16
16
|
SparsePauliOp,
|
17
17
|
)
|
18
|
-
from classiq.
|
18
|
+
from classiq.applications.combinatorial_helpers.pauli_helpers.pauli_utils import (
|
19
|
+
PauliTerm,
|
20
|
+
get_pauli_operator,
|
19
21
|
pauli_operator_to_hamiltonian,
|
22
|
+
pauli_string_to_int,
|
20
23
|
)
|
21
|
-
from classiq.
|
24
|
+
from classiq.applications.combinatorial_helpers.pyomo_utils import (
|
22
25
|
convert_pyomo_to_global_presentation,
|
23
26
|
)
|
24
27
|
|
@@ -39,7 +42,7 @@ def compute_qaoa_initial_point(
|
|
39
42
|
return list(itertools.chain(*zip(gamma_params, beta_params)))
|
40
43
|
|
41
44
|
|
42
|
-
def
|
45
|
+
def _internal_pyo_model_to_hamiltonian(
|
43
46
|
pyo_model: pyo.ConcreteModel, penalty_energy: float
|
44
47
|
) -> List[QmodPyStruct]:
|
45
48
|
pauli_list = OptimizationModel(
|
@@ -48,6 +51,23 @@ def pyo_model_to_hamiltonian(
|
|
48
51
|
return pauli_operator_to_hamiltonian(pauli_list)
|
49
52
|
|
50
53
|
|
54
|
+
def pyo_model_to_hamiltonian(
|
55
|
+
pyo_model: pyo.ConcreteModel, penalty_energy: float
|
56
|
+
) -> List[PauliTerm]:
|
57
|
+
hamiltonian = _internal_pyo_model_to_hamiltonian(pyo_model, penalty_energy)
|
58
|
+
pauli_operator = get_pauli_operator(hamiltonian).pauli_list
|
59
|
+
pauli_terms = []
|
60
|
+
for item in pauli_operator:
|
61
|
+
term = PauliTerm()
|
62
|
+
term.pauli, term.coefficient = (
|
63
|
+
pauli_string_to_int(item[0]),
|
64
|
+
cast(complex, item[1]).real,
|
65
|
+
)
|
66
|
+
pauli_terms.append(term)
|
67
|
+
|
68
|
+
return pauli_terms
|
69
|
+
|
70
|
+
|
51
71
|
def _str_to_list_int(str_ints: str) -> List[int]:
|
52
72
|
return list(map(int, list(str_ints)))
|
53
73
|
|
classiq/{applications_model_constructors → applications}/combinatorial_helpers/encoding_mapping.py
RENAMED
@@ -8,7 +8,7 @@ from pyomo.core.expr.visitor import clone_expression, identify_variables
|
|
8
8
|
|
9
9
|
from classiq.interface.combinatorial_optimization.encoding_types import EncodingType
|
10
10
|
|
11
|
-
from classiq.
|
11
|
+
from classiq.applications.combinatorial_helpers import pyomo_utils
|
12
12
|
from classiq.exceptions import ClassiqCombOptError
|
13
13
|
|
14
14
|
|
classiq/{applications_model_constructors → applications}/combinatorial_helpers/encoding_utils.py
RENAMED
@@ -14,7 +14,7 @@ from pyomo.core.expr.numeric_expr import (
|
|
14
14
|
)
|
15
15
|
from sympy import Expr
|
16
16
|
|
17
|
-
from classiq.
|
17
|
+
from classiq.applications.combinatorial_helpers import pyomo_utils
|
18
18
|
from classiq.exceptions import ClassiqCombOptNoSolutionError
|
19
19
|
|
20
20
|
_INTEGER_TYPES = [pyo.NonNegativeIntegers, pyo.Integers, pyo.PositiveIntegers]
|
@@ -6,10 +6,8 @@ from pyomo.core.base import _GeneralVarData
|
|
6
6
|
|
7
7
|
from classiq.interface.generator.function_params import IOName
|
8
8
|
|
9
|
-
from classiq.
|
10
|
-
from classiq.
|
11
|
-
EncodingMapping,
|
12
|
-
)
|
9
|
+
from classiq.applications.combinatorial_helpers import encoding_utils
|
10
|
+
from classiq.applications.combinatorial_helpers.encoding_mapping import EncodingMapping
|
13
11
|
|
14
12
|
AUXILIARY_NAME = "auxiliary"
|
15
13
|
|
classiq/{applications_model_constructors → applications}/combinatorial_helpers/optimization_model.py
RENAMED
@@ -13,28 +13,24 @@ from classiq.interface.combinatorial_optimization import sense
|
|
13
13
|
from classiq.interface.combinatorial_optimization.encoding_types import EncodingType
|
14
14
|
from classiq.interface.combinatorial_optimization.solver_types import QSolver
|
15
15
|
|
16
|
-
from classiq.
|
16
|
+
from classiq.applications.combinatorial_helpers import (
|
17
17
|
encoding_utils,
|
18
18
|
memory,
|
19
19
|
pyomo_utils,
|
20
20
|
)
|
21
|
-
from classiq.
|
22
|
-
|
23
|
-
|
24
|
-
from classiq.applications_model_constructors.combinatorial_helpers.memory import (
|
25
|
-
InternalQuantumReg,
|
26
|
-
)
|
27
|
-
from classiq.applications_model_constructors.combinatorial_helpers.transformations import (
|
21
|
+
from classiq.applications.combinatorial_helpers.encoding_mapping import EncodingMapping
|
22
|
+
from classiq.applications.combinatorial_helpers.memory import InternalQuantumReg
|
23
|
+
from classiq.applications.combinatorial_helpers.transformations import (
|
28
24
|
encoding,
|
29
25
|
ising_converter,
|
30
26
|
penalty,
|
31
27
|
slack_variables,
|
32
28
|
)
|
33
|
-
from classiq.
|
29
|
+
from classiq.applications.combinatorial_helpers.transformations.fixed_variables import (
|
34
30
|
add_fixed_variables_to_solution,
|
35
31
|
remove_fixed_variables,
|
36
32
|
)
|
37
|
-
from classiq.
|
33
|
+
from classiq.applications.combinatorial_helpers.transformations.penalty_support import (
|
38
34
|
is_model_penalty_supported,
|
39
35
|
)
|
40
36
|
from classiq.exceptions import ClassiqCombOptError
|
@@ -12,6 +12,16 @@ from classiq.exceptions import (
|
|
12
12
|
)
|
13
13
|
|
14
14
|
|
15
|
+
class PauliTerm:
|
16
|
+
pauli: List[int]
|
17
|
+
coefficient: float
|
18
|
+
|
19
|
+
|
20
|
+
def pauli_string_to_int(pauli_str: str) -> List[int]:
|
21
|
+
pauli_map = {"I": 0, "X": 1, "Y": 2, "Z": 3}
|
22
|
+
return [pauli_map[char] for char in pauli_str]
|
23
|
+
|
24
|
+
|
15
25
|
def _pauli_str_to_enums(pauli_str: str) -> str:
|
16
26
|
return ", ".join(f"Pauli.{pauli_term}" for pauli_term in pauli_str)
|
17
27
|
|
classiq/{applications_model_constructors → applications}/combinatorial_helpers/pyomo_utils.py
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
import json
|
2
2
|
from enum import Enum
|
3
|
-
from typing import Any, Dict, List, Type, TypeVar, Union
|
3
|
+
from typing import Any, Dict, List, Optional, Tuple, Type, TypeVar, Union
|
4
4
|
|
5
5
|
import pydantic
|
6
6
|
import pyomo.core.expr.numeric_expr as pyo_expr
|
@@ -120,7 +120,9 @@ def get_name(component: Union[IndexedComponent, ComponentData]) -> str:
|
|
120
120
|
|
121
121
|
|
122
122
|
class FixedSympy2PyomoVisitor(Sympy2PyomoVisitor):
|
123
|
-
def beforeChild(
|
123
|
+
def beforeChild( # noqa: N802
|
124
|
+
self, node: Optional[sympy.Expr], child: sympy.Expr, child_idx: Optional[int]
|
125
|
+
) -> Tuple[bool, Union[int, float, None]]:
|
124
126
|
if not child._args:
|
125
127
|
item = self.object_map.getPyomoSymbol(child, None)
|
126
128
|
if item is None:
|
@@ -10,16 +10,9 @@ from pyomo.core.expr.relational_expr import EqualityExpression
|
|
10
10
|
from classiq.interface.combinatorial_optimization.encoding_types import EncodingType
|
11
11
|
from classiq.interface.combinatorial_optimization.solver_types import QSolver
|
12
12
|
|
13
|
-
from classiq.
|
14
|
-
|
15
|
-
|
16
|
-
)
|
17
|
-
from classiq.applications_model_constructors.combinatorial_helpers.encoding_mapping import (
|
18
|
-
EncodingMapping,
|
19
|
-
)
|
20
|
-
from classiq.applications_model_constructors.combinatorial_helpers.encoding_utils import (
|
21
|
-
ONE_HOT_SUFFIX,
|
22
|
-
)
|
13
|
+
from classiq.applications.combinatorial_helpers import encoding_utils, pyomo_utils
|
14
|
+
from classiq.applications.combinatorial_helpers.encoding_mapping import EncodingMapping
|
15
|
+
from classiq.applications.combinatorial_helpers.encoding_utils import ONE_HOT_SUFFIX
|
23
16
|
from classiq.exceptions import ClassiqCombOptInvalidEncodingTypeError
|
24
17
|
|
25
18
|
|
@@ -7,18 +7,16 @@ from pyomo.core.expr.relational_expr import EqualityExpression
|
|
7
7
|
from pyomo.core.expr.visitor import identify_variables
|
8
8
|
from pyomo.repn.standard_repn import _GeneralVarData
|
9
9
|
|
10
|
-
from classiq.
|
10
|
+
from classiq.applications.combinatorial_helpers import (
|
11
11
|
encoding_utils,
|
12
12
|
pyomo_utils,
|
13
13
|
sympy_utils,
|
14
14
|
)
|
15
|
-
from classiq.
|
16
|
-
|
17
|
-
)
|
18
|
-
from classiq.applications_model_constructors.combinatorial_helpers.encoding_utils import (
|
15
|
+
from classiq.applications.combinatorial_helpers.arithmetic.isolation import isolate
|
16
|
+
from classiq.applications.combinatorial_helpers.encoding_utils import (
|
19
17
|
deal_with_trivial_boolean_constraint,
|
20
18
|
)
|
21
|
-
from classiq.
|
19
|
+
from classiq.applications.combinatorial_helpers.sympy_utils import (
|
22
20
|
sympyify_expression,
|
23
21
|
sympyify_vars,
|
24
22
|
)
|
@@ -7,11 +7,9 @@ from pyomo.core.base import _GeneralVarData
|
|
7
7
|
from classiq.interface.chemistry.operator import PauliOperator
|
8
8
|
from classiq.interface.helpers import custom_pydantic_types
|
9
9
|
|
10
|
-
from classiq.
|
11
|
-
from classiq.
|
12
|
-
|
13
|
-
)
|
14
|
-
from classiq.applications_model_constructors.combinatorial_helpers.sympy_utils import (
|
10
|
+
from classiq.applications.combinatorial_helpers import memory
|
11
|
+
from classiq.applications.combinatorial_helpers.memory import InternalQuantumReg
|
12
|
+
from classiq.applications.combinatorial_helpers.sympy_utils import (
|
15
13
|
sympyify_expression,
|
16
14
|
sympyify_vars,
|
17
15
|
)
|
@@ -3,16 +3,12 @@ from pyomo.core.base.constraint import _GeneralConstraintData
|
|
3
3
|
from pyomo.core.expr.relational_expr import EqualityExpression
|
4
4
|
from pyomo.repn.standard_repn import _GeneralVarData
|
5
5
|
|
6
|
-
from classiq.
|
6
|
+
from classiq.applications.combinatorial_helpers import (
|
7
7
|
allowed_constraints,
|
8
8
|
encoding_utils,
|
9
9
|
)
|
10
|
-
from classiq.
|
11
|
-
|
12
|
-
)
|
13
|
-
from classiq.applications_model_constructors.combinatorial_helpers.sympy_utils import (
|
14
|
-
sympyify_expression,
|
15
|
-
)
|
10
|
+
from classiq.applications.combinatorial_helpers.pyomo_utils import extract
|
11
|
+
from classiq.applications.combinatorial_helpers.sympy_utils import sympyify_expression
|
16
12
|
|
17
13
|
|
18
14
|
def is_model_penalty_supported(model: ConcreteModel) -> bool:
|
@@ -7,14 +7,12 @@ import pyomo.core as pyo
|
|
7
7
|
from pyomo.core.base.component import _ComponentBase
|
8
8
|
from pyomo.core.expr.sympy_tools import sympy2pyomo_expression, sympyify_expression
|
9
9
|
|
10
|
-
from classiq.
|
11
|
-
from classiq.
|
10
|
+
from classiq.applications.combinatorial_helpers import pyomo_utils
|
11
|
+
from classiq.applications.combinatorial_helpers.arithmetic.arithmetic_expression import (
|
12
12
|
multivariate_extremum,
|
13
13
|
)
|
14
|
-
from classiq.
|
15
|
-
|
16
|
-
)
|
17
|
-
from classiq.applications_model_constructors.combinatorial_helpers.transformations.sign_seperation import (
|
14
|
+
from classiq.applications.combinatorial_helpers.transformations import penalty_support
|
15
|
+
from classiq.applications.combinatorial_helpers.transformations.sign_seperation import (
|
18
16
|
sign_separation,
|
19
17
|
)
|
20
18
|
|
@@ -1,19 +1,25 @@
|
|
1
1
|
from typing import List
|
2
2
|
|
3
3
|
from classiq.interface.combinatorial_optimization import examples
|
4
|
+
from classiq.interface.combinatorial_optimization.encoding_types import EncodingType
|
4
5
|
from classiq.interface.combinatorial_optimization.solver_types import QSolver
|
5
6
|
|
6
|
-
from classiq.
|
7
|
+
from classiq.applications.combinatorial_helpers.combinatorial_problem_utils import (
|
7
8
|
get_optimization_solution_from_pyo,
|
8
9
|
)
|
9
10
|
|
10
11
|
from .combinatorial_optimization_config import OptimizerConfig, QAOAConfig
|
12
|
+
from .combinatorial_optimization_model_constructor import (
|
13
|
+
construct_combinatorial_optimization_model,
|
14
|
+
)
|
11
15
|
|
12
16
|
__all__ = [
|
17
|
+
"EncodingType",
|
18
|
+
"OptimizerConfig",
|
19
|
+
"QAOAConfig",
|
13
20
|
"QSolver",
|
21
|
+
"construct_combinatorial_optimization_model",
|
14
22
|
"examples",
|
15
|
-
"QAOAConfig",
|
16
|
-
"OptimizerConfig",
|
17
23
|
"get_optimization_solution_from_pyo",
|
18
24
|
]
|
19
25
|
|
@@ -20,19 +20,16 @@ from classiq.interface.model.native_function_definition import NativeFunctionDef
|
|
20
20
|
from classiq.interface.model.port_declaration import PortDeclaration
|
21
21
|
from classiq.interface.model.quantum_function_call import QuantumFunctionCall
|
22
22
|
|
23
|
-
from classiq.applications.
|
24
|
-
|
25
|
-
QAOAConfig,
|
26
|
-
)
|
27
|
-
from classiq.applications_model_constructors.combinatorial_helpers.combinatorial_problem_utils import (
|
23
|
+
from classiq.applications.combinatorial_helpers.combinatorial_problem_utils import (
|
24
|
+
_internal_pyo_model_to_hamiltonian,
|
28
25
|
compute_qaoa_initial_point,
|
29
26
|
convert_pyomo_to_global_presentation,
|
30
|
-
pyo_model_to_hamiltonian,
|
31
27
|
)
|
32
|
-
from classiq.
|
28
|
+
from classiq.applications.combinatorial_helpers.pauli_helpers.pauli_utils import (
|
33
29
|
_pauli_operator_to_qmod,
|
34
30
|
get_pauli_operator,
|
35
31
|
)
|
32
|
+
from classiq.applications.combinatorial_optimization import OptimizerConfig, QAOAConfig
|
36
33
|
|
37
34
|
|
38
35
|
def construct_combi_opt_py_model(
|
@@ -50,7 +47,9 @@ def construct_combi_opt_py_model(
|
|
50
47
|
if optimizer_config.max_iteration is not None:
|
51
48
|
max_iteration = optimizer_config.max_iteration
|
52
49
|
|
53
|
-
hamiltonian =
|
50
|
+
hamiltonian = _internal_pyo_model_to_hamiltonian(
|
51
|
+
pyo_model, qaoa_config.penalty_energy
|
52
|
+
)
|
54
53
|
qaoa_initial_point = compute_qaoa_initial_point(hamiltonian, qaoa_config.num_layers)
|
55
54
|
len_hamiltonian = len(hamiltonian[0]["pauli"])
|
56
55
|
pauli_oper = get_pauli_operator(hamiltonian)
|
@@ -4,14 +4,15 @@ from classiq.interface.finance import (
|
|
4
4
|
function_input,
|
5
5
|
gaussian_model_input,
|
6
6
|
log_normal_model_input,
|
7
|
-
model_input,
|
8
7
|
)
|
9
8
|
|
9
|
+
from .finance_model_constructor import construct_finance_model
|
10
|
+
|
10
11
|
__all__ = [
|
12
|
+
"construct_finance_model",
|
11
13
|
"function_input",
|
12
14
|
"gaussian_model_input",
|
13
15
|
"log_normal_model_input",
|
14
|
-
"model_input",
|
15
16
|
]
|
16
17
|
|
17
18
|
|
classiq/{applications_model_constructors → applications/finance}/finance_model_constructor.py
RENAMED
@@ -18,10 +18,10 @@ from classiq.interface.model.variable_declaration_statement import (
|
|
18
18
|
VariableDeclarationStatement,
|
19
19
|
)
|
20
20
|
|
21
|
-
from classiq.
|
21
|
+
from classiq.applications.libraries.ampltitude_estimation_library import (
|
22
22
|
AE_CLASSICAL_LIBRARY,
|
23
23
|
)
|
24
|
-
from classiq.
|
24
|
+
from classiq.applications.libraries.qmci_library import QMCI_LIBRARY
|
25
25
|
from classiq.exceptions import ClassiqError
|
26
26
|
|
27
27
|
_OUTPUT_VARIABLE_NAME = "result"
|
@@ -75,16 +75,26 @@ def construct_finance_model(
|
|
75
75
|
},
|
76
76
|
body=[
|
77
77
|
VariableDeclarationStatement(name="unitary_port"),
|
78
|
+
QuantumFunctionCall(
|
79
|
+
function="allocate",
|
80
|
+
positional_args=[
|
81
|
+
Expression(expr=f"{num_unitary_qubits}"),
|
82
|
+
HandleBinding(name="unitary_port"),
|
83
|
+
],
|
84
|
+
),
|
85
|
+
QuantumFunctionCall(
|
86
|
+
function="allocate_num",
|
87
|
+
positional_args=[
|
88
|
+
Expression(expr=f"{phase_port_size}"),
|
89
|
+
Expression(expr="False"),
|
90
|
+
Expression(expr=f"{phase_port_size}"),
|
91
|
+
HandleBinding(name="phase_port"),
|
92
|
+
],
|
93
|
+
),
|
78
94
|
QuantumFunctionCall(
|
79
95
|
function="qmci",
|
80
|
-
params={
|
81
|
-
"num_phase_qubits": Expression(expr=f"{phase_port_size}"),
|
82
|
-
"num_unitary_qubits": Expression(
|
83
|
-
expr=f"{num_unitary_qubits}"
|
84
|
-
),
|
85
|
-
},
|
86
96
|
operands={
|
87
|
-
"
|
97
|
+
"space_transform": QuantumLambdaFunction(
|
88
98
|
body=[
|
89
99
|
QuantumFunctionCall(
|
90
100
|
function=finance_function,
|
@@ -97,16 +107,16 @@ def construct_finance_model(
|
|
97
107
|
),
|
98
108
|
},
|
99
109
|
inouts={
|
100
|
-
"func_port": HandleBinding(name="
|
101
|
-
"obj_port": HandleBinding(name="
|
110
|
+
"func_port": HandleBinding(name="arg0"),
|
111
|
+
"obj_port": HandleBinding(name="arg1"),
|
102
112
|
},
|
103
113
|
),
|
104
114
|
],
|
105
115
|
),
|
106
116
|
},
|
107
|
-
|
108
|
-
"
|
109
|
-
"
|
117
|
+
inouts={
|
118
|
+
"phase": HandleBinding(name="phase_port"),
|
119
|
+
"packed_vars": HandleBinding(name="unitary_port"),
|
110
120
|
},
|
111
121
|
),
|
112
122
|
],
|