classiq 0.37.1__py3-none-any.whl → 0.65.3__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 +49 -34
- classiq/_analyzer_extras/_ipywidgets_async_extension.py +3 -2
- classiq/_analyzer_extras/interactive_hardware.py +3 -3
- classiq/_internals/api_wrapper.py +241 -95
- classiq/_internals/async_utils.py +2 -77
- classiq/_internals/authentication/auth0.py +26 -10
- classiq/_internals/authentication/authentication.py +11 -0
- classiq/_internals/authentication/device.py +18 -8
- classiq/_internals/authentication/password_manager.py +40 -13
- classiq/_internals/authentication/token_manager.py +11 -6
- classiq/_internals/client.py +106 -37
- classiq/_internals/config.py +3 -4
- classiq/_internals/host_checker.py +38 -15
- classiq/_internals/jobs.py +56 -50
- classiq/_internals/type_validation.py +9 -9
- classiq/analyzer/__init__.py +1 -3
- classiq/analyzer/analyzer.py +50 -47
- classiq/analyzer/analyzer_utilities.py +15 -15
- classiq/analyzer/rb.py +19 -20
- classiq/analyzer/show_interactive_hack.py +30 -7
- classiq/analyzer/url_utils.py +2 -3
- classiq/applications/__init__.py +3 -12
- classiq/applications/chemistry/__init__.py +14 -10
- classiq/applications/chemistry/ansatz_parameters.py +4 -4
- classiq/{applications_model_constructors → applications/chemistry}/chemistry_model_constructor.py +170 -170
- classiq/applications/chemistry/ground_state_problem.py +1 -1
- classiq/applications/combinatorial_helpers/allowed_constraints.py +23 -0
- classiq/applications/combinatorial_helpers/arithmetic/arithmetic_expression.py +35 -0
- classiq/applications/combinatorial_helpers/arithmetic/isolation.py +42 -0
- classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +166 -0
- classiq/applications/combinatorial_helpers/encoding_mapping.py +107 -0
- classiq/applications/combinatorial_helpers/encoding_utils.py +124 -0
- classiq/applications/combinatorial_helpers/memory.py +75 -0
- classiq/applications/combinatorial_helpers/optimization_model.py +193 -0
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_sparsing.py +31 -0
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_utils.py +46 -0
- classiq/applications/combinatorial_helpers/pyomo_utils.py +447 -0
- classiq/applications/combinatorial_helpers/sympy_utils.py +22 -0
- classiq/applications/combinatorial_helpers/transformations/encoding.py +189 -0
- classiq/applications/combinatorial_helpers/transformations/fixed_variables.py +143 -0
- classiq/applications/combinatorial_helpers/transformations/ising_converter.py +120 -0
- classiq/applications/combinatorial_helpers/transformations/penalty.py +31 -0
- classiq/applications/combinatorial_helpers/transformations/penalty_support.py +37 -0
- classiq/applications/combinatorial_helpers/transformations/sign_seperation.py +74 -0
- classiq/applications/combinatorial_helpers/transformations/slack_variables.py +87 -0
- classiq/applications/combinatorial_optimization/__init__.py +24 -5
- classiq/applications/combinatorial_optimization/combinatorial_optimization_config.py +2 -2
- classiq/applications/combinatorial_optimization/combinatorial_optimization_model_constructor.py +137 -0
- classiq/applications/combinatorial_optimization/combinatorial_problem.py +229 -0
- classiq/applications/combinatorial_optimization/examples/__init__.py +1 -3
- classiq/applications/finance/__init__.py +4 -5
- classiq/{applications_model_constructors → applications/finance}/finance_model_constructor.py +50 -57
- classiq/applications/grover/__init__.py +9 -0
- classiq/applications/grover/grover_model_constructor.py +157 -0
- classiq/applications/hamiltonian/__init__.py +0 -0
- classiq/applications/hamiltonian/pauli_decomposition.py +113 -0
- classiq/applications/libraries/__init__.py +0 -0
- classiq/applications/libraries/qmci_library.py +22 -0
- classiq/applications/qnn/__init__.py +2 -4
- classiq/applications/qnn/circuit_utils.py +8 -8
- classiq/applications/qnn/datasets/__init__.py +9 -11
- classiq/applications/qnn/datasets/dataset_base_classes.py +7 -5
- classiq/applications/qnn/datasets/dataset_not.py +2 -1
- classiq/applications/qnn/datasets/dataset_parity.py +2 -2
- classiq/applications/qnn/gradients/quantum_gradient.py +2 -2
- classiq/applications/qnn/gradients/simple_quantum_gradient.py +2 -1
- classiq/applications/qnn/qlayer.py +30 -10
- classiq/applications/qnn/torch_utils.py +4 -3
- classiq/applications/qnn/types.py +7 -7
- classiq/applications/qsvm/__init__.py +6 -4
- classiq/applications/qsvm/qsvm.py +4 -10
- classiq/applications/qsvm/qsvm_data_generation.py +5 -8
- classiq/{applications_model_constructors → applications/qsvm}/qsvm_model_constructor.py +30 -28
- classiq/execution/__init__.py +8 -3
- classiq/execution/all_hardware_devices.py +11 -0
- classiq/execution/execution_session.py +400 -0
- classiq/execution/iqcc.py +63 -0
- classiq/execution/jobs.py +197 -25
- classiq/execution/qnn.py +79 -0
- classiq/executor.py +23 -117
- classiq/interface/_version.py +1 -1
- classiq/interface/analyzer/analysis_params.py +49 -16
- classiq/interface/analyzer/cytoscape_graph.py +15 -9
- classiq/interface/analyzer/result.py +36 -32
- classiq/interface/applications/qsvm.py +28 -25
- classiq/interface/ast_node.py +16 -0
- classiq/interface/backend/backend_preferences.py +390 -119
- classiq/interface/backend/ionq/ionq_quantum_program.py +15 -23
- classiq/interface/backend/pydantic_backend.py +27 -22
- classiq/interface/backend/quantum_backend_providers.py +70 -16
- classiq/interface/chemistry/fermionic_operator.py +43 -32
- classiq/interface/chemistry/ground_state_problem.py +42 -24
- classiq/interface/chemistry/molecule.py +20 -14
- classiq/interface/chemistry/operator.py +75 -236
- classiq/interface/combinatorial_optimization/encoding_types.py +1 -1
- classiq/interface/combinatorial_optimization/examples/ascending_sequence.py +2 -4
- classiq/interface/combinatorial_optimization/examples/greater_than_ilp.py +1 -1
- classiq/interface/combinatorial_optimization/examples/ilp.py +2 -1
- classiq/interface/combinatorial_optimization/examples/integer_portfolio_optimization.py +2 -4
- classiq/interface/combinatorial_optimization/examples/knapsack.py +3 -3
- classiq/interface/combinatorial_optimization/examples/mds.py +2 -1
- classiq/interface/combinatorial_optimization/examples/mht.py +10 -6
- classiq/interface/combinatorial_optimization/examples/mis.py +4 -1
- classiq/interface/combinatorial_optimization/examples/mvc.py +2 -1
- classiq/interface/combinatorial_optimization/examples/portfolio_variations.py +2 -2
- classiq/interface/combinatorial_optimization/examples/set_cover.py +3 -3
- classiq/interface/combinatorial_optimization/examples/tsp.py +4 -3
- classiq/interface/combinatorial_optimization/examples/tsp_digraph.py +6 -2
- classiq/interface/combinatorial_optimization/mht_qaoa_input.py +14 -9
- classiq/interface/combinatorial_optimization/optimization_problem.py +2 -2
- classiq/interface/combinatorial_optimization/result.py +1 -3
- classiq/interface/combinatorial_optimization/solver_types.py +1 -1
- classiq/interface/debug_info/__init__.py +0 -0
- classiq/interface/debug_info/debug_info.py +86 -0
- classiq/interface/exceptions.py +201 -0
- classiq/interface/execution/iqcc.py +19 -0
- classiq/interface/execution/jobs.py +15 -12
- classiq/interface/execution/primitives.py +18 -0
- classiq/interface/executor/constants.py +1 -0
- classiq/interface/executor/estimation.py +2 -2
- classiq/interface/executor/execution_preferences.py +26 -143
- classiq/interface/executor/execution_request.py +36 -56
- classiq/interface/executor/execution_result.py +30 -8
- classiq/interface/executor/iqae_result.py +4 -6
- classiq/interface/executor/optimizer_preferences.py +34 -22
- classiq/interface/executor/{quantum_program.py → quantum_code.py} +44 -34
- classiq/interface/executor/quantum_instruction_set.py +3 -2
- classiq/interface/executor/register_initialization.py +12 -17
- classiq/interface/executor/result.py +122 -64
- classiq/interface/executor/vqe_result.py +11 -11
- classiq/interface/finance/function_input.py +42 -19
- classiq/interface/finance/gaussian_model_input.py +7 -5
- classiq/interface/finance/log_normal_model_input.py +6 -4
- classiq/interface/finance/model_input.py +6 -4
- classiq/interface/generator/adjacency.py +1 -3
- classiq/interface/generator/amplitude_loading.py +27 -14
- classiq/interface/generator/ansatz_library.py +5 -5
- classiq/interface/generator/application_apis/__init__.py +1 -0
- classiq/interface/generator/application_apis/arithmetic_declarations.py +17 -0
- classiq/interface/generator/application_apis/chemistry_declarations.py +27 -187
- classiq/interface/generator/application_apis/combinatorial_optimization_declarations.py +18 -21
- classiq/interface/generator/application_apis/entangler_declarations.py +11 -6
- classiq/interface/generator/application_apis/finance_declarations.py +48 -69
- classiq/interface/generator/application_apis/qsvm_declarations.py +0 -70
- classiq/interface/generator/arith/argument_utils.py +57 -6
- classiq/interface/generator/arith/arithmetic.py +37 -16
- classiq/interface/generator/arith/arithmetic_arg_type_validator.py +15 -17
- classiq/interface/generator/arith/arithmetic_expression_abc.py +70 -26
- classiq/interface/generator/arith/arithmetic_expression_parser.py +18 -12
- classiq/interface/generator/arith/arithmetic_expression_validator.py +61 -43
- classiq/interface/generator/arith/arithmetic_operations.py +19 -16
- classiq/interface/generator/arith/arithmetic_param_getters.py +7 -8
- classiq/interface/generator/arith/arithmetic_result_builder.py +21 -17
- classiq/interface/generator/arith/ast_node_rewrite.py +4 -3
- classiq/interface/generator/arith/binary_ops.py +375 -139
- classiq/interface/generator/arith/endianness.py +1 -1
- classiq/interface/generator/arith/extremum_operations.py +96 -23
- classiq/interface/generator/arith/logical_ops.py +16 -12
- classiq/interface/generator/arith/machine_precision.py +3 -0
- classiq/interface/generator/arith/number_utils.py +44 -48
- classiq/interface/generator/arith/register_user_input.py +70 -27
- classiq/interface/generator/arith/unary_ops.py +57 -46
- classiq/interface/generator/arith/uncomputation_methods.py +1 -1
- classiq/interface/generator/builtin_api_builder.py +2 -9
- classiq/interface/generator/chemistry_function_params.py +5 -5
- classiq/interface/generator/circuit_code/circuit_code.py +7 -7
- classiq/interface/generator/circuit_code/types_and_constants.py +4 -7
- classiq/interface/generator/commuting_pauli_exponentiation.py +8 -6
- classiq/interface/generator/compiler_keywords.py +8 -0
- classiq/interface/generator/complex_type.py +13 -25
- classiq/interface/generator/constant.py +3 -4
- classiq/interface/generator/control_state.py +35 -28
- classiq/interface/generator/copy.py +47 -0
- classiq/interface/generator/custom_ansatz.py +2 -5
- classiq/interface/generator/distance.py +3 -5
- classiq/interface/generator/excitations.py +3 -2
- classiq/interface/generator/expressions/atomic_expression_functions.py +26 -8
- classiq/interface/generator/expressions/enums/__init__.py +0 -10
- classiq/interface/generator/expressions/enums/finance_functions.py +12 -22
- classiq/interface/generator/expressions/evaluated_expression.py +21 -7
- classiq/interface/generator/expressions/expression.py +27 -15
- classiq/interface/generator/expressions/expression_constants.py +9 -3
- classiq/interface/generator/expressions/non_symbolic_expr.py +119 -0
- classiq/interface/generator/expressions/qmod_qarray_proxy.py +99 -0
- classiq/interface/generator/expressions/qmod_qscalar_proxy.py +59 -0
- classiq/interface/generator/expressions/qmod_qstruct_proxy.py +36 -0
- classiq/interface/generator/expressions/qmod_sized_proxy.py +30 -2
- classiq/interface/generator/expressions/qmod_struct_instance.py +14 -2
- classiq/interface/generator/expressions/sympy_supported_expressions.py +20 -11
- classiq/interface/generator/finance.py +3 -3
- classiq/interface/generator/function_param_library.py +6 -6
- classiq/interface/generator/function_param_list_without_self_reference.py +2 -10
- classiq/interface/generator/function_params.py +42 -69
- classiq/interface/generator/functions/__init__.py +0 -22
- classiq/interface/generator/functions/builtins/__init__.py +0 -0
- classiq/interface/generator/functions/builtins/internal_operators.py +16 -0
- classiq/interface/generator/functions/classical_function_declaration.py +18 -9
- classiq/interface/generator/functions/classical_type.py +47 -166
- classiq/interface/generator/functions/concrete_types.py +55 -0
- classiq/interface/generator/functions/function_declaration.py +13 -14
- classiq/interface/generator/functions/port_declaration.py +1 -13
- classiq/interface/generator/functions/qmod_python_interface.py +2 -1
- classiq/interface/generator/functions/type_name.py +90 -0
- classiq/interface/generator/generated_circuit_data.py +155 -22
- classiq/interface/generator/grover_diffuser.py +32 -25
- classiq/interface/generator/grover_operator.py +34 -23
- classiq/interface/generator/hamiltonian_evolution/exponentiation.py +4 -6
- classiq/interface/generator/hamiltonian_evolution/qdrift.py +4 -4
- classiq/interface/generator/hamiltonian_evolution/suzuki_trotter.py +12 -8
- classiq/interface/generator/hardware/hardware_data.py +76 -36
- classiq/interface/generator/hardware_efficient_ansatz.py +38 -17
- classiq/interface/generator/hartree_fock.py +14 -4
- classiq/interface/generator/identity.py +10 -6
- classiq/interface/generator/linear_pauli_rotations.py +33 -19
- classiq/interface/generator/mcmt_method.py +1 -1
- classiq/interface/generator/mcu.py +20 -16
- classiq/interface/generator/mcx.py +29 -20
- classiq/interface/generator/model/__init__.py +2 -5
- classiq/interface/generator/model/constraints.py +27 -8
- classiq/interface/generator/model/model.py +32 -203
- classiq/interface/generator/model/preferences/preferences.py +118 -43
- classiq/{quantum_register.py → interface/generator/model/quantum_register.py} +27 -22
- classiq/interface/generator/oracles/arithmetic_oracle.py +2 -4
- classiq/interface/generator/oracles/custom_oracle.py +17 -13
- classiq/interface/generator/oracles/oracle_abc.py +9 -9
- classiq/interface/generator/partitioned_register.py +7 -7
- classiq/interface/generator/piecewise_linear_amplitude_loading.py +45 -29
- classiq/interface/generator/preferences/optimization.py +1 -2
- classiq/interface/generator/qpe.py +47 -34
- classiq/interface/generator/qsvm.py +13 -17
- classiq/interface/generator/quantum_function_call.py +107 -87
- classiq/interface/generator/{generated_circuit.py → quantum_program.py} +50 -37
- classiq/interface/generator/range_types.py +13 -12
- classiq/interface/generator/register_role.py +18 -6
- classiq/interface/generator/slice_parsing_utils.py +11 -6
- classiq/interface/generator/standard_gates/controlled_standard_gates.py +32 -39
- classiq/interface/generator/standard_gates/standard_angle_metaclass.py +2 -6
- classiq/interface/generator/standard_gates/standard_gates.py +3 -3
- classiq/interface/generator/standard_gates/u_gate.py +7 -10
- classiq/interface/generator/state_preparation/bell_state_preparation.py +3 -3
- classiq/interface/generator/state_preparation/computational_basis_state_preparation.py +2 -1
- classiq/interface/generator/state_preparation/distributions.py +16 -15
- classiq/interface/generator/state_preparation/metrics.py +5 -7
- classiq/interface/generator/state_preparation/state_preparation.py +30 -23
- classiq/interface/generator/synthesis_metadata/synthesis_duration.py +0 -4
- classiq/interface/generator/synthesis_metadata/synthesis_execution_data.py +20 -6
- classiq/interface/generator/transpiler_basis_gates.py +7 -3
- classiq/interface/generator/types/builtin_enum_declarations.py +178 -0
- classiq/interface/generator/types/compilation_metadata.py +6 -0
- classiq/interface/generator/types/enum_declaration.py +54 -0
- classiq/interface/generator/types/qstruct_declaration.py +18 -0
- classiq/interface/generator/types/struct_declaration.py +15 -14
- classiq/interface/generator/ucc.py +9 -6
- classiq/interface/generator/unitary_gate.py +10 -6
- classiq/interface/generator/user_defined_function_params.py +4 -1
- classiq/interface/generator/validations/flow_graph.py +11 -9
- classiq/interface/generator/validations/validator_functions.py +8 -6
- classiq/interface/generator/visitor.py +23 -16
- classiq/interface/hardware.py +31 -10
- classiq/interface/helpers/classproperty.py +8 -0
- classiq/interface/helpers/custom_encoders.py +3 -0
- classiq/interface/helpers/custom_pydantic_types.py +40 -50
- classiq/interface/helpers/datastructures.py +26 -0
- classiq/interface/helpers/hashable_mixin.py +3 -2
- classiq/interface/helpers/hashable_pydantic_base_model.py +2 -1
- classiq/interface/helpers/pydantic_model_helpers.py +7 -11
- classiq/interface/helpers/validation_helpers.py +4 -21
- classiq/interface/helpers/versioned_model.py +1 -1
- classiq/interface/ide/ide_data.py +16 -20
- classiq/interface/ide/visual_model.py +130 -0
- classiq/interface/interface_version.py +1 -0
- classiq/interface/jobs.py +35 -6
- classiq/interface/model/allocate.py +16 -0
- classiq/interface/model/bind_operation.py +44 -14
- classiq/interface/model/classical_if.py +15 -0
- classiq/interface/model/classical_parameter_declaration.py +33 -3
- classiq/interface/model/control.py +45 -0
- classiq/interface/model/handle_binding.py +298 -20
- classiq/interface/model/inplace_binary_operation.py +31 -26
- classiq/interface/model/invert.py +12 -0
- classiq/interface/model/model.py +87 -73
- classiq/interface/model/native_function_definition.py +16 -21
- classiq/interface/model/parameter.py +13 -0
- classiq/interface/model/phase_operation.py +11 -0
- classiq/interface/model/port_declaration.py +27 -9
- classiq/interface/model/power.py +14 -0
- classiq/interface/model/quantum_expressions/amplitude_loading_operation.py +38 -21
- classiq/interface/model/quantum_expressions/arithmetic_operation.py +51 -14
- classiq/interface/model/quantum_expressions/quantum_expression.py +12 -35
- classiq/interface/model/quantum_function_call.py +146 -462
- classiq/interface/model/quantum_function_declaration.py +193 -152
- classiq/interface/model/quantum_lambda_function.py +65 -0
- classiq/interface/model/quantum_statement.py +71 -12
- classiq/interface/model/quantum_type.py +205 -67
- classiq/interface/model/quantum_variable_declaration.py +4 -26
- classiq/interface/model/repeat.py +15 -0
- classiq/interface/model/statement_block.py +58 -0
- classiq/interface/model/validation_handle.py +13 -6
- classiq/interface/model/variable_declaration_statement.py +3 -1
- classiq/interface/model/within_apply_operation.py +13 -0
- classiq/interface/pyomo_extension/pyomo_sympy_bimap.py +4 -1
- classiq/interface/server/global_versions.py +6 -7
- classiq/interface/server/routes.py +22 -21
- classiq/interface/source_reference.py +59 -0
- classiq/model_expansions/__init__.py +0 -0
- classiq/model_expansions/atomic_expression_functions_defs.py +253 -0
- classiq/model_expansions/capturing/__init__.py +0 -0
- classiq/model_expansions/capturing/captured_vars.py +435 -0
- classiq/model_expansions/capturing/mangling_utils.py +56 -0
- classiq/model_expansions/closure.py +171 -0
- classiq/model_expansions/debug_flag.py +3 -0
- classiq/model_expansions/evaluators/__init__.py +0 -0
- classiq/model_expansions/evaluators/arg_type_match.py +158 -0
- classiq/model_expansions/evaluators/argument_types.py +42 -0
- classiq/model_expansions/evaluators/classical_expression.py +36 -0
- classiq/model_expansions/evaluators/control.py +144 -0
- classiq/model_expansions/evaluators/parameter_types.py +226 -0
- classiq/model_expansions/evaluators/quantum_type_utils.py +239 -0
- classiq/model_expansions/evaluators/type_type_match.py +90 -0
- classiq/model_expansions/expression_evaluator.py +135 -0
- classiq/model_expansions/expression_renamer.py +76 -0
- classiq/model_expansions/function_builder.py +247 -0
- classiq/model_expansions/generative_functions.py +158 -0
- classiq/model_expansions/interpreters/__init__.py +0 -0
- classiq/model_expansions/interpreters/base_interpreter.py +263 -0
- classiq/model_expansions/interpreters/frontend_generative_interpreter.py +28 -0
- classiq/model_expansions/interpreters/generative_interpreter.py +249 -0
- classiq/model_expansions/model_tables.py +18 -0
- classiq/model_expansions/quantum_operations/__init__.py +9 -0
- classiq/model_expansions/quantum_operations/bind.py +60 -0
- classiq/model_expansions/quantum_operations/call_emitter.py +266 -0
- classiq/model_expansions/quantum_operations/classicalif.py +53 -0
- classiq/model_expansions/quantum_operations/declarative_call_emitter.py +87 -0
- classiq/model_expansions/quantum_operations/emitter.py +181 -0
- classiq/model_expansions/quantum_operations/quantum_function_call.py +33 -0
- classiq/model_expansions/quantum_operations/repeat.py +56 -0
- classiq/model_expansions/quantum_operations/shallow_emitter.py +180 -0
- classiq/model_expansions/quantum_operations/variable_decleration.py +28 -0
- classiq/model_expansions/scope.py +240 -0
- classiq/model_expansions/scope_initialization.py +150 -0
- classiq/model_expansions/sympy_conversion/__init__.py +0 -0
- classiq/model_expansions/sympy_conversion/arithmetics.py +49 -0
- classiq/model_expansions/sympy_conversion/expression_to_sympy.py +179 -0
- classiq/model_expansions/sympy_conversion/sympy_to_python.py +123 -0
- classiq/model_expansions/transformers/__init__.py +0 -0
- classiq/model_expansions/transformers/ast_renamer.py +26 -0
- classiq/model_expansions/transformers/var_splitter.py +299 -0
- classiq/model_expansions/utils/__init__.py +0 -0
- classiq/model_expansions/utils/counted_name_allocator.py +11 -0
- classiq/model_expansions/utils/handles_collector.py +33 -0
- classiq/model_expansions/visitors/__init__.py +0 -0
- classiq/model_expansions/visitors/boolean_expression_transformers.py +214 -0
- classiq/model_expansions/visitors/variable_references.py +144 -0
- classiq/open_library/__init__.py +4 -0
- classiq/open_library/functions/__init__.py +130 -0
- classiq/open_library/functions/amplitude_estimation.py +30 -0
- classiq/open_library/functions/discrete_sine_cosine_transform.py +181 -0
- classiq/open_library/functions/grover.py +157 -0
- classiq/open_library/functions/hea.py +115 -0
- classiq/open_library/functions/linear_pauli_rotation.py +82 -0
- classiq/open_library/functions/modular_exponentiation.py +201 -0
- classiq/open_library/functions/qaoa_penalty.py +117 -0
- classiq/open_library/functions/qft_functions.py +54 -0
- classiq/open_library/functions/qpe.py +46 -0
- classiq/open_library/functions/qsvt.py +331 -0
- classiq/open_library/functions/state_preparation.py +301 -0
- classiq/open_library/functions/swap_test.py +27 -0
- classiq/open_library/functions/utility_functions.py +81 -0
- classiq/open_library/functions/variational.py +52 -0
- classiq/qmod/__init__.py +17 -10
- classiq/qmod/builtins/__init__.py +19 -2
- classiq/qmod/builtins/classical_execution_primitives.py +60 -47
- classiq/qmod/builtins/classical_functions.py +44 -38
- classiq/qmod/builtins/constants.py +10 -0
- classiq/qmod/builtins/enums.py +208 -0
- classiq/qmod/builtins/functions/__init__.py +137 -0
- classiq/qmod/builtins/functions/allocation.py +150 -0
- classiq/qmod/builtins/functions/arithmetic.py +55 -0
- classiq/qmod/builtins/functions/benchmarking.py +8 -0
- classiq/qmod/builtins/functions/chemistry.py +91 -0
- classiq/qmod/builtins/functions/exponentiation.py +105 -0
- classiq/qmod/builtins/functions/finance.py +34 -0
- classiq/qmod/builtins/functions/operators.py +16 -0
- classiq/qmod/builtins/functions/qsvm.py +24 -0
- classiq/qmod/builtins/functions/standard_gates.py +651 -0
- classiq/qmod/builtins/operations.py +379 -57
- classiq/qmod/builtins/structs.py +103 -80
- classiq/qmod/cfunc.py +42 -0
- classiq/qmod/classical_function.py +8 -20
- classiq/qmod/cparam.py +64 -0
- classiq/qmod/create_model_function.py +56 -0
- classiq/qmod/declaration_inferrer.py +145 -112
- classiq/qmod/expression_query.py +39 -0
- classiq/qmod/generative.py +42 -0
- classiq/qmod/model_state_container.py +19 -5
- classiq/qmod/native/__init__.py +7 -0
- classiq/qmod/native/expression_to_qmod.py +194 -0
- classiq/qmod/native/pretty_printer.py +401 -0
- classiq/qmod/pretty_print/__init__.py +7 -0
- classiq/qmod/pretty_print/expression_to_python.py +222 -0
- classiq/qmod/pretty_print/pretty_printer.py +572 -0
- classiq/qmod/python_classical_type.py +67 -0
- classiq/qmod/qfunc.py +79 -0
- classiq/qmod/qmod_constant.py +143 -0
- classiq/qmod/qmod_parameter.py +84 -53
- classiq/qmod/qmod_variable.py +497 -100
- classiq/qmod/quantum_callable.py +17 -7
- classiq/qmod/quantum_expandable.py +278 -105
- classiq/qmod/quantum_function.py +232 -48
- classiq/qmod/semantics/__init__.py +0 -0
- classiq/qmod/semantics/annotation/__init__.py +0 -0
- classiq/qmod/semantics/annotation/call_annotation.py +92 -0
- classiq/qmod/semantics/annotation/qstruct_annotator.py +23 -0
- classiq/qmod/semantics/error_manager.py +88 -0
- classiq/qmod/semantics/lambdas.py +25 -0
- classiq/qmod/semantics/static_semantics_visitor.py +384 -0
- classiq/qmod/semantics/validation/__init__.py +0 -0
- classiq/qmod/semantics/validation/constants_validation.py +16 -0
- classiq/qmod/semantics/validation/func_call_validation.py +99 -0
- classiq/qmod/semantics/validation/function_name_collisions_validation.py +23 -0
- classiq/qmod/semantics/validation/handle_validation.py +85 -0
- classiq/qmod/semantics/validation/main_validation.py +33 -0
- classiq/qmod/semantics/validation/types_validation.py +128 -0
- classiq/qmod/symbolic.py +178 -111
- classiq/qmod/symbolic_expr.py +36 -12
- classiq/qmod/symbolic_type.py +2 -5
- classiq/qmod/type_attribute_remover.py +32 -0
- classiq/qmod/utilities.py +108 -1
- classiq/qmod/write_qmod.py +53 -0
- classiq/synthesis.py +210 -22
- {classiq-0.37.1.dist-info → classiq-0.65.3.dist-info}/METADATA +16 -8
- classiq-0.65.3.dist-info/RECORD +521 -0
- {classiq-0.37.1.dist-info → classiq-0.65.3.dist-info}/WHEEL +1 -1
- classiq/_internals/_qfunc_ext.py +0 -6
- classiq/applications/benchmarking/__init__.py +0 -9
- classiq/applications/benchmarking/mirror_benchmarking.py +0 -67
- classiq/applications/numpy_utils.py +0 -37
- classiq/applications_model_constructors/__init__.py +0 -17
- classiq/applications_model_constructors/combinatorial_optimization_model_constructor.py +0 -178
- classiq/applications_model_constructors/grover_model_constructor.py +0 -227
- classiq/applications_model_constructors/libraries/ampltitude_estimation_library.py +0 -11
- classiq/applications_model_constructors/libraries/qmci_library.py +0 -109
- classiq/builtin_functions/__init__.py +0 -43
- classiq/builtin_functions/amplitude_loading.py +0 -3
- classiq/builtin_functions/binary_ops.py +0 -1
- classiq/builtin_functions/exponentiation.py +0 -5
- classiq/builtin_functions/qpe.py +0 -4
- classiq/builtin_functions/qsvm.py +0 -7
- classiq/builtin_functions/range_types.py +0 -5
- classiq/builtin_functions/standard_gates.py +0 -1
- classiq/builtin_functions/state_preparation.py +0 -6
- classiq/builtin_functions/suzuki_trotter.py +0 -3
- classiq/exceptions.py +0 -131
- classiq/interface/executor/aws_execution_cost.py +0 -72
- classiq/interface/executor/error_mitigation.py +0 -6
- classiq/interface/generator/credit_risk_example/linear_gci.py +0 -115
- classiq/interface/generator/credit_risk_example/weighted_adder.py +0 -59
- classiq/interface/generator/expressions/enums/chemistry.py +0 -28
- classiq/interface/generator/expressions/enums/classical_enum.py +0 -5
- classiq/interface/generator/expressions/enums/ladder_operator.py +0 -16
- classiq/interface/generator/expressions/enums/optimizers.py +0 -9
- classiq/interface/generator/expressions/enums/pauli.py +0 -8
- classiq/interface/generator/expressions/enums/qsvm_feature_map_entanglement.py +0 -9
- classiq/interface/generator/expressions/qmod_qnum_proxy.py +0 -22
- classiq/interface/generator/functions/core_lib_declarations/quantum_functions/__init__.py +0 -18
- classiq/interface/generator/functions/core_lib_declarations/quantum_functions/atomic_quantum_functions.py +0 -641
- classiq/interface/generator/functions/core_lib_declarations/quantum_functions/exponentiation_functions.py +0 -89
- classiq/interface/generator/functions/core_lib_declarations/quantum_functions/std_lib_functions.py +0 -862
- classiq/interface/generator/functions/core_lib_declarations/quantum_operators.py +0 -169
- classiq/interface/generator/functions/foreign_function_definition.py +0 -106
- classiq/interface/generator/functions/function_implementation.py +0 -103
- classiq/interface/generator/functions/native_function_definition.py +0 -153
- classiq/interface/generator/functions/quantum_function_declaration.py +0 -69
- classiq/interface/generator/functions/register.py +0 -42
- classiq/interface/generator/functions/register_mapping_data.py +0 -102
- classiq/interface/generator/inequality_mixer.py +0 -51
- classiq/interface/generator/model/classical_main_validator.py +0 -106
- classiq/interface/generator/range_mixer.py +0 -56
- classiq/interface/generator/state_propagator.py +0 -63
- classiq/interface/generator/types/builtin_struct_declarations/__init__.py +0 -2
- classiq/interface/generator/types/builtin_struct_declarations/pauli_struct_declarations.py +0 -22
- classiq/interface/generator/types/builtin_struct_declarations/qaoa_declarations.py +0 -23
- classiq/interface/generator/types/combinatorial_problem.py +0 -26
- classiq/interface/ide/show.py +0 -34
- classiq/interface/model/common_model_types.py +0 -23
- classiq/interface/model/numeric_reinterpretation.py +0 -25
- classiq/interface/model/operator_synthesis_data.py +0 -48
- classiq/interface/model/quantum_expressions/control_state.py +0 -38
- classiq/interface/model/quantum_if_operation.py +0 -95
- classiq/interface/model/resolvers/function_call_resolver.py +0 -43
- classiq/interface/model/validations/handle_validation_base.py +0 -55
- classiq/interface/model/validations/handles_validator.py +0 -154
- classiq/interface/model/validations/port_to_wire_name_generator.py +0 -12
- classiq/model/__init__.py +0 -14
- classiq/model/composite_function_generator.py +0 -33
- classiq/model/function_handler.py +0 -466
- classiq/model/function_handler.pyi +0 -152
- classiq/model/logic_flow.py +0 -149
- classiq/model/logic_flow_change_handler.py +0 -71
- classiq/model/model.py +0 -246
- classiq/qmod/builtins/functions.py +0 -896
- classiq/qmod/qmod_struct.py +0 -37
- classiq/quantum_functions/__init__.py +0 -17
- classiq/quantum_functions/annotation_parser.py +0 -207
- classiq/quantum_functions/decorators.py +0 -22
- classiq/quantum_functions/function_library.py +0 -181
- classiq/quantum_functions/function_parser.py +0 -74
- classiq/quantum_functions/quantum_function.py +0 -236
- classiq-0.37.1.dist-info/RECORD +0 -418
- /classiq/{applications_model_constructors/libraries → applications/combinatorial_helpers}/__init__.py +0 -0
- /classiq/{interface/generator/credit_risk_example → applications/combinatorial_helpers/arithmetic}/__init__.py +0 -0
- /classiq/{interface/generator/functions/core_lib_declarations → applications/combinatorial_helpers/pauli_helpers}/__init__.py +0 -0
- /classiq/{interface/generator/functions/core_lib_declarations/quantum_functions/chemistry_functions.py → applications/combinatorial_helpers/py.typed} +0 -0
- /classiq/{interface/model/resolvers → applications/combinatorial_helpers/solvers}/__init__.py +0 -0
- /classiq/{interface/model/validations → applications/combinatorial_helpers/transformations}/__init__.py +0 -0
- /classiq/{_internals → interface}/enum_utils.py +0 -0
@@ -1,10 +0,0 @@
|
|
1
|
-
from enum import EnumMeta
|
2
|
-
|
3
|
-
from .chemistry import Element, FermionMapping
|
4
|
-
from .finance_functions import FinanceFunctionType
|
5
|
-
from .ladder_operator import LadderOperator
|
6
|
-
from .optimizers import Optimizer
|
7
|
-
from .pauli import Pauli
|
8
|
-
from .qsvm_feature_map_entanglement import QSVMFeatureMapEntanglement
|
9
|
-
|
10
|
-
BUILTIN_ENUMS = dict(filter(lambda pair: isinstance(pair[1], EnumMeta), vars().items()))
|
@@ -1,22 +1,12 @@
|
|
1
|
-
from
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
def from_string(func_str: str) -> "FinanceFunctionType":
|
14
|
-
return FINANCE_FUNCTION_STRING[func_str]
|
15
|
-
|
16
|
-
|
17
|
-
FINANCE_FUNCTION_STRING: Dict[str, FinanceFunctionType] = {
|
18
|
-
"var": FinanceFunctionType.VAR,
|
19
|
-
"expected shortfall": FinanceFunctionType.SHORTFALL,
|
20
|
-
"x**2": FinanceFunctionType.X_SQUARE,
|
21
|
-
"european call option": FinanceFunctionType.EUROPEAN_CALL_OPTION,
|
22
|
-
}
|
1
|
+
from classiq.interface.generator.types.builtin_enum_declarations import (
|
2
|
+
FinanceFunctionType,
|
3
|
+
)
|
4
|
+
|
5
|
+
|
6
|
+
def get_finance_function_dict() -> dict[str, "FinanceFunctionType"]:
|
7
|
+
return {
|
8
|
+
"var": FinanceFunctionType.VAR,
|
9
|
+
"expected shortfall": FinanceFunctionType.SHORTFALL,
|
10
|
+
"x**2": FinanceFunctionType.X_SQUARE,
|
11
|
+
"european call option": FinanceFunctionType.EUROPEAN_CALL_OPTION,
|
12
|
+
}
|
@@ -1,8 +1,13 @@
|
|
1
|
+
import re
|
2
|
+
from collections.abc import Mapping
|
1
3
|
from dataclasses import dataclass
|
2
|
-
from typing import Any,
|
4
|
+
from typing import Any, Optional
|
3
5
|
|
6
|
+
from sympy import Expr
|
4
7
|
from typing_extensions import get_args
|
5
8
|
|
9
|
+
from classiq.interface.backend.pydantic_backend import EXECUTION_PARAMETER_PATTERN
|
10
|
+
from classiq.interface.exceptions import ClassiqValueError
|
6
11
|
from classiq.interface.generator.expressions.expression_types import (
|
7
12
|
ExpressionValue,
|
8
13
|
QmodStructInstance,
|
@@ -10,22 +15,25 @@ from classiq.interface.generator.expressions.expression_types import (
|
|
10
15
|
)
|
11
16
|
from classiq.interface.generator.expressions.handle_identifier import HandleIdentifier
|
12
17
|
|
13
|
-
from classiq.exceptions import ClassiqValueError
|
14
|
-
|
15
18
|
|
16
19
|
@dataclass(frozen=True)
|
17
20
|
class EvaluatedExpression:
|
18
21
|
value: ExpressionValue
|
19
22
|
|
20
|
-
def is_constant(self) -> bool:
|
23
|
+
def is_constant(self, constant_type: Optional[type] = None) -> bool:
|
21
24
|
if self.value is None:
|
22
25
|
return False
|
23
26
|
|
24
|
-
return isinstance(
|
27
|
+
return isinstance(
|
28
|
+
self.value,
|
29
|
+
get_args(RuntimeConstant) if constant_type is None else constant_type,
|
30
|
+
)
|
25
31
|
|
26
|
-
def as_constant_type(self, constant_type:
|
32
|
+
def as_constant_type(self, constant_type: type) -> Any:
|
27
33
|
if not self.is_constant():
|
28
|
-
raise ClassiqValueError(
|
34
|
+
raise ClassiqValueError(
|
35
|
+
f"Invalid access to expression {self.value!r} as {constant_type}"
|
36
|
+
)
|
29
37
|
|
30
38
|
return constant_type(self.value)
|
31
39
|
|
@@ -62,3 +70,9 @@ class EvaluatedExpression:
|
|
62
70
|
raise ClassiqValueError("Invalid access to unevaluated expression")
|
63
71
|
|
64
72
|
return str(self.value)
|
73
|
+
|
74
|
+
def is_identifier(self) -> bool:
|
75
|
+
return (
|
76
|
+
isinstance(self.value, Expr)
|
77
|
+
and re.fullmatch(EXECUTION_PARAMETER_PATTERN, str(self.value)) is not None
|
78
|
+
)
|
@@ -1,14 +1,17 @@
|
|
1
1
|
import ast
|
2
|
-
from
|
2
|
+
from collections.abc import Mapping
|
3
|
+
from typing import Any, Optional
|
3
4
|
|
4
5
|
import pydantic
|
5
|
-
from pydantic import PrivateAttr
|
6
|
+
from pydantic import ConfigDict, PrivateAttr
|
6
7
|
|
8
|
+
from classiq.interface.ast_node import HashableASTNode
|
9
|
+
from classiq.interface.exceptions import ClassiqError
|
7
10
|
from classiq.interface.generator.arith.arithmetic_expression_validator import (
|
8
11
|
DEFAULT_SUPPORTED_FUNC_NAMES,
|
9
12
|
)
|
10
13
|
from classiq.interface.generator.expressions.atomic_expression_functions import (
|
11
|
-
|
14
|
+
SUPPORTED_ATOMIC_EXPRESSION_FUNCTIONS_QMOD,
|
12
15
|
)
|
13
16
|
from classiq.interface.generator.expressions.evaluated_expression import (
|
14
17
|
EvaluatedExpression,
|
@@ -17,14 +20,9 @@ from classiq.interface.generator.expressions.sympy_supported_expressions import
|
|
17
20
|
SYMPY_SUPPORTED_EXPRESSIONS,
|
18
21
|
)
|
19
22
|
from classiq.interface.generator.function_params import validate_expression_str
|
20
|
-
from classiq.interface.helpers.hashable_pydantic_base_model import (
|
21
|
-
HashablePydanticBaseModel,
|
22
|
-
)
|
23
|
-
|
24
|
-
from classiq.exceptions import ClassiqError
|
25
23
|
|
26
24
|
|
27
|
-
class Expression(
|
25
|
+
class Expression(HashableASTNode):
|
28
26
|
expr: str
|
29
27
|
_evaluated_expr: Optional[EvaluatedExpression] = PrivateAttr(default=None)
|
30
28
|
|
@@ -33,20 +31,27 @@ class Expression(HashablePydanticBaseModel):
|
|
33
31
|
|
34
32
|
self._try_to_immediate_evaluate()
|
35
33
|
|
36
|
-
@pydantic.
|
34
|
+
@pydantic.field_validator("expr")
|
35
|
+
@classmethod
|
37
36
|
def validate_expression(cls, expr: str) -> str:
|
38
37
|
supported_functions = (
|
39
|
-
|
38
|
+
SUPPORTED_ATOMIC_EXPRESSION_FUNCTIONS_QMOD
|
40
39
|
| set(SYMPY_SUPPORTED_EXPRESSIONS)
|
41
40
|
| set(DEFAULT_SUPPORTED_FUNC_NAMES)
|
42
41
|
)
|
43
42
|
validate_expression_str(expr, supported_functions=supported_functions)
|
44
43
|
return expr
|
45
44
|
|
45
|
+
@pydantic.field_validator("expr")
|
46
|
+
@classmethod
|
47
|
+
def format_expression(cls, expr: str) -> str:
|
48
|
+
expr = ast.unparse(ast.parse(expr))
|
49
|
+
return expr
|
50
|
+
|
46
51
|
def is_evaluated(self) -> bool:
|
47
52
|
return self._evaluated_expr is not None
|
48
53
|
|
49
|
-
def as_constant(self, constant_type:
|
54
|
+
def as_constant(self, constant_type: type) -> Any:
|
50
55
|
return self.value.as_constant_type(constant_type)
|
51
56
|
|
52
57
|
def to_int_value(self) -> int:
|
@@ -65,11 +70,19 @@ class Expression(HashablePydanticBaseModel):
|
|
65
70
|
return self.as_constant(list)
|
66
71
|
|
67
72
|
def _try_to_immediate_evaluate(self) -> None:
|
73
|
+
# FIXME remove special treatment (CAD-22999)
|
74
|
+
if self.expr == "SIGNED":
|
75
|
+
self._evaluated_expr = EvaluatedExpression(value=True)
|
76
|
+
return
|
77
|
+
if self.expr == "UNSIGNED":
|
78
|
+
self._evaluated_expr = EvaluatedExpression(value=False)
|
79
|
+
return
|
80
|
+
|
68
81
|
try:
|
69
82
|
result = ast.literal_eval(self.expr)
|
70
83
|
if isinstance(result, (int, float, bool)):
|
71
84
|
self._evaluated_expr = EvaluatedExpression(value=result)
|
72
|
-
except Exception: #
|
85
|
+
except Exception: # noqa: S110
|
73
86
|
pass
|
74
87
|
|
75
88
|
@property
|
@@ -85,8 +98,7 @@ class Expression(HashablePydanticBaseModel):
|
|
85
98
|
def is_constant(self) -> bool:
|
86
99
|
return self.value.is_constant()
|
87
100
|
|
88
|
-
|
89
|
-
frozen = True
|
101
|
+
model_config = ConfigDict(frozen=True)
|
90
102
|
|
91
103
|
def __str__(self) -> str:
|
92
104
|
return self.expr
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import keyword
|
2
|
-
from typing import
|
2
|
+
from typing import Final
|
3
3
|
|
4
4
|
from classiq.interface.generator.arith.arithmetic_expression_parser import (
|
5
5
|
DEFAULT_SUPPORTED_FUNC_NAMES,
|
@@ -11,9 +11,15 @@ from classiq.interface.generator.function_params import NAME_REGEX
|
|
11
11
|
|
12
12
|
SUPPORTED_VAR_NAMES_REG = NAME_REGEX
|
13
13
|
|
14
|
-
SUPPORTED_FUNC_NAMES:
|
14
|
+
SUPPORTED_FUNC_NAMES: set[str] = (
|
15
15
|
{"or", "and"}
|
16
16
|
.union(DEFAULT_SUPPORTED_FUNC_NAMES)
|
17
17
|
.union(set(SYMPY_SUPPORTED_EXPRESSIONS))
|
18
18
|
)
|
19
|
-
|
19
|
+
BOOLEAN_LITERALS = {"True", "False"}
|
20
|
+
FORBIDDEN_LITERALS: set[str] = set(keyword.kwlist) - SUPPORTED_FUNC_NAMES
|
21
|
+
CPARAM_EXECUTION_SUFFIX: Final[str] = "_param"
|
22
|
+
RESERVED_EXPRESSIONS: frozenset[str] = frozenset({"i"})
|
23
|
+
CPARAM_EXECUTION_SUFFIX_PATTERN = (
|
24
|
+
rf"({CPARAM_EXECUTION_SUFFIX}|^({'|'.join(RESERVED_EXPRESSIONS)}))(_\d+)*$"
|
25
|
+
)
|
@@ -0,0 +1,119 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
from typing import Any, NoReturn
|
4
|
+
|
5
|
+
from classiq.interface.exceptions import ClassiqArithmeticError
|
6
|
+
|
7
|
+
|
8
|
+
class NonSymbolicExpr:
|
9
|
+
@property
|
10
|
+
def type_name(self) -> str:
|
11
|
+
raise NotImplementedError
|
12
|
+
|
13
|
+
@staticmethod
|
14
|
+
def _raise_error(type_name: str, op: str) -> NoReturn:
|
15
|
+
raise ClassiqArithmeticError(
|
16
|
+
f"Unsupported operand type for {op!r}: {type_name}"
|
17
|
+
)
|
18
|
+
|
19
|
+
def __add__(self, other: Any) -> NoReturn:
|
20
|
+
NonSymbolicExpr._raise_error(self.type_name, "+")
|
21
|
+
|
22
|
+
def __sub__(self, other: Any) -> NoReturn:
|
23
|
+
NonSymbolicExpr._raise_error(self.type_name, "-")
|
24
|
+
|
25
|
+
def __mul__(self, other: Any) -> NoReturn:
|
26
|
+
NonSymbolicExpr._raise_error(self.type_name, "*")
|
27
|
+
|
28
|
+
def __truediv__(self, other: Any) -> NoReturn:
|
29
|
+
NonSymbolicExpr._raise_error(self.type_name, "/")
|
30
|
+
|
31
|
+
def __floordiv__(self, other: Any) -> NoReturn:
|
32
|
+
NonSymbolicExpr._raise_error(self.type_name, "//")
|
33
|
+
|
34
|
+
def __mod__(self, other: Any) -> NoReturn:
|
35
|
+
NonSymbolicExpr._raise_error(self.type_name, "%")
|
36
|
+
|
37
|
+
def __pow__(self, other: Any) -> NoReturn:
|
38
|
+
NonSymbolicExpr._raise_error(self.type_name, "**")
|
39
|
+
|
40
|
+
def __lshift__(self, other: Any) -> NoReturn:
|
41
|
+
NonSymbolicExpr._raise_error(self.type_name, "<<")
|
42
|
+
|
43
|
+
def __rshift__(self, other: Any) -> NoReturn:
|
44
|
+
NonSymbolicExpr._raise_error(self.type_name, ">>")
|
45
|
+
|
46
|
+
def __and__(self, other: Any) -> NoReturn:
|
47
|
+
NonSymbolicExpr._raise_error(self.type_name, "&")
|
48
|
+
|
49
|
+
def __xor__(self, other: Any) -> NoReturn:
|
50
|
+
NonSymbolicExpr._raise_error(self.type_name, "^")
|
51
|
+
|
52
|
+
def __or__(self, other: Any) -> NoReturn:
|
53
|
+
NonSymbolicExpr._raise_error(self.type_name, "|")
|
54
|
+
|
55
|
+
def __radd__(self, other: Any) -> NoReturn:
|
56
|
+
NonSymbolicExpr._raise_error(self.type_name, "+")
|
57
|
+
|
58
|
+
def __rsub__(self, other: Any) -> NoReturn:
|
59
|
+
NonSymbolicExpr._raise_error(self.type_name, "-")
|
60
|
+
|
61
|
+
def __rmul__(self, other: Any) -> NoReturn:
|
62
|
+
NonSymbolicExpr._raise_error(self.type_name, "*")
|
63
|
+
|
64
|
+
def __rtruediv__(self, other: Any) -> NoReturn:
|
65
|
+
NonSymbolicExpr._raise_error(self.type_name, "/")
|
66
|
+
|
67
|
+
def __rfloordiv__(self, other: Any) -> NoReturn:
|
68
|
+
NonSymbolicExpr._raise_error(self.type_name, "//")
|
69
|
+
|
70
|
+
def __rmod__(self, other: Any) -> NoReturn:
|
71
|
+
NonSymbolicExpr._raise_error(self.type_name, "%")
|
72
|
+
|
73
|
+
def __rpow__(self, other: Any) -> NoReturn:
|
74
|
+
NonSymbolicExpr._raise_error(self.type_name, "**")
|
75
|
+
|
76
|
+
def __rlshift__(self, other: Any) -> NoReturn:
|
77
|
+
NonSymbolicExpr._raise_error(self.type_name, "<<")
|
78
|
+
|
79
|
+
def __rrshift__(self, other: Any) -> NoReturn:
|
80
|
+
NonSymbolicExpr._raise_error(self.type_name, ">>")
|
81
|
+
|
82
|
+
def __rand__(self, other: Any) -> NoReturn:
|
83
|
+
NonSymbolicExpr._raise_error(self.type_name, "&")
|
84
|
+
|
85
|
+
def __rxor__(self, other: Any) -> NoReturn:
|
86
|
+
NonSymbolicExpr._raise_error(self.type_name, "^")
|
87
|
+
|
88
|
+
def __ror__(self, other: Any) -> NoReturn:
|
89
|
+
NonSymbolicExpr._raise_error(self.type_name, "|")
|
90
|
+
|
91
|
+
def __lt__(self, other: Any) -> NoReturn:
|
92
|
+
NonSymbolicExpr._raise_error(self.type_name, "<")
|
93
|
+
|
94
|
+
def __le__(self, other: Any) -> NoReturn:
|
95
|
+
NonSymbolicExpr._raise_error(self.type_name, "<=")
|
96
|
+
|
97
|
+
def __eq__(self, other: Any) -> NoReturn:
|
98
|
+
NonSymbolicExpr._raise_error(self.type_name, "==")
|
99
|
+
|
100
|
+
def __ne__(self, other: Any) -> NoReturn:
|
101
|
+
NonSymbolicExpr._raise_error(self.type_name, "!=")
|
102
|
+
|
103
|
+
def __gt__(self, other: Any) -> NoReturn:
|
104
|
+
NonSymbolicExpr._raise_error(self.type_name, ">")
|
105
|
+
|
106
|
+
def __ge__(self, other: Any) -> NoReturn:
|
107
|
+
NonSymbolicExpr._raise_error(self.type_name, ">=")
|
108
|
+
|
109
|
+
def __neg__(self) -> NoReturn:
|
110
|
+
NonSymbolicExpr._raise_error(self.type_name, "-")
|
111
|
+
|
112
|
+
def __pos__(self) -> NoReturn:
|
113
|
+
NonSymbolicExpr._raise_error(self.type_name, "+")
|
114
|
+
|
115
|
+
def __abs__(self) -> NoReturn:
|
116
|
+
NonSymbolicExpr._raise_error(self.type_name, "abs")
|
117
|
+
|
118
|
+
def __invert__(self) -> NoReturn:
|
119
|
+
NonSymbolicExpr._raise_error(self.type_name, "~")
|
@@ -0,0 +1,99 @@
|
|
1
|
+
from collections.abc import Mapping
|
2
|
+
from typing import TYPE_CHECKING, Any, Union
|
3
|
+
|
4
|
+
from sympy import Integer
|
5
|
+
|
6
|
+
from classiq.interface.exceptions import (
|
7
|
+
ClassiqInternalExpansionError,
|
8
|
+
ClassiqValueError,
|
9
|
+
)
|
10
|
+
from classiq.interface.generator.expressions.expression import Expression
|
11
|
+
from classiq.interface.generator.expressions.non_symbolic_expr import NonSymbolicExpr
|
12
|
+
from classiq.interface.generator.expressions.qmod_sized_proxy import QmodSizedProxy
|
13
|
+
from classiq.interface.model.handle_binding import (
|
14
|
+
HandleBinding,
|
15
|
+
SlicedHandleBinding,
|
16
|
+
SubscriptHandleBinding,
|
17
|
+
)
|
18
|
+
|
19
|
+
if TYPE_CHECKING:
|
20
|
+
from classiq.interface.model.quantum_type import QuantumType
|
21
|
+
|
22
|
+
|
23
|
+
ILLEGAL_SLICING_STEP_MSG = "Slicing with a step of a quantum variable is not supported"
|
24
|
+
ILLEGAL_SLICE_MSG = "Quantum array slice must be of the form [<int-value>:<int-value>]."
|
25
|
+
|
26
|
+
|
27
|
+
class QmodQArrayProxy(NonSymbolicExpr, QmodSizedProxy):
|
28
|
+
def __init__(
|
29
|
+
self,
|
30
|
+
handle: HandleBinding,
|
31
|
+
element_type: "QuantumType",
|
32
|
+
element_size: int,
|
33
|
+
length: int,
|
34
|
+
) -> None:
|
35
|
+
super().__init__(handle, element_size * length)
|
36
|
+
self._length = length
|
37
|
+
self._element_type = element_type
|
38
|
+
self._element_size = element_size
|
39
|
+
|
40
|
+
def __getitem__(self, key: Union[slice, int, Integer]) -> "QmodSizedProxy":
|
41
|
+
return (
|
42
|
+
self._get_slice(key) if isinstance(key, slice) else self._get_subscript(key)
|
43
|
+
)
|
44
|
+
|
45
|
+
def _get_subscript(self, index: Union[int, Integer]) -> "QmodSizedProxy":
|
46
|
+
if isinstance(index, Integer):
|
47
|
+
index = int(index)
|
48
|
+
if index < 0 or index >= self._length:
|
49
|
+
raise ClassiqInternalExpansionError
|
50
|
+
|
51
|
+
return self._element_type.get_proxy(
|
52
|
+
SubscriptHandleBinding(
|
53
|
+
base_handle=self.handle,
|
54
|
+
index=Expression(expr=str(index)),
|
55
|
+
)
|
56
|
+
)
|
57
|
+
|
58
|
+
def _get_slice(self, slice_: slice) -> "QmodSizedProxy":
|
59
|
+
if slice_.step is not None:
|
60
|
+
raise ClassiqValueError(ILLEGAL_SLICING_STEP_MSG)
|
61
|
+
if isinstance(slice_.start, Integer):
|
62
|
+
slice_ = slice(int(slice_.start), slice_.stop)
|
63
|
+
if isinstance(slice_.stop, Integer):
|
64
|
+
slice_ = slice(slice_.start, int(slice_.stop))
|
65
|
+
if not isinstance(slice_.start, int) or not isinstance(slice_.stop, int):
|
66
|
+
raise ClassiqValueError(ILLEGAL_SLICE_MSG)
|
67
|
+
if (
|
68
|
+
slice_.start >= slice_.stop
|
69
|
+
or slice_.start < 0
|
70
|
+
or slice_.stop > self._length
|
71
|
+
):
|
72
|
+
raise ClassiqInternalExpansionError
|
73
|
+
|
74
|
+
return QmodQArrayProxy(
|
75
|
+
SlicedHandleBinding(
|
76
|
+
base_handle=self.handle,
|
77
|
+
start=Expression(expr=str(slice_.start)),
|
78
|
+
end=Expression(expr=str(slice_.stop)),
|
79
|
+
),
|
80
|
+
self._element_type,
|
81
|
+
self._element_size,
|
82
|
+
slice_.stop - slice_.start,
|
83
|
+
)
|
84
|
+
|
85
|
+
@property
|
86
|
+
def type_name(self) -> str:
|
87
|
+
return "Quantum array"
|
88
|
+
|
89
|
+
@property
|
90
|
+
def len(self) -> int:
|
91
|
+
return self._length
|
92
|
+
|
93
|
+
@property
|
94
|
+
def fields(self) -> Mapping[str, Any]:
|
95
|
+
return {**super().fields, "len": self.len}
|
96
|
+
|
97
|
+
@property
|
98
|
+
def size(self) -> int:
|
99
|
+
return self.len * self._element_size
|
@@ -0,0 +1,59 @@
|
|
1
|
+
from collections.abc import Mapping
|
2
|
+
from typing import Any
|
3
|
+
|
4
|
+
from sympy import Symbol
|
5
|
+
|
6
|
+
from classiq.interface.exceptions import ClassiqValueError
|
7
|
+
from classiq.interface.generator.expressions.qmod_sized_proxy import QmodSizedProxy
|
8
|
+
from classiq.interface.model.handle_binding import HandleBinding
|
9
|
+
|
10
|
+
|
11
|
+
class QmodQScalarProxy(Symbol, QmodSizedProxy):
|
12
|
+
def __new__(cls, handle: HandleBinding, **assumptions: bool) -> "QmodQScalarProxy":
|
13
|
+
return super().__new__(cls, str(handle), **assumptions)
|
14
|
+
|
15
|
+
def __init__(self, handle: HandleBinding, size: int) -> None:
|
16
|
+
super().__init__(handle, size)
|
17
|
+
|
18
|
+
|
19
|
+
class QmodQBitProxy(QmodQScalarProxy):
|
20
|
+
def __init__(self, handle: HandleBinding) -> None:
|
21
|
+
super().__init__(handle, 1)
|
22
|
+
|
23
|
+
@property
|
24
|
+
def type_name(self) -> str:
|
25
|
+
return "Quantum bit"
|
26
|
+
|
27
|
+
|
28
|
+
class QmodQNumProxy(QmodQScalarProxy):
|
29
|
+
def __init__(
|
30
|
+
self, handle: HandleBinding, size: int, fraction_digits: int, is_signed: bool
|
31
|
+
) -> None:
|
32
|
+
super().__init__(handle, size)
|
33
|
+
if fraction_digits > size:
|
34
|
+
raise ClassiqValueError(
|
35
|
+
f"Quantum numeric of size {size} cannot have {fraction_digits} "
|
36
|
+
f"fraction digits"
|
37
|
+
)
|
38
|
+
self._fraction_digits = fraction_digits
|
39
|
+
self._is_signed = is_signed
|
40
|
+
|
41
|
+
@property
|
42
|
+
def type_name(self) -> str:
|
43
|
+
return "Quantum numeric"
|
44
|
+
|
45
|
+
@property
|
46
|
+
def fraction_digits(self) -> int:
|
47
|
+
return self._fraction_digits
|
48
|
+
|
49
|
+
@property
|
50
|
+
def is_signed(self) -> bool:
|
51
|
+
return self._is_signed
|
52
|
+
|
53
|
+
@property
|
54
|
+
def fields(self) -> Mapping[str, Any]:
|
55
|
+
return {
|
56
|
+
**super().fields,
|
57
|
+
"is_signed": self.is_signed,
|
58
|
+
"fraction_digits": self.fraction_digits,
|
59
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
from collections.abc import Mapping
|
2
|
+
from typing import TYPE_CHECKING
|
3
|
+
|
4
|
+
from classiq.interface.generator.expressions.non_symbolic_expr import NonSymbolicExpr
|
5
|
+
from classiq.interface.generator.expressions.qmod_sized_proxy import QmodSizedProxy
|
6
|
+
from classiq.interface.model.handle_binding import (
|
7
|
+
FieldHandleBinding,
|
8
|
+
HandleBinding,
|
9
|
+
)
|
10
|
+
|
11
|
+
if TYPE_CHECKING:
|
12
|
+
from classiq.interface.model.quantum_type import QuantumType
|
13
|
+
|
14
|
+
|
15
|
+
class QmodQStructProxy(NonSymbolicExpr, QmodSizedProxy):
|
16
|
+
def __init__(
|
17
|
+
self,
|
18
|
+
handle: HandleBinding,
|
19
|
+
struct_name: str,
|
20
|
+
fields: Mapping[str, "QuantumType"],
|
21
|
+
) -> None:
|
22
|
+
self._fields = {
|
23
|
+
name: type_.get_proxy(FieldHandleBinding(base_handle=handle, field=name))
|
24
|
+
for name, type_ in fields.items()
|
25
|
+
}
|
26
|
+
size = sum(proxy.size for proxy in self._fields.values())
|
27
|
+
super().__init__(handle, size)
|
28
|
+
self._struct_name = struct_name
|
29
|
+
|
30
|
+
@property
|
31
|
+
def type_name(self) -> str:
|
32
|
+
return self._struct_name
|
33
|
+
|
34
|
+
@property
|
35
|
+
def fields(self) -> Mapping[str, QmodSizedProxy]:
|
36
|
+
return {**super().fields, **self._fields}
|
@@ -1,6 +1,34 @@
|
|
1
|
+
from collections.abc import Mapping
|
2
|
+
from typing import TYPE_CHECKING, Any
|
3
|
+
|
4
|
+
if TYPE_CHECKING:
|
5
|
+
from classiq.interface.model.handle_binding import HandleBinding
|
6
|
+
|
7
|
+
|
1
8
|
class QmodSizedProxy:
|
2
|
-
def __init__(self, size: int) -> None:
|
9
|
+
def __init__(self, handle: "HandleBinding", size: int) -> None:
|
10
|
+
self._handle = handle
|
3
11
|
self._size = size
|
4
12
|
|
5
|
-
|
13
|
+
@property
|
14
|
+
def size(self) -> int:
|
6
15
|
return self._size
|
16
|
+
|
17
|
+
def __str__(self) -> str:
|
18
|
+
return str(self.handle)
|
19
|
+
|
20
|
+
@property
|
21
|
+
def type_name(self) -> str:
|
22
|
+
raise NotImplementedError
|
23
|
+
|
24
|
+
@property
|
25
|
+
def handle(self) -> "HandleBinding":
|
26
|
+
return self._handle
|
27
|
+
|
28
|
+
@property
|
29
|
+
def len(self) -> int:
|
30
|
+
return self._size
|
31
|
+
|
32
|
+
@property
|
33
|
+
def fields(self) -> Mapping[str, Any]:
|
34
|
+
return {"size": self._size}
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import types
|
2
|
-
from
|
2
|
+
from collections.abc import Mapping
|
3
|
+
from typing import TYPE_CHECKING, Any
|
3
4
|
|
4
5
|
if TYPE_CHECKING:
|
5
6
|
from classiq.interface.generator.expressions.expression_types import ExpressionValue
|
@@ -16,9 +17,20 @@ class QmodStructInstance:
|
|
16
17
|
self.struct_declaration = struct_declaration
|
17
18
|
self._fields = fields
|
18
19
|
|
20
|
+
@property
|
21
|
+
def type_name(self) -> str:
|
22
|
+
return f"Struct {self.struct_declaration.name}"
|
23
|
+
|
19
24
|
@property
|
20
25
|
def fields(self) -> Mapping[str, Any]:
|
21
26
|
return types.MappingProxyType(self._fields)
|
22
27
|
|
28
|
+
def __str__(self) -> str:
|
29
|
+
return repr(self)
|
30
|
+
|
23
31
|
def __repr__(self) -> str:
|
24
|
-
|
32
|
+
fields = ", ".join(
|
33
|
+
f"{field_name}={field_value}"
|
34
|
+
for field_name, field_value in self._fields.items()
|
35
|
+
)
|
36
|
+
return f"{self.struct_declaration.name}({fields})"
|
@@ -1,7 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
BASIC_ARITHMETIC_OPERATORS: List[str] = ["+", "-", "*", "/", "%"]
|
4
|
-
MATHEMATICAL_FUNCTIONS: List[str] = [
|
1
|
+
BASIC_ARITHMETIC_OPERATORS: list[str] = ["+", "-", "*", "/", "%"]
|
2
|
+
MATHEMATICAL_FUNCTIONS: list[str] = [
|
5
3
|
"sin",
|
6
4
|
"cos",
|
7
5
|
"tan",
|
@@ -34,8 +32,9 @@ MATHEMATICAL_FUNCTIONS: List[str] = [
|
|
34
32
|
"ceiling",
|
35
33
|
"Max",
|
36
34
|
"Min",
|
35
|
+
"mod_inverse",
|
37
36
|
]
|
38
|
-
SPECIAL_FUNCTIONS:
|
37
|
+
SPECIAL_FUNCTIONS: list[str] = [
|
39
38
|
"erf",
|
40
39
|
"erfc",
|
41
40
|
"gamma",
|
@@ -56,10 +55,20 @@ SPECIAL_FUNCTIONS: List[str] = [
|
|
56
55
|
"euler",
|
57
56
|
"catalan",
|
58
57
|
]
|
59
|
-
PIECEWISE_FUNCTIONS:
|
60
|
-
|
61
|
-
|
62
|
-
|
58
|
+
PIECEWISE_FUNCTIONS: list[str] = ["Piecewise", "Heaviside"]
|
59
|
+
NUMERIC_CONSTANTS: list[str] = [
|
60
|
+
"pi",
|
61
|
+
"E",
|
62
|
+
"I",
|
63
|
+
"GoldenRatio",
|
64
|
+
"EulerGamma",
|
65
|
+
"Catalan",
|
66
|
+
]
|
67
|
+
BOOLEAN_CONSTANTS: list[str] = ["true", "false"]
|
68
|
+
CONSTANTS: list[str] = NUMERIC_CONSTANTS + BOOLEAN_CONSTANTS
|
69
|
+
|
70
|
+
DATA_TYPES: list[str] = ["Matrix"]
|
71
|
+
LOGIC_OPERATORS: list[str] = [
|
63
72
|
"And",
|
64
73
|
"Or",
|
65
74
|
"Not",
|
@@ -69,9 +78,9 @@ LOGIC_OPERATORS: List[str] = [
|
|
69
78
|
"Nand",
|
70
79
|
"Nor",
|
71
80
|
]
|
72
|
-
RELATIONAL_OPERATORS:
|
81
|
+
RELATIONAL_OPERATORS: list[str] = ["<", "<=", ">", ">=", "!=", "<>", "Eq", "Ne"]
|
73
82
|
|
74
|
-
SYMPY_SUPPORTED_EXPRESSIONS:
|
83
|
+
SYMPY_SUPPORTED_EXPRESSIONS: list[str] = (
|
75
84
|
BASIC_ARITHMETIC_OPERATORS
|
76
85
|
+ MATHEMATICAL_FUNCTIONS
|
77
86
|
+ SPECIAL_FUNCTIONS
|