classiq 0.92.0__py3-none-any.whl → 0.99.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 +11 -19
- classiq/_analyzer_extras/_ipywidgets_async_extension.py +7 -7
- classiq/_analyzer_extras/interactive_hardware.py +19 -12
- classiq/_internals/api_wrapper.py +31 -142
- classiq/_internals/async_utils.py +4 -7
- classiq/_internals/authentication/auth0.py +41 -15
- classiq/_internals/authentication/authorization_code.py +9 -0
- classiq/_internals/authentication/authorization_flow.py +41 -0
- classiq/_internals/authentication/device.py +33 -52
- classiq/_internals/authentication/hybrid_flow.py +19 -0
- classiq/_internals/authentication/password_manager.py +13 -13
- classiq/_internals/authentication/token_manager.py +9 -9
- classiq/_internals/client.py +17 -44
- classiq/_internals/config.py +19 -5
- classiq/_internals/help.py +1 -2
- classiq/_internals/host_checker.py +3 -3
- classiq/_internals/jobs.py +14 -14
- classiq/_internals/type_validation.py +3 -3
- classiq/analyzer/analyzer.py +18 -18
- classiq/analyzer/rb.py +17 -8
- classiq/analyzer/show_interactive_hack.py +1 -1
- classiq/applications/__init__.py +2 -2
- classiq/applications/chemistry/__init__.py +0 -30
- classiq/applications/chemistry/op_utils.py +4 -4
- classiq/applications/chemistry/problems.py +3 -3
- classiq/applications/chemistry/ucc.py +1 -2
- classiq/applications/chemistry/z2_symmetries.py +4 -4
- classiq/applications/combinatorial_helpers/allowed_constraints.py +1 -3
- classiq/applications/combinatorial_helpers/arithmetic/arithmetic_expression.py +2 -1
- classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +2 -2
- classiq/applications/combinatorial_helpers/encoding_mapping.py +2 -3
- classiq/applications/combinatorial_helpers/encoding_utils.py +2 -2
- classiq/applications/combinatorial_helpers/optimization_model.py +3 -4
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_sparsing.py +2 -2
- classiq/applications/combinatorial_helpers/pyomo_utils.py +8 -8
- classiq/applications/combinatorial_helpers/sympy_utils.py +1 -3
- classiq/applications/combinatorial_helpers/transformations/encoding.py +3 -3
- classiq/applications/combinatorial_helpers/transformations/fixed_variables.py +1 -2
- classiq/applications/combinatorial_optimization/combinatorial_optimization_config.py +2 -3
- classiq/applications/combinatorial_optimization/combinatorial_optimization_model_constructor.py +4 -6
- classiq/applications/combinatorial_optimization/combinatorial_problem.py +15 -10
- classiq/applications/hamiltonian/pauli_decomposition.py +6 -4
- classiq/applications/iqae/iqae.py +14 -11
- classiq/applications/qnn/datasets/dataset_base_classes.py +6 -6
- classiq/applications/qnn/datasets/dataset_parity.py +6 -6
- classiq/applications/qnn/gradients/simple_quantum_gradient.py +1 -1
- classiq/applications/qnn/qlayer.py +9 -8
- classiq/applications/qnn/torch_utils.py +5 -6
- classiq/applications/qnn/types.py +2 -1
- classiq/applications/qsp/__init__.py +20 -2
- classiq/applications/qsp/qsp.py +239 -11
- classiq/applications/qsvm/qsvm_data_generation.py +1 -2
- classiq/evaluators/classical_expression.py +0 -4
- classiq/evaluators/parameter_types.py +20 -12
- classiq/evaluators/qmod_annotated_expression.py +31 -26
- classiq/evaluators/qmod_expression_visitors/qmod_expression_evaluator.py +14 -14
- classiq/evaluators/qmod_expression_visitors/qmod_expression_simplifier.py +2 -1
- classiq/evaluators/qmod_expression_visitors/sympy_wrappers.py +8 -8
- classiq/evaluators/qmod_node_evaluators/binary_op_evaluation.py +4 -4
- classiq/evaluators/qmod_node_evaluators/classical_function_evaluation.py +14 -4
- classiq/evaluators/qmod_node_evaluators/list_evaluation.py +2 -2
- classiq/evaluators/qmod_node_evaluators/numeric_attrs_utils.py +3 -3
- classiq/evaluators/qmod_node_evaluators/subscript_evaluation.py +9 -9
- classiq/evaluators/qmod_node_evaluators/utils.py +6 -6
- classiq/evaluators/qmod_type_inference/classical_type_inference.py +9 -10
- classiq/evaluators/qmod_type_inference/quantum_type_inference.py +5 -5
- classiq/execution/__init__.py +0 -3
- classiq/execution/execution_session.py +28 -21
- classiq/execution/jobs.py +26 -26
- classiq/execution/qnn.py +1 -2
- classiq/execution/user_budgets.py +71 -37
- classiq/executor.py +1 -3
- classiq/interface/_version.py +1 -1
- classiq/interface/analyzer/analysis_params.py +4 -4
- classiq/interface/analyzer/cytoscape_graph.py +3 -3
- classiq/interface/analyzer/result.py +4 -4
- classiq/interface/ast_node.py +3 -3
- classiq/interface/backend/backend_preferences.py +26 -50
- classiq/interface/backend/ionq/ionq_quantum_program.py +5 -5
- classiq/interface/backend/provider_config/__init__.py +0 -0
- classiq/interface/backend/provider_config/provider_config.py +8 -0
- classiq/interface/backend/provider_config/providers/__init__.py +0 -0
- classiq/interface/backend/provider_config/providers/alice_bob.py +47 -0
- classiq/interface/backend/provider_config/providers/aqt.py +16 -0
- classiq/interface/backend/provider_config/providers/azure.py +37 -0
- classiq/interface/backend/provider_config/providers/braket.py +39 -0
- classiq/interface/backend/provider_config/providers/ibm.py +26 -0
- classiq/interface/backend/provider_config/providers/ionq.py +22 -0
- classiq/interface/backend/quantum_backend_providers.py +20 -2
- classiq/interface/chemistry/ansatz_library.py +3 -5
- classiq/interface/chemistry/operator.py +3 -3
- classiq/interface/combinatorial_optimization/examples/knapsack.py +2 -4
- classiq/interface/combinatorial_optimization/examples/tsp_digraph.py +1 -2
- classiq/interface/compression_utils.py +2 -3
- classiq/interface/debug_info/debug_info.py +8 -7
- classiq/interface/exceptions.py +10 -7
- classiq/interface/execution/primitives.py +6 -6
- classiq/interface/executor/estimate_cost.py +1 -1
- classiq/interface/executor/execution_preferences.py +3 -5
- classiq/interface/executor/execution_request.py +10 -10
- classiq/interface/executor/execution_result.py +1 -2
- classiq/interface/executor/quantum_code.py +8 -8
- classiq/interface/executor/result.py +28 -18
- classiq/interface/executor/user_budget.py +25 -17
- classiq/interface/executor/vqe_result.py +5 -6
- classiq/interface/generator/ansatz_library.py +6 -8
- classiq/interface/generator/application_apis/__init__.py +0 -3
- classiq/interface/generator/arith/arithmetic.py +2 -2
- classiq/interface/generator/arith/arithmetic_arg_type_validator.py +2 -3
- classiq/interface/generator/arith/arithmetic_expression_abc.py +4 -5
- classiq/interface/generator/arith/arithmetic_expression_parser.py +11 -4
- classiq/interface/generator/arith/arithmetic_expression_validator.py +12 -15
- classiq/interface/generator/arith/arithmetic_operations.py +4 -6
- classiq/interface/generator/arith/arithmetic_param_getters.py +70 -107
- classiq/interface/generator/arith/arithmetic_result_builder.py +4 -4
- classiq/interface/generator/arith/ast_node_rewrite.py +8 -4
- classiq/interface/generator/arith/binary_ops.py +15 -40
- classiq/interface/generator/arith/logical_ops.py +2 -3
- classiq/interface/generator/arith/number_utils.py +2 -2
- classiq/interface/generator/arith/register_user_input.py +3 -3
- classiq/interface/generator/arith/unary_ops.py +2 -2
- classiq/interface/generator/circuit_code/circuit_code.py +8 -10
- classiq/interface/generator/circuit_code/types_and_constants.py +1 -1
- classiq/interface/generator/complex_type.py +2 -2
- classiq/interface/generator/copy.py +1 -3
- classiq/interface/generator/expressions/atomic_expression_functions.py +0 -5
- classiq/interface/generator/expressions/evaluated_expression.py +2 -3
- classiq/interface/generator/expressions/expression.py +2 -2
- classiq/interface/generator/expressions/proxies/classical/classical_array_proxy.py +4 -7
- classiq/interface/generator/function_param_list.py +0 -40
- classiq/interface/generator/function_params.py +5 -6
- classiq/interface/generator/functions/classical_function_declaration.py +2 -2
- classiq/interface/generator/functions/classical_type.py +3 -3
- classiq/interface/generator/functions/type_modifier.py +0 -15
- classiq/interface/generator/functions/type_name.py +2 -2
- classiq/interface/generator/generated_circuit_data.py +14 -18
- classiq/interface/generator/hamiltonian_evolution/exponentiation.py +2 -4
- classiq/interface/generator/hardware/hardware_data.py +8 -8
- classiq/interface/generator/hardware_efficient_ansatz.py +9 -9
- classiq/interface/generator/mcu.py +3 -3
- classiq/interface/generator/mcx.py +3 -3
- classiq/interface/generator/model/constraints.py +34 -5
- classiq/interface/generator/model/preferences/preferences.py +15 -21
- classiq/interface/generator/model/quantum_register.py +7 -10
- classiq/interface/generator/noise_properties.py +3 -7
- classiq/interface/generator/parameters.py +1 -1
- classiq/interface/generator/partitioned_register.py +1 -2
- classiq/interface/generator/preferences/qasm_to_qmod_params.py +11 -0
- classiq/interface/generator/quantum_function_call.py +9 -12
- classiq/interface/generator/quantum_program.py +10 -23
- classiq/interface/generator/range_types.py +3 -3
- classiq/interface/generator/slice_parsing_utils.py +4 -5
- classiq/interface/generator/standard_gates/standard_gates.py +2 -4
- classiq/interface/generator/synthesis_execution_parameter.py +1 -3
- classiq/interface/generator/synthesis_metadata/synthesis_duration.py +9 -0
- classiq/interface/generator/synthesis_metadata/synthesis_execution_data.py +2 -3
- classiq/interface/generator/transpiler_basis_gates.py +12 -4
- classiq/interface/generator/types/builtin_enum_declarations.py +0 -145
- classiq/interface/generator/types/compilation_metadata.py +12 -1
- classiq/interface/generator/types/enum_declaration.py +2 -1
- classiq/interface/generator/validations/flow_graph.py +3 -3
- classiq/interface/generator/visitor.py +10 -12
- classiq/interface/hardware.py +2 -3
- classiq/interface/helpers/classproperty.py +2 -2
- classiq/interface/helpers/custom_encoders.py +2 -1
- classiq/interface/helpers/custom_pydantic_types.py +1 -1
- classiq/interface/helpers/text_utils.py +1 -4
- classiq/interface/ide/visual_model.py +6 -5
- classiq/interface/interface_version.py +1 -1
- classiq/interface/jobs.py +3 -3
- classiq/interface/model/allocate.py +4 -4
- classiq/interface/model/block.py +6 -2
- classiq/interface/model/bounds.py +3 -3
- classiq/interface/model/classical_if.py +4 -0
- classiq/interface/model/control.py +8 -1
- classiq/interface/model/inplace_binary_operation.py +2 -2
- classiq/interface/model/invert.py +4 -0
- classiq/interface/model/model.py +4 -4
- classiq/interface/model/model_visitor.py +40 -1
- classiq/interface/model/parameter.py +1 -3
- classiq/interface/model/port_declaration.py +1 -1
- classiq/interface/model/power.py +4 -0
- classiq/interface/model/quantum_expressions/quantum_expression.py +1 -2
- classiq/interface/model/quantum_function_call.py +3 -6
- classiq/interface/model/quantum_function_declaration.py +1 -0
- classiq/interface/model/quantum_lambda_function.py +4 -4
- classiq/interface/model/quantum_statement.py +11 -4
- classiq/interface/model/quantum_type.py +14 -14
- classiq/interface/model/repeat.py +4 -0
- classiq/interface/model/skip_control.py +4 -0
- classiq/interface/model/validation_handle.py +2 -3
- classiq/interface/model/variable_declaration_statement.py +2 -2
- classiq/interface/model/within_apply_operation.py +4 -0
- classiq/interface/pretty_print/expression_to_qmod.py +3 -4
- classiq/interface/server/routes.py +0 -16
- classiq/interface/source_reference.py +3 -4
- classiq/model_expansions/arithmetic.py +11 -7
- classiq/model_expansions/arithmetic_compute_result_attrs.py +30 -27
- classiq/model_expansions/capturing/captured_vars.py +3 -3
- classiq/model_expansions/capturing/mangling_utils.py +1 -2
- classiq/model_expansions/closure.py +12 -11
- classiq/model_expansions/function_builder.py +14 -6
- classiq/model_expansions/generative_functions.py +7 -12
- classiq/model_expansions/interpreters/base_interpreter.py +3 -7
- classiq/model_expansions/interpreters/frontend_generative_interpreter.py +2 -1
- classiq/model_expansions/interpreters/generative_interpreter.py +8 -4
- classiq/model_expansions/quantum_operations/allocate.py +4 -4
- classiq/model_expansions/quantum_operations/assignment_result_processor.py +8 -4
- classiq/model_expansions/quantum_operations/call_emitter.py +31 -37
- classiq/model_expansions/quantum_operations/declarative_call_emitter.py +2 -2
- classiq/model_expansions/quantum_operations/emitter.py +3 -5
- classiq/model_expansions/quantum_operations/expression_evaluator.py +3 -3
- classiq/model_expansions/quantum_operations/skip_control_verifier.py +1 -2
- classiq/model_expansions/quantum_operations/variable_decleration.py +61 -29
- classiq/model_expansions/scope.py +7 -7
- classiq/model_expansions/scope_initialization.py +4 -0
- classiq/model_expansions/visitors/symbolic_param_inference.py +6 -6
- classiq/model_expansions/visitors/uncomputation_signature_inference.py +328 -0
- classiq/model_expansions/visitors/variable_references.py +15 -14
- classiq/open_library/functions/__init__.py +28 -11
- classiq/open_library/functions/amplitude_loading.py +81 -0
- classiq/open_library/functions/discrete_sine_cosine_transform.py +19 -14
- classiq/open_library/functions/grover.py +8 -10
- classiq/open_library/functions/lcu.py +47 -18
- classiq/open_library/functions/modular_exponentiation.py +93 -8
- classiq/open_library/functions/qsvt.py +66 -79
- classiq/open_library/functions/qsvt_temp.py +536 -0
- classiq/open_library/functions/state_preparation.py +130 -27
- classiq/qmod/__init__.py +6 -4
- classiq/qmod/builtins/classical_execution_primitives.py +4 -23
- classiq/qmod/builtins/classical_functions.py +1 -42
- classiq/qmod/builtins/enums.py +15 -153
- classiq/qmod/builtins/functions/__init__.py +9 -18
- classiq/qmod/builtins/functions/allocation.py +25 -4
- classiq/qmod/builtins/functions/arithmetic.py +22 -27
- classiq/qmod/builtins/functions/exponentiation.py +51 -2
- classiq/qmod/builtins/functions/mcx_func.py +7 -0
- classiq/qmod/builtins/functions/standard_gates.py +46 -27
- classiq/qmod/builtins/operations.py +173 -79
- classiq/qmod/builtins/structs.py +24 -91
- classiq/qmod/cfunc.py +3 -2
- classiq/qmod/classical_function.py +2 -1
- classiq/qmod/classical_variable.py +4 -2
- classiq/qmod/cparam.py +2 -8
- classiq/qmod/create_model_function.py +7 -7
- classiq/qmod/declaration_inferrer.py +33 -30
- classiq/qmod/expression_query.py +7 -4
- classiq/qmod/model_state_container.py +2 -2
- classiq/qmod/native/pretty_printer.py +25 -14
- classiq/qmod/pretty_print/expression_to_python.py +5 -3
- classiq/qmod/pretty_print/pretty_printer.py +39 -17
- classiq/qmod/python_classical_type.py +40 -13
- classiq/qmod/qfunc.py +124 -19
- classiq/qmod/qmod_constant.py +2 -2
- classiq/qmod/qmod_parameter.py +5 -2
- classiq/qmod/qmod_variable.py +47 -46
- classiq/qmod/quantum_callable.py +18 -13
- classiq/qmod/quantum_expandable.py +33 -26
- classiq/qmod/quantum_function.py +84 -36
- classiq/qmod/semantics/annotation/call_annotation.py +5 -5
- classiq/qmod/semantics/error_manager.py +12 -14
- classiq/qmod/semantics/lambdas.py +1 -2
- classiq/qmod/semantics/validation/types_validation.py +1 -2
- classiq/qmod/symbolic.py +2 -4
- classiq/qmod/symbolic_expr.py +12 -4
- classiq/qmod/utilities.py +13 -20
- classiq/qmod/write_qmod.py +3 -4
- classiq/quantum_program.py +1 -3
- classiq/synthesis.py +11 -7
- {classiq-0.92.0.dist-info → classiq-0.99.0.dist-info}/METADATA +38 -37
- {classiq-0.92.0.dist-info → classiq-0.99.0.dist-info}/RECORD +273 -300
- classiq-0.99.0.dist-info/WHEEL +4 -0
- classiq-0.99.0.dist-info/licenses/LICENSE.txt +27 -0
- classiq/applications/chemistry/ansatz_parameters.py +0 -29
- classiq/applications/chemistry/chemistry_execution_parameters.py +0 -16
- classiq/applications/chemistry/chemistry_model_constructor.py +0 -532
- classiq/applications/chemistry/ground_state_problem.py +0 -42
- classiq/applications/qsvm/__init__.py +0 -8
- classiq/applications/qsvm/qsvm.py +0 -11
- classiq/evaluators/qmod_expression_visitors/qmod_expression_bwc.py +0 -129
- classiq/execution/iqcc.py +0 -128
- classiq/interface/applications/qsvm.py +0 -117
- classiq/interface/chemistry/elements.py +0 -120
- classiq/interface/chemistry/fermionic_operator.py +0 -208
- classiq/interface/chemistry/ground_state_problem.py +0 -132
- classiq/interface/chemistry/ground_state_result.py +0 -8
- classiq/interface/chemistry/molecule.py +0 -71
- classiq/interface/execution/iqcc.py +0 -44
- classiq/interface/generator/application_apis/chemistry_declarations.py +0 -69
- classiq/interface/generator/application_apis/entangler_declarations.py +0 -29
- classiq/interface/generator/application_apis/qsvm_declarations.py +0 -6
- classiq/interface/generator/chemistry_function_params.py +0 -50
- classiq/interface/generator/entangler_params.py +0 -72
- classiq/interface/generator/entanglers.py +0 -14
- classiq/interface/generator/hamiltonian_evolution/qdrift.py +0 -27
- classiq/interface/generator/hartree_fock.py +0 -26
- classiq/interface/generator/hva.py +0 -22
- classiq/interface/generator/linear_pauli_rotations.py +0 -92
- classiq/interface/generator/qft.py +0 -37
- classiq/interface/generator/qsvm.py +0 -96
- classiq/interface/generator/state_preparation/__init__.py +0 -14
- classiq/interface/generator/state_preparation/bell_state_preparation.py +0 -27
- classiq/interface/generator/state_preparation/computational_basis_state_preparation.py +0 -28
- classiq/interface/generator/state_preparation/distributions.py +0 -53
- classiq/interface/generator/state_preparation/exponential_state_preparation.py +0 -14
- classiq/interface/generator/state_preparation/ghz_state_preparation.py +0 -14
- classiq/interface/generator/state_preparation/metrics.py +0 -41
- classiq/interface/generator/state_preparation/state_preparation.py +0 -113
- classiq/interface/generator/state_preparation/state_preparation_abc.py +0 -24
- classiq/interface/generator/state_preparation/uniform_distibution_state_preparation.py +0 -13
- classiq/interface/generator/state_preparation/w_state_preparation.py +0 -13
- classiq/interface/generator/ucc.py +0 -74
- classiq/interface/helpers/backward_compatibility.py +0 -9
- classiq/model_expansions/transformers/type_modifier_inference.py +0 -392
- classiq/open_library/functions/lookup_table.py +0 -58
- classiq/qmod/builtins/functions/chemistry.py +0 -123
- classiq/qmod/builtins/functions/qsvm.py +0 -24
- classiq-0.92.0.dist-info/WHEEL +0 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from
|
|
1
|
+
from collections.abc import Callable
|
|
2
2
|
|
|
3
3
|
from classiq.interface.exceptions import ClassiqArithmeticError
|
|
4
4
|
from classiq.interface.generator.arith.argument_utils import (
|
|
@@ -16,7 +16,6 @@ from classiq.interface.generator.arith.binary_ops import (
|
|
|
16
16
|
BitwiseAnd,
|
|
17
17
|
BitwiseOr,
|
|
18
18
|
BitwiseXor,
|
|
19
|
-
CyclicShift,
|
|
20
19
|
Equal,
|
|
21
20
|
GreaterEqual,
|
|
22
21
|
GreaterThan,
|
|
@@ -57,9 +56,9 @@ def get_params(
|
|
|
57
56
|
node_id: str,
|
|
58
57
|
args: list[RegisterOrFloat],
|
|
59
58
|
machine_precision: int,
|
|
60
|
-
output_size:
|
|
61
|
-
inplace_arg:
|
|
62
|
-
target:
|
|
59
|
+
output_size: int | None = None,
|
|
60
|
+
inplace_arg: str | None = None,
|
|
61
|
+
target: RegisterArithmeticInfo | None = None,
|
|
63
62
|
) -> ArithmeticOperationParams:
|
|
64
63
|
operation = id2op(node_id)
|
|
65
64
|
if target and not operation_allows_target(operation):
|
|
@@ -78,9 +77,9 @@ def or_params_getter(
|
|
|
78
77
|
left_arg: RegisterOrInt,
|
|
79
78
|
right_arg: RegisterOrInt,
|
|
80
79
|
machine_precision: int,
|
|
81
|
-
output_size:
|
|
82
|
-
inplace_arg:
|
|
83
|
-
target:
|
|
80
|
+
output_size: int | None = None,
|
|
81
|
+
inplace_arg: str | None = None,
|
|
82
|
+
target: RegisterArithmeticInfo | None = None,
|
|
84
83
|
) -> ArithmeticOperationParams:
|
|
85
84
|
return BitwiseOr(
|
|
86
85
|
left_arg=left_arg,
|
|
@@ -94,9 +93,9 @@ def and_params_getter(
|
|
|
94
93
|
left_arg: RegisterOrInt,
|
|
95
94
|
right_arg: RegisterOrInt,
|
|
96
95
|
machine_precision: int,
|
|
97
|
-
output_size:
|
|
98
|
-
inplace_arg:
|
|
99
|
-
target:
|
|
96
|
+
output_size: int | None = None,
|
|
97
|
+
inplace_arg: str | None = None,
|
|
98
|
+
target: RegisterArithmeticInfo | None = None,
|
|
100
99
|
) -> ArithmeticOperationParams:
|
|
101
100
|
return BitwiseAnd(
|
|
102
101
|
left_arg=left_arg,
|
|
@@ -110,9 +109,9 @@ def xor_params_getter(
|
|
|
110
109
|
left_arg: RegisterOrInt,
|
|
111
110
|
right_arg: RegisterOrInt,
|
|
112
111
|
machine_precision: int,
|
|
113
|
-
output_size:
|
|
114
|
-
inplace_arg:
|
|
115
|
-
target:
|
|
112
|
+
output_size: int | None = None,
|
|
113
|
+
inplace_arg: str | None = None,
|
|
114
|
+
target: RegisterArithmeticInfo | None = None,
|
|
116
115
|
) -> ArithmeticOperationParams:
|
|
117
116
|
return BitwiseXor(
|
|
118
117
|
left_arg=left_arg,
|
|
@@ -126,9 +125,9 @@ def xor_params_getter(
|
|
|
126
125
|
def invert_params_getter(
|
|
127
126
|
arg: RegisterOrInt,
|
|
128
127
|
machine_precision: int,
|
|
129
|
-
output_size:
|
|
130
|
-
inplace_arg:
|
|
131
|
-
target:
|
|
128
|
+
output_size: int | None = None,
|
|
129
|
+
inplace_arg: str | None = None,
|
|
130
|
+
target: RegisterArithmeticInfo | None = None,
|
|
132
131
|
) -> ArithmeticOperationParams:
|
|
133
132
|
return BitwiseInvert(
|
|
134
133
|
arg=arg,
|
|
@@ -141,9 +140,9 @@ def invert_params_getter(
|
|
|
141
140
|
def usub_params_getter(
|
|
142
141
|
arg: RegisterOrInt,
|
|
143
142
|
machine_precision: int,
|
|
144
|
-
output_size:
|
|
145
|
-
inplace_arg:
|
|
146
|
-
target:
|
|
143
|
+
output_size: int | None = None,
|
|
144
|
+
inplace_arg: str | None = None,
|
|
145
|
+
target: RegisterArithmeticInfo | None = None,
|
|
147
146
|
) -> ArithmeticOperationParams:
|
|
148
147
|
return Negation(
|
|
149
148
|
arg=arg,
|
|
@@ -157,9 +156,9 @@ def adder_params_getter(
|
|
|
157
156
|
left_arg: RegisterOrFloat,
|
|
158
157
|
right_arg: RegisterOrFloat,
|
|
159
158
|
machine_precision: int,
|
|
160
|
-
output_size:
|
|
161
|
-
inplace_arg:
|
|
162
|
-
target:
|
|
159
|
+
output_size: int | None = None,
|
|
160
|
+
inplace_arg: str | None = None,
|
|
161
|
+
target: RegisterArithmeticInfo | None = None,
|
|
163
162
|
) -> ArithmeticOperationParams:
|
|
164
163
|
return Adder(
|
|
165
164
|
left_arg=left_arg,
|
|
@@ -174,9 +173,9 @@ def multiplier_params_getter(
|
|
|
174
173
|
left_arg: RegisterOrFloat,
|
|
175
174
|
right_arg: RegisterOrFloat,
|
|
176
175
|
machine_precision: int,
|
|
177
|
-
output_size:
|
|
178
|
-
inplace_arg:
|
|
179
|
-
target:
|
|
176
|
+
output_size: int | None = None,
|
|
177
|
+
inplace_arg: str | None = None,
|
|
178
|
+
target: RegisterArithmeticInfo | None = None,
|
|
180
179
|
) -> ArithmeticOperationParams:
|
|
181
180
|
return Multiplier(
|
|
182
181
|
left_arg=left_arg,
|
|
@@ -190,9 +189,9 @@ def power_params_getter(
|
|
|
190
189
|
left_arg: RegisterArithmeticInfo,
|
|
191
190
|
right_arg: int,
|
|
192
191
|
machine_precision: int,
|
|
193
|
-
output_size:
|
|
194
|
-
inplace_arg:
|
|
195
|
-
target:
|
|
192
|
+
output_size: int | None = None,
|
|
193
|
+
inplace_arg: str | None = None,
|
|
194
|
+
target: RegisterArithmeticInfo | None = None,
|
|
196
195
|
) -> ArithmeticOperationParams:
|
|
197
196
|
return Power(
|
|
198
197
|
left_arg=left_arg,
|
|
@@ -206,9 +205,9 @@ def min_params_getter(
|
|
|
206
205
|
left_arg: RegisterOrFloat,
|
|
207
206
|
right_arg: RegisterOrFloat,
|
|
208
207
|
machine_precision: int,
|
|
209
|
-
output_size:
|
|
210
|
-
inplace_arg:
|
|
211
|
-
target:
|
|
208
|
+
output_size: int | None = None,
|
|
209
|
+
inplace_arg: str | None = None,
|
|
210
|
+
target: RegisterArithmeticInfo | None = None,
|
|
212
211
|
) -> ArithmeticOperationParams:
|
|
213
212
|
return Min(
|
|
214
213
|
left_arg=left_arg,
|
|
@@ -222,9 +221,9 @@ def max_params_getter(
|
|
|
222
221
|
left_arg: RegisterOrFloat,
|
|
223
222
|
right_arg: RegisterOrFloat,
|
|
224
223
|
machine_precision: int,
|
|
225
|
-
output_size:
|
|
226
|
-
inplace_arg:
|
|
227
|
-
target:
|
|
224
|
+
output_size: int | None = None,
|
|
225
|
+
inplace_arg: str | None = None,
|
|
226
|
+
target: RegisterArithmeticInfo | None = None,
|
|
228
227
|
) -> ArithmeticOperationParams:
|
|
229
228
|
return Max(
|
|
230
229
|
left_arg=left_arg,
|
|
@@ -238,9 +237,9 @@ def sub_params_getter(
|
|
|
238
237
|
left_arg: RegisterOrFloat,
|
|
239
238
|
right_arg: RegisterOrFloat,
|
|
240
239
|
machine_precision: int,
|
|
241
|
-
output_size:
|
|
242
|
-
inplace_arg:
|
|
243
|
-
target:
|
|
240
|
+
output_size: int | None = None,
|
|
241
|
+
inplace_arg: str | None = None,
|
|
242
|
+
target: RegisterArithmeticInfo | None = None,
|
|
244
243
|
) -> ArithmeticOperationParams:
|
|
245
244
|
return Subtractor(
|
|
246
245
|
left_arg=left_arg,
|
|
@@ -255,9 +254,9 @@ def equal_params_getter(
|
|
|
255
254
|
left_arg: RegisterOrFloat,
|
|
256
255
|
right_arg: RegisterOrFloat,
|
|
257
256
|
machine_precision: int,
|
|
258
|
-
output_size:
|
|
259
|
-
inplace_arg:
|
|
260
|
-
target:
|
|
257
|
+
output_size: int | None = None,
|
|
258
|
+
inplace_arg: str | None = None,
|
|
259
|
+
target: RegisterArithmeticInfo | None = None,
|
|
261
260
|
) -> ArithmeticOperationParams:
|
|
262
261
|
return Equal(
|
|
263
262
|
left_arg=left_arg, right_arg=right_arg, machine_precision=machine_precision
|
|
@@ -268,9 +267,9 @@ def not_equal_params_getter(
|
|
|
268
267
|
left_arg: RegisterOrFloat,
|
|
269
268
|
right_arg: RegisterOrFloat,
|
|
270
269
|
machine_precision: int,
|
|
271
|
-
output_size:
|
|
272
|
-
inplace_arg:
|
|
273
|
-
target:
|
|
270
|
+
output_size: int | None = None,
|
|
271
|
+
inplace_arg: str | None = None,
|
|
272
|
+
target: RegisterArithmeticInfo | None = None,
|
|
274
273
|
) -> ArithmeticOperationParams:
|
|
275
274
|
return NotEqual(
|
|
276
275
|
left_arg=left_arg, right_arg=right_arg, machine_precision=machine_precision
|
|
@@ -281,9 +280,9 @@ def greater_than_params_getter(
|
|
|
281
280
|
left_arg: RegisterOrFloat,
|
|
282
281
|
right_arg: RegisterOrFloat,
|
|
283
282
|
machine_precision: int,
|
|
284
|
-
output_size:
|
|
285
|
-
inplace_arg:
|
|
286
|
-
target:
|
|
283
|
+
output_size: int | None = None,
|
|
284
|
+
inplace_arg: str | None = None,
|
|
285
|
+
target: RegisterArithmeticInfo | None = None,
|
|
287
286
|
) -> ArithmeticOperationParams:
|
|
288
287
|
return GreaterThan(
|
|
289
288
|
left_arg=left_arg, right_arg=right_arg, machine_precision=machine_precision
|
|
@@ -294,9 +293,9 @@ def greater_equal_params_getter(
|
|
|
294
293
|
left_arg: RegisterOrFloat,
|
|
295
294
|
right_arg: RegisterOrFloat,
|
|
296
295
|
machine_precision: int,
|
|
297
|
-
output_size:
|
|
298
|
-
inplace_arg:
|
|
299
|
-
target:
|
|
296
|
+
output_size: int | None = None,
|
|
297
|
+
inplace_arg: str | None = None,
|
|
298
|
+
target: RegisterArithmeticInfo | None = None,
|
|
300
299
|
) -> ArithmeticOperationParams:
|
|
301
300
|
return GreaterEqual(
|
|
302
301
|
left_arg=left_arg, right_arg=right_arg, machine_precision=machine_precision
|
|
@@ -307,9 +306,9 @@ def less_than_params_getter(
|
|
|
307
306
|
left_arg: RegisterOrFloat,
|
|
308
307
|
right_arg: RegisterOrFloat,
|
|
309
308
|
machine_precision: int,
|
|
310
|
-
output_size:
|
|
311
|
-
inplace_arg:
|
|
312
|
-
target:
|
|
309
|
+
output_size: int | None = None,
|
|
310
|
+
inplace_arg: str | None = None,
|
|
311
|
+
target: RegisterArithmeticInfo | None = None,
|
|
313
312
|
) -> ArithmeticOperationParams:
|
|
314
313
|
return LessThan(
|
|
315
314
|
left_arg=left_arg, right_arg=right_arg, machine_precision=machine_precision
|
|
@@ -320,9 +319,9 @@ def less_equal_params_getter(
|
|
|
320
319
|
left_arg: RegisterOrFloat,
|
|
321
320
|
right_arg: RegisterOrFloat,
|
|
322
321
|
machine_precision: int,
|
|
323
|
-
output_size:
|
|
324
|
-
inplace_arg:
|
|
325
|
-
target:
|
|
322
|
+
output_size: int | None = None,
|
|
323
|
+
inplace_arg: str | None = None,
|
|
324
|
+
target: RegisterArithmeticInfo | None = None,
|
|
326
325
|
) -> ArithmeticOperationParams:
|
|
327
326
|
return LessEqual(
|
|
328
327
|
left_arg=left_arg, right_arg=right_arg, machine_precision=machine_precision
|
|
@@ -332,9 +331,9 @@ def less_equal_params_getter(
|
|
|
332
331
|
def logical_and_params_getter(
|
|
333
332
|
*arg: list[RegisterOrFloat],
|
|
334
333
|
machine_precision: int,
|
|
335
|
-
output_size:
|
|
336
|
-
inplace_arg:
|
|
337
|
-
target:
|
|
334
|
+
output_size: int | None = None,
|
|
335
|
+
inplace_arg: str | None = None,
|
|
336
|
+
target: RegisterArithmeticInfo | None = None,
|
|
338
337
|
) -> ArithmeticOperationParams:
|
|
339
338
|
return LogicalAnd(args=arg, target=target, machine_precision=machine_precision)
|
|
340
339
|
|
|
@@ -342,9 +341,9 @@ def logical_and_params_getter(
|
|
|
342
341
|
def logical_or_params_getter(
|
|
343
342
|
*arg: list[RegisterOrFloat],
|
|
344
343
|
machine_precision: int,
|
|
345
|
-
output_size:
|
|
346
|
-
inplace_arg:
|
|
347
|
-
target:
|
|
344
|
+
output_size: int | None = None,
|
|
345
|
+
inplace_arg: str | None = None,
|
|
346
|
+
target: RegisterArithmeticInfo | None = None,
|
|
348
347
|
) -> ArithmeticOperationParams:
|
|
349
348
|
return LogicalOr(args=arg, target=target, machine_precision=machine_precision)
|
|
350
349
|
|
|
@@ -353,9 +352,9 @@ def lshift_params_getter(
|
|
|
353
352
|
left_arg: RegisterArithmeticInfo,
|
|
354
353
|
right_arg: int,
|
|
355
354
|
machine_precision: int,
|
|
356
|
-
output_size:
|
|
357
|
-
inplace_arg:
|
|
358
|
-
target:
|
|
355
|
+
output_size: int | None = None,
|
|
356
|
+
inplace_arg: str | None = None,
|
|
357
|
+
target: RegisterArithmeticInfo | None = None,
|
|
359
358
|
) -> ArithmeticOperationParams:
|
|
360
359
|
return LShift(
|
|
361
360
|
left_arg=left_arg,
|
|
@@ -370,9 +369,9 @@ def rshift_params_getter(
|
|
|
370
369
|
left_arg: RegisterArithmeticInfo,
|
|
371
370
|
right_arg: int,
|
|
372
371
|
machine_precision: int,
|
|
373
|
-
output_size:
|
|
374
|
-
inplace_arg:
|
|
375
|
-
target:
|
|
372
|
+
output_size: int | None = None,
|
|
373
|
+
inplace_arg: str | None = None,
|
|
374
|
+
target: RegisterArithmeticInfo | None = None,
|
|
376
375
|
) -> ArithmeticOperationParams:
|
|
377
376
|
return RShift(
|
|
378
377
|
left_arg=left_arg,
|
|
@@ -383,47 +382,13 @@ def rshift_params_getter(
|
|
|
383
382
|
)
|
|
384
383
|
|
|
385
384
|
|
|
386
|
-
def clshift_params_getter(
|
|
387
|
-
left_arg: RegisterArithmeticInfo,
|
|
388
|
-
right_arg: int,
|
|
389
|
-
machine_precision: int,
|
|
390
|
-
output_size: Optional[int] = None,
|
|
391
|
-
inplace_arg: Optional[str] = None,
|
|
392
|
-
target: Optional[RegisterArithmeticInfo] = None,
|
|
393
|
-
) -> ArithmeticOperationParams:
|
|
394
|
-
return CyclicShift(
|
|
395
|
-
left_arg=left_arg,
|
|
396
|
-
right_arg=-right_arg,
|
|
397
|
-
machine_precision=machine_precision,
|
|
398
|
-
inplace_arg=inplace_arg,
|
|
399
|
-
output_size=output_size,
|
|
400
|
-
)
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
def crshift_params_getter(
|
|
404
|
-
left_arg: RegisterArithmeticInfo,
|
|
405
|
-
right_arg: int,
|
|
406
|
-
machine_precision: int,
|
|
407
|
-
output_size: Optional[int] = None,
|
|
408
|
-
inplace_arg: Optional[str] = None,
|
|
409
|
-
target: Optional[RegisterArithmeticInfo] = None,
|
|
410
|
-
) -> ArithmeticOperationParams:
|
|
411
|
-
return CyclicShift(
|
|
412
|
-
left_arg=left_arg,
|
|
413
|
-
right_arg=right_arg,
|
|
414
|
-
machine_precision=machine_precision,
|
|
415
|
-
inplace_arg=inplace_arg,
|
|
416
|
-
output_size=output_size,
|
|
417
|
-
)
|
|
418
|
-
|
|
419
|
-
|
|
420
385
|
def modulo_params_getter(
|
|
421
386
|
left_arg: RegisterArithmeticInfo,
|
|
422
387
|
right_arg: int,
|
|
423
388
|
machine_precision: int,
|
|
424
|
-
output_size:
|
|
425
|
-
inplace_arg:
|
|
426
|
-
target:
|
|
389
|
+
output_size: int | None = None,
|
|
390
|
+
inplace_arg: str | None = None,
|
|
391
|
+
target: RegisterArithmeticInfo | None = None,
|
|
427
392
|
) -> ArithmeticOperationParams:
|
|
428
393
|
return Modulo(
|
|
429
394
|
left_arg=left_arg,
|
|
@@ -453,8 +418,6 @@ params_getter_map: dict[str, ParamsGetter] = dict(
|
|
|
453
418
|
NotEq=not_equal_params_getter,
|
|
454
419
|
RShift=rshift_params_getter,
|
|
455
420
|
LShift=lshift_params_getter,
|
|
456
|
-
CRShift=crshift_params_getter,
|
|
457
|
-
CLShift=clshift_params_getter,
|
|
458
421
|
Mod=modulo_params_getter,
|
|
459
422
|
min=min_params_getter,
|
|
460
423
|
max=max_params_getter,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Any
|
|
1
|
+
from typing import Any
|
|
2
2
|
|
|
3
3
|
import networkx as nx
|
|
4
4
|
|
|
@@ -27,7 +27,7 @@ class ArithmeticResultBuilder:
|
|
|
27
27
|
|
|
28
28
|
@staticmethod
|
|
29
29
|
def convert_result_definition(
|
|
30
|
-
node: Any, definition:
|
|
30
|
+
node: Any, definition: RegisterOrConst | None, machine_precision: int
|
|
31
31
|
) -> RegisterOrConst:
|
|
32
32
|
if definition:
|
|
33
33
|
return definition
|
|
@@ -61,7 +61,7 @@ class ArithmeticResultBuilder:
|
|
|
61
61
|
graph: nx.DiGraph,
|
|
62
62
|
result_definitions: ArithmeticDefinitions,
|
|
63
63
|
machine_precision: int,
|
|
64
|
-
) -> tuple[RegisterArithmeticInfo,
|
|
64
|
+
) -> tuple[RegisterArithmeticInfo, RegisterArithmeticInfo | None]:
|
|
65
65
|
inputs_node_set: set[str] = {
|
|
66
66
|
vertex for vertex, deg in graph.in_degree if deg == 0
|
|
67
67
|
}
|
|
@@ -95,7 +95,7 @@ class ArithmeticResultBuilder:
|
|
|
95
95
|
node: str,
|
|
96
96
|
*,
|
|
97
97
|
machine_precision: int,
|
|
98
|
-
) -> tuple[RegisterArithmeticInfo,
|
|
98
|
+
) -> tuple[RegisterArithmeticInfo, RegisterArithmeticInfo | None]:
|
|
99
99
|
node_params = arithmetic_param_getters.get_params(
|
|
100
100
|
node_id=node,
|
|
101
101
|
args=args,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import ast
|
|
2
2
|
import itertools
|
|
3
3
|
from collections.abc import Iterator
|
|
4
|
-
from typing import Any,
|
|
4
|
+
from typing import Any, cast
|
|
5
5
|
|
|
6
6
|
from classiq.interface.exceptions import ClassiqArithmeticError
|
|
7
7
|
|
|
@@ -25,13 +25,17 @@ class AstNodeRewrite(ast.NodeTransformer):
|
|
|
25
25
|
new_node.id = self.extract_node_id(new_node)
|
|
26
26
|
return new_node
|
|
27
27
|
|
|
28
|
-
def extract_node_id(self, node: ast.AST) ->
|
|
28
|
+
def extract_node_id(self, node: ast.AST) -> str | float | None:
|
|
29
29
|
if hasattr(node, "id"):
|
|
30
30
|
return node.id
|
|
31
31
|
elif hasattr(node, "op"):
|
|
32
32
|
return type(node.op).__name__ + next(self.count_str_gen)
|
|
33
|
-
elif
|
|
34
|
-
|
|
33
|
+
elif (
|
|
34
|
+
hasattr(node, "func")
|
|
35
|
+
and hasattr(node.func, "id")
|
|
36
|
+
and isinstance(node.func.id, str)
|
|
37
|
+
):
|
|
38
|
+
return node.func.id + next(self.count_str_gen)
|
|
35
39
|
elif hasattr(node, "value"):
|
|
36
40
|
return node.value
|
|
37
41
|
elif hasattr(node, "ops"):
|
|
@@ -5,7 +5,6 @@ from typing import (
|
|
|
5
5
|
ClassVar,
|
|
6
6
|
Generic,
|
|
7
7
|
Literal,
|
|
8
|
-
Optional,
|
|
9
8
|
TypeVar,
|
|
10
9
|
Union,
|
|
11
10
|
)
|
|
@@ -120,7 +119,7 @@ class BinaryOpParams(
|
|
|
120
119
|
class InplacableBinaryOpParams(
|
|
121
120
|
BinaryOpParams[LeftDataT, RightDataT], Generic[LeftDataT, RightDataT]
|
|
122
121
|
):
|
|
123
|
-
inplace_arg:
|
|
122
|
+
inplace_arg: ArgToInplace | None = None
|
|
124
123
|
|
|
125
124
|
@pydantic.model_validator(mode="before")
|
|
126
125
|
@classmethod
|
|
@@ -128,7 +127,7 @@ class InplacableBinaryOpParams(
|
|
|
128
127
|
if isinstance(values, dict):
|
|
129
128
|
left_arg = values.get("left_arg")
|
|
130
129
|
right_arg = values.get("right_arg")
|
|
131
|
-
inplace_arg:
|
|
130
|
+
inplace_arg: ArgToInplace | None = values.get("inplace_arg")
|
|
132
131
|
if inplace_arg == ArgToInplace.RIGHT and isinstance(right_arg, Numeric):
|
|
133
132
|
raise ClassiqValueError(
|
|
134
133
|
_NumericArgumentInplaceErrorMessage.format(right_arg)
|
|
@@ -179,7 +178,7 @@ class InplacableBinaryOpParams(
|
|
|
179
178
|
0, arg.fraction_places - self.result_register.fraction_places # type: ignore[attr-defined]
|
|
180
179
|
)
|
|
181
180
|
|
|
182
|
-
def _carried_arguments(self) -> tuple[
|
|
181
|
+
def _carried_arguments(self) -> tuple[LeftDataT | None, RightDataT | None]:
|
|
183
182
|
if self.inplace_arg == ArgToInplace.RIGHT and isinstance(
|
|
184
183
|
self.left_arg, RegisterArithmeticInfo
|
|
185
184
|
):
|
|
@@ -598,8 +597,9 @@ class Power(BinaryOpParams[RegisterArithmeticInfo, pydantic.PositiveInt]):
|
|
|
598
597
|
left_attrs = NumericAttributes.from_register_arithmetic_info(
|
|
599
598
|
self.left_arg, self.machine_precision
|
|
600
599
|
)
|
|
600
|
+
right_attrs = NumericAttributes.from_constant(self.right_arg)
|
|
601
601
|
result_attrs = compute_result_attrs_power(
|
|
602
|
-
left_attrs,
|
|
602
|
+
left_attrs, right_attrs, self.machine_precision
|
|
603
603
|
)
|
|
604
604
|
|
|
605
605
|
return RegisterArithmeticInfo(
|
|
@@ -611,7 +611,7 @@ class Power(BinaryOpParams[RegisterArithmeticInfo, pydantic.PositiveInt]):
|
|
|
611
611
|
|
|
612
612
|
def _get_inner_action_garbage_size(
|
|
613
613
|
self,
|
|
614
|
-
action_type:
|
|
614
|
+
action_type: type["Power"] | type[Multiplier],
|
|
615
615
|
*,
|
|
616
616
|
arg: RegisterArithmeticInfo,
|
|
617
617
|
action_right_arg: RegisterOrConst,
|
|
@@ -662,7 +662,7 @@ class EffectiveUnaryOpParams(
|
|
|
662
662
|
|
|
663
663
|
class LShift(EffectiveUnaryOpParams[pydantic.NonNegativeInt]):
|
|
664
664
|
output_name = "left_shifted"
|
|
665
|
-
inplace_arg:
|
|
665
|
+
inplace_arg: ArgToInplace | None = ArgToInplace.LEFT
|
|
666
666
|
|
|
667
667
|
@pydantic.model_validator(mode="after")
|
|
668
668
|
def _validate_legal_modulo(self) -> Self:
|
|
@@ -690,8 +690,9 @@ class LShift(EffectiveUnaryOpParams[pydantic.NonNegativeInt]):
|
|
|
690
690
|
left_attrs = NumericAttributes.from_register_arithmetic_info(
|
|
691
691
|
self.left_arg, self.machine_precision
|
|
692
692
|
)
|
|
693
|
+
right_attrs = NumericAttributes.from_constant(self.right_arg)
|
|
693
694
|
result_attrs = compute_result_attrs_lshift(
|
|
694
|
-
left_attrs,
|
|
695
|
+
left_attrs, right_attrs, self.machine_precision
|
|
695
696
|
)
|
|
696
697
|
return RegisterArithmeticInfo(
|
|
697
698
|
size=self.output_size or result_attrs.size,
|
|
@@ -703,7 +704,7 @@ class LShift(EffectiveUnaryOpParams[pydantic.NonNegativeInt]):
|
|
|
703
704
|
|
|
704
705
|
class RShift(EffectiveUnaryOpParams[pydantic.NonNegativeInt]):
|
|
705
706
|
output_name = "right_shifted"
|
|
706
|
-
inplace_arg:
|
|
707
|
+
inplace_arg: ArgToInplace | None = ArgToInplace.LEFT
|
|
707
708
|
|
|
708
709
|
@staticmethod
|
|
709
710
|
def _shifted_fraction_places(*, arg: RegisterArithmeticInfo, shift: int) -> int:
|
|
@@ -740,8 +741,9 @@ class RShift(EffectiveUnaryOpParams[pydantic.NonNegativeInt]):
|
|
|
740
741
|
left_attrs = NumericAttributes.from_register_arithmetic_info(
|
|
741
742
|
self.left_arg, self.machine_precision
|
|
742
743
|
)
|
|
744
|
+
right_attrs = NumericAttributes.from_constant(self.right_arg)
|
|
743
745
|
result_attrs = compute_result_attrs_rshift(
|
|
744
|
-
left_attrs,
|
|
746
|
+
left_attrs, right_attrs, self.machine_precision
|
|
745
747
|
)
|
|
746
748
|
return RegisterArithmeticInfo(
|
|
747
749
|
size=self.output_size or result_attrs.size,
|
|
@@ -751,37 +753,9 @@ class RShift(EffectiveUnaryOpParams[pydantic.NonNegativeInt]):
|
|
|
751
753
|
)
|
|
752
754
|
|
|
753
755
|
|
|
754
|
-
class CyclicShift(EffectiveUnaryOpParams[int]):
|
|
755
|
-
output_name = "cyclic_shifted"
|
|
756
|
-
inplace_arg: Optional[ArgToInplace] = ArgToInplace.LEFT
|
|
757
|
-
|
|
758
|
-
@pydantic.model_validator(mode="after")
|
|
759
|
-
def _validate_legal_modulo(self) -> Self:
|
|
760
|
-
output_size = self.output_size
|
|
761
|
-
if output_size is None:
|
|
762
|
-
return self
|
|
763
|
-
arg = self.left_arg
|
|
764
|
-
if not isinstance(arg, RegisterArithmeticInfo):
|
|
765
|
-
raise ClassiqValueError("left arg must be a RegisterArithmeticInfo")
|
|
766
|
-
assert arg.fraction_places == 0, _FLOATING_POINT_MODULO_ERROR_MESSAGE
|
|
767
|
-
return self
|
|
768
|
-
|
|
769
|
-
def garbage_output_size(self) -> pydantic.NonNegativeInt:
|
|
770
|
-
if self.inplace_arg is None:
|
|
771
|
-
return 0
|
|
772
|
-
return max(0, self.left_arg.size - self.result_register.size)
|
|
773
|
-
|
|
774
|
-
def _get_result_register(self) -> RegisterArithmeticInfo:
|
|
775
|
-
return RegisterArithmeticInfo(
|
|
776
|
-
size=self.output_size or self.left_arg.size,
|
|
777
|
-
is_signed=self._include_sign and self.left_arg.is_signed,
|
|
778
|
-
fraction_places=self.left_arg.fraction_places,
|
|
779
|
-
)
|
|
780
|
-
|
|
781
|
-
|
|
782
756
|
class Modulo(EffectiveUnaryOpParams[int]):
|
|
783
757
|
output_name = "modulus"
|
|
784
|
-
inplace_arg:
|
|
758
|
+
inplace_arg: ArgToInplace | None = ArgToInplace.LEFT
|
|
785
759
|
|
|
786
760
|
@pydantic.field_validator("left_arg", mode="before")
|
|
787
761
|
@classmethod
|
|
@@ -809,8 +783,9 @@ class Modulo(EffectiveUnaryOpParams[int]):
|
|
|
809
783
|
left_attrs = NumericAttributes.from_register_arithmetic_info(
|
|
810
784
|
self.left_arg, self.machine_precision
|
|
811
785
|
)
|
|
786
|
+
right_attrs = NumericAttributes.from_constant(self.right_arg)
|
|
812
787
|
result_attrs = compute_result_attrs_modulo(
|
|
813
|
-
left_attrs,
|
|
788
|
+
left_attrs, right_attrs, self.machine_precision
|
|
814
789
|
)
|
|
815
790
|
return RegisterArithmeticInfo(
|
|
816
791
|
size=result_attrs.size,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
from collections.abc import Iterable
|
|
2
|
-
from typing import Optional
|
|
3
2
|
|
|
4
3
|
import pydantic
|
|
5
4
|
from pydantic import ConfigDict
|
|
@@ -19,7 +18,7 @@ def get_arg_name(idx: int) -> str:
|
|
|
19
18
|
|
|
20
19
|
class LogicalOps(ArithmeticOperationParams):
|
|
21
20
|
args: list[RegisterOrConst]
|
|
22
|
-
target:
|
|
21
|
+
target: RegisterArithmeticInfo | None
|
|
23
22
|
_should_invert_node_list: list[str] = pydantic.PrivateAttr(default_factory=list)
|
|
24
23
|
|
|
25
24
|
def update_should_invert_node_list(self, invert_args: list[str]) -> None:
|
|
@@ -27,7 +26,7 @@ class LogicalOps(ArithmeticOperationParams):
|
|
|
27
26
|
|
|
28
27
|
@pydantic.field_validator("output_size")
|
|
29
28
|
@classmethod
|
|
30
|
-
def _validate_output_size(cls, output_size:
|
|
29
|
+
def _validate_output_size(cls, output_size: int | None) -> int:
|
|
31
30
|
if output_size is not None and output_size != 1:
|
|
32
31
|
raise ClassiqValueError("logical operation output size must be 1")
|
|
33
32
|
return 1
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Final
|
|
1
|
+
from typing import Final
|
|
2
2
|
|
|
3
3
|
MAXIMAL_MACHINE_PRECISION: Final[int] = 20
|
|
4
4
|
|
|
@@ -25,7 +25,7 @@ def binary_to_float(
|
|
|
25
25
|
|
|
26
26
|
def binary_to_float_or_int(
|
|
27
27
|
bin_rep: str, fraction_part_size: int = 0, is_signed: bool = False
|
|
28
|
-
) ->
|
|
28
|
+
) -> float | int:
|
|
29
29
|
if fraction_part_size == 0:
|
|
30
30
|
return binary_to_int(bin_rep, is_signed)
|
|
31
31
|
return binary_to_float(bin_rep, fraction_part_size, is_signed)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Any
|
|
1
|
+
from typing import Any
|
|
2
2
|
|
|
3
3
|
import pydantic
|
|
4
4
|
from pydantic import ConfigDict
|
|
@@ -19,7 +19,7 @@ class RegisterArithmeticInfo(HashablePydanticBaseModel):
|
|
|
19
19
|
is_signed: bool = pydantic.Field(default=False)
|
|
20
20
|
fraction_places: pydantic.NonNegativeInt = pydantic.Field(default=0)
|
|
21
21
|
bypass_bounds_validation: bool = pydantic.Field(default=False)
|
|
22
|
-
bounds: PydanticFloatTuple = pydantic.Field(
|
|
22
|
+
bounds: PydanticFloatTuple = pydantic.Field(
|
|
23
23
|
default=None,
|
|
24
24
|
validate_default=True,
|
|
25
25
|
)
|
|
@@ -51,7 +51,7 @@ class RegisterArithmeticInfo(HashablePydanticBaseModel):
|
|
|
51
51
|
@pydantic.field_validator("bounds", mode="before")
|
|
52
52
|
@classmethod
|
|
53
53
|
def _validate_bounds(
|
|
54
|
-
cls, bounds:
|
|
54
|
+
cls, bounds: PydanticFloatTuple | None, info: ValidationInfo
|
|
55
55
|
) -> PydanticFloatTuple:
|
|
56
56
|
size = info.data.get("size")
|
|
57
57
|
is_signed = info.data.get("is_signed", False)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from collections.abc import Iterable
|
|
2
|
-
from typing import Final
|
|
2
|
+
from typing import Final
|
|
3
3
|
|
|
4
4
|
import pydantic
|
|
5
5
|
from pydantic import ConfigDict
|
|
@@ -127,7 +127,7 @@ class Sign(UnaryOpParams):
|
|
|
127
127
|
@pydantic.field_validator("output_size")
|
|
128
128
|
@classmethod
|
|
129
129
|
def _validate_output_size(
|
|
130
|
-
cls, output_size:
|
|
130
|
+
cls, output_size: pydantic.PositiveInt | None
|
|
131
131
|
) -> pydantic.PositiveInt:
|
|
132
132
|
if output_size is not None and output_size != 1:
|
|
133
133
|
raise ClassiqValueError("Sign output size must be 1")
|