classiq 0.44.0__py3-none-any.whl → 0.45.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 +1 -2
- classiq/_internals/api_wrapper.py +2 -2
- classiq/_internals/authentication/auth0.py +1 -1
- classiq/_internals/authentication/device.py +5 -1
- classiq/_internals/authentication/token_manager.py +5 -4
- classiq/_internals/client.py +1 -1
- classiq/_internals/config.py +1 -2
- classiq/_internals/host_checker.py +1 -2
- classiq/_internals/jobs.py +1 -1
- classiq/analyzer/analyzer.py +1 -1
- classiq/analyzer/analyzer_utilities.py +1 -1
- classiq/analyzer/rb.py +1 -1
- classiq/applications/chemistry/chemistry_model_constructor.py +1 -1
- classiq/applications/combinatorial_helpers/arithmetic/isolation.py +1 -1
- classiq/applications/combinatorial_helpers/encoding_mapping.py +1 -1
- classiq/applications/combinatorial_helpers/encoding_utils.py +2 -1
- classiq/applications/combinatorial_helpers/optimization_model.py +1 -1
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_utils.py +1 -1
- classiq/applications/combinatorial_helpers/pyomo_utils.py +1 -2
- classiq/applications/combinatorial_helpers/transformations/encoding.py +1 -1
- classiq/applications/combinatorial_helpers/transformations/fixed_variables.py +5 -4
- classiq/applications/combinatorial_helpers/transformations/ising_converter.py +1 -1
- classiq/applications/combinatorial_helpers/transformations/sign_seperation.py +1 -1
- classiq/applications/finance/finance_model_constructor.py +1 -1
- classiq/applications/qnn/circuit_utils.py +1 -1
- classiq/applications/qnn/datasets/dataset_base_classes.py +2 -1
- classiq/applications/qnn/datasets/dataset_not.py +2 -1
- classiq/applications/qnn/qlayer.py +2 -1
- classiq/applications/qnn/torch_utils.py +2 -1
- classiq/applications/qsvm/qsvm_model_constructor.py +1 -1
- classiq/execution/execution_session.py +1 -1
- classiq/execution/jobs.py +5 -2
- classiq/interface/_version.py +1 -1
- classiq/interface/analyzer/cytoscape_graph.py +1 -2
- classiq/interface/analyzer/result.py +2 -3
- classiq/interface/backend/backend_preferences.py +1 -2
- classiq/interface/backend/quantum_backend_providers.py +1 -1
- classiq/interface/chemistry/fermionic_operator.py +1 -2
- classiq/interface/chemistry/ground_state_problem.py +2 -3
- classiq/interface/chemistry/molecule.py +1 -2
- classiq/interface/chemistry/operator.py +3 -9
- classiq/interface/combinatorial_optimization/encoding_types.py +1 -1
- classiq/interface/combinatorial_optimization/mht_qaoa_input.py +1 -1
- classiq/interface/combinatorial_optimization/solver_types.py +1 -1
- classiq/interface/executor/aws_execution_cost.py +2 -2
- classiq/interface/executor/execution_preferences.py +1 -2
- classiq/interface/executor/execution_result.py +1 -2
- classiq/interface/executor/optimizer_preferences.py +2 -3
- classiq/interface/executor/quantum_code.py +1 -2
- classiq/interface/executor/quantum_instruction_set.py +2 -2
- classiq/interface/executor/register_initialization.py +1 -2
- classiq/interface/executor/result.py +4 -2
- classiq/interface/finance/function_input.py +6 -11
- classiq/interface/generator/amplitude_loading.py +2 -3
- classiq/interface/generator/ansatz_library.py +1 -1
- classiq/interface/generator/application_apis/finance_declarations.py +1 -22
- classiq/interface/generator/arith/arithmetic.py +10 -8
- classiq/interface/generator/arith/arithmetic_arg_type_validator.py +1 -2
- classiq/interface/generator/arith/arithmetic_expression_abc.py +1 -2
- classiq/interface/generator/arith/arithmetic_expression_parser.py +3 -4
- classiq/interface/generator/arith/arithmetic_expression_validator.py +1 -2
- classiq/interface/generator/arith/arithmetic_param_getters.py +1 -2
- classiq/interface/generator/arith/arithmetic_result_builder.py +15 -11
- classiq/interface/generator/arith/ast_node_rewrite.py +1 -1
- classiq/interface/generator/arith/binary_ops.py +2 -3
- classiq/interface/generator/arith/endianness.py +1 -1
- classiq/interface/generator/arith/extremum_operations.py +1 -2
- classiq/interface/generator/arith/logical_ops.py +1 -2
- classiq/interface/generator/arith/register_user_input.py +1 -2
- classiq/interface/generator/arith/unary_ops.py +1 -2
- classiq/interface/generator/arith/uncomputation_methods.py +1 -1
- classiq/interface/generator/chemistry_function_params.py +1 -2
- classiq/interface/generator/circuit_code/circuit_code.py +1 -2
- classiq/interface/generator/circuit_code/types_and_constants.py +1 -2
- classiq/interface/generator/commuting_pauli_exponentiation.py +1 -2
- classiq/interface/generator/control_state.py +1 -2
- classiq/interface/generator/custom_ansatz.py +1 -2
- classiq/interface/generator/expressions/enums/finance_functions.py +4 -5
- classiq/interface/generator/expressions/evaluated_expression.py +1 -2
- classiq/interface/generator/expressions/expression.py +1 -2
- classiq/interface/generator/expressions/non_symbolic_expr.py +1 -1
- classiq/interface/generator/expressions/qmod_qarray_proxy.py +2 -5
- classiq/interface/generator/expressions/qmod_qscalar_proxy.py +2 -7
- classiq/interface/generator/expressions/qmod_qstruct_proxy.py +1 -1
- classiq/interface/generator/expressions/qmod_sized_proxy.py +1 -1
- classiq/interface/generator/function_params.py +2 -3
- classiq/interface/generator/functions/classical_type.py +0 -38
- classiq/interface/generator/functions/port_declaration.py +1 -2
- classiq/interface/generator/functions/type_name.py +2 -26
- classiq/interface/generator/grover_diffuser.py +1 -2
- classiq/interface/generator/grover_operator.py +1 -2
- classiq/interface/generator/hamiltonian_evolution/exponentiation.py +1 -2
- classiq/interface/generator/hamiltonian_evolution/suzuki_trotter.py +1 -2
- classiq/interface/generator/hardware/hardware_data.py +1 -2
- classiq/interface/generator/hardware_efficient_ansatz.py +2 -3
- classiq/interface/generator/hartree_fock.py +1 -2
- classiq/interface/generator/linear_pauli_rotations.py +1 -2
- classiq/interface/generator/mcmt_method.py +1 -1
- classiq/interface/generator/mcu.py +1 -2
- classiq/interface/generator/mcx.py +1 -2
- classiq/interface/generator/model/constraints.py +2 -3
- classiq/interface/generator/model/model.py +1 -2
- classiq/interface/generator/model/preferences/preferences.py +2 -3
- classiq/interface/generator/model/quantum_register.py +1 -2
- classiq/interface/generator/oracles/arithmetic_oracle.py +1 -2
- classiq/interface/generator/oracles/custom_oracle.py +1 -2
- classiq/interface/generator/oracles/oracle_abc.py +1 -2
- classiq/interface/generator/partitioned_register.py +1 -2
- classiq/interface/generator/piecewise_linear_amplitude_loading.py +1 -2
- classiq/interface/generator/preferences/optimization.py +1 -2
- classiq/interface/generator/qpe.py +1 -2
- classiq/interface/generator/qsvm.py +2 -3
- classiq/interface/generator/quantum_function_call.py +1 -2
- classiq/interface/generator/quantum_program.py +4 -5
- classiq/interface/generator/range_types.py +1 -1
- classiq/interface/generator/register_role.py +1 -1
- classiq/interface/generator/slice_parsing_utils.py +1 -2
- classiq/interface/generator/standard_gates/controlled_standard_gates.py +1 -2
- classiq/interface/generator/state_preparation/metrics.py +2 -3
- classiq/interface/generator/state_preparation/state_preparation.py +1 -2
- classiq/interface/generator/transpiler_basis_gates.py +1 -1
- classiq/interface/generator/types/builtin_enum_declarations.py +38 -45
- classiq/interface/generator/types/enum_declaration.py +1 -2
- classiq/interface/generator/types/struct_declaration.py +1 -2
- classiq/interface/generator/ucc.py +1 -2
- classiq/interface/generator/unitary_gate.py +1 -2
- classiq/interface/generator/validations/flow_graph.py +1 -2
- classiq/interface/generator/validations/validator_functions.py +1 -2
- classiq/interface/hardware.py +1 -1
- classiq/interface/helpers/validation_helpers.py +1 -2
- classiq/interface/ide/visual_model.py +1 -2
- classiq/interface/jobs.py +2 -3
- classiq/interface/model/bind_operation.py +1 -2
- classiq/interface/model/inplace_binary_operation.py +1 -2
- classiq/interface/model/model.py +1 -2
- classiq/interface/model/parameter.py +1 -2
- classiq/interface/model/port_declaration.py +1 -2
- classiq/interface/model/quantum_expressions/amplitude_loading_operation.py +1 -2
- classiq/interface/model/quantum_function_call.py +1 -2
- classiq/interface/model/quantum_lambda_function.py +1 -2
- classiq/interface/model/quantum_type.py +1 -22
- classiq/interface/model/validation_handle.py +1 -2
- classiq/interface/server/global_versions.py +2 -2
- classiq/qmod/builtins/classical_execution_primitives.py +1 -1
- classiq/qmod/builtins/operations.py +1 -1
- classiq/qmod/classical_function.py +1 -1
- classiq/qmod/declaration_inferrer.py +9 -7
- classiq/qmod/qmod_constant.py +1 -1
- classiq/qmod/qmod_parameter.py +26 -2
- classiq/qmod/qmod_variable.py +47 -8
- classiq/qmod/quantum_expandable.py +9 -3
- classiq/qmod/quantum_function.py +9 -2
- classiq/qmod/semantics/annotation.py +1 -2
- classiq/qmod/semantics/static_semantics_visitor.py +1 -1
- classiq/qmod/semantics/validation/func_call_validation.py +1 -1
- classiq/qmod/symbolic.py +2 -1
- classiq/show.py +1 -1
- {classiq-0.44.0.dist-info → classiq-0.45.0.dist-info}/METADATA +1 -1
- {classiq-0.44.0.dist-info → classiq-0.45.0.dist-info}/RECORD +162 -162
- /classiq/{_internals → interface}/enum_utils.py +0 -0
- /classiq/{exceptions.py → interface/exceptions.py} +0 -0
- {classiq-0.44.0.dist-info → classiq-0.45.0.dist-info}/WHEEL +0 -0
@@ -14,6 +14,7 @@ from typing import (
|
|
14
14
|
overload,
|
15
15
|
)
|
16
16
|
|
17
|
+
from classiq.interface.exceptions import ClassiqValueError
|
17
18
|
from classiq.interface.generator.expressions.expression import Expression
|
18
19
|
from classiq.interface.generator.functions.builtins.internal_operators import (
|
19
20
|
REPEAT_OPERATOR_NAME,
|
@@ -40,7 +41,6 @@ from classiq.interface.model.repeat import Repeat
|
|
40
41
|
from classiq.interface.model.statement_block import StatementBlock
|
41
42
|
from classiq.interface.model.within_apply_operation import WithinApply
|
42
43
|
|
43
|
-
from classiq.exceptions import ClassiqValueError
|
44
44
|
from classiq.qmod.qmod_variable import Input, Output, QArray, QBit, QNum, QVar
|
45
45
|
from classiq.qmod.quantum_callable import QCallable
|
46
46
|
from classiq.qmod.quantum_expandable import prepare_arg
|
@@ -4,7 +4,7 @@ import sys
|
|
4
4
|
from textwrap import dedent
|
5
5
|
from typing import Any, Callable, Dict
|
6
6
|
|
7
|
-
from classiq.exceptions import ClassiqValueError
|
7
|
+
from classiq.interface.exceptions import ClassiqValueError
|
8
8
|
|
9
9
|
|
10
10
|
def _unparse_function_body(code: str, func: ast.FunctionDef) -> str:
|
@@ -6,6 +6,7 @@ from typing import (
|
|
6
6
|
Any,
|
7
7
|
Callable,
|
8
8
|
List,
|
9
|
+
Literal,
|
9
10
|
Optional,
|
10
11
|
Sequence,
|
11
12
|
Tuple,
|
@@ -17,6 +18,7 @@ from typing import (
|
|
17
18
|
|
18
19
|
from typing_extensions import _AnnotatedAlias
|
19
20
|
|
21
|
+
from classiq.interface.exceptions import ClassiqValueError
|
20
22
|
from classiq.interface.generator.functions.classical_type import (
|
21
23
|
Bool,
|
22
24
|
ClassicalArray,
|
@@ -45,7 +47,6 @@ from classiq.interface.model.quantum_function_declaration import (
|
|
45
47
|
)
|
46
48
|
|
47
49
|
from classiq import Struct, StructDeclaration
|
48
|
-
from classiq.exceptions import ClassiqValueError
|
49
50
|
from classiq.qmod.model_state_container import ModelStateContainer
|
50
51
|
from classiq.qmod.qmod_parameter import CArray, CBool, CInt, CReal
|
51
52
|
from classiq.qmod.qmod_variable import QVar, get_type_hint_expr
|
@@ -165,12 +166,13 @@ def _extract_operand_param(py_type: Any) -> Tuple[Optional[str], Any]:
|
|
165
166
|
return None, py_type
|
166
167
|
elif isinstance(args[1], str):
|
167
168
|
return args[1], args[0]
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
169
|
+
elif get_origin(args[1]) is Literal:
|
170
|
+
return version_portable_get_args(args[1])[0], args[0]
|
171
|
+
elif len(args) == 3 and isinstance(args[1], PortDeclarationDirection):
|
172
|
+
if isinstance(args[2], str):
|
173
|
+
return args[2], Annotated[args[0], args[1]]
|
174
|
+
elif get_origin(args[2]) is Literal:
|
175
|
+
return version_portable_get_args(args[2])[0], Annotated[args[0], args[1]]
|
174
176
|
raise ClassiqValueError(
|
175
177
|
f"Operand parameter declaration must be of the form <param-type> or "
|
176
178
|
f"Annotated[<param-type>, <param-name>]. Got {py_type}"
|
classiq/qmod/qmod_constant.py
CHANGED
@@ -2,6 +2,7 @@ import inspect
|
|
2
2
|
from dataclasses import is_dataclass
|
3
3
|
from typing import Any, Optional
|
4
4
|
|
5
|
+
from classiq.interface.exceptions import ClassiqError
|
5
6
|
from classiq.interface.generator.constant import Constant
|
6
7
|
from classiq.interface.generator.expressions.expression import Expression
|
7
8
|
from classiq.interface.generator.functions.classical_type import (
|
@@ -9,7 +10,6 @@ from classiq.interface.generator.functions.classical_type import (
|
|
9
10
|
ClassicalList,
|
10
11
|
)
|
11
12
|
|
12
|
-
from classiq.exceptions import ClassiqError
|
13
13
|
from classiq.qmod.declaration_inferrer import python_type_to_qmod
|
14
14
|
from classiq.qmod.model_state_container import ModelStateContainer
|
15
15
|
from classiq.qmod.qmod_parameter import CParam, CParamList, CParamStruct
|
classiq/qmod/qmod_parameter.py
CHANGED
@@ -10,20 +10,23 @@ from typing import ( # type: ignore[attr-defined]
|
|
10
10
|
|
11
11
|
from typing_extensions import ParamSpec
|
12
12
|
|
13
|
+
from classiq.interface.exceptions import ClassiqValueError
|
13
14
|
from classiq.interface.generator.functions.classical_type import (
|
15
|
+
Bool,
|
14
16
|
ClassicalArray,
|
15
17
|
ClassicalList,
|
16
18
|
ClassicalType,
|
19
|
+
Integer,
|
20
|
+
Real,
|
17
21
|
)
|
22
|
+
from classiq.interface.generator.functions.type_name import TypeName
|
18
23
|
|
19
24
|
from classiq import Struct, StructDeclaration
|
20
|
-
from classiq.exceptions import ClassiqValueError
|
21
25
|
from classiq.qmod.model_state_container import ModelStateContainer
|
22
26
|
from classiq.qmod.symbolic_expr import Symbolic, SymbolicExpr
|
23
27
|
|
24
28
|
_T = TypeVar("_T")
|
25
29
|
|
26
|
-
|
27
30
|
if TYPE_CHECKING:
|
28
31
|
from classiq.qmod.qmod_variable import QNum
|
29
32
|
|
@@ -160,3 +163,24 @@ def create_param(
|
|
160
163
|
|
161
164
|
|
162
165
|
Array = CArray
|
166
|
+
|
167
|
+
|
168
|
+
def get_qmod_type(ctype: ClassicalType) -> type:
|
169
|
+
if isinstance(ctype, Integer):
|
170
|
+
return CInt
|
171
|
+
elif isinstance(ctype, Real):
|
172
|
+
return CReal
|
173
|
+
elif isinstance(ctype, Bool):
|
174
|
+
return CBool
|
175
|
+
elif isinstance(ctype, ClassicalList):
|
176
|
+
return CArray[get_qmod_type(ctype.element_type)] # type: ignore[misc]
|
177
|
+
elif isinstance(ctype, ClassicalArray):
|
178
|
+
return CArray[get_qmod_type(ctype.element_type), ctype.size] # type: ignore[misc]
|
179
|
+
elif isinstance(ctype, TypeName):
|
180
|
+
type_ = type(ctype.name, (TypeName,), dict())
|
181
|
+
if isinstance(ctype, Struct):
|
182
|
+
type_.__dataclass_fields__ = [] # type:ignore[attr-defined]
|
183
|
+
return type_
|
184
|
+
raise NotImplementedError(
|
185
|
+
f"{ctype.__class__.__name__!r} has no QMOD SDK equivalent"
|
186
|
+
)
|
classiq/qmod/qmod_variable.py
CHANGED
@@ -22,6 +22,7 @@ from typing import ( # type: ignore[attr-defined]
|
|
22
22
|
|
23
23
|
from typing_extensions import Annotated, ParamSpec, Self, _AnnotatedAlias
|
24
24
|
|
25
|
+
from classiq.interface.exceptions import ClassiqValueError
|
25
26
|
from classiq.interface.generator.expressions.expression import Expression
|
26
27
|
from classiq.interface.generator.expressions.qmod_qarray_proxy import (
|
27
28
|
ILLEGAL_SLICE_BOUNDS_MSG,
|
@@ -56,7 +57,6 @@ from classiq.interface.model.quantum_type import (
|
|
56
57
|
)
|
57
58
|
from classiq.interface.source_reference import SourceReference
|
58
59
|
|
59
|
-
from classiq.exceptions import ClassiqValueError
|
60
60
|
from classiq.qmod.model_state_container import QMODULE, ModelStateContainer
|
61
61
|
from classiq.qmod.qmod_parameter import ArrayBase, CBool, CInt, CParamScalar
|
62
62
|
from classiq.qmod.quantum_callable import QCallable
|
@@ -169,6 +169,16 @@ class QVar(Symbolic):
|
|
169
169
|
def __str__(self) -> str:
|
170
170
|
return self._expr_str
|
171
171
|
|
172
|
+
@property
|
173
|
+
def size(self) -> Union[CParamScalar, int]:
|
174
|
+
if not QVAR_PROPERTIES_ARE_SYMBOLIC:
|
175
|
+
return self._evaluate_size()
|
176
|
+
return CParamScalar(f"get_field({self}, 'size')")
|
177
|
+
|
178
|
+
@abc.abstractmethod
|
179
|
+
def _evaluate_size(self) -> int:
|
180
|
+
raise NotImplementedError
|
181
|
+
|
172
182
|
|
173
183
|
_Q = TypeVar("_Q", bound=QVar)
|
174
184
|
Output = Annotated[_Q, PortDeclarationDirection.Output]
|
@@ -259,6 +269,9 @@ class QBit(QScalar):
|
|
259
269
|
def get_qmod_type(self) -> QuantumType:
|
260
270
|
return QuantumBit()
|
261
271
|
|
272
|
+
def _evaluate_size(self) -> int:
|
273
|
+
return 1
|
274
|
+
|
262
275
|
|
263
276
|
_P = ParamSpec("_P")
|
264
277
|
|
@@ -345,13 +358,10 @@ class QNum(Generic[_P], QScalar):
|
|
345
358
|
fraction_digits=self._fraction_digits,
|
346
359
|
)
|
347
360
|
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
assert self._size is not None
|
353
|
-
return self._size.to_int_value()
|
354
|
-
return CParamScalar(f"get_field({self}, 'size')")
|
361
|
+
def _evaluate_size(self) -> int:
|
362
|
+
if TYPE_CHECKING:
|
363
|
+
assert self._size is not None
|
364
|
+
return self._size.to_int_value()
|
355
365
|
|
356
366
|
@property
|
357
367
|
def fraction_digits(self) -> Union[CParamScalar, int]:
|
@@ -475,6 +485,11 @@ class QArray(ArrayBase[_P], QVar):
|
|
475
485
|
return CParamScalar(f"{self._length}")
|
476
486
|
return CParamScalar(f"get_field({self}, 'len')")
|
477
487
|
|
488
|
+
def _evaluate_size(self) -> int:
|
489
|
+
if TYPE_CHECKING:
|
490
|
+
assert self._length is not None
|
491
|
+
return self._element_type.size_in_bits * self._length.to_int_value()
|
492
|
+
|
478
493
|
@classmethod
|
479
494
|
def _get_attributes(cls, type_hint: Any) -> Tuple[Type[QVar], Any]:
|
480
495
|
type_args = version_portable_get_args(type_hint)
|
@@ -604,6 +619,9 @@ class QStruct(QVar):
|
|
604
619
|
fields={name: qvar.get_qmod_type() for name, qvar in self._fields.items()},
|
605
620
|
)
|
606
621
|
|
622
|
+
def _evaluate_size(self) -> int:
|
623
|
+
return sum(var._evaluate_size() for var in self._fields.values())
|
624
|
+
|
607
625
|
|
608
626
|
def create_qvar_for_port_decl(port: AnonPortDeclaration, name: str) -> QVar:
|
609
627
|
return _create_qvar_for_qtype(port.quantum_type, HandleBinding(name=name))
|
@@ -642,3 +660,24 @@ def _create_qvar_for_qtype(
|
|
642
660
|
if TYPE_CHECKING:
|
643
661
|
assert isinstance(qtype, QuantumBitvector)
|
644
662
|
return QArray(origin, qtype.element_type, qtype.length, _expr_str=expr_str)
|
663
|
+
|
664
|
+
|
665
|
+
def get_qvar(qtype: QuantumType, origin: HandleBinding) -> "QVar":
|
666
|
+
if isinstance(qtype, QuantumBit):
|
667
|
+
return QBit(origin)
|
668
|
+
elif isinstance(qtype, QuantumBitvector):
|
669
|
+
return QArray(origin, qtype.element_type, qtype.length)
|
670
|
+
elif isinstance(qtype, QuantumNumeric):
|
671
|
+
return QNum(origin, qtype.size, qtype.is_signed, qtype.fraction_digits)
|
672
|
+
elif isinstance(qtype, TypeName):
|
673
|
+
return QStruct(
|
674
|
+
origin,
|
675
|
+
qtype.name,
|
676
|
+
{
|
677
|
+
field_name: get_qvar(
|
678
|
+
field_type, FieldHandleBinding(base_handle=origin, field=field_name)
|
679
|
+
)
|
680
|
+
for field_name, field_type in qtype.fields.items()
|
681
|
+
},
|
682
|
+
)
|
683
|
+
raise NotImplementedError
|
@@ -20,6 +20,7 @@ from typing import (
|
|
20
20
|
from sympy import Basic
|
21
21
|
from typing_extensions import Self
|
22
22
|
|
23
|
+
from classiq.interface.exceptions import ClassiqValueError
|
23
24
|
from classiq.interface.generator.expressions.expression import Expression
|
24
25
|
from classiq.interface.generator.functions.concrete_types import PythonClassicalTypes
|
25
26
|
from classiq.interface.model.classical_parameter_declaration import (
|
@@ -45,10 +46,15 @@ from classiq.interface.model.variable_declaration_statement import (
|
|
45
46
|
)
|
46
47
|
from classiq.interface.source_reference import SourceReference
|
47
48
|
|
48
|
-
from classiq.exceptions import ClassiqValueError
|
49
49
|
from classiq.qmod.model_state_container import QMODULE, ModelStateContainer
|
50
50
|
from classiq.qmod.qmod_constant import QConstant
|
51
|
-
from classiq.qmod.qmod_parameter import
|
51
|
+
from classiq.qmod.qmod_parameter import (
|
52
|
+
CInt,
|
53
|
+
CParam,
|
54
|
+
CParamScalar,
|
55
|
+
create_param,
|
56
|
+
get_qmod_type,
|
57
|
+
)
|
52
58
|
from classiq.qmod.qmod_variable import (
|
53
59
|
QVar,
|
54
60
|
create_qvar_for_port_decl,
|
@@ -321,7 +327,7 @@ def _validate_classical_arg(
|
|
321
327
|
raise ClassiqValueError(
|
322
328
|
f"Argument {str(arg)!r} to parameter {arg_decl.name!r}{func_name_message} "
|
323
329
|
f"has incompatible type; expected "
|
324
|
-
f"{arg_decl.classical_type.
|
330
|
+
f"{get_qmod_type(arg_decl.classical_type).__name__}"
|
325
331
|
)
|
326
332
|
|
327
333
|
|
classiq/qmod/quantum_function.py
CHANGED
@@ -5,6 +5,7 @@ from enum import EnumMeta
|
|
5
5
|
from inspect import isclass
|
6
6
|
from typing import Any, Callable, Dict, List, Optional, Tuple, get_origin
|
7
7
|
|
8
|
+
from classiq.interface.exceptions import ClassiqError
|
8
9
|
from classiq.interface.executor.execution_preferences import ExecutionPreferences
|
9
10
|
from classiq.interface.generator.model.constraints import Constraints
|
10
11
|
from classiq.interface.generator.model.preferences.preferences import Preferences
|
@@ -15,7 +16,6 @@ from classiq.interface.model.quantum_function_declaration import (
|
|
15
16
|
QuantumFunctionDeclaration,
|
16
17
|
)
|
17
18
|
|
18
|
-
from classiq.exceptions import ClassiqError
|
19
19
|
from classiq.qmod.classical_function import CFunc
|
20
20
|
from classiq.qmod.declaration_inferrer import infer_func_decl
|
21
21
|
from classiq.qmod.model_state_container import QMODULE
|
@@ -25,6 +25,7 @@ from classiq.qmod.qmod_variable import QVar
|
|
25
25
|
from classiq.qmod.quantum_callable import QCallable, QCallableList
|
26
26
|
from classiq.qmod.quantum_expandable import QExpandable, QTerminalCallable
|
27
27
|
from classiq.qmod.utilities import mangle_keyword, unmangle_keyword
|
28
|
+
from classiq.qmod.write_qmod import write_qmod
|
28
29
|
|
29
30
|
|
30
31
|
def _lookup_qfunc(name: str) -> Optional[NamedParamsQuantumFunctionDeclaration]:
|
@@ -38,15 +39,21 @@ def create_model(
|
|
38
39
|
execution_preferences: Optional[ExecutionPreferences] = None,
|
39
40
|
preferences: Optional[Preferences] = None,
|
40
41
|
classical_execution_function: Optional[CFunc] = None,
|
42
|
+
out_file: Optional[str] = None,
|
41
43
|
) -> SerializedModel:
|
42
44
|
if entry_point.func_decl.name != "main":
|
43
45
|
raise ClassiqError(
|
44
46
|
f"The entry point function must be named 'main', got '{entry_point.func_decl.name}'"
|
45
47
|
)
|
46
|
-
|
48
|
+
result = entry_point.create_model(
|
47
49
|
constraints, execution_preferences, preferences, classical_execution_function
|
48
50
|
).get_model()
|
49
51
|
|
52
|
+
if out_file is not None:
|
53
|
+
write_qmod(result, out_file)
|
54
|
+
|
55
|
+
return result
|
56
|
+
|
50
57
|
|
51
58
|
class QFunc(QExpandable):
|
52
59
|
FRAME_DEPTH = 2
|
@@ -1,5 +1,6 @@
|
|
1
1
|
from typing import Mapping
|
2
2
|
|
3
|
+
from classiq.interface.exceptions import ClassiqError
|
3
4
|
from classiq.interface.model.quantum_function_call import QuantumFunctionCall
|
4
5
|
from classiq.interface.model.quantum_function_declaration import (
|
5
6
|
AnonQuantumOperandDeclaration,
|
@@ -9,8 +10,6 @@ from classiq.interface.model.quantum_lambda_function import (
|
|
9
10
|
QuantumLambdaFunction,
|
10
11
|
)
|
11
12
|
|
12
|
-
from classiq.exceptions import ClassiqError
|
13
|
-
|
14
13
|
|
15
14
|
def annotate_function_call_decl(
|
16
15
|
fc: QuantumFunctionCall,
|
@@ -12,6 +12,7 @@ from typing import (
|
|
12
12
|
Type,
|
13
13
|
)
|
14
14
|
|
15
|
+
from classiq.interface.exceptions import ClassiqSemanticError
|
15
16
|
from classiq.interface.generator.function_params import PortDirection
|
16
17
|
from classiq.interface.generator.functions.concrete_types import ConcreteQuantumType
|
17
18
|
from classiq.interface.generator.functions.port_declaration import (
|
@@ -45,7 +46,6 @@ from classiq.interface.model.variable_declaration_statement import (
|
|
45
46
|
from classiq.interface.model.within_apply_operation import WithinApply
|
46
47
|
|
47
48
|
from classiq import AnonClassicalParameterDeclaration
|
48
|
-
from classiq.exceptions import ClassiqSemanticError
|
49
49
|
from classiq.qmod.semantics.annotation import annotate_function_call_decl
|
50
50
|
from classiq.qmod.semantics.error_manager import ErrorManager
|
51
51
|
from classiq.qmod.semantics.validation.func_call_validation import (
|
@@ -1,5 +1,6 @@
|
|
1
1
|
from typing import List, Mapping
|
2
2
|
|
3
|
+
from classiq.interface.exceptions import ClassiqError
|
3
4
|
from classiq.interface.generator.expressions.expression import Expression
|
4
5
|
from classiq.interface.model.handle_binding import HandleBinding
|
5
6
|
from classiq.interface.model.quantum_function_call import QuantumFunctionCall
|
@@ -13,7 +14,6 @@ from classiq.interface.model.quantum_lambda_function import (
|
|
13
14
|
QuantumOperand,
|
14
15
|
)
|
15
16
|
|
16
|
-
from classiq.exceptions import ClassiqError
|
17
17
|
from classiq.qmod.semantics.error_manager import ErrorManager
|
18
18
|
|
19
19
|
|
classiq/qmod/symbolic.py
CHANGED
@@ -11,7 +11,8 @@ from typing import (
|
|
11
11
|
overload,
|
12
12
|
)
|
13
13
|
|
14
|
-
from classiq.exceptions import ClassiqValueError
|
14
|
+
from classiq.interface.exceptions import ClassiqValueError
|
15
|
+
|
15
16
|
from classiq.qmod import model_state_container
|
16
17
|
from classiq.qmod.declaration_inferrer import python_type_to_qmod
|
17
18
|
from classiq.qmod.qmod_parameter import (
|
classiq/show.py
CHANGED
@@ -3,11 +3,11 @@ import re
|
|
3
3
|
import pydantic
|
4
4
|
|
5
5
|
from classiq.interface.analyzer.result import QasmCode
|
6
|
+
from classiq.interface.exceptions import ClassiqValueError
|
6
7
|
|
7
8
|
from classiq import QuantumProgram
|
8
9
|
from classiq._internals.api_wrapper import ApiWrapper
|
9
10
|
from classiq._internals.async_utils import syncify_function
|
10
|
-
from classiq.exceptions import ClassiqValueError
|
11
11
|
from classiq.synthesis import SerializedQuantumProgram
|
12
12
|
|
13
13
|
QASM_VERSION_REGEX = re.compile("OPENQASM (\\d*.\\d*);")
|