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
@@ -1,10 +1,10 @@
|
|
1
1
|
import itertools
|
2
2
|
import re
|
3
|
-
from typing import Any, Dict, List, Mapping, Optional, Set, Union
|
3
|
+
from typing import Any, Dict, List, Mapping, Optional, Set, Type, Union
|
4
4
|
|
5
5
|
import pydantic
|
6
|
-
from pydantic import BaseModel
|
7
6
|
|
7
|
+
from classiq.interface.ast_node import ASTNode
|
8
8
|
from classiq.interface.generator.expressions.expression import Expression
|
9
9
|
from classiq.interface.generator.functions.function_declaration import (
|
10
10
|
FunctionDeclaration,
|
@@ -77,8 +77,13 @@ def _validate_no_duplicated_handles(
|
|
77
77
|
def _validate_no_mixing_sliced_and_whole_handles(
|
78
78
|
inouts: Mapping[str, HandleBinding],
|
79
79
|
) -> None:
|
80
|
+
def _treat_subscript_as_slice(type_: Type[HandleBinding]) -> Type[HandleBinding]:
|
81
|
+
if type_ == SubscriptHandleBinding:
|
82
|
+
return SlicedHandleBinding
|
83
|
+
return type_
|
84
|
+
|
80
85
|
inout_handle_names_to_types = {
|
81
|
-
handle_name: {type(handle) for handle in handles}
|
86
|
+
handle_name: {_treat_subscript_as_slice(type(handle)) for handle in handles}
|
82
87
|
for handle_name, handles in itertools.groupby(
|
83
88
|
inouts.values(), lambda handle: handle.name
|
84
89
|
)
|
@@ -103,7 +108,7 @@ ArgValue = Union[
|
|
103
108
|
]
|
104
109
|
|
105
110
|
|
106
|
-
class OperandIdentifier(
|
111
|
+
class OperandIdentifier(ASTNode):
|
107
112
|
name: str
|
108
113
|
index: Expression
|
109
114
|
|
@@ -17,7 +17,7 @@ from classiq.interface.model.quantum_expressions.quantum_expression import (
|
|
17
17
|
from classiq.exceptions import ClassiqValueError
|
18
18
|
|
19
19
|
if TYPE_CHECKING:
|
20
|
-
from classiq.interface.model.
|
20
|
+
from classiq.interface.model.statement_block import StatementBlock
|
21
21
|
|
22
22
|
QUANTUM_IF_INOUT_NAME = "ctrl"
|
23
23
|
QUANTUM_IF_CONDITION_ARG_ERROR_MESSAGE_FORMAT = (
|
@@ -26,8 +26,8 @@ QUANTUM_IF_CONDITION_ARG_ERROR_MESSAGE_FORMAT = (
|
|
26
26
|
)
|
27
27
|
|
28
28
|
|
29
|
-
class
|
30
|
-
then: "
|
29
|
+
class QuantumIf(QuantumExpressionOperation):
|
30
|
+
then: "StatementBlock"
|
31
31
|
_ctrl: Optional[QmodQNumProxy] = pydantic.PrivateAttr(
|
32
32
|
default=None,
|
33
33
|
)
|
@@ -1,21 +1,18 @@
|
|
1
1
|
from typing import TYPE_CHECKING, Dict, List, Optional, Union
|
2
2
|
|
3
3
|
import pydantic
|
4
|
-
from pydantic import BaseModel
|
5
4
|
|
5
|
+
from classiq.interface.ast_node import ASTNode
|
6
6
|
from classiq.interface.generator.expressions.expression import Expression
|
7
7
|
from classiq.interface.model.quantum_function_declaration import (
|
8
8
|
QuantumOperandDeclaration,
|
9
9
|
)
|
10
|
-
from classiq.interface.model.quantum_if_operation import QuantumIfOperation
|
11
10
|
|
12
11
|
if TYPE_CHECKING:
|
13
12
|
from classiq.interface.model.statement_block import StatementBlock
|
14
13
|
|
15
|
-
from classiq.interface.model.within_apply_operation import WithinApplyOperation
|
16
14
|
|
17
|
-
|
18
|
-
class QuantumLambdaFunction(BaseModel):
|
15
|
+
class QuantumLambdaFunction(ASTNode):
|
19
16
|
"""
|
20
17
|
The definition of an anonymous function passed as operand to higher-level functions
|
21
18
|
"""
|
@@ -39,7 +36,7 @@ class QuantumLambdaFunction(BaseModel):
|
|
39
36
|
self._func_decl = fd
|
40
37
|
|
41
38
|
|
42
|
-
class LambdaListComprehension(
|
39
|
+
class LambdaListComprehension(ASTNode):
|
43
40
|
"""
|
44
41
|
Specification of a list of lambda functions iteratively
|
45
42
|
"""
|
@@ -59,6 +56,3 @@ class LambdaListComprehension(BaseModel):
|
|
59
56
|
|
60
57
|
QuantumCallable = Union[str, QuantumLambdaFunction]
|
61
58
|
QuantumOperand = Union[QuantumCallable, List[QuantumCallable], LambdaListComprehension]
|
62
|
-
|
63
|
-
QuantumIfOperation.update_forward_refs(QuantumOperand=QuantumOperand)
|
64
|
-
WithinApplyOperation.update_forward_refs(QuantumOperand=QuantumOperand)
|
@@ -1,7 +1,8 @@
|
|
1
1
|
from typing import Mapping, Union
|
2
2
|
|
3
|
-
from pydantic import
|
3
|
+
from pydantic import Extra
|
4
4
|
|
5
|
+
from classiq.interface.ast_node import ASTNode
|
5
6
|
from classiq.interface.model.handle_binding import (
|
6
7
|
HandleBinding,
|
7
8
|
SlicedHandleBinding,
|
@@ -9,7 +10,7 @@ from classiq.interface.model.handle_binding import (
|
|
9
10
|
)
|
10
11
|
|
11
12
|
|
12
|
-
class QuantumStatement(
|
13
|
+
class QuantumStatement(ASTNode):
|
13
14
|
class Config:
|
14
15
|
extra = Extra.forbid
|
15
16
|
|
@@ -4,6 +4,7 @@ import pydantic
|
|
4
4
|
from pydantic import Extra, Field
|
5
5
|
from typing_extensions import Annotated
|
6
6
|
|
7
|
+
from classiq.interface.ast_node import HashableASTNode
|
7
8
|
from classiq.interface.generator.arith.register_user_input import (
|
8
9
|
RegisterArithmeticInfo,
|
9
10
|
RegisterUserInput,
|
@@ -14,15 +15,12 @@ from classiq.interface.generator.expressions.qmod_qscalar_proxy import (
|
|
14
15
|
QmodQScalarProxy,
|
15
16
|
)
|
16
17
|
from classiq.interface.generator.expressions.qmod_sized_proxy import QmodSizedProxy
|
17
|
-
from classiq.interface.helpers.hashable_pydantic_base_model import (
|
18
|
-
HashablePydanticBaseModel,
|
19
|
-
)
|
20
18
|
from classiq.interface.helpers.pydantic_model_helpers import values_with_discriminator
|
21
19
|
|
22
20
|
from classiq.exceptions import ClassiqValueError
|
23
21
|
|
24
22
|
|
25
|
-
class QuantumType(
|
23
|
+
class QuantumType(HashableASTNode):
|
26
24
|
class Config:
|
27
25
|
extra = Extra.forbid
|
28
26
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
from typing import Any, Mapping, Optional
|
2
2
|
|
3
3
|
import pydantic
|
4
|
-
from pydantic import BaseModel
|
5
4
|
|
5
|
+
from classiq.interface.ast_node import ASTNode
|
6
6
|
from classiq.interface.generator.expressions.expression import Expression
|
7
7
|
from classiq.interface.model.quantum_type import (
|
8
8
|
ConcreteQuantumType,
|
@@ -11,7 +11,7 @@ from classiq.interface.model.quantum_type import (
|
|
11
11
|
)
|
12
12
|
|
13
13
|
|
14
|
-
class QuantumVariableDeclaration(
|
14
|
+
class QuantumVariableDeclaration(ASTNode):
|
15
15
|
name: str
|
16
16
|
quantum_type: ConcreteQuantumType
|
17
17
|
size: Optional[Expression] = pydantic.Field(default=None)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
from typing import TYPE_CHECKING
|
2
|
+
|
3
|
+
from classiq.interface.generator.expressions.expression import Expression
|
4
|
+
from classiq.interface.model.quantum_statement import QuantumOperation
|
5
|
+
|
6
|
+
if TYPE_CHECKING:
|
7
|
+
from classiq.interface.model.statement_block import StatementBlock
|
8
|
+
|
9
|
+
|
10
|
+
class Repeat(QuantumOperation):
|
11
|
+
iter_var: str
|
12
|
+
count: Expression
|
13
|
+
body: "StatementBlock"
|
@@ -1,11 +1,17 @@
|
|
1
|
+
import itertools
|
1
2
|
from typing import Any, Mapping
|
2
3
|
|
3
4
|
from classiq.interface.generator.visitor import Visitor
|
5
|
+
from classiq.interface.model.control import Control
|
6
|
+
from classiq.interface.model.invert import Invert
|
4
7
|
from classiq.interface.model.native_function_definition import NativeFunctionDefinition
|
5
8
|
from classiq.interface.model.quantum_function_call import QuantumFunctionCall
|
6
9
|
from classiq.interface.model.quantum_function_declaration import (
|
7
10
|
QuantumFunctionDeclaration,
|
8
11
|
)
|
12
|
+
from classiq.interface.model.quantum_if_operation import QuantumIf
|
13
|
+
from classiq.interface.model.repeat import Repeat
|
14
|
+
from classiq.interface.model.within_apply_operation import WithinApply
|
9
15
|
|
10
16
|
|
11
17
|
class FunctionCallResolver(Visitor):
|
@@ -15,6 +21,26 @@ class FunctionCallResolver(Visitor):
|
|
15
21
|
) -> None:
|
16
22
|
self._quantum_function_dict = quantum_function_dict
|
17
23
|
|
24
|
+
def visit_Invert(self, invert: Invert) -> None:
|
25
|
+
for fc in invert.body:
|
26
|
+
self.visit(fc)
|
27
|
+
|
28
|
+
def visit_Repeat(self, repeat: Repeat) -> None:
|
29
|
+
for fc in repeat.body:
|
30
|
+
self.visit(fc)
|
31
|
+
|
32
|
+
def visit_Control(self, control: Control) -> None:
|
33
|
+
for fc in control.body:
|
34
|
+
self.visit(fc)
|
35
|
+
|
36
|
+
def visit_QuantumIf(self, quantum_if: QuantumIf) -> None:
|
37
|
+
for fc in quantum_if.then:
|
38
|
+
self.visit(fc)
|
39
|
+
|
40
|
+
def visit_WithinApply(self, within_apply: WithinApply) -> None:
|
41
|
+
for fc in itertools.chain(within_apply.compute, within_apply.action):
|
42
|
+
self.visit(fc)
|
43
|
+
|
18
44
|
def visit_QuantumFunctionCall(self, fc: QuantumFunctionCall) -> None:
|
19
45
|
fc.resolve_function_decl(self._quantum_function_dict, check_operands=True)
|
20
46
|
self.visit_BaseModel(fc)
|
@@ -1,7 +1,11 @@
|
|
1
1
|
from typing import List, Union
|
2
2
|
|
3
3
|
from classiq.interface.model.bind_operation import BindOperation
|
4
|
+
from classiq.interface.model.classical_if import ClassicalIf
|
5
|
+
from classiq.interface.model.control import Control
|
4
6
|
from classiq.interface.model.inplace_binary_operation import InplaceBinaryOperation
|
7
|
+
from classiq.interface.model.invert import Invert
|
8
|
+
from classiq.interface.model.power import Power
|
5
9
|
from classiq.interface.model.quantum_expressions.amplitude_loading_operation import (
|
6
10
|
AmplitudeLoadingOperation,
|
7
11
|
)
|
@@ -9,12 +13,13 @@ from classiq.interface.model.quantum_expressions.arithmetic_operation import (
|
|
9
13
|
ArithmeticOperation,
|
10
14
|
)
|
11
15
|
from classiq.interface.model.quantum_function_call import QuantumFunctionCall
|
12
|
-
from classiq.interface.model.quantum_if_operation import
|
16
|
+
from classiq.interface.model.quantum_if_operation import QuantumIf
|
13
17
|
from classiq.interface.model.quantum_lambda_function import QuantumLambdaFunction
|
18
|
+
from classiq.interface.model.repeat import Repeat
|
14
19
|
from classiq.interface.model.variable_declaration_statement import (
|
15
20
|
VariableDeclarationStatement,
|
16
21
|
)
|
17
|
-
from classiq.interface.model.within_apply_operation import
|
22
|
+
from classiq.interface.model.within_apply_operation import WithinApply
|
18
23
|
|
19
24
|
ConcreteQuantumStatement = Union[
|
20
25
|
QuantumFunctionCall,
|
@@ -23,10 +28,22 @@ ConcreteQuantumStatement = Union[
|
|
23
28
|
VariableDeclarationStatement,
|
24
29
|
BindOperation,
|
25
30
|
InplaceBinaryOperation,
|
26
|
-
|
27
|
-
|
31
|
+
Control,
|
32
|
+
Repeat,
|
33
|
+
Power,
|
34
|
+
Invert,
|
35
|
+
ClassicalIf,
|
36
|
+
QuantumIf,
|
37
|
+
WithinApply,
|
28
38
|
]
|
29
39
|
|
30
40
|
StatementBlock = List[ConcreteQuantumStatement]
|
31
41
|
|
42
|
+
Control.update_forward_refs(StatementBlock=StatementBlock)
|
43
|
+
QuantumIf.update_forward_refs(StatementBlock=StatementBlock)
|
32
44
|
QuantumLambdaFunction.update_forward_refs(StatementBlock=StatementBlock)
|
45
|
+
Repeat.update_forward_refs(StatementBlock=StatementBlock)
|
46
|
+
Power.update_forward_refs(StatementBlock=StatementBlock)
|
47
|
+
Invert.update_forward_refs(StatementBlock=StatementBlock)
|
48
|
+
WithinApply.update_forward_refs(StatementBlock=StatementBlock)
|
49
|
+
ClassicalIf.update_forward_refs(StatementBlock=StatementBlock)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
from typing import Dict, Mapping, Set, Union
|
2
2
|
|
3
3
|
from classiq.interface.generator.function_params import PortDirection
|
4
|
-
from classiq.interface.generator.functions.
|
4
|
+
from classiq.interface.generator.functions.builtins.quantum_operators import (
|
5
5
|
APPLY_OPERATOR,
|
6
6
|
)
|
7
7
|
from classiq.interface.model.handle_binding import (
|
@@ -11,11 +11,8 @@ from classiq.interface.model.handle_binding import (
|
|
11
11
|
)
|
12
12
|
from classiq.interface.model.port_declaration import PortDeclaration
|
13
13
|
from classiq.interface.model.quantum_function_call import QuantumFunctionCall
|
14
|
-
from classiq.interface.model.quantum_lambda_function import (
|
15
|
-
QuantumLambdaFunction,
|
16
|
-
QuantumOperand,
|
17
|
-
)
|
18
14
|
from classiq.interface.model.quantum_statement import QuantumOperation
|
15
|
+
from classiq.interface.model.statement_block import StatementBlock
|
19
16
|
from classiq.interface.model.validation_handle import HandleState, ValidationHandle
|
20
17
|
from classiq.interface.model.validations.handle_validation_base import (
|
21
18
|
HandleValidationBase,
|
@@ -23,7 +20,7 @@ from classiq.interface.model.validations.handle_validation_base import (
|
|
23
20
|
from classiq.interface.model.variable_declaration_statement import (
|
24
21
|
VariableDeclarationStatement,
|
25
22
|
)
|
26
|
-
from classiq.interface.model.within_apply_operation import
|
23
|
+
from classiq.interface.model.within_apply_operation import WithinApply
|
27
24
|
|
28
25
|
from classiq.exceptions import ClassiqValueError
|
29
26
|
|
@@ -60,8 +57,9 @@ class HandleValidator(HandleValidationBase):
|
|
60
57
|
|
61
58
|
def handle_operation(self, op: QuantumOperation) -> None:
|
62
59
|
if isinstance(op, QuantumFunctionCall) and op.function == APPLY_OPERATOR.name:
|
63
|
-
|
64
|
-
|
60
|
+
call_name = op.operands[APPLY_OPERATOR.operand_names[0]]
|
61
|
+
self._handle_apply([QuantumFunctionCall(function=call_name)])
|
62
|
+
elif isinstance(op, WithinApply):
|
65
63
|
self._handle_apply(op.action)
|
66
64
|
self._handle_inputs(op.wiring_inputs)
|
67
65
|
self._handle_outputs(op.wiring_outputs)
|
@@ -133,12 +131,10 @@ class HandleValidator(HandleValidationBase):
|
|
133
131
|
f"Invalid use of inout handle {handle!r}, used both in slice or subscript and whole"
|
134
132
|
)
|
135
133
|
|
136
|
-
def _handle_apply(self,
|
137
|
-
if not isinstance(operand, QuantumLambdaFunction):
|
138
|
-
return
|
134
|
+
def _handle_apply(self, body: StatementBlock) -> None:
|
139
135
|
local_variables: Set[str] = set()
|
140
136
|
output_capturing_variables: Set[str] = set()
|
141
|
-
for statement in
|
137
|
+
for statement in body:
|
142
138
|
if isinstance(statement, VariableDeclarationStatement):
|
143
139
|
local_variables.add(statement.name)
|
144
140
|
elif isinstance(statement, QuantumOperation):
|
@@ -3,9 +3,9 @@ from typing import TYPE_CHECKING
|
|
3
3
|
from classiq.interface.model.quantum_statement import QuantumOperation
|
4
4
|
|
5
5
|
if TYPE_CHECKING:
|
6
|
-
from classiq.interface.model.
|
6
|
+
from classiq.interface.model.statement_block import StatementBlock
|
7
7
|
|
8
8
|
|
9
|
-
class
|
10
|
-
compute: "
|
11
|
-
action: "
|
9
|
+
class WithinApply(QuantumOperation):
|
10
|
+
compute: "StatementBlock"
|
11
|
+
action: "StatementBlock"
|
@@ -78,10 +78,6 @@ FINANCE_GENERATE_MODEL_PATH = MODEL_GENERATE_PREFIX + "/finance"
|
|
78
78
|
|
79
79
|
GROVER_GENERATE_MODEL_PATH = MODEL_GENERATE_PREFIX + "/grover"
|
80
80
|
|
81
|
-
QMOD_PREFIX = ANALYZER_PREFIX + "/qmods"
|
82
|
-
QMOD_METADATA_PATH = QMOD_PREFIX + "/metadata"
|
83
|
-
QMOD_FILE_PATH = QMOD_PREFIX + "/file"
|
84
|
-
|
85
81
|
CONVERSION_GENERATED_CIRCUIT_TO_EXECUTION_INPUT_SUFFIX = "/execution_input"
|
86
82
|
CONVERSION_GENERATED_CIRCUIT_TO_EXECUTION_INPUT_FULL = (
|
87
83
|
CONVERSION_PREFIX + CONVERSION_GENERATED_CIRCUIT_TO_EXECUTION_INPUT_SUFFIX
|
@@ -8,6 +8,14 @@ from classiq.qmod.symbolic import symbolic_function
|
|
8
8
|
from .structs import *
|
9
9
|
|
10
10
|
|
11
|
+
def qft_const_adder_phase(
|
12
|
+
bit_index: QParam[int],
|
13
|
+
value: QParam[int],
|
14
|
+
reg_len: QParam[int],
|
15
|
+
) -> QParam[float]:
|
16
|
+
return symbolic_function(bit_index, value, reg_len, return_type=QParam[float])
|
17
|
+
|
18
|
+
|
11
19
|
def molecule_problem_to_hamiltonian(
|
12
20
|
problem: QParam[MoleculeProblem],
|
13
21
|
) -> QParam[List[PauliTerm]]:
|
@@ -59,20 +67,12 @@ def gaussian_finance_post_process(
|
|
59
67
|
)
|
60
68
|
|
61
69
|
|
62
|
-
def qft_const_adder_phase(
|
63
|
-
bit_index: QParam[int],
|
64
|
-
value: QParam[int],
|
65
|
-
reg_len: QParam[int],
|
66
|
-
) -> QParam[float]:
|
67
|
-
return symbolic_function(bit_index, value, reg_len, return_type=QParam[float])
|
68
|
-
|
69
|
-
|
70
70
|
__all__ = [
|
71
|
+
"qft_const_adder_phase",
|
71
72
|
"molecule_problem_to_hamiltonian",
|
72
73
|
"fock_hamiltonian_problem_to_hamiltonian",
|
73
74
|
"grid_entangler_graph",
|
74
75
|
"hypercube_entangler_graph",
|
75
76
|
"log_normal_finance_post_process",
|
76
77
|
"gaussian_finance_post_process",
|
77
|
-
"qft_const_adder_phase",
|
78
78
|
]
|