classiq 0.32.1__py3-none-any.whl → 0.34.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 +2 -1
- classiq/_analyzer_extras/_ipywidgets_async_extension.py +1 -1
- classiq/_internals/api_wrapper.py +34 -23
- classiq/_internals/jobs.py +41 -14
- classiq/analyzer/__init__.py +3 -1
- classiq/applications/__init__.py +3 -1
- classiq/applications/benchmarking/__init__.py +3 -1
- classiq/applications/chemistry/__init__.py +3 -1
- classiq/applications/combinatorial_optimization/__init__.py +3 -1
- classiq/applications/combinatorial_optimization/examples/__init__.py +3 -1
- classiq/applications/finance/__init__.py +3 -1
- classiq/applications/qnn/__init__.py +3 -1
- classiq/applications/qnn/datasets/__init__.py +3 -1
- classiq/applications/qsvm/qsvm.py +1 -1
- classiq/applications_model_constructors/grover_model_constructor.py +25 -8
- classiq/builtin_functions/__init__.py +3 -1
- classiq/execution/__init__.py +3 -1
- classiq/execution/jobs.py +57 -20
- classiq/executor.py +4 -11
- classiq/interface/_version.py +1 -1
- classiq/interface/analyzer/analysis_params.py +1 -1
- classiq/interface/backend/backend_preferences.py +17 -0
- classiq/interface/backend/pydantic_backend.py +8 -0
- classiq/interface/backend/quantum_backend_providers.py +15 -1
- classiq/interface/chemistry/ground_state_problem.py +1 -1
- classiq/interface/chemistry/operator.py +198 -0
- classiq/interface/executor/execution_request.py +5 -12
- classiq/interface/generator/circuit_code/types_and_constants.py +1 -1
- classiq/interface/generator/complex_type.py +4 -1
- classiq/interface/generator/functions/__init__.py +3 -1
- classiq/interface/generator/functions/core_lib_declarations/quantum_functions/__init__.py +0 -1
- classiq/interface/generator/functions/core_lib_declarations/quantum_functions/atomic_quantum_functions.py +39 -39
- classiq/interface/generator/functions/core_lib_declarations/quantum_functions/std_lib_functions.py +251 -87
- classiq/interface/generator/functions/core_lib_declarations/quantum_operators.py +5 -54
- classiq/interface/generator/generated_circuit.py +14 -43
- classiq/interface/generator/generated_circuit_data.py +26 -34
- classiq/interface/generator/model/preferences/preferences.py +3 -3
- classiq/interface/generator/partitioned_register.py +1 -1
- classiq/interface/generator/quantum_function_call.py +1 -1
- classiq/interface/generator/validations/validator_functions.py +4 -2
- classiq/interface/hardware.py +3 -2
- classiq/interface/ide/show.py +1 -14
- classiq/interface/model/bind_operation.py +20 -0
- classiq/interface/model/handle_binding.py +8 -0
- classiq/interface/model/native_function_definition.py +15 -5
- classiq/interface/model/quantum_expressions/amplitude_loading_operation.py +8 -3
- classiq/interface/model/quantum_expressions/arithmetic_operation.py +9 -4
- classiq/interface/model/quantum_expressions/quantum_expression.py +10 -5
- classiq/interface/model/quantum_function_call.py +24 -347
- classiq/interface/model/quantum_function_declaration.py +7 -11
- classiq/interface/model/quantum_statement.py +13 -7
- classiq/interface/model/validations/handle_validation_base.py +1 -2
- classiq/interface/model/validations/handles_validator.py +34 -8
- classiq/interface/model/variable_declaration_statement.py +8 -0
- classiq/interface/server/routes.py +11 -16
- classiq/model/__init__.py +3 -1
- classiq/model/function_handler.py +1 -1
- classiq/model/function_handler.pyi +88 -88
- classiq/qmod/declaration_inferrer.py +37 -18
- classiq/qmod/model_state_container.py +6 -3
- classiq/qmod/qmod_builtins.py +892 -4
- classiq/qmod/qmod_parameter.py +24 -8
- classiq/qmod/qmod_variable.py +2 -1
- classiq/qmod/quantum_expandable.py +6 -2
- classiq/qmod/quantum_function.py +11 -10
- classiq/quantum_functions/quantum_function.py +4 -1
- {classiq-0.32.1.dist-info → classiq-0.34.0.dist-info}/METADATA +1 -1
- {classiq-0.32.1.dist-info → classiq-0.34.0.dist-info}/RECORD +69 -72
- classiq/interface/generator/functions/core_lib_declarations/quantum_functions/apps_lib_functions.py +0 -262
- classiq/interface/model/clients/__init__.py +0 -0
- classiq/interface/model/clients/qmod/__init__.py +0 -0
- classiq/interface/model/clients/qmod/qmod_builtins.py +0 -908
- classiq/interface/model/semantics.py +0 -15
- {classiq-0.32.1.dist-info → classiq-0.34.0.dist-info}/WHEEL +0 -0
@@ -1,7 +1,11 @@
|
|
1
1
|
from typing import Dict, Iterable, Mapping, Union
|
2
2
|
|
3
|
-
from classiq.interface.generator.function_params import
|
4
|
-
from classiq.interface.model.handle_binding import
|
3
|
+
from classiq.interface.generator.function_params import PortDirection
|
4
|
+
from classiq.interface.model.handle_binding import (
|
5
|
+
HandleBinding,
|
6
|
+
SlicedHandleBinding,
|
7
|
+
SubscriptHandleBinding,
|
8
|
+
)
|
5
9
|
from classiq.interface.model.local_variable_declaration import LocalVariableDeclaration
|
6
10
|
from classiq.interface.model.port_declaration import PortDeclaration
|
7
11
|
from classiq.interface.model.quantum_statement import QuantumOperation
|
@@ -9,12 +13,15 @@ from classiq.interface.model.validation_handle import HandleState, ValidationHan
|
|
9
13
|
from classiq.interface.model.validations.handle_validation_base import (
|
10
14
|
HandleValidationBase,
|
11
15
|
)
|
16
|
+
from classiq.interface.model.variable_declaration_statement import (
|
17
|
+
VariableDeclarationStatement,
|
18
|
+
)
|
12
19
|
|
13
20
|
|
14
21
|
def _initialize_handles_to_state(
|
15
|
-
port_declarations: Mapping[
|
22
|
+
port_declarations: Mapping[str, PortDeclaration],
|
16
23
|
local_handles: Iterable[LocalVariableDeclaration],
|
17
|
-
) ->
|
24
|
+
) -> Dict[str, ValidationHandle]:
|
18
25
|
handles_to_state: Dict[str, ValidationHandle] = dict()
|
19
26
|
|
20
27
|
for port_decl in port_declarations.values():
|
@@ -35,7 +42,7 @@ def _initialize_handles_to_state(
|
|
35
42
|
class HandleValidator(HandleValidationBase):
|
36
43
|
def __init__(
|
37
44
|
self,
|
38
|
-
port_declarations: Mapping[
|
45
|
+
port_declarations: Mapping[str, PortDeclaration],
|
39
46
|
local_handles: Iterable[LocalVariableDeclaration],
|
40
47
|
) -> None:
|
41
48
|
super().__init__(port_declarations)
|
@@ -53,6 +60,20 @@ class HandleValidator(HandleValidationBase):
|
|
53
60
|
self._handle_outputs(call.wiring_outputs)
|
54
61
|
self._handle_inouts(call.wiring_inouts)
|
55
62
|
|
63
|
+
def handle_variable_declaration(
|
64
|
+
self, declaration: VariableDeclarationStatement
|
65
|
+
) -> None:
|
66
|
+
handle_wiring_state = self._handles_to_state.get(declaration.name)
|
67
|
+
if handle_wiring_state is not None:
|
68
|
+
handle_wiring_state.append_error(
|
69
|
+
f"Trying to declare a variable of the same name as previously declared variable {declaration.name}"
|
70
|
+
)
|
71
|
+
return
|
72
|
+
|
73
|
+
self._handles_to_state[declaration.name] = ValidationHandle(
|
74
|
+
HandleState.UNINITIALIZED
|
75
|
+
)
|
76
|
+
|
56
77
|
def _handle_inputs(self, inputs: Mapping[str, HandleBinding]) -> None:
|
57
78
|
for handle_binding in inputs.values():
|
58
79
|
handle_wiring_state = self._handles_to_state[handle_binding.name]
|
@@ -77,7 +98,10 @@ class HandleValidator(HandleValidationBase):
|
|
77
98
|
handle_wiring_state.initialize()
|
78
99
|
|
79
100
|
def _handle_inouts(
|
80
|
-
self,
|
101
|
+
self,
|
102
|
+
inouts: Mapping[
|
103
|
+
str, Union[SlicedHandleBinding, SubscriptHandleBinding, HandleBinding]
|
104
|
+
],
|
81
105
|
) -> None:
|
82
106
|
sliced_handles = set()
|
83
107
|
whole_handles = set()
|
@@ -90,12 +114,14 @@ class HandleValidator(HandleValidationBase):
|
|
90
114
|
f"Trying to access handle {handle_binding.name} as inout but it is in incorrect state"
|
91
115
|
)
|
92
116
|
|
93
|
-
if isinstance(
|
117
|
+
if isinstance(
|
118
|
+
handle_binding, (SlicedHandleBinding, SubscriptHandleBinding)
|
119
|
+
):
|
94
120
|
sliced_handles.add(handle_binding.name)
|
95
121
|
else:
|
96
122
|
whole_handles.add(handle_binding.name)
|
97
123
|
|
98
124
|
for handle in sliced_handles & whole_handles:
|
99
125
|
self._handles_to_state[handle].append_error(
|
100
|
-
f"Invalid use of inout handle {handle_binding.name}, used both
|
126
|
+
f"Invalid use of inout handle {handle_binding.name}, used both in slice or subscript and whole"
|
101
127
|
)
|
@@ -0,0 +1,8 @@
|
|
1
|
+
from classiq.interface.model.quantum_statement import QuantumStatement
|
2
|
+
from classiq.interface.model.quantum_variable_declaration import (
|
3
|
+
QuantumVariableDeclaration,
|
4
|
+
)
|
5
|
+
|
6
|
+
|
7
|
+
class VariableDeclarationStatement(QuantumStatement, QuantumVariableDeclaration):
|
8
|
+
pass
|
@@ -1,6 +1,9 @@
|
|
1
1
|
ANALYZER_PREFIX = "/analyzer"
|
2
2
|
CHEMISTRY_PREFIX = "/chemistry"
|
3
|
-
|
3
|
+
LEGACY_EXECUTE_PREFIX = "/execute"
|
4
|
+
EXECUTION_PREFIX = "/execution"
|
5
|
+
|
6
|
+
SYNTHESIS_SERVICE_PREFIX = "/synthesis/v1"
|
4
7
|
|
5
8
|
ANALYZER_CIRCUIT_PAGE = "circuit"
|
6
9
|
DEFAULT_IDE_FE_APP = "https://platform.classiq.io/"
|
@@ -17,9 +20,7 @@ ANALYZER_OPTIONAL_DEVICES = "/graphs/available_devices"
|
|
17
20
|
ANALYZER_OPTIONAL_DEVICES_FULL_PATH = ANALYZER_PREFIX + ANALYZER_OPTIONAL_DEVICES
|
18
21
|
|
19
22
|
TASKS_SUFFIX = "/tasks"
|
20
|
-
GENERATED_CIRCUIT_SUFFIX = "/generated_circuit"
|
21
23
|
QUANTUM_PROGRAM_SUFFIX = "/quantum_program"
|
22
|
-
FINANCE_SUFFIX = "/finance"
|
23
24
|
ESTIMATE_SUFFIX = "/estimate"
|
24
25
|
RB = "/rb"
|
25
26
|
ANALYZER_DATA_TASK = f"{TASKS_SUFFIX}/data"
|
@@ -35,10 +36,7 @@ DATA_DOG_EVENT_TASK_FULL_PATH = f"{ANALYZER_PREFIX}{DATA_DOG_EVENT_TASK}"
|
|
35
36
|
|
36
37
|
IDE_QASM_TASK = f"{TASKS_SUFFIX}/generated_circuit_from_qasm"
|
37
38
|
IDE_QASM_FULL_PATH = f"{ANALYZER_PREFIX}{IDE_QASM_TASK}"
|
38
|
-
IDE_EXECUTION_RESULTS_PATH = f"/results{EXECUTE_PREFIX}"
|
39
|
-
ASYNC_TASKS_SUFFIX = "/async_tasks"
|
40
39
|
TASKS_GENERATE_SUFFIX = TASKS_SUFFIX + "/generate"
|
41
|
-
SEMANTICS_CHECK_SUFFIX = TASKS_SUFFIX + "/semantic_checks"
|
42
40
|
TASKS_VISUALIZE_SUFFIX = TASKS_SUFFIX + "/visualize"
|
43
41
|
TASKS_SOLVE_SUFFIX = "/tasks/solve"
|
44
42
|
MODEL_GENERATE_PREFIX = "/generate_model"
|
@@ -52,25 +50,22 @@ TASKS_GENERATE_FULL_PATH = TASKS_GENERATE_SUFFIX
|
|
52
50
|
TASKS_SOLVE_EXACT_SUFFIX = "/tasks/solve_exact"
|
53
51
|
TASKS_UCC_OPERATORS_SUFFIX = "/tasks/ucc_operators"
|
54
52
|
|
55
|
-
TASKS_GET_MAX_CUT_MODEL = "/tasks/get_max_cut_model"
|
56
53
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
EXECUTE_ESTIMATE_FULL_PATH = EXECUTE_PREFIX + ESTIMATE_SUFFIX
|
62
|
-
EXECUTE_ASYNC_TASKS_FULL_PATH = EXECUTE_PREFIX + ASYNC_TASKS_SUFFIX
|
54
|
+
EXECUTION_JOBS_SUFFIX = "/jobs"
|
55
|
+
EXECUTION_JOBS_FULL_PATH = EXECUTION_PREFIX + EXECUTION_JOBS_SUFFIX
|
56
|
+
EXECUTE_QUANTUM_PROGRAM_FULL_PATH = LEGACY_EXECUTE_PREFIX + QUANTUM_PROGRAM_SUFFIX
|
57
|
+
EXECUTE_ESTIMATE_FULL_PATH = LEGACY_EXECUTE_PREFIX + ESTIMATE_SUFFIX
|
63
58
|
|
64
59
|
ANALYZER_FULL_PATH = ANALYZER_PREFIX + TASKS_SUFFIX
|
65
60
|
ANALYZER_RB_FULL_PATH = ANALYZER_PREFIX + TASK_RB_SUFFIX
|
66
61
|
GENERATE_RESOURCE_ESTIMATOR_REPORT = "/resource_estimator_report"
|
67
62
|
|
68
|
-
|
63
|
+
GENERATE_HAMILTONIAN_SUFFIX = "/generate_hamiltonian"
|
64
|
+
GENERATE_HAMILTONIAN_FULL_PATH = SYNTHESIS_SERVICE_PREFIX + GENERATE_HAMILTONIAN_SUFFIX
|
65
|
+
|
69
66
|
CHEMISTRY_GENERATE_UCC_OPERATORS_FULL_PATH = (
|
70
67
|
CHEMISTRY_PREFIX + TASKS_UCC_OPERATORS_SUFFIX
|
71
68
|
)
|
72
|
-
CHEMISTRY_SOLVE_EXACT_FULL_PATH = CHEMISTRY_PREFIX + TASKS_SOLVE_EXACT_SUFFIX
|
73
|
-
CHEMISTRY_SOLVE_FULL_PATH = CHEMISTRY_PREFIX + TASKS_SOLVE_SUFFIX
|
74
69
|
|
75
70
|
FINANCE_GENERATE_MODEL_PATH = MODEL_GENERATE_PREFIX + "/finance"
|
76
71
|
|
classiq/model/__init__.py
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
from typing import List
|
2
|
+
|
1
3
|
from classiq.interface.generator.model import * # noqa: F403
|
2
4
|
from classiq.interface.generator.model import __all__ as _model_all
|
3
5
|
|
@@ -8,5 +10,5 @@ __all__ = ["FunctionGenerator", "Model"]
|
|
8
10
|
__all__.extend(_model_all)
|
9
11
|
|
10
12
|
|
11
|
-
def __dir__():
|
13
|
+
def __dir__() -> List[str]:
|
12
14
|
return __all__
|
@@ -454,7 +454,7 @@ class FunctionHandler(abc.ABC):
|
|
454
454
|
|
455
455
|
raise AttributeError(f"{self.__class__.__name__!r} has no attribute {item!r}")
|
456
456
|
|
457
|
-
def __dir__(self):
|
457
|
+
def __dir__(self) -> List[str]:
|
458
458
|
builtin_func_name = [
|
459
459
|
func.__name__
|
460
460
|
for func in function_param_list.function_param_library.param_list
|
@@ -24,7 +24,7 @@ from classiq.model import logic_flow_change_handler as logic_flow_change_handler
|
|
24
24
|
from classiq.model.logic_flow import LogicFlowBuilder as LogicFlowBuilder
|
25
25
|
from classiq.quantum_functions.function_library import FunctionLibrary as FunctionLibrary, QuantumFunction as QuantumFunction, SynthesisQuantumFunctionDeclaration as SynthesisQuantumFunctionDeclaration
|
26
26
|
from classiq.quantum_register import QReg as QReg, QRegGenericAlias as QRegGenericAlias
|
27
|
-
from typing import Any, Callable, Collection, Dict, Iterable, Mapping, Optional, Union
|
27
|
+
from typing import Any, Callable, Collection, Dict, Iterable, List, Mapping, Optional, Union
|
28
28
|
|
29
29
|
SupportedInputArgs = Union[Mapping[IOName, QReg], Collection[QReg], QReg]
|
30
30
|
WireNameDict = Dict[IOName, WireName]
|
@@ -40,114 +40,114 @@ class FunctionHandler(abc.ABC, metaclass=abc.ABCMeta):
|
|
40
40
|
def output_wires(self) -> WireNameDict: ...
|
41
41
|
def create_inputs(self, inputs: Mapping[IOName, QRegGenericAlias]) -> Dict[IOName, QReg]: ...
|
42
42
|
def set_outputs(self, outputs: Mapping[IOName, QReg]) -> None: ...
|
43
|
-
def apply(self, function_name: Union[str, SynthesisQuantumFunctionDeclaration, QuantumFunction], in_wires: Optional[SupportedInputArgs] =
|
43
|
+
def apply(self, function_name: Union[str, SynthesisQuantumFunctionDeclaration, QuantumFunction], in_wires: Optional[SupportedInputArgs] = None, out_wires: Optional[SupportedInputArgs] = None, is_inverse: bool = False, strict_zero_ios: bool = True, release_by_inverse: bool = False, control_states: Optional[Union[ControlState, Iterable[ControlState]]] = None, should_control: bool = True, power: int = 1, call_name: Optional[str] = None, parameters_dict: Optional[Dict[str, ParameterFloatType]] = None) -> Dict[IOName, QReg]: ...
|
44
44
|
def release_qregs(self, qregs: Union[QReg, Collection[QReg]]) -> None: ...
|
45
45
|
def __getattr__(self, item: str) -> Callable[..., Any]: ...
|
46
|
-
def __dir__(self): ...
|
46
|
+
def __dir__(self) -> List[str]: ...
|
47
47
|
def include_library(self, library: FunctionLibrary) -> None: ...
|
48
48
|
@abc.abstractmethod
|
49
49
|
def create_library(self) -> None: ...
|
50
|
-
def
|
51
|
-
def
|
52
|
-
def RZZGate(self, params: RZZGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
53
|
-
def HartreeFock(self, params: HartreeFock, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
54
|
-
def RandomizedBenchmarking(self, params: RandomizedBenchmarking, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
55
|
-
def CXGate(self, params: CXGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
56
|
-
def BitwiseOr(self, params: BitwiseOr, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
57
|
-
def MCPhaseGate(self, params: MCPhaseGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
58
|
-
def LShift(self, params: LShift, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
59
|
-
def BitwiseXor(self, params: BitwiseXor, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
50
|
+
def HadamardTransform(self, params: HadamardTransform, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
51
|
+
def RShift(self, params: RShift, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
60
52
|
def RGate(self, params: RGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
61
|
-
def
|
62
|
-
def
|
63
|
-
def
|
53
|
+
def LogicalAnd(self, params: LogicalAnd, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
54
|
+
def HardwareEfficientAnsatz(self, params: HardwareEfficientAnsatz, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
55
|
+
def NotEqual(self, params: NotEqual, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
56
|
+
def LinearGCI(self, params: LinearGCI, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
57
|
+
def GreaterThan(self, params: GreaterThan, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
58
|
+
def GreaterEqual(self, params: GreaterEqual, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
59
|
+
def LessThan(self, params: LessThan, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
60
|
+
def LessEqual(self, params: LessEqual, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
61
|
+
def CRZGate(self, params: CRZGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
62
|
+
def CPhaseGate(self, params: CPhaseGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
63
|
+
def ExponentialStatePreparation(self, params: ExponentialStatePreparation, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
64
|
+
def HVA(self, params: HVA, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
65
|
+
def RZGate(self, params: RZGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
66
|
+
def FinancePayoff(self, params: FinancePayoff, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
67
|
+
def Exponentiation(self, params: Exponentiation, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
68
|
+
def UnitaryGate(self, params: UnitaryGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
69
|
+
def QSVMFeatureMap(self, params: QSVMFeatureMap, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
70
|
+
def CyclicShift(self, params: CyclicShift, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
71
|
+
def StatePreparation(self, params: StatePreparation, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
72
|
+
def LShift(self, params: LShift, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
73
|
+
def BitwiseAnd(self, params: BitwiseAnd, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
74
|
+
def UniformDistributionStatePreparation(self, params: UniformDistributionStatePreparation, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
75
|
+
def XGate(self, params: XGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
76
|
+
def RYGate(self, params: RYGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
77
|
+
def Negation(self, params: Negation, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
78
|
+
def MCPhaseGate(self, params: MCPhaseGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
79
|
+
def Subtractor(self, params: Subtractor, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
80
|
+
def HartreeFock(self, params: HartreeFock, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
81
|
+
def Finance(self, params: Finance, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
82
|
+
def Identity(self, params: Identity, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
83
|
+
def Mcu(self, params: Mcu, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
84
|
+
def HypercubeEntangler(self, params: HypercubeEntangler, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
64
85
|
def C3XGate(self, params: C3XGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
65
|
-
def UCC(self, params: UCC, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
66
86
|
def CYGate(self, params: CYGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
67
|
-
def YGate(self, params: YGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
68
87
|
def CZGate(self, params: CZGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
88
|
+
def UGate(self, params: UGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
89
|
+
def RandomizedBenchmarking(self, params: RandomizedBenchmarking, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
90
|
+
def PhaseEstimation(self, params: PhaseEstimation, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
91
|
+
def InequalityMixer(self, params: InequalityMixer, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
92
|
+
def Sign(self, params: Sign, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
93
|
+
def CommutingPauliExponentiation(self, params: CommutingPauliExponentiation, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
94
|
+
def Equal(self, params: Equal, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
95
|
+
def AmplitudeLoading(self, params: AmplitudeLoading, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
96
|
+
def ComputationalBasisStatePreparation(self, params: ComputationalBasisStatePreparation, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
97
|
+
def GridEntangler(self, params: GridEntangler, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
98
|
+
def RXGate(self, params: RXGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
99
|
+
def WStatePreparation(self, params: WStatePreparation, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
100
|
+
def Mcx(self, params: Mcx, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
101
|
+
def RYYGate(self, params: RYYGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
102
|
+
def SwapGate(self, params: SwapGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
103
|
+
def BellStatePreparation(self, params: BellStatePreparation, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
104
|
+
def GroverOperator(self, params: GroverOperator, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
105
|
+
def AmplitudeEstimation(self, params: AmplitudeEstimation, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
106
|
+
def PiecewiseLinearRotationAmplitudeLoading(self, params: PiecewiseLinearRotationAmplitudeLoading, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
107
|
+
def QFT(self, params: QFT, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
108
|
+
def YGate(self, params: YGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
109
|
+
def TwoDimensionalEntangler(self, params: TwoDimensionalEntangler, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
69
110
|
def ZGate(self, params: ZGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
70
111
|
def HGate(self, params: HGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
71
|
-
def
|
72
|
-
def
|
112
|
+
def CHGate(self, params: CHGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
113
|
+
def CustomFunction(self, params: CustomFunction, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
114
|
+
def CSXGate(self, params: CSXGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
73
115
|
def SGate(self, params: SGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
74
|
-
def
|
75
|
-
def
|
76
|
-
def SXGate(self, params: SXGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
116
|
+
def IGate(self, params: IGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
117
|
+
def RZZGate(self, params: RZZGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
77
118
|
def SuzukiTrotter(self, params: SuzukiTrotter, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
119
|
+
def SXGate(self, params: SXGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
120
|
+
def SdgGate(self, params: SdgGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
78
121
|
def SXdgGate(self, params: SXdgGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
122
|
+
def GHZStatePreparation(self, params: GHZStatePreparation, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
79
123
|
def TGate(self, params: TGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
80
|
-
def
|
81
|
-
def
|
82
|
-
def
|
83
|
-
def
|
84
|
-
def
|
85
|
-
def Equal(self, params: Equal, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
86
|
-
def NotEqual(self, params: NotEqual, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
87
|
-
def Mcu(self, params: Mcu, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
88
|
-
def GreaterThan(self, params: GreaterThan, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
89
|
-
def GreaterEqual(self, params: GreaterEqual, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
90
|
-
def LessThan(self, params: LessThan, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
91
|
-
def SwapGate(self, params: SwapGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
92
|
-
def LessEqual(self, params: LessEqual, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
93
|
-
def RYGate(self, params: RYGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
124
|
+
def TdgGate(self, params: TdgGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
125
|
+
def iSwapGate(self, params: iSwapGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
126
|
+
def QDrift(self, params: QDrift, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
127
|
+
def CustomOracle(self, params: CustomOracle, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
128
|
+
def BitwiseXor(self, params: BitwiseXor, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
94
129
|
def Modulo(self, params: Modulo, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
95
130
|
def LogicalOr(self, params: LogicalOr, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
96
|
-
def FinanceModels(self, params: FinanceModels, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
97
|
-
def GroverDiffuser(self, params: GroverDiffuser, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
98
|
-
def WStatePreparation(self, params: WStatePreparation, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
99
|
-
def InequalityMixer(self, params: InequalityMixer, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
100
|
-
def CustomFunction(self, params: CustomFunction, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
101
|
-
def RangeMixer(self, params: RangeMixer, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
102
|
-
def Arithmetic(self, params: Arithmetic, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
103
|
-
def CHGate(self, params: CHGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
104
|
-
def HardwareEfficientAnsatz(self, params: HardwareEfficientAnsatz, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
105
|
-
def CSXGate(self, params: CSXGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
106
|
-
def BitwiseInvert(self, params: BitwiseInvert, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
107
|
-
def CustomOracle(self, params: CustomOracle, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
108
|
-
def UnitaryGate(self, params: UnitaryGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
109
|
-
def Negation(self, params: Negation, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
110
|
-
def HadamardTransform(self, params: HadamardTransform, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
111
|
-
def TdgGate(self, params: TdgGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
112
131
|
def Multiplier(self, params: Multiplier, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
113
|
-
def PhaseEstimation(self, params: PhaseEstimation, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
114
|
-
def StatePreparation(self, params: StatePreparation, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
115
|
-
def Subtractor(self, params: Subtractor, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
116
132
|
def Min(self, params: Min, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
133
|
+
def BitwiseInvert(self, params: BitwiseInvert, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
117
134
|
def Max(self, params: Max, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
118
|
-
def
|
119
|
-
def
|
135
|
+
def GroverDiffuser(self, params: GroverDiffuser, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
136
|
+
def LinearPauliRotations(self, params: LinearPauliRotations, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
137
|
+
def RangeMixer(self, params: RangeMixer, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
138
|
+
def Arithmetic(self, params: Arithmetic, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
139
|
+
def FinanceModels(self, params: FinanceModels, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
140
|
+
def RXXGate(self, params: RXXGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
141
|
+
def PiecewiseLinearAmplitudeLoading(self, params: PiecewiseLinearAmplitudeLoading, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
120
142
|
def CCXGate(self, params: CCXGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
121
|
-
def LogicalAnd(self, params: LogicalAnd, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
122
|
-
def FinancePayoff(self, params: FinancePayoff, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
123
143
|
def CRYGate(self, params: CRYGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
144
|
+
def StatePropagator(self, params: StatePropagator, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
124
145
|
def CRXGate(self, params: CRXGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
125
|
-
def
|
126
|
-
def
|
127
|
-
def BitwiseAnd(self, params: BitwiseAnd, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
128
|
-
def LinearGCI(self, params: LinearGCI, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
129
|
-
def C4XGate(self, params: C4XGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
130
|
-
def HVA(self, params: HVA, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
131
|
-
def iSwapGate(self, params: iSwapGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
132
|
-
def QSVMFeatureMap(self, params: QSVMFeatureMap, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
133
|
-
def CyclicShift(self, params: CyclicShift, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
134
|
-
def QDrift(self, params: QDrift, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
135
|
-
def WeightedAdder(self, params: WeightedAdder, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
136
|
-
def UniformDistributionStatePreparation(self, params: UniformDistributionStatePreparation, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
137
|
-
def Mcx(self, params: Mcx, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
138
|
-
def GHZStatePreparation(self, params: GHZStatePreparation, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
139
|
-
def BellStatePreparation(self, params: BellStatePreparation, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
140
|
-
def GroverOperator(self, params: GroverOperator, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
141
|
-
def TwoDimensionalEntangler(self, params: TwoDimensionalEntangler, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
142
|
-
def RShift(self, params: RShift, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
143
|
-
def AmplitudeEstimation(self, params: AmplitudeEstimation, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
144
|
-
def RYYGate(self, params: RYYGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
145
|
-
def CRZGate(self, params: CRZGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
146
|
+
def PhaseGate(self, params: PhaseGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
147
|
+
def CXGate(self, params: CXGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
146
148
|
def ArithmeticOracle(self, params: ArithmeticOracle, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
147
|
-
def
|
148
|
-
def
|
149
|
-
def
|
150
|
-
def
|
151
|
-
def
|
152
|
-
def PiecewiseLinearAmplitudeLoading(self, params: PiecewiseLinearAmplitudeLoading, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
153
|
-
def XGate(self, params: XGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
149
|
+
def WeightedAdder(self, params: WeightedAdder, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
150
|
+
def UCC(self, params: UCC, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
151
|
+
def C4XGate(self, params: C4XGate, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
152
|
+
def Adder(self, params: Adder, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
153
|
+
def BitwiseOr(self, params: BitwiseOr, in_wires: Optional[Dict[str, Wire]] = None) -> Dict[str, Wire]: ...
|
@@ -36,13 +36,17 @@ OPERAND_ARG_NAME = "arg{i}"
|
|
36
36
|
|
37
37
|
|
38
38
|
def _version_portable_get_args(py_type: type) -> tuple:
|
39
|
+
if get_origin(py_type) is None:
|
40
|
+
return tuple()
|
39
41
|
if sys.version_info[0:2] < (3, 10):
|
40
42
|
return get_args(py_type) # The result of __class_getitem__
|
41
43
|
else:
|
42
44
|
return get_args(py_type)[0]
|
43
45
|
|
44
46
|
|
45
|
-
def _python_type_to_qmod(
|
47
|
+
def _python_type_to_qmod(
|
48
|
+
py_type: type, *, qmodule: ModelStateContainer
|
49
|
+
) -> Optional[ConcreteClassicalType]:
|
46
50
|
if py_type == int:
|
47
51
|
return Integer()
|
48
52
|
elif py_type == float:
|
@@ -50,7 +54,9 @@ def _python_type_to_qmod(py_type: type) -> Optional[ConcreteClassicalType]:
|
|
50
54
|
elif py_type == bool:
|
51
55
|
return Bool()
|
52
56
|
elif get_origin(py_type) == list:
|
53
|
-
return ClassicalList(
|
57
|
+
return ClassicalList(
|
58
|
+
element_type=_python_type_to_qmod(get_args(py_type)[0], qmodule=qmodule)
|
59
|
+
)
|
54
60
|
elif get_origin(py_type) == Array:
|
55
61
|
array_args = _version_portable_get_args(py_type)
|
56
62
|
if len(array_args) != 2:
|
@@ -58,36 +64,41 @@ def _python_type_to_qmod(py_type: type) -> Optional[ConcreteClassicalType]:
|
|
58
64
|
"Array accepts two generic parameters in the form 'Array[<element-type>, <size>]'"
|
59
65
|
)
|
60
66
|
return ClassicalArray(
|
61
|
-
element_type=_python_type_to_qmod(array_args[0]),
|
67
|
+
element_type=_python_type_to_qmod(array_args[0], qmodule=qmodule),
|
62
68
|
size=get_type_hint_expr(array_args[1]),
|
63
69
|
)
|
64
70
|
elif inspect.isclass(py_type) and issubclass(py_type, QStructBase):
|
65
|
-
_add_qmod_struct(py_type)
|
71
|
+
_add_qmod_struct(py_type, qmodule=qmodule)
|
66
72
|
return Struct(name=py_type.__name__)
|
67
73
|
return None
|
68
74
|
|
69
75
|
|
70
|
-
def _add_qmod_struct(
|
76
|
+
def _add_qmod_struct(
|
77
|
+
py_type: Type[QStructBase], *, qmodule: ModelStateContainer
|
78
|
+
) -> None:
|
71
79
|
if (
|
72
80
|
py_type.__name__ in StructDeclaration.BUILTIN_STRUCT_DECLARATIONS
|
73
|
-
or py_type.__name__ in
|
81
|
+
or py_type.__name__ in qmodule.type_decls.keys()
|
74
82
|
):
|
75
83
|
return
|
76
84
|
|
77
|
-
|
85
|
+
qmodule.type_decls[py_type.__name__] = StructDeclaration(
|
78
86
|
name=py_type.__name__,
|
79
87
|
variables={
|
80
|
-
f.name: _python_type_to_qmod(f.type
|
88
|
+
f.name: _python_type_to_qmod(f.type, qmodule=qmodule)
|
89
|
+
for f in dataclasses.fields(py_type)
|
81
90
|
},
|
82
91
|
)
|
83
92
|
|
84
93
|
|
85
|
-
def _extract_param_decl(
|
94
|
+
def _extract_param_decl(
|
95
|
+
name: str, py_type: Any, *, qmodule: ModelStateContainer
|
96
|
+
) -> ClassicalParameterDeclaration:
|
86
97
|
if len(get_args(py_type)) != 1:
|
87
98
|
raise ValueError("QParam takes exactly one generic argument")
|
88
99
|
py_type = get_args(py_type)[0]
|
89
100
|
return ClassicalParameterDeclaration(
|
90
|
-
name=name, classical_type=_python_type_to_qmod(py_type)
|
101
|
+
name=name, classical_type=_python_type_to_qmod(py_type, qmodule=qmodule)
|
91
102
|
)
|
92
103
|
|
93
104
|
|
@@ -104,35 +115,43 @@ def _extract_port_decl(name: str, py_type: Any) -> PortDeclaration:
|
|
104
115
|
)
|
105
116
|
|
106
117
|
|
107
|
-
def _extract_operand_decl(
|
118
|
+
def _extract_operand_decl(
|
119
|
+
name: str, py_type: Any, qmodule: ModelStateContainer
|
120
|
+
) -> QuantumOperandDeclaration:
|
108
121
|
qc_args = _version_portable_get_args(py_type)
|
109
122
|
arg_dict = {
|
110
123
|
OPERAND_ARG_NAME.format(i=i): arg_type for i, arg_type in enumerate(qc_args)
|
111
124
|
}
|
112
125
|
return QuantumOperandDeclaration(
|
113
126
|
name=name,
|
114
|
-
positional_arg_declarations=_extract_positional_args(arg_dict),
|
127
|
+
positional_arg_declarations=_extract_positional_args(arg_dict, qmodule=qmodule),
|
115
128
|
)
|
116
129
|
|
117
130
|
|
118
|
-
def _extract_positional_args(
|
131
|
+
def _extract_positional_args(
|
132
|
+
args: Dict[str, Any], qmodule: ModelStateContainer
|
133
|
+
) -> List[PositionalArg]:
|
119
134
|
result: List[PositionalArg] = []
|
120
135
|
for name, py_type in args.items():
|
121
136
|
if name == "return":
|
122
137
|
continue
|
123
138
|
name = unmangle_keyword(name)
|
124
139
|
if get_origin(py_type) is QParam:
|
125
|
-
result.append(_extract_param_decl(name, py_type))
|
140
|
+
result.append(_extract_param_decl(name, py_type, qmodule=qmodule))
|
126
141
|
elif QVar.from_type_hint(py_type) is not None:
|
127
142
|
result.append(_extract_port_decl(name, py_type))
|
128
143
|
else:
|
129
|
-
assert get_origin(py_type) is QCallable
|
130
|
-
result.append(_extract_operand_decl(name, py_type))
|
144
|
+
assert get_origin(py_type) or py_type is QCallable
|
145
|
+
result.append(_extract_operand_decl(name, py_type, qmodule=qmodule))
|
131
146
|
return result
|
132
147
|
|
133
148
|
|
134
|
-
def infer_func_decl(
|
149
|
+
def infer_func_decl(
|
150
|
+
py_func: Callable, qmodule: ModelStateContainer
|
151
|
+
) -> QuantumFunctionDeclaration:
|
135
152
|
return QuantumFunctionDeclaration(
|
136
153
|
name=unmangle_keyword(py_func.__name__),
|
137
|
-
positional_arg_declarations=_extract_positional_args(
|
154
|
+
positional_arg_declarations=_extract_positional_args(
|
155
|
+
py_func.__annotations__, qmodule=qmodule
|
156
|
+
),
|
138
157
|
)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import
|
1
|
+
from typing import Dict
|
2
2
|
|
3
3
|
from classiq.interface.model.native_function_definition import NativeFunctionDefinition
|
4
4
|
|
@@ -6,5 +6,8 @@ from classiq import StructDeclaration
|
|
6
6
|
|
7
7
|
|
8
8
|
class ModelStateContainer:
|
9
|
-
|
10
|
-
|
9
|
+
type_decls: Dict[str, StructDeclaration]
|
10
|
+
native_defs: Dict[str, NativeFunctionDefinition]
|
11
|
+
|
12
|
+
|
13
|
+
QMODULE = ModelStateContainer()
|