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
@@ -4,8 +4,8 @@ from typing import Any, Dict, List, Optional
|
|
4
4
|
import pydantic
|
5
5
|
from pydantic import validator
|
6
6
|
|
7
|
-
from classiq.
|
8
|
-
from classiq.exceptions import ClassiqValueError
|
7
|
+
from classiq.interface.enum_utils import StrEnum
|
8
|
+
from classiq.interface.exceptions import ClassiqValueError
|
9
9
|
|
10
10
|
|
11
11
|
class Granularity(StrEnum):
|
@@ -9,6 +9,7 @@ from classiq.interface.backend.backend_preferences import (
|
|
9
9
|
from classiq.interface.backend.quantum_backend_providers import (
|
10
10
|
ClassiqSimulatorBackendNames,
|
11
11
|
)
|
12
|
+
from classiq.interface.enum_utils import ReprEnum
|
12
13
|
from classiq.interface.executor.optimizer_preferences import OptimizerType
|
13
14
|
from classiq.interface.generator.model.preferences.preferences import (
|
14
15
|
TranspilationOption,
|
@@ -16,8 +17,6 @@ from classiq.interface.generator.model.preferences.preferences import (
|
|
16
17
|
from classiq.interface.generator.model.preferences.randomness import create_random_seed
|
17
18
|
from classiq.interface.generator.noise_properties import NoiseProperties
|
18
19
|
|
19
|
-
from classiq._internals.enum_utils import ReprEnum
|
20
|
-
|
21
20
|
|
22
21
|
class QaeWithQpeEstimationMethod(int, ReprEnum):
|
23
22
|
MAXIMUM_LIKELIHOOD = 0
|
@@ -3,6 +3,7 @@ from typing import Any, List, Literal, Union
|
|
3
3
|
from pydantic import BaseModel, Field
|
4
4
|
from typing_extensions import Annotated, TypeAlias
|
5
5
|
|
6
|
+
from classiq.interface.enum_utils import StrEnum
|
6
7
|
from classiq.interface.executor.iqae_result import IQAEResult
|
7
8
|
from classiq.interface.executor.result import (
|
8
9
|
EstimationResult,
|
@@ -13,8 +14,6 @@ from classiq.interface.executor.result import (
|
|
13
14
|
from classiq.interface.executor.vqe_result import VQESolverResult
|
14
15
|
from classiq.interface.helpers.versioned_model import VersionedModel
|
15
16
|
|
16
|
-
from classiq._internals.enum_utils import StrEnum
|
17
|
-
|
18
17
|
|
19
18
|
class SavedResultValueType(StrEnum):
|
20
19
|
Integer = "int"
|
@@ -3,11 +3,10 @@ from typing import Any, Dict, List, Optional
|
|
3
3
|
import pydantic
|
4
4
|
from pydantic import BaseModel
|
5
5
|
|
6
|
+
from classiq.interface.enum_utils import StrEnum
|
7
|
+
from classiq.interface.exceptions import ClassiqValueError
|
6
8
|
from classiq.interface.helpers.custom_pydantic_types import PydanticAlphaParamCVAR
|
7
9
|
|
8
|
-
from classiq._internals.enum_utils import StrEnum
|
9
|
-
from classiq.exceptions import ClassiqValueError
|
10
|
-
|
11
10
|
|
12
11
|
class CostType(StrEnum):
|
13
12
|
MIN = "MIN"
|
@@ -8,14 +8,13 @@ from pydantic import BaseModel
|
|
8
8
|
|
9
9
|
from classiq.interface.backend.ionq.ionq_quantum_program import IonqQuantumCircuit
|
10
10
|
from classiq.interface.backend.pydantic_backend import PydanticArgumentNameType
|
11
|
+
from classiq.interface.exceptions import ClassiqValueError
|
11
12
|
from classiq.interface.executor.quantum_instruction_set import QuantumInstructionSet
|
12
13
|
from classiq.interface.executor.register_initialization import RegisterInitialization
|
13
14
|
from classiq.interface.generator.synthesis_metadata.synthesis_execution_data import (
|
14
15
|
ExecutionData,
|
15
16
|
)
|
16
17
|
|
17
|
-
from classiq.exceptions import ClassiqValueError
|
18
|
-
|
19
18
|
Arguments = Dict[PydanticArgumentNameType, Any]
|
20
19
|
MultipleArguments = Tuple[Arguments, ...]
|
21
20
|
CodeType = str
|
@@ -2,10 +2,9 @@ from typing import Any, Dict, List
|
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
|
5
|
+
from classiq.interface.exceptions import ClassiqStateInitializationError
|
5
6
|
from classiq.interface.generator.arith import number_utils
|
6
7
|
|
7
|
-
from classiq.exceptions import ClassiqStateInitializationError
|
8
|
-
|
9
8
|
_NON_INTEGER_INITIALIZATION_ERROR_MSG: str = (
|
10
9
|
"Only natural numbers are supported as initial conditions"
|
11
10
|
)
|
@@ -18,6 +18,7 @@ import pydantic
|
|
18
18
|
from pydantic import BaseModel
|
19
19
|
from typing_extensions import TypeAlias
|
20
20
|
|
21
|
+
from classiq.interface.exceptions import ClassiqError
|
21
22
|
from classiq.interface.executor.quantum_code import OutputQubitsMap, Qubits
|
22
23
|
from classiq.interface.generator.arith import number_utils
|
23
24
|
from classiq.interface.generator.complex_type import Complex
|
@@ -25,8 +26,6 @@ from classiq.interface.generator.functions.classical_type import QmodPyObject
|
|
25
26
|
from classiq.interface.helpers.custom_pydantic_types import PydanticNonNegIntTuple
|
26
27
|
from classiq.interface.helpers.versioned_model import VersionedModel
|
27
28
|
|
28
|
-
from classiq.exceptions import ClassiqError
|
29
|
-
|
30
29
|
_ILLEGAL_QUBIT_ERROR_MSG: str = "Illegal qubit index requested"
|
31
30
|
_REPEATED_QUBIT_ERROR_MSG: str = "Requested a qubit more than once"
|
32
31
|
_UNAVAILABLE_OUTPUT_ERROR_MSG: str = "Requested output doesn't exist in the circuit"
|
@@ -152,6 +151,9 @@ class ExecutionDetails(BaseModel, QmodPyObject):
|
|
152
151
|
True,
|
153
152
|
description="Is the qubit order of counts field such that the LSB is right?",
|
154
153
|
)
|
154
|
+
probabilities: Dict[State, pydantic.NonNegativeFloat] = pydantic.Field(
|
155
|
+
default_factory=dict, description="Probabilities of each state"
|
156
|
+
)
|
155
157
|
parsed_states: ParsedStates = pydantic.Field(
|
156
158
|
default_factory=dict,
|
157
159
|
description="A mapping between the raw states of counts (bitstrings) to their parsed states (registers' values)",
|
@@ -1,19 +1,18 @@
|
|
1
|
-
from typing import
|
1
|
+
from typing import Any, Dict, Optional, Union
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
|
5
|
+
from classiq.interface.exceptions import ClassiqValueError
|
5
6
|
from classiq.interface.generator.expressions.enums.finance_functions import (
|
6
7
|
get_finance_function_dict,
|
7
8
|
)
|
9
|
+
from classiq.interface.generator.types.builtin_enum_declarations import (
|
10
|
+
FinanceFunctionType,
|
11
|
+
)
|
8
12
|
from classiq.interface.helpers.custom_pydantic_types import (
|
9
13
|
PydanticNonZeroProbabilityFloat,
|
10
14
|
)
|
11
15
|
|
12
|
-
from classiq.exceptions import ClassiqValueError
|
13
|
-
|
14
|
-
if TYPE_CHECKING:
|
15
|
-
from classiq.qmod.builtins.enums import FinanceFunctionType
|
16
|
-
|
17
16
|
|
18
17
|
class FunctionCondition(pydantic.BaseModel):
|
19
18
|
threshold: float
|
@@ -71,9 +70,7 @@ class FinanceFunctionInput(pydantic.BaseModel):
|
|
71
70
|
@pydantic.validator("f")
|
72
71
|
def _validate_finance_function(
|
73
72
|
cls, f: Union[int, str, "FinanceFunctionType"]
|
74
|
-
) ->
|
75
|
-
from classiq.qmod.builtins.enums import FinanceFunctionType
|
76
|
-
|
73
|
+
) -> FinanceFunctionType:
|
77
74
|
if isinstance(f, FinanceFunctionType):
|
78
75
|
return f
|
79
76
|
if isinstance(f, int):
|
@@ -86,8 +83,6 @@ class FinanceFunctionInput(pydantic.BaseModel):
|
|
86
83
|
tail_probability: Optional[PydanticNonZeroProbabilityFloat],
|
87
84
|
values: Dict[str, Any],
|
88
85
|
) -> Optional[PydanticNonZeroProbabilityFloat]:
|
89
|
-
from classiq.qmod.builtins.enums import FinanceFunctionType
|
90
|
-
|
91
86
|
if values.get("f") == FinanceFunctionType.SHORTFALL and not tail_probability:
|
92
87
|
raise ClassiqValueError(
|
93
88
|
"Tail probability must be set for expected shortfall"
|
@@ -4,6 +4,8 @@ from typing import Any, Dict, get_args
|
|
4
4
|
import pydantic
|
5
5
|
import sympy
|
6
6
|
|
7
|
+
from classiq.interface.enum_utils import StrEnum
|
8
|
+
from classiq.interface.exceptions import ClassiqValueError
|
7
9
|
from classiq.interface.generator.arith.arithmetic_expression_validator import (
|
8
10
|
validate_expression,
|
9
11
|
)
|
@@ -20,9 +22,6 @@ from classiq.interface.generator.function_params import (
|
|
20
22
|
)
|
21
23
|
from classiq.interface.helpers.custom_pydantic_types import PydanticExpressionStr
|
22
24
|
|
23
|
-
from classiq._internals.enum_utils import StrEnum
|
24
|
-
from classiq.exceptions import ClassiqValueError
|
25
|
-
|
26
25
|
AMPLITUDE_IO_NAME = "AMPLITUDE"
|
27
26
|
TARGET_OUTPUT_NAME = "TARGET"
|
28
27
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
from enum import Enum
|
2
|
-
from typing import
|
2
|
+
from typing import Mapping
|
3
3
|
|
4
4
|
from classiq.interface.generator.expressions.expression import Expression
|
5
5
|
from classiq.interface.generator.functions.classical_function_declaration import (
|
@@ -24,10 +24,6 @@ from classiq.interface.model.quantum_function_declaration import (
|
|
24
24
|
NamedParamsQuantumFunctionDeclaration,
|
25
25
|
)
|
26
26
|
|
27
|
-
if TYPE_CHECKING:
|
28
|
-
from classiq.qmod.builtins.structs import GaussianModel
|
29
|
-
from classiq.qmod.symbolic_expr import SymbolicExpr
|
30
|
-
|
31
27
|
FUNCTION_PORT_NAME = "func_port"
|
32
28
|
OBJECTIVE_PORT_NAME = "obj_port"
|
33
29
|
|
@@ -43,23 +39,6 @@ FINANCE_FUNCTION_PORT_SIZE_MAPPING: Mapping[FinanceModelType, str] = {
|
|
43
39
|
}
|
44
40
|
|
45
41
|
|
46
|
-
def _get_gaussian_size(finance_model: "GaussianModel") -> "SymbolicExpr":
|
47
|
-
from classiq.qmod.symbolic import floor, log, sum as sym_sum
|
48
|
-
|
49
|
-
return (
|
50
|
-
finance_model.num_qubits
|
51
|
-
+ finance_model.rhos.len
|
52
|
-
+ floor(log(sym_sum(finance_model.loss), 2))
|
53
|
-
+ 1
|
54
|
-
)
|
55
|
-
|
56
|
-
|
57
|
-
FINANCE_FUNCTION_PORT_SIZE_FUNCTION_MAPPING: Mapping[FinanceModelType, Callable] = {
|
58
|
-
FinanceModelType.Gaussian: _get_gaussian_size,
|
59
|
-
FinanceModelType.LogNormal: lambda finance_model: finance_model.num_qubits,
|
60
|
-
}
|
61
|
-
|
62
|
-
|
63
42
|
def _generate_finance_function(
|
64
43
|
finance_model: FinanceModelType,
|
65
44
|
) -> NamedParamsQuantumFunctionDeclaration:
|
@@ -1,8 +1,9 @@
|
|
1
|
-
from typing import Any, Dict, Optional, Set
|
1
|
+
from typing import Any, Dict, Final, Optional, Set
|
2
2
|
|
3
3
|
import networkx as nx
|
4
4
|
import pydantic
|
5
5
|
|
6
|
+
from classiq.interface.exceptions import ClassiqValueError
|
6
7
|
from classiq.interface.generator.arith import arithmetic_expression_parser
|
7
8
|
from classiq.interface.generator.arith.arithmetic_expression_abc import (
|
8
9
|
ArithmeticExpressionABC,
|
@@ -21,10 +22,9 @@ from classiq.interface.model.quantum_type import (
|
|
21
22
|
register_info_to_quantum_type,
|
22
23
|
)
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
ARITHMETIC_EXPRESSION_RESULT_NAME: str = "expression_result"
|
25
|
+
ARITHMETIC_EXPRESSION_TARGET_NAME: Final[str] = "arithmetic_target"
|
26
|
+
ARITHMETIC_EXPRESSION_RESULT_NAME: Final[str] = "expression_result"
|
27
|
+
ARITHMETIC_EXPRESSION_GARBAGE_NAME: Final[str] = "expression_garbage"
|
28
28
|
|
29
29
|
|
30
30
|
class Arithmetic(ArithmeticExpressionABC):
|
@@ -64,12 +64,14 @@ class Arithmetic(ArithmeticExpressionABC):
|
|
64
64
|
if name in self._inputs
|
65
65
|
}
|
66
66
|
# TODO: avoid calling the result builder again, as it is called in validation
|
67
|
-
|
67
|
+
result_builder = ArithmeticResultBuilder(
|
68
68
|
graph=arithmetic_expression_parser.parse_expression(self.expression),
|
69
69
|
definitions=self.definitions,
|
70
70
|
machine_precision=self.machine_precision,
|
71
|
-
)
|
72
|
-
self._outputs[ARITHMETIC_EXPRESSION_RESULT_NAME] =
|
71
|
+
)
|
72
|
+
self._outputs[ARITHMETIC_EXPRESSION_RESULT_NAME] = result_builder.result
|
73
|
+
if result_builder.garbage:
|
74
|
+
self._outputs[ARITHMETIC_EXPRESSION_GARBAGE_NAME] = result_builder.garbage
|
73
75
|
if self.target:
|
74
76
|
self._inputs[ARITHMETIC_EXPRESSION_TARGET_NAME] = self.target
|
75
77
|
|
@@ -2,11 +2,10 @@ from typing import Callable, Dict, List
|
|
2
2
|
|
3
3
|
from typing_extensions import TypeAlias
|
4
4
|
|
5
|
+
from classiq.interface.exceptions import ClassiqArithmeticError
|
5
6
|
from classiq.interface.generator.arith import argument_utils
|
6
7
|
from classiq.interface.generator.arith.binary_ops import BOOLEAN_OP_WITH_FRACTIONS_ERROR
|
7
8
|
|
8
|
-
from classiq.exceptions import ClassiqArithmeticError
|
9
|
-
|
10
9
|
ArgTypeValidator: TypeAlias = Callable[[List[argument_utils.RegisterOrConst]], None]
|
11
10
|
|
12
11
|
|
@@ -7,6 +7,7 @@ import networkx as nx
|
|
7
7
|
import pydantic
|
8
8
|
from typing_extensions import TypeAlias
|
9
9
|
|
10
|
+
from classiq.interface.exceptions import ClassiqValueError
|
10
11
|
from classiq.interface.generator.arith import number_utils
|
11
12
|
from classiq.interface.generator.arith.arithmetic_expression_parser import (
|
12
13
|
parse_expression,
|
@@ -30,8 +31,6 @@ from classiq.interface.generator.expressions.expression_constants import (
|
|
30
31
|
from classiq.interface.generator.function_params import FunctionParams
|
31
32
|
from classiq.interface.helpers.custom_pydantic_types import PydanticExpressionStr
|
32
33
|
|
33
|
-
from classiq.exceptions import ClassiqValueError
|
34
|
-
|
35
34
|
ValidDefinitions: TypeAlias = Union[
|
36
35
|
pydantic.StrictInt, pydantic.StrictFloat, RegisterArithmeticInfo
|
37
36
|
]
|
@@ -4,6 +4,7 @@ from typing import Collection, List, Optional, Set, Tuple, Type, Union, cast
|
|
4
4
|
|
5
5
|
import networkx as nx
|
6
6
|
|
7
|
+
from classiq.interface.exceptions import ClassiqArithmeticError
|
7
8
|
from classiq.interface.generator.arith.arithmetic_expression_validator import (
|
8
9
|
DEFAULT_EXPRESSION_TYPE,
|
9
10
|
DEFAULT_SUPPORTED_FUNC_NAMES,
|
@@ -16,11 +17,9 @@ from classiq.interface.generator.arith.ast_node_rewrite import (
|
|
16
17
|
AstNodeRewrite,
|
17
18
|
)
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
_MULTIPLE_RESULTS_ERROR_MESSAGE: str = "Expression cannot contain multiple result"
|
20
|
+
_MULTIPLE_RESULTS_ERROR_MESSAGE: str = "Expression cannot contain multiple results"
|
22
21
|
_UNEXPECTED_ARITHMETIC_ERROR_MESSAGE: str = (
|
23
|
-
"
|
22
|
+
"Quantum expressions that evaluate to a classical value are not supported"
|
24
23
|
)
|
25
24
|
_ALLOWED_MULTI_ARGUMENT_FUNCTIONS = ("min", "max")
|
26
25
|
Node = Union[str, float, int]
|
@@ -5,13 +5,12 @@ from typing import Any, Dict, Optional, Set, Tuple, Type, Union
|
|
5
5
|
|
6
6
|
from typing_extensions import TypeAlias, get_args
|
7
7
|
|
8
|
+
from classiq.interface.exceptions import ClassiqArithmeticError, ClassiqValueError
|
8
9
|
from classiq.interface.generator.arith.ast_node_rewrite import AstNodeRewrite
|
9
10
|
from classiq.interface.generator.expressions.sympy_supported_expressions import (
|
10
11
|
SYMPY_SUPPORTED_EXPRESSIONS,
|
11
12
|
)
|
12
13
|
|
13
|
-
from classiq.exceptions import ClassiqArithmeticError, ClassiqValueError
|
14
|
-
|
15
14
|
DEFAULT_SUPPORTED_FUNC_NAMES: Set[str] = {"CLShift", "CRShift", "min", "max"}
|
16
15
|
|
17
16
|
DEFAULT_EXPRESSION_TYPE = "arithmetic"
|
@@ -1,5 +1,6 @@
|
|
1
1
|
from typing import Callable, Dict, FrozenSet, List, Optional
|
2
2
|
|
3
|
+
from classiq.interface.exceptions import ClassiqArithmeticError
|
3
4
|
from classiq.interface.generator.arith.argument_utils import (
|
4
5
|
RegisterOrConst as RegisterOrFloat,
|
5
6
|
)
|
@@ -35,8 +36,6 @@ from classiq.interface.generator.arith.logical_ops import LogicalAnd, LogicalOr
|
|
35
36
|
from classiq.interface.generator.arith.register_user_input import RegisterArithmeticInfo
|
36
37
|
from classiq.interface.generator.arith.unary_ops import BitwiseInvert, Negation
|
37
38
|
|
38
|
-
from classiq.exceptions import ClassiqArithmeticError
|
39
|
-
|
40
39
|
ParamsGetter = Callable[..., ArithmeticOperationParams] # Argument vary
|
41
40
|
|
42
41
|
_TARGET_ERROR_MESSAGE: str = "Target unavailable for the requested operation"
|
@@ -1,14 +1,13 @@
|
|
1
|
-
from typing import Any, Dict, List, Optional, Set
|
1
|
+
from typing import Any, Dict, List, Optional, Set, Tuple
|
2
2
|
|
3
3
|
import networkx as nx
|
4
4
|
|
5
|
+
from classiq.interface.exceptions import ClassiqArithmeticError
|
5
6
|
from classiq.interface.generator.arith import arithmetic_param_getters, number_utils
|
6
7
|
from classiq.interface.generator.arith.argument_utils import RegisterOrConst
|
7
8
|
from classiq.interface.generator.arith.ast_node_rewrite import OUTPUT_SIZE
|
8
9
|
from classiq.interface.generator.arith.register_user_input import RegisterArithmeticInfo
|
9
10
|
|
10
|
-
from classiq.exceptions import ClassiqArithmeticError
|
11
|
-
|
12
11
|
ArithmeticDefinitions = Dict[str, RegisterOrConst]
|
13
12
|
|
14
13
|
|
@@ -20,7 +19,7 @@ class ArithmeticResultBuilder:
|
|
20
19
|
definitions: ArithmeticDefinitions,
|
21
20
|
machine_precision: int,
|
22
21
|
) -> None:
|
23
|
-
self.result = self._fill_operation_results(
|
22
|
+
self.result, self.garbage = self._fill_operation_results(
|
24
23
|
graph=graph,
|
25
24
|
result_definitions=definitions,
|
26
25
|
machine_precision=machine_precision,
|
@@ -62,7 +61,7 @@ class ArithmeticResultBuilder:
|
|
62
61
|
graph: nx.DiGraph,
|
63
62
|
result_definitions: ArithmeticDefinitions,
|
64
63
|
machine_precision: int,
|
65
|
-
) -> RegisterArithmeticInfo:
|
64
|
+
) -> Tuple[RegisterArithmeticInfo, Optional[RegisterArithmeticInfo]]:
|
66
65
|
inputs_node_set: Set[str] = {
|
67
66
|
vertex for vertex, deg in graph.in_degree if deg == 0
|
68
67
|
}
|
@@ -80,29 +79,34 @@ class ArithmeticResultBuilder:
|
|
80
79
|
for predecessor_node in graph.predecessors(node)
|
81
80
|
]
|
82
81
|
if graph.out_degree(node) == 0:
|
83
|
-
return cls.
|
82
|
+
return cls._get_node_result_and_garbage(
|
84
83
|
graph, args, node, machine_precision=machine_precision
|
85
84
|
)
|
86
|
-
node_results[node] = cls.
|
85
|
+
node_results[node], _ = cls._get_node_result_and_garbage(
|
87
86
|
graph, args, node, machine_precision=machine_precision
|
88
87
|
)
|
89
88
|
raise ClassiqArithmeticError("Expression has no result")
|
90
89
|
|
91
90
|
@classmethod
|
92
|
-
def
|
91
|
+
def _get_node_result_and_garbage(
|
93
92
|
cls,
|
94
93
|
graph: nx.DiGraph,
|
95
94
|
args: List[RegisterOrConst],
|
96
95
|
node: str,
|
97
96
|
*,
|
98
97
|
machine_precision: int,
|
99
|
-
) -> RegisterArithmeticInfo:
|
100
|
-
|
98
|
+
) -> Tuple[RegisterArithmeticInfo, Optional[RegisterArithmeticInfo]]:
|
99
|
+
node_params = arithmetic_param_getters.get_params(
|
101
100
|
node_id=node,
|
102
101
|
args=args,
|
103
102
|
output_size=graph.nodes[node].get(OUTPUT_SIZE, None),
|
104
103
|
machine_precision=machine_precision,
|
105
|
-
)
|
104
|
+
)
|
105
|
+
|
106
|
+
return (
|
107
|
+
node_params.outputs[node_params.output_name],
|
108
|
+
node_params.outputs.get(node_params.garbage_output_name),
|
109
|
+
)
|
106
110
|
|
107
111
|
@staticmethod
|
108
112
|
def _convert_int_to_float_str(node: Any) -> str:
|
@@ -2,7 +2,7 @@ import ast
|
|
2
2
|
import itertools
|
3
3
|
from typing import Any, Iterator, Optional, Union, cast
|
4
4
|
|
5
|
-
from classiq.exceptions import ClassiqArithmeticError
|
5
|
+
from classiq.interface.exceptions import ClassiqArithmeticError
|
6
6
|
|
7
7
|
SEPARATOR: str = "_"
|
8
8
|
OUTPUT_SIZE: str = "output_size"
|
@@ -16,6 +16,8 @@ from typing import (
|
|
16
16
|
import pydantic
|
17
17
|
from pydantic.generics import GenericModel
|
18
18
|
|
19
|
+
from classiq.interface.enum_utils import StrEnum
|
20
|
+
from classiq.interface.exceptions import ClassiqValueError
|
19
21
|
from classiq.interface.generator.arith import argument_utils, number_utils
|
20
22
|
from classiq.interface.generator.arith.argument_utils import RegisterOrConst
|
21
23
|
from classiq.interface.generator.arith.arithmetic_operations import (
|
@@ -28,9 +30,6 @@ from classiq.interface.generator.arith.register_user_input import RegisterArithm
|
|
28
30
|
from classiq.interface.generator.arith.unary_ops import Negation
|
29
31
|
from classiq.interface.generator.function_params import get_zero_input_name
|
30
32
|
|
31
|
-
from classiq._internals.enum_utils import StrEnum
|
32
|
-
from classiq.exceptions import ClassiqValueError
|
33
|
-
|
34
33
|
LeftDataT = TypeVar("LeftDataT")
|
35
34
|
RightDataT = TypeVar("RightDataT")
|
36
35
|
_NumericArgumentInplaceErrorMessage: str = "Cannot inplace the numeric argument {}"
|
@@ -3,6 +3,7 @@ from typing import Any, Dict, Iterable
|
|
3
3
|
|
4
4
|
import pydantic
|
5
5
|
|
6
|
+
from classiq.interface.exceptions import ClassiqValueError
|
6
7
|
from classiq.interface.generator.arith import argument_utils
|
7
8
|
from classiq.interface.generator.arith.argument_utils import RegisterOrConst
|
8
9
|
from classiq.interface.generator.arith.arithmetic_operations import (
|
@@ -15,8 +16,6 @@ from classiq.interface.generator.arith.binary_ops import (
|
|
15
16
|
from classiq.interface.generator.arith.register_user_input import RegisterArithmeticInfo
|
16
17
|
from classiq.interface.generator.function_params import get_zero_input_name
|
17
18
|
|
18
|
-
from classiq.exceptions import ClassiqValueError
|
19
|
-
|
20
19
|
Numeric = (float, int)
|
21
20
|
|
22
21
|
|
@@ -2,6 +2,7 @@ from typing import Iterable, List, Optional
|
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
|
5
|
+
from classiq.interface.exceptions import ClassiqValueError
|
5
6
|
from classiq.interface.generator.arith.argument_utils import RegisterOrConst
|
6
7
|
from classiq.interface.generator.arith.arithmetic_operations import (
|
7
8
|
ArithmeticOperationParams,
|
@@ -9,8 +10,6 @@ from classiq.interface.generator.arith.arithmetic_operations import (
|
|
9
10
|
from classiq.interface.generator.arith.register_user_input import RegisterArithmeticInfo
|
10
11
|
from classiq.interface.generator.function_params import get_zero_input_name
|
11
12
|
|
12
|
-
from classiq.exceptions import ClassiqValueError
|
13
|
-
|
14
13
|
|
15
14
|
def get_arg_name(idx: int) -> str:
|
16
15
|
return f"arg_{idx}"
|
@@ -2,14 +2,13 @@ from typing import Any, Dict, Optional
|
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
|
5
|
+
from classiq.interface.exceptions import ClassiqValueError
|
5
6
|
from classiq.interface.generator.arith import number_utils
|
6
7
|
from classiq.interface.helpers.custom_pydantic_types import PydanticFloatTuple
|
7
8
|
from classiq.interface.helpers.hashable_pydantic_base_model import (
|
8
9
|
HashablePydanticBaseModel,
|
9
10
|
)
|
10
11
|
|
11
|
-
from classiq.exceptions import ClassiqValueError
|
12
|
-
|
13
12
|
|
14
13
|
class RegisterArithmeticInfo(HashablePydanticBaseModel):
|
15
14
|
size: pydantic.PositiveInt
|
@@ -2,6 +2,7 @@ from typing import TYPE_CHECKING, Final, Iterable, Optional
|
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
|
5
|
+
from classiq.interface.exceptions import ClassiqValueError
|
5
6
|
from classiq.interface.generator.arith import argument_utils, number_utils
|
6
7
|
from classiq.interface.generator.arith.arithmetic_operations import (
|
7
8
|
ArithmeticOperationParams,
|
@@ -9,8 +10,6 @@ from classiq.interface.generator.arith.arithmetic_operations import (
|
|
9
10
|
from classiq.interface.generator.arith.register_user_input import RegisterArithmeticInfo
|
10
11
|
from classiq.interface.generator.function_params import get_zero_input_name
|
11
12
|
|
12
|
-
from classiq.exceptions import ClassiqValueError
|
13
|
-
|
14
13
|
UNARY_ARG_NAME: Final[str] = "arg"
|
15
14
|
|
16
15
|
|
@@ -4,6 +4,7 @@ from classiq.interface.chemistry.ground_state_problem import (
|
|
4
4
|
CHEMISTRY_PROBLEMS_TYPE,
|
5
5
|
GroundStateProblem,
|
6
6
|
)
|
7
|
+
from classiq.interface.exceptions import ClassiqValueError
|
7
8
|
from classiq.interface.generator.arith.register_user_input import RegisterUserInput
|
8
9
|
from classiq.interface.generator.function_params import (
|
9
10
|
DEFAULT_INPUT_NAME,
|
@@ -11,8 +12,6 @@ from classiq.interface.generator.function_params import (
|
|
11
12
|
FunctionParams,
|
12
13
|
)
|
13
14
|
|
14
|
-
from classiq.exceptions import ClassiqValueError
|
15
|
-
|
16
15
|
|
17
16
|
class ChemistryFunctionParams(FunctionParams):
|
18
17
|
gs_problem: CHEMISTRY_PROBLEMS_TYPE
|
@@ -2,6 +2,7 @@ from typing import Dict, Optional
|
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
|
5
|
+
from classiq.interface.exceptions import ClassiqMissingOutputFormatError
|
5
6
|
from classiq.interface.executor.quantum_instruction_set import QuantumInstructionSet
|
6
7
|
from classiq.interface.generator.circuit_code.types_and_constants import (
|
7
8
|
INSTRUCTION_SET_TO_FORMAT,
|
@@ -12,8 +13,6 @@ from classiq.interface.generator.circuit_code.types_and_constants import (
|
|
12
13
|
)
|
13
14
|
from classiq.interface.generator.model.preferences.preferences import QuantumFormat
|
14
15
|
|
15
|
-
from classiq.exceptions import ClassiqMissingOutputFormatError
|
16
|
-
|
17
16
|
|
18
17
|
class CircuitCodeInterface(pydantic.BaseModel):
|
19
18
|
outputs: Dict[QuantumFormat, Code]
|
@@ -2,12 +2,11 @@ from typing import Dict, Tuple
|
|
2
2
|
|
3
3
|
from typing_extensions import TypeAlias
|
4
4
|
|
5
|
+
from classiq.interface.enum_utils import StrEnum
|
5
6
|
from classiq.interface.executor.quantum_instruction_set import QuantumInstructionSet
|
6
7
|
from classiq.interface.generator.model.preferences.preferences import QuantumFormat
|
7
8
|
from classiq.interface.hardware import Provider
|
8
9
|
|
9
|
-
from classiq._internals.enum_utils import StrEnum
|
10
|
-
|
11
10
|
Code: TypeAlias = str
|
12
11
|
CodeAndSyntax: TypeAlias = Tuple[Code, QuantumInstructionSet]
|
13
12
|
|
@@ -2,6 +2,7 @@ import pydantic
|
|
2
2
|
|
3
3
|
from classiq.interface.chemistry import operator
|
4
4
|
from classiq.interface.chemistry.operator import PauliOperator
|
5
|
+
from classiq.interface.exceptions import ClassiqValueError
|
5
6
|
from classiq.interface.generator.arith.register_user_input import RegisterUserInput
|
6
7
|
from classiq.interface.generator.function_params import (
|
7
8
|
DEFAULT_INPUT_NAME,
|
@@ -10,8 +11,6 @@ from classiq.interface.generator.function_params import (
|
|
10
11
|
)
|
11
12
|
from classiq.interface.generator.parameters import ParameterFloatType
|
12
13
|
|
13
|
-
from classiq.exceptions import ClassiqValueError
|
14
|
-
|
15
14
|
|
16
15
|
class CommutingPauliExponentiation(FunctionParams):
|
17
16
|
"""
|