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
@@ -0,0 +1,35 @@
|
|
1
|
+
from typing import cast
|
2
|
+
|
3
|
+
from classiq.interface.model.native_function_definition import NativeFunctionDefinition
|
4
|
+
|
5
|
+
from classiq.qmod import ( # type:ignore[attr-defined]
|
6
|
+
QArray,
|
7
|
+
QBit,
|
8
|
+
QCallable,
|
9
|
+
QNum,
|
10
|
+
Z,
|
11
|
+
amplitude_estimation,
|
12
|
+
qfunc,
|
13
|
+
)
|
14
|
+
|
15
|
+
|
16
|
+
@qfunc
|
17
|
+
def qmci(
|
18
|
+
space_transform: QCallable[QArray[QBit], QBit],
|
19
|
+
phase: QNum,
|
20
|
+
packed_vars: QArray[QBit],
|
21
|
+
) -> None:
|
22
|
+
amplitude_estimation(
|
23
|
+
lambda reg: Z(reg[reg.len - 1]),
|
24
|
+
lambda reg: space_transform(reg[0 : reg.len - 1], reg[reg.len - 1]),
|
25
|
+
phase,
|
26
|
+
packed_vars,
|
27
|
+
)
|
28
|
+
|
29
|
+
|
30
|
+
QMCI_LIBRARY = [
|
31
|
+
cast(
|
32
|
+
NativeFunctionDefinition,
|
33
|
+
qmci.create_model().function_dict["qmci"],
|
34
|
+
),
|
35
|
+
]
|
@@ -4,5 +4,9 @@ from classiq.interface.generator.expressions.enums.qsvm_feature_map_entanglement
|
|
4
4
|
|
5
5
|
from ..qsvm import qsvm_data_generation
|
6
6
|
from .qsvm import * # noqa: F403
|
7
|
+
from .qsvm_model_constructor import construct_qsvm_model
|
7
8
|
|
8
|
-
__all__ = [
|
9
|
+
__all__ = [
|
10
|
+
"QSVMFeatureMapEntanglement",
|
11
|
+
"construct_qsvm_model",
|
12
|
+
]
|
@@ -0,0 +1,13 @@
|
|
1
|
+
from typing import List
|
2
|
+
|
3
|
+
from classiq.interface.hardware import HardwareInformation
|
4
|
+
|
5
|
+
from classiq._internals import async_utils
|
6
|
+
from classiq._internals.api_wrapper import ApiWrapper
|
7
|
+
|
8
|
+
|
9
|
+
def get_all_hardware_devices() -> List[HardwareInformation]:
|
10
|
+
"""
|
11
|
+
Returns a list of all hardware devices known to Classiq.
|
12
|
+
"""
|
13
|
+
return async_utils.run(ApiWrapper.call_get_all_hardware_devices())
|
classiq/executor.py
CHANGED
@@ -29,9 +29,10 @@ from classiq.interface.generator.quantum_program import QuantumProgram
|
|
29
29
|
from classiq._internals.api_wrapper import ApiWrapper
|
30
30
|
from classiq._internals.async_utils import syncify_function
|
31
31
|
from classiq.execution.jobs import ExecutionJob
|
32
|
-
from classiq.model.model import DEFAULT_RESULT_NAME
|
33
32
|
from classiq.synthesis import SerializedQuantumProgram
|
34
33
|
|
34
|
+
DEFAULT_RESULT_NAME = "result"
|
35
|
+
|
35
36
|
BatchExecutionResult: TypeAlias = Union[ExecutionDetails, BaseException]
|
36
37
|
ProgramAndResult: TypeAlias = Tuple[QuantumCode, BatchExecutionResult]
|
37
38
|
BackendPreferencesAndResult: TypeAlias = Tuple[
|
classiq/interface/_version.py
CHANGED
@@ -2,7 +2,7 @@ from typing import Dict, List, Literal, Optional, Set, Tuple, Union
|
|
2
2
|
from uuid import UUID
|
3
3
|
|
4
4
|
import pydantic
|
5
|
-
from pydantic import
|
5
|
+
from pydantic import Field
|
6
6
|
from typing_extensions import Annotated
|
7
7
|
|
8
8
|
from classiq.interface.helpers.custom_pydantic_types import PydanticNonEmptyString
|
@@ -41,10 +41,6 @@ class QasmCode(pydantic.BaseModel):
|
|
41
41
|
code: str
|
42
42
|
|
43
43
|
|
44
|
-
class PreSignedS3Url(VersionedModel):
|
45
|
-
url: AnyHttpUrl
|
46
|
-
|
47
|
-
|
48
44
|
class AnalysisStatus(StrEnum):
|
49
45
|
NONE = "none"
|
50
46
|
SUCCESS = "success"
|
@@ -103,11 +103,13 @@ class QSVMData(VersionedModel):
|
|
103
103
|
extra = "forbid"
|
104
104
|
|
105
105
|
@pydantic.validator("data", pre=True)
|
106
|
-
def set_data(cls, data):
|
106
|
+
def set_data(cls, data: Union[IterableType, ArrayLike]) -> list:
|
107
107
|
return listify(data)
|
108
108
|
|
109
109
|
@pydantic.validator("labels", pre=True)
|
110
|
-
def set_labels(
|
110
|
+
def set_labels(
|
111
|
+
cls, labels: Optional[Union[IterableType, ArrayLike]]
|
112
|
+
) -> Optional[list]:
|
111
113
|
if labels is None:
|
112
114
|
return None
|
113
115
|
else:
|
@@ -0,0 +1,23 @@
|
|
1
|
+
from typing import Optional
|
2
|
+
|
3
|
+
import pydantic
|
4
|
+
|
5
|
+
from classiq.interface.helpers.hashable_pydantic_base_model import (
|
6
|
+
HashablePydanticBaseModel,
|
7
|
+
)
|
8
|
+
|
9
|
+
|
10
|
+
class SourceReference(pydantic.BaseModel):
|
11
|
+
start_line: int
|
12
|
+
start_column: int
|
13
|
+
end_line: int
|
14
|
+
end_column: int
|
15
|
+
file_name: Optional[str] = pydantic.Field(default=None)
|
16
|
+
|
17
|
+
|
18
|
+
class ASTNode(pydantic.BaseModel):
|
19
|
+
source_ref: Optional[SourceReference] = pydantic.Field(default=None)
|
20
|
+
|
21
|
+
|
22
|
+
class HashableASTNode(ASTNode, HashablePydanticBaseModel):
|
23
|
+
pass
|
@@ -3,6 +3,7 @@ from typing import Dict, Tuple
|
|
3
3
|
|
4
4
|
import networkx as nx
|
5
5
|
import pyomo.core as pyo
|
6
|
+
import pyomo.core.expr.numeric_expr as pyo_expr
|
6
7
|
|
7
8
|
Node = int
|
8
9
|
Edge = Tuple[Node, Node]
|
@@ -22,7 +23,9 @@ def build_mht_pyomo_model(
|
|
22
23
|
if has_constraints:
|
23
24
|
|
24
25
|
@model.Constraint(model.Nodes)
|
25
|
-
def out_edges_rule(
|
26
|
+
def out_edges_rule(
|
27
|
+
model: pyo.ConcreteModel, idx: int
|
28
|
+
) -> pyo_expr.ExpressionBase:
|
26
29
|
out_nodes = [
|
27
30
|
node_id for node_id in model.Nodes if [idx, node_id] in model.Arcs
|
28
31
|
]
|
@@ -32,7 +35,9 @@ def build_mht_pyomo_model(
|
|
32
35
|
return pyo.Constraint.Feasible
|
33
36
|
|
34
37
|
@model.Constraint(model.Nodes)
|
35
|
-
def in_edges_rule(
|
38
|
+
def in_edges_rule(
|
39
|
+
model: pyo.ConcreteModel, idx: int
|
40
|
+
) -> pyo_expr.ExpressionBase:
|
36
41
|
in_nodes = [
|
37
42
|
node_id for node_id in model.Nodes if [node_id, idx] in model.Arcs
|
38
43
|
]
|
@@ -41,7 +46,7 @@ def build_mht_pyomo_model(
|
|
41
46
|
else:
|
42
47
|
return pyo.Constraint.Feasible
|
43
48
|
|
44
|
-
def obj_expression(model: pyo.ConcreteModel) ->
|
49
|
+
def obj_expression(model: pyo.ConcreteModel) -> pyo_expr.ExpressionBase:
|
45
50
|
return sum(
|
46
51
|
round(pubo_energy, _decimals)
|
47
52
|
* math.prod(model.x[edge] for edge in pubo_edges)
|
@@ -1,21 +1,18 @@
|
|
1
1
|
from datetime import datetime
|
2
|
-
from typing import
|
2
|
+
from typing import List, Literal, Optional, Union
|
3
3
|
|
4
4
|
import pydantic
|
5
5
|
from pydantic import BaseModel, Field
|
6
6
|
from typing_extensions import Annotated
|
7
7
|
|
8
|
-
from classiq.interface.backend.backend_preferences import IonqBackendPreferences
|
9
8
|
from classiq.interface.executor.estimation import OperatorsEstimation
|
10
9
|
from classiq.interface.executor.execution_preferences import ExecutionPreferences
|
11
|
-
from classiq.interface.executor.quantum_code import QuantumCode
|
10
|
+
from classiq.interface.executor.quantum_code import QuantumCode
|
12
11
|
from classiq.interface.generator.quantum_program import QuantumProgram
|
13
12
|
from classiq.interface.helpers.custom_encoders import CUSTOM_ENCODERS
|
14
13
|
from classiq.interface.helpers.versioned_model import VersionedModel
|
15
14
|
from classiq.interface.jobs import JobStatus
|
16
15
|
|
17
|
-
from classiq.exceptions import ClassiqValueError
|
18
|
-
|
19
16
|
|
20
17
|
class QuantumProgramExecution(QuantumProgram):
|
21
18
|
execution_type: Literal["quantum_program2"] = "quantum_program2"
|
@@ -42,38 +39,6 @@ class ExecutionRequest(BaseModel, json_encoders=CUSTOM_ENCODERS):
|
|
42
39
|
description="preferences for the execution",
|
43
40
|
)
|
44
41
|
|
45
|
-
@pydantic.validator("preferences")
|
46
|
-
def validate_ionq_backend(
|
47
|
-
cls, preferences: ExecutionPreferences, values: Dict[str, Any]
|
48
|
-
) -> ExecutionPreferences:
|
49
|
-
"""
|
50
|
-
This function implement the following check:
|
51
|
-
BE \\ payload | IonQ program | Qasm program | Other
|
52
|
-
--------------|--------------|--------------|------
|
53
|
-
IonQ backend | V | V | X
|
54
|
-
Other backend | X | V | V
|
55
|
-
Since:
|
56
|
-
- We can't execute non-programs on the IonQ backends
|
57
|
-
- We can't execute IonQ programs on non-IonQ backends
|
58
|
-
"""
|
59
|
-
quantum_program = values.get("execution_payload")
|
60
|
-
is_ionq_backend = isinstance(
|
61
|
-
preferences.backend_preferences, IonqBackendPreferences
|
62
|
-
)
|
63
|
-
if isinstance(quantum_program, QuantumCode):
|
64
|
-
if (
|
65
|
-
quantum_program.syntax == QuantumInstructionSet.IONQ
|
66
|
-
and not is_ionq_backend
|
67
|
-
):
|
68
|
-
raise ClassiqValueError("Can only execute IonQ code on IonQ backend.")
|
69
|
-
else:
|
70
|
-
# If we handle anything other than a program.
|
71
|
-
if is_ionq_backend:
|
72
|
-
raise ClassiqValueError(
|
73
|
-
"IonQ backend supports only execution of QuantumPrograms"
|
74
|
-
)
|
75
|
-
return preferences
|
76
|
-
|
77
42
|
|
78
43
|
class QuantumProgramExecutionRequest(ExecutionRequest):
|
79
44
|
execution_payload: QuantumCodeExecution
|
@@ -63,7 +63,7 @@ class VQESolverResult(SolverResult, QmodPyObject):
|
|
63
63
|
self.convergence_graph.show()
|
64
64
|
|
65
65
|
@property
|
66
|
-
def convergence_graph(self):
|
66
|
+
def convergence_graph(self) -> Image.Image:
|
67
67
|
return Image.open(io.BytesIO(base64.b64decode(self.convergence_graph_str)))
|
68
68
|
|
69
69
|
@property
|
@@ -4,15 +4,10 @@ from classiq.interface.generator.functions.classical_function_declaration import
|
|
4
4
|
ClassicalFunctionDeclaration,
|
5
5
|
)
|
6
6
|
from classiq.interface.generator.types.struct_declaration import StructDeclaration
|
7
|
-
from classiq.interface.model.quantum_function_declaration import (
|
8
|
-
QuantumFunctionDeclaration,
|
9
|
-
)
|
10
7
|
|
11
8
|
|
12
9
|
def populate_builtin_declarations(decls: Iterable[Any]) -> None:
|
13
10
|
for decl in decls:
|
14
|
-
if isinstance(decl, QuantumFunctionDeclaration):
|
15
|
-
QuantumFunctionDeclaration.BUILTIN_FUNCTION_DECLARATIONS[decl.name] = decl
|
16
11
|
if isinstance(decl, ClassicalFunctionDeclaration):
|
17
12
|
ClassicalFunctionDeclaration.FOREIGN_FUNCTION_DECLARATIONS[decl.name] = decl
|
18
13
|
if isinstance(decl, StructDeclaration):
|
@@ -1,10 +1,9 @@
|
|
1
|
-
import
|
2
|
-
|
1
|
+
from classiq.interface.ast_node import ASTNode
|
3
2
|
from classiq.interface.generator.expressions.expression import Expression
|
4
3
|
from classiq.interface.generator.functions.classical_type import ConcreteClassicalType
|
5
4
|
|
6
5
|
|
7
|
-
class Constant(
|
6
|
+
class Constant(ASTNode):
|
8
7
|
name: str
|
9
8
|
const_type: ConcreteClassicalType
|
10
9
|
value: Expression
|
@@ -4,6 +4,7 @@ from typing import Any, Mapping, Optional, Type
|
|
4
4
|
import pydantic
|
5
5
|
from pydantic import PrivateAttr
|
6
6
|
|
7
|
+
from classiq.interface.ast_node import HashableASTNode
|
7
8
|
from classiq.interface.generator.arith.arithmetic_expression_validator import (
|
8
9
|
DEFAULT_SUPPORTED_FUNC_NAMES,
|
9
10
|
)
|
@@ -17,14 +18,11 @@ from classiq.interface.generator.expressions.sympy_supported_expressions import
|
|
17
18
|
SYMPY_SUPPORTED_EXPRESSIONS,
|
18
19
|
)
|
19
20
|
from classiq.interface.generator.function_params import validate_expression_str
|
20
|
-
from classiq.interface.helpers.hashable_pydantic_base_model import (
|
21
|
-
HashablePydanticBaseModel,
|
22
|
-
)
|
23
21
|
|
24
22
|
from classiq.exceptions import ClassiqError
|
25
23
|
|
26
24
|
|
27
|
-
class Expression(
|
25
|
+
class Expression(HashableASTNode):
|
28
26
|
expr: str
|
29
27
|
_evaluated_expr: Optional[EvaluatedExpression] = PrivateAttr(default=None)
|
30
28
|
|
@@ -4,7 +4,7 @@ from classiq.interface.generator.expressions.qmod_sized_proxy import QmodSizedPr
|
|
4
4
|
|
5
5
|
|
6
6
|
class QmodQScalarProxy(Symbol, QmodSizedProxy):
|
7
|
-
def __new__(cls, name, **assumptions):
|
7
|
+
def __new__(cls, name: str, **assumptions: bool) -> "QmodQScalarProxy":
|
8
8
|
return super().__new__(cls, name, **assumptions)
|
9
9
|
|
10
10
|
def __init__(self, name: str, size: int) -> None:
|
@@ -1,7 +1,7 @@
|
|
1
1
|
from typing import List
|
2
2
|
|
3
|
-
import classiq.interface.generator.functions.
|
4
|
-
import classiq.interface.generator.functions.
|
3
|
+
import classiq.interface.generator.functions.builtins.core_library
|
4
|
+
import classiq.interface.generator.functions.builtins.quantum_operators
|
5
5
|
from classiq.interface.generator.functions.foreign_function_definition import *
|
6
6
|
from classiq.interface.generator.functions.foreign_function_definition import (
|
7
7
|
SynthesisForeignFunctionDefinition as ForeignFunctionDefinition,
|
@@ -0,0 +1,15 @@
|
|
1
|
+
from classiq.interface.generator.functions.builtins.core_library import CORE_LIB_DECLS
|
2
|
+
from classiq.interface.generator.functions.builtins.open_lib_functions import (
|
3
|
+
OPEN_LIB_DECLS,
|
4
|
+
)
|
5
|
+
from classiq.interface.generator.functions.builtins.quantum_operators import (
|
6
|
+
STD_QMOD_OPERATORS,
|
7
|
+
)
|
8
|
+
from classiq.interface.helpers.pydantic_model_helpers import nameables_to_dict
|
9
|
+
from classiq.interface.model.quantum_function_declaration import (
|
10
|
+
QuantumFunctionDeclaration,
|
11
|
+
)
|
12
|
+
|
13
|
+
QuantumFunctionDeclaration.BUILTIN_FUNCTION_DECLARATIONS.update(
|
14
|
+
nameables_to_dict(STD_QMOD_OPERATORS + CORE_LIB_DECLS + OPEN_LIB_DECLS)
|
15
|
+
)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
from classiq.interface.generator.application_apis.chemistry_declarations import * # noqa: F403
|
2
|
+
from classiq.interface.generator.application_apis.combinatorial_optimization_declarations import * # noqa: F403
|
3
|
+
from classiq.interface.generator.application_apis.finance_declarations import * # noqa: F403
|
4
|
+
from classiq.interface.generator.application_apis.qsvm_declarations import * # noqa: F403
|
5
|
+
from classiq.interface.model.quantum_function_declaration import (
|
6
|
+
QuantumFunctionDeclaration,
|
7
|
+
)
|
8
|
+
|
9
|
+
from .atomic_quantum_functions import * # noqa: F403
|
10
|
+
from .exponentiation_functions import * # noqa: F403
|
11
|
+
|
12
|
+
CORE_LIB_DECLS = [
|
13
|
+
func for func in vars().values() if isinstance(func, QuantumFunctionDeclaration)
|
14
|
+
]
|
@@ -0,0 +1,62 @@
|
|
1
|
+
from classiq.interface.generator.functions.builtins.quantum_operators import (
|
2
|
+
get_single_empty_operand_operator,
|
3
|
+
)
|
4
|
+
from classiq.interface.generator.functions.classical_type import Bool, Integer
|
5
|
+
from classiq.interface.generator.functions.port_declaration import (
|
6
|
+
PortDeclarationDirection,
|
7
|
+
)
|
8
|
+
from classiq.interface.helpers.pydantic_model_helpers import nameables_to_dict
|
9
|
+
from classiq.interface.model.port_declaration import PortDeclaration
|
10
|
+
from classiq.interface.model.quantum_function_declaration import (
|
11
|
+
QuantumFunctionDeclaration,
|
12
|
+
QuantumOperandDeclaration,
|
13
|
+
)
|
14
|
+
|
15
|
+
_CTRL_FIELD_NAME = "ctrl"
|
16
|
+
CONTROL_OPERATOR = get_single_empty_operand_operator(
|
17
|
+
operator_name="control",
|
18
|
+
port_declarations={
|
19
|
+
_CTRL_FIELD_NAME: PortDeclaration(
|
20
|
+
name=_CTRL_FIELD_NAME,
|
21
|
+
direction=PortDeclarationDirection.Inout,
|
22
|
+
)
|
23
|
+
},
|
24
|
+
)
|
25
|
+
|
26
|
+
REPEAT_OPERATOR = QuantumFunctionDeclaration(
|
27
|
+
name="repeat",
|
28
|
+
param_decls={"count": Integer()},
|
29
|
+
operand_declarations={
|
30
|
+
"iteration": QuantumOperandDeclaration(
|
31
|
+
name="iteration", param_decls={"index": Integer()}
|
32
|
+
)
|
33
|
+
},
|
34
|
+
)
|
35
|
+
POWER_OPERATOR = get_single_empty_operand_operator(
|
36
|
+
operator_name="power", param_decls={"power": Integer()}
|
37
|
+
)
|
38
|
+
INVERT_OPERATOR = get_single_empty_operand_operator(operator_name="invert")
|
39
|
+
|
40
|
+
IF_OPERATOR = QuantumFunctionDeclaration(
|
41
|
+
name="if",
|
42
|
+
param_decls={"condition": Bool()},
|
43
|
+
operand_declarations={
|
44
|
+
"then": QuantumOperandDeclaration(name="then"),
|
45
|
+
"else": QuantumOperandDeclaration(name="else"),
|
46
|
+
},
|
47
|
+
)
|
48
|
+
COMPUTE = get_single_empty_operand_operator(operator_name="compute")
|
49
|
+
UNCOMPUTE = get_single_empty_operand_operator(operator_name="uncompute")
|
50
|
+
|
51
|
+
|
52
|
+
INTERNAL_OPERATORS = nameables_to_dict(
|
53
|
+
[
|
54
|
+
CONTROL_OPERATOR,
|
55
|
+
REPEAT_OPERATOR,
|
56
|
+
POWER_OPERATOR,
|
57
|
+
INVERT_OPERATOR,
|
58
|
+
IF_OPERATOR,
|
59
|
+
COMPUTE,
|
60
|
+
UNCOMPUTE,
|
61
|
+
]
|
62
|
+
)
|