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
@@ -0,0 +1,128 @@
|
|
1
|
+
from collections.abc import Sequence
|
2
|
+
from typing import Union
|
3
|
+
|
4
|
+
from classiq.interface.generator.functions.type_name import TypeName
|
5
|
+
from classiq.interface.generator.types.enum_declaration import EnumDeclaration
|
6
|
+
from classiq.interface.generator.types.qstruct_declaration import QStructDeclaration
|
7
|
+
from classiq.interface.generator.types.struct_declaration import StructDeclaration
|
8
|
+
from classiq.interface.model.quantum_type import QuantumBitvector
|
9
|
+
|
10
|
+
from classiq.qmod.builtins.enums import BUILTIN_ENUM_DECLARATIONS
|
11
|
+
from classiq.qmod.builtins.structs import BUILTIN_STRUCT_DECLARATIONS
|
12
|
+
from classiq.qmod.model_state_container import QMODULE
|
13
|
+
from classiq.qmod.semantics.error_manager import ErrorManager
|
14
|
+
|
15
|
+
|
16
|
+
def check_duplicate_types(
|
17
|
+
types: Sequence[Union[EnumDeclaration, StructDeclaration, QStructDeclaration]]
|
18
|
+
) -> None:
|
19
|
+
known_types = {type_.name for type_ in BUILTIN_ENUM_DECLARATIONS.values()}
|
20
|
+
known_types |= {type_.name for type_ in BUILTIN_STRUCT_DECLARATIONS.values()}
|
21
|
+
for type_ in types:
|
22
|
+
if type_.name in known_types:
|
23
|
+
with ErrorManager().node_context(type_):
|
24
|
+
ErrorManager().add_error(f"Type {type_.name!r} already exists")
|
25
|
+
else:
|
26
|
+
known_types.add(type_.name)
|
27
|
+
|
28
|
+
|
29
|
+
def check_qstruct_flexibility(qstruct: QStructDeclaration) -> None:
|
30
|
+
_check_qstruct_no_array_without_size_and_element_size(qstruct)
|
31
|
+
_check_qstruct_at_most_one_type_without_size(qstruct)
|
32
|
+
|
33
|
+
|
34
|
+
def _check_qstruct_no_array_without_size_and_element_size(
|
35
|
+
qstruct: QStructDeclaration,
|
36
|
+
) -> None:
|
37
|
+
offending_array_fields = [
|
38
|
+
field_name
|
39
|
+
for field_name, field_type in qstruct.fields.items()
|
40
|
+
if isinstance(field_type, QuantumBitvector)
|
41
|
+
and not field_type.has_length
|
42
|
+
and not field_type.element_type.has_size_in_bits
|
43
|
+
]
|
44
|
+
if len(offending_array_fields) > 0:
|
45
|
+
with ErrorManager().node_context(qstruct):
|
46
|
+
ErrorManager().add_error(
|
47
|
+
f"Quantum struct {qstruct.name} contains arrays whose neither length "
|
48
|
+
f"nor element size are constants. Offending fields: "
|
49
|
+
f"{', '.join(offending_array_fields)}"
|
50
|
+
)
|
51
|
+
|
52
|
+
|
53
|
+
def _check_qstruct_at_most_one_type_without_size(qstruct: QStructDeclaration) -> None:
|
54
|
+
fields_without_size = [
|
55
|
+
field_name
|
56
|
+
for field_name, field_type in qstruct.fields.items()
|
57
|
+
if not field_type.has_size_in_bits
|
58
|
+
]
|
59
|
+
if len(fields_without_size) > 1:
|
60
|
+
with ErrorManager().node_context(qstruct):
|
61
|
+
ErrorManager().add_error(
|
62
|
+
f"Quantum struct {qstruct.name} has more than one field whose size is "
|
63
|
+
f"not constant. Offending fields: {', '.join(fields_without_size)}"
|
64
|
+
)
|
65
|
+
|
66
|
+
|
67
|
+
def check_qstruct_fields_are_defined(qstruct: QStructDeclaration) -> bool:
|
68
|
+
all_defined = True
|
69
|
+
for field_type in qstruct.fields.values():
|
70
|
+
if (
|
71
|
+
isinstance(field_type, TypeName)
|
72
|
+
and field_type.name not in QMODULE.qstruct_decls
|
73
|
+
):
|
74
|
+
with ErrorManager().node_context(field_type):
|
75
|
+
ErrorManager().add_error(
|
76
|
+
f"Quantum struct {field_type.name!r} is not defined."
|
77
|
+
)
|
78
|
+
all_defined = False
|
79
|
+
return all_defined
|
80
|
+
|
81
|
+
|
82
|
+
def check_qstruct_has_fields(qstruct: QStructDeclaration) -> None:
|
83
|
+
if len(qstruct.fields) == 0:
|
84
|
+
with ErrorManager().node_context(qstruct):
|
85
|
+
ErrorManager().add_error(
|
86
|
+
f"Quantum struct {qstruct.name!r} must have at least one field."
|
87
|
+
)
|
88
|
+
|
89
|
+
|
90
|
+
def check_cstruct_has_fields(cstruct: StructDeclaration) -> None:
|
91
|
+
if len(cstruct.variables) == 0:
|
92
|
+
with ErrorManager().node_context(cstruct):
|
93
|
+
ErrorManager().add_error(
|
94
|
+
f"Classical struct {cstruct.name!r} must have at least one field."
|
95
|
+
)
|
96
|
+
|
97
|
+
|
98
|
+
def check_qstruct_is_not_recursive(qstruct: QStructDeclaration) -> bool:
|
99
|
+
non_recursive = True
|
100
|
+
for main_field_name, main_field in qstruct.fields.items():
|
101
|
+
if (
|
102
|
+
not isinstance(main_field, TypeName)
|
103
|
+
or main_field.name not in QMODULE.qstruct_decls
|
104
|
+
):
|
105
|
+
continue
|
106
|
+
main_field_qstruct = QMODULE.qstruct_decls[main_field.name]
|
107
|
+
seen_qstructs = {qstruct.name}
|
108
|
+
stack = [main_field_qstruct]
|
109
|
+
while stack:
|
110
|
+
qstruct = stack.pop()
|
111
|
+
if qstruct.name in seen_qstructs:
|
112
|
+
with ErrorManager().node_context(qstruct):
|
113
|
+
ErrorManager().add_error(
|
114
|
+
f"Declaration of field {main_field_name!r} in quantum struct "
|
115
|
+
f"{qstruct.name!r} creates a recursive definition."
|
116
|
+
)
|
117
|
+
non_recursive = False
|
118
|
+
break
|
119
|
+
seen_qstructs.add(qstruct.name)
|
120
|
+
stack.extend(
|
121
|
+
[
|
122
|
+
QMODULE.qstruct_decls[field.name]
|
123
|
+
for field in qstruct.fields.values()
|
124
|
+
if isinstance(field, TypeName)
|
125
|
+
and field.name in QMODULE.qstruct_decls
|
126
|
+
]
|
127
|
+
)
|
128
|
+
return non_recursive
|
classiq/qmod/symbolic.py
CHANGED
@@ -1,228 +1,277 @@
|
|
1
1
|
import sys
|
2
|
-
from typing import
|
3
|
-
|
4
|
-
|
2
|
+
from typing import (
|
3
|
+
TYPE_CHECKING,
|
4
|
+
Any,
|
5
|
+
Optional,
|
6
|
+
TypeVar,
|
7
|
+
Union,
|
8
|
+
overload,
|
9
|
+
)
|
10
|
+
|
11
|
+
from classiq.interface.exceptions import ClassiqValueError
|
12
|
+
|
13
|
+
from classiq.qmod import model_state_container
|
14
|
+
from classiq.qmod.declaration_inferrer import python_type_to_qmod
|
15
|
+
from classiq.qmod.qmod_parameter import (
|
16
|
+
CArray,
|
17
|
+
CParam,
|
18
|
+
CParamScalar,
|
19
|
+
CReal,
|
20
|
+
create_param,
|
21
|
+
)
|
22
|
+
from classiq.qmod.qmod_variable import QNum
|
5
23
|
from classiq.qmod.symbolic_expr import SymbolicExpr
|
6
24
|
from classiq.qmod.symbolic_type import SymbolicTypes
|
7
25
|
|
8
|
-
pi = SymbolicExpr("pi")
|
9
|
-
E = SymbolicExpr("E")
|
10
|
-
I = SymbolicExpr("I") # noqa: E741
|
11
|
-
GoldenRatio = SymbolicExpr("GoldenRatio")
|
12
|
-
EulerGamma = SymbolicExpr("EulerGamma")
|
13
|
-
Catalan = SymbolicExpr("Catalan")
|
26
|
+
pi = SymbolicExpr("pi", False)
|
27
|
+
E = SymbolicExpr("E", False)
|
28
|
+
I = SymbolicExpr("I", False) # noqa: E741
|
29
|
+
GoldenRatio = SymbolicExpr("GoldenRatio", False)
|
30
|
+
EulerGamma = SymbolicExpr("EulerGamma", False)
|
31
|
+
Catalan = SymbolicExpr("Catalan", False)
|
32
|
+
|
33
|
+
T = TypeVar("T", bound=CParam)
|
34
|
+
|
35
|
+
|
36
|
+
@overload
|
37
|
+
def symbolic_function(*args: Any, return_type: None = None) -> CParamScalar: ...
|
14
38
|
|
15
39
|
|
16
|
-
|
40
|
+
@overload
|
41
|
+
def symbolic_function(*args: Any, return_type: type[T]) -> T: ...
|
42
|
+
|
43
|
+
|
44
|
+
def symbolic_function(*args: Any, return_type: Optional[type[T]] = None) -> CParam:
|
45
|
+
qmodule = (
|
46
|
+
model_state_container.QMODULE
|
47
|
+
) # FIXME: https://classiq.atlassian.net/browse/CAD-15126
|
17
48
|
str_args = [str(x) for x in args]
|
18
|
-
|
49
|
+
expr = f"{sys._getframe(1).f_code.co_name}({','.join(str_args)})"
|
50
|
+
|
51
|
+
if return_type is None:
|
52
|
+
return CParamScalar(expr)
|
19
53
|
|
54
|
+
if TYPE_CHECKING:
|
55
|
+
assert return_type is not None
|
20
56
|
|
21
|
-
|
57
|
+
qmod_type = python_type_to_qmod(return_type, qmodule=qmodule)
|
58
|
+
if qmod_type is None:
|
59
|
+
raise ClassiqValueError(
|
60
|
+
f"Unsupported return type for symbolic function: {return_type}"
|
61
|
+
)
|
62
|
+
|
63
|
+
return create_param(
|
64
|
+
expr,
|
65
|
+
qmod_type,
|
66
|
+
qmodule,
|
67
|
+
)
|
68
|
+
|
69
|
+
|
70
|
+
def sin(x: SymbolicTypes) -> CParamScalar:
|
22
71
|
return symbolic_function(x)
|
23
72
|
|
24
73
|
|
25
|
-
def cos(x: SymbolicTypes) ->
|
74
|
+
def cos(x: SymbolicTypes) -> CParamScalar:
|
26
75
|
return symbolic_function(x)
|
27
76
|
|
28
77
|
|
29
|
-
def tan(x: SymbolicTypes) ->
|
78
|
+
def tan(x: SymbolicTypes) -> CParamScalar:
|
30
79
|
return symbolic_function(x)
|
31
80
|
|
32
81
|
|
33
|
-
def cot(x: SymbolicTypes) ->
|
82
|
+
def cot(x: SymbolicTypes) -> CParamScalar:
|
34
83
|
return symbolic_function(x)
|
35
84
|
|
36
85
|
|
37
|
-
def sec(x: SymbolicTypes) ->
|
86
|
+
def sec(x: SymbolicTypes) -> CParamScalar:
|
38
87
|
return symbolic_function(x)
|
39
88
|
|
40
89
|
|
41
|
-
def csc(x: SymbolicTypes) ->
|
90
|
+
def csc(x: SymbolicTypes) -> CParamScalar:
|
42
91
|
return symbolic_function(x)
|
43
92
|
|
44
93
|
|
45
|
-
def asin(x: SymbolicTypes) ->
|
94
|
+
def asin(x: SymbolicTypes) -> CParamScalar:
|
46
95
|
return symbolic_function(x)
|
47
96
|
|
48
97
|
|
49
|
-
def acos(x: SymbolicTypes) ->
|
98
|
+
def acos(x: SymbolicTypes) -> CParamScalar:
|
50
99
|
return symbolic_function(x)
|
51
100
|
|
52
101
|
|
53
|
-
def atan(x: SymbolicTypes) ->
|
102
|
+
def atan(x: SymbolicTypes) -> CParamScalar:
|
54
103
|
return symbolic_function(x)
|
55
104
|
|
56
105
|
|
57
|
-
def acot(x: SymbolicTypes) ->
|
106
|
+
def acot(x: SymbolicTypes) -> CParamScalar:
|
58
107
|
return symbolic_function(x)
|
59
108
|
|
60
109
|
|
61
|
-
def asec(x: SymbolicTypes) ->
|
110
|
+
def asec(x: SymbolicTypes) -> CParamScalar:
|
62
111
|
return symbolic_function(x)
|
63
112
|
|
64
113
|
|
65
|
-
def acsc(x: SymbolicTypes) ->
|
114
|
+
def acsc(x: SymbolicTypes) -> CParamScalar:
|
66
115
|
return symbolic_function(x)
|
67
116
|
|
68
117
|
|
69
|
-
def sinh(x: SymbolicTypes) ->
|
118
|
+
def sinh(x: SymbolicTypes) -> CParamScalar:
|
70
119
|
return symbolic_function(x)
|
71
120
|
|
72
121
|
|
73
|
-
def cosh(x: SymbolicTypes) ->
|
122
|
+
def cosh(x: SymbolicTypes) -> CParamScalar:
|
74
123
|
return symbolic_function(x)
|
75
124
|
|
76
125
|
|
77
|
-
def tanh(x: SymbolicTypes) ->
|
126
|
+
def tanh(x: SymbolicTypes) -> CParamScalar:
|
78
127
|
return symbolic_function(x)
|
79
128
|
|
80
129
|
|
81
|
-
def coth(x: SymbolicTypes) ->
|
130
|
+
def coth(x: SymbolicTypes) -> CParamScalar:
|
82
131
|
return symbolic_function(x)
|
83
132
|
|
84
133
|
|
85
|
-
def sech(x: SymbolicTypes) ->
|
134
|
+
def sech(x: SymbolicTypes) -> CParamScalar:
|
86
135
|
return symbolic_function(x)
|
87
136
|
|
88
137
|
|
89
|
-
def csch(x: SymbolicTypes) ->
|
138
|
+
def csch(x: SymbolicTypes) -> CParamScalar:
|
90
139
|
return symbolic_function(x)
|
91
140
|
|
92
141
|
|
93
|
-
def asinh(x: SymbolicTypes) ->
|
142
|
+
def asinh(x: SymbolicTypes) -> CParamScalar:
|
94
143
|
return symbolic_function(x)
|
95
144
|
|
96
145
|
|
97
|
-
def acosh(x: SymbolicTypes) ->
|
146
|
+
def acosh(x: SymbolicTypes) -> CParamScalar:
|
98
147
|
return symbolic_function(x)
|
99
148
|
|
100
149
|
|
101
|
-
def atanh(x: SymbolicTypes) ->
|
150
|
+
def atanh(x: SymbolicTypes) -> CParamScalar:
|
102
151
|
return symbolic_function(x)
|
103
152
|
|
104
153
|
|
105
|
-
def acoth(x: SymbolicTypes) ->
|
154
|
+
def acoth(x: SymbolicTypes) -> CParamScalar:
|
106
155
|
return symbolic_function(x)
|
107
156
|
|
108
157
|
|
109
|
-
def asech(x: SymbolicTypes) ->
|
158
|
+
def asech(x: SymbolicTypes) -> CParamScalar:
|
110
159
|
return symbolic_function(x)
|
111
160
|
|
112
161
|
|
113
|
-
def exp(x: SymbolicTypes) ->
|
162
|
+
def exp(x: SymbolicTypes) -> CParamScalar:
|
114
163
|
return symbolic_function(x)
|
115
164
|
|
116
165
|
|
117
|
-
def log(x: SymbolicTypes, base: SymbolicTypes = E) ->
|
166
|
+
def log(x: SymbolicTypes, base: SymbolicTypes = E) -> CParamScalar:
|
118
167
|
return symbolic_function(x, base)
|
119
168
|
|
120
169
|
|
121
|
-
def ln(x: SymbolicTypes) ->
|
170
|
+
def ln(x: SymbolicTypes) -> CParamScalar:
|
122
171
|
return symbolic_function(x)
|
123
172
|
|
124
173
|
|
125
|
-
def sqrt(x: SymbolicTypes) ->
|
174
|
+
def sqrt(x: SymbolicTypes) -> CParamScalar:
|
126
175
|
return symbolic_function(x)
|
127
176
|
|
128
177
|
|
129
|
-
def abs(x: SymbolicTypes) ->
|
178
|
+
def abs(x: SymbolicTypes) -> CParamScalar:
|
130
179
|
return symbolic_function(x)
|
131
180
|
|
132
181
|
|
133
|
-
def floor(x: SymbolicTypes) ->
|
182
|
+
def floor(x: SymbolicTypes) -> CParamScalar:
|
134
183
|
return symbolic_function(x)
|
135
184
|
|
136
185
|
|
137
|
-
def ceiling(x: SymbolicTypes) ->
|
186
|
+
def ceiling(x: SymbolicTypes) -> CParamScalar:
|
138
187
|
return symbolic_function(x)
|
139
188
|
|
140
189
|
|
141
|
-
def erf(x: SymbolicTypes) ->
|
190
|
+
def erf(x: SymbolicTypes) -> CParamScalar:
|
142
191
|
return symbolic_function(x)
|
143
192
|
|
144
193
|
|
145
|
-
def erfc(x: SymbolicTypes) ->
|
194
|
+
def erfc(x: SymbolicTypes) -> CParamScalar:
|
146
195
|
return symbolic_function(x)
|
147
196
|
|
148
197
|
|
149
|
-
def gamma(x: SymbolicTypes) ->
|
198
|
+
def gamma(x: SymbolicTypes) -> CParamScalar:
|
150
199
|
return symbolic_function(x)
|
151
200
|
|
152
201
|
|
153
|
-
def beta(x: SymbolicTypes) ->
|
202
|
+
def beta(x: SymbolicTypes) -> CParamScalar:
|
154
203
|
return symbolic_function(x)
|
155
204
|
|
156
205
|
|
157
|
-
def besselj(x: SymbolicTypes) ->
|
206
|
+
def besselj(x: SymbolicTypes) -> CParamScalar:
|
158
207
|
return symbolic_function(x)
|
159
208
|
|
160
209
|
|
161
|
-
def bessely(x: SymbolicTypes) ->
|
210
|
+
def bessely(x: SymbolicTypes) -> CParamScalar:
|
162
211
|
return symbolic_function(x)
|
163
212
|
|
164
213
|
|
165
|
-
def besseli(x: SymbolicTypes) ->
|
214
|
+
def besseli(x: SymbolicTypes) -> CParamScalar:
|
166
215
|
return symbolic_function(x)
|
167
216
|
|
168
217
|
|
169
|
-
def besselk(x: SymbolicTypes) ->
|
218
|
+
def besselk(x: SymbolicTypes) -> CParamScalar:
|
170
219
|
return symbolic_function(x)
|
171
220
|
|
172
221
|
|
173
|
-
def dirichlet_eta(x: SymbolicTypes) ->
|
222
|
+
def dirichlet_eta(x: SymbolicTypes) -> CParamScalar:
|
174
223
|
return symbolic_function(x)
|
175
224
|
|
176
225
|
|
177
|
-
def polygamma(x: SymbolicTypes) ->
|
226
|
+
def polygamma(x: SymbolicTypes) -> CParamScalar:
|
178
227
|
return symbolic_function(x)
|
179
228
|
|
180
229
|
|
181
|
-
def loggamma(x: SymbolicTypes) ->
|
230
|
+
def loggamma(x: SymbolicTypes) -> CParamScalar:
|
182
231
|
return symbolic_function(x)
|
183
232
|
|
184
233
|
|
185
|
-
def factorial(x: SymbolicTypes) ->
|
234
|
+
def factorial(x: SymbolicTypes) -> CParamScalar:
|
186
235
|
return symbolic_function(x)
|
187
236
|
|
188
237
|
|
189
|
-
def binomial(x: SymbolicTypes) ->
|
238
|
+
def binomial(x: SymbolicTypes) -> CParamScalar:
|
190
239
|
return symbolic_function(x)
|
191
240
|
|
192
241
|
|
193
|
-
def subfactorial(x: SymbolicTypes) ->
|
242
|
+
def subfactorial(x: SymbolicTypes) -> CParamScalar:
|
194
243
|
return symbolic_function(x)
|
195
244
|
|
196
245
|
|
197
|
-
def primorial(x: SymbolicTypes) ->
|
246
|
+
def primorial(x: SymbolicTypes) -> CParamScalar:
|
198
247
|
return symbolic_function(x)
|
199
248
|
|
200
249
|
|
201
|
-
def bell(x: SymbolicTypes) ->
|
250
|
+
def bell(x: SymbolicTypes) -> CParamScalar:
|
202
251
|
return symbolic_function(x)
|
203
252
|
|
204
253
|
|
205
|
-
def bernoulli(x: SymbolicTypes) ->
|
254
|
+
def bernoulli(x: SymbolicTypes) -> CParamScalar:
|
206
255
|
return symbolic_function(x)
|
207
256
|
|
208
257
|
|
209
|
-
def euler(x: SymbolicTypes) ->
|
258
|
+
def euler(x: SymbolicTypes) -> CParamScalar:
|
210
259
|
return symbolic_function(x)
|
211
260
|
|
212
261
|
|
213
|
-
def catalan(x: SymbolicTypes) ->
|
262
|
+
def catalan(x: SymbolicTypes) -> CParamScalar:
|
214
263
|
return symbolic_function(x)
|
215
264
|
|
216
265
|
|
217
|
-
def Piecewise(*args:
|
266
|
+
def Piecewise(*args: tuple[SymbolicTypes, SymbolicTypes]) -> CParamScalar: # noqa: N802
|
218
267
|
return symbolic_function(*args)
|
219
268
|
|
220
269
|
|
221
|
-
def max(x: SymbolicTypes, y: SymbolicTypes) ->
|
270
|
+
def max(x: SymbolicTypes, y: SymbolicTypes) -> CParamScalar:
|
222
271
|
return symbolic_function(x, y)
|
223
272
|
|
224
273
|
|
225
|
-
def min(x: SymbolicTypes, y: SymbolicTypes) ->
|
274
|
+
def min(x: SymbolicTypes, y: SymbolicTypes) -> CParamScalar:
|
226
275
|
return symbolic_function(x, y)
|
227
276
|
|
228
277
|
|
@@ -238,70 +287,88 @@ def logical_not(x: SymbolicTypes) -> SymbolicExpr:
|
|
238
287
|
return SymbolicExpr._unary_op(x, "not")
|
239
288
|
|
240
289
|
|
290
|
+
def mod_inverse(a: SymbolicTypes, m: SymbolicTypes) -> CParamScalar:
|
291
|
+
return symbolic_function(a, m)
|
292
|
+
|
293
|
+
|
294
|
+
def sum(arr: SymbolicTypes) -> CParamScalar:
|
295
|
+
return symbolic_function(arr)
|
296
|
+
|
297
|
+
|
298
|
+
def subscript(
|
299
|
+
amplitudes: Union[list[float], list[CReal], list[CParamScalar], CArray[CReal]],
|
300
|
+
index: QNum,
|
301
|
+
) -> CParamScalar:
|
302
|
+
return CParamScalar(expr=f"{amplitudes}[{index}]")
|
303
|
+
|
304
|
+
|
241
305
|
__all__ = [
|
242
|
-
"
|
306
|
+
"Catalan",
|
243
307
|
"E",
|
244
|
-
"I",
|
245
|
-
"GoldenRatio",
|
246
308
|
"EulerGamma",
|
247
|
-
"
|
248
|
-
"
|
249
|
-
"
|
250
|
-
"
|
251
|
-
"cot",
|
252
|
-
"sec",
|
253
|
-
"csc",
|
254
|
-
"asin",
|
309
|
+
"GoldenRatio",
|
310
|
+
"I",
|
311
|
+
"Piecewise",
|
312
|
+
"abs",
|
255
313
|
"acos",
|
256
|
-
"
|
314
|
+
"acosh",
|
257
315
|
"acot",
|
258
|
-
"
|
316
|
+
"acoth",
|
259
317
|
"acsc",
|
260
|
-
"
|
261
|
-
"
|
262
|
-
"
|
263
|
-
"coth",
|
264
|
-
"sech",
|
265
|
-
"csch",
|
318
|
+
"asec",
|
319
|
+
"asech",
|
320
|
+
"asin",
|
266
321
|
"asinh",
|
267
|
-
"
|
322
|
+
"atan",
|
268
323
|
"atanh",
|
269
|
-
"
|
270
|
-
"
|
271
|
-
"
|
272
|
-
"
|
273
|
-
"
|
274
|
-
"
|
275
|
-
"
|
276
|
-
"
|
324
|
+
"bell",
|
325
|
+
"bernoulli",
|
326
|
+
"besseli",
|
327
|
+
"besselj",
|
328
|
+
"besselk",
|
329
|
+
"bessely",
|
330
|
+
"beta",
|
331
|
+
"binomial",
|
332
|
+
"catalan",
|
277
333
|
"ceiling",
|
334
|
+
"cos",
|
335
|
+
"cosh",
|
336
|
+
"cot",
|
337
|
+
"coth",
|
338
|
+
"csc",
|
339
|
+
"csch",
|
340
|
+
"dirichlet_eta",
|
278
341
|
"erf",
|
279
342
|
"erfc",
|
343
|
+
"euler",
|
344
|
+
"exp",
|
345
|
+
"factorial",
|
346
|
+
"floor",
|
280
347
|
"gamma",
|
281
|
-
"
|
282
|
-
"
|
283
|
-
"bessely",
|
284
|
-
"besseli",
|
285
|
-
"besselk",
|
286
|
-
"dirichlet_eta",
|
287
|
-
"polygamma",
|
348
|
+
"ln",
|
349
|
+
"log",
|
288
350
|
"loggamma",
|
289
|
-
"factorial",
|
290
|
-
"binomial",
|
291
|
-
"subfactorial",
|
292
|
-
"primorial",
|
293
|
-
"bell",
|
294
|
-
"bernoulli",
|
295
|
-
"euler",
|
296
|
-
"catalan",
|
297
|
-
"Piecewise",
|
298
|
-
"max",
|
299
|
-
"min",
|
300
351
|
"logical_and",
|
301
|
-
"logical_or",
|
302
352
|
"logical_not",
|
353
|
+
"logical_or",
|
354
|
+
"max",
|
355
|
+
"min",
|
356
|
+
"mod_inverse",
|
357
|
+
"pi",
|
358
|
+
"polygamma",
|
359
|
+
"primorial",
|
360
|
+
"sec",
|
361
|
+
"sech",
|
362
|
+
"sin",
|
363
|
+
"sinh",
|
364
|
+
"sqrt",
|
365
|
+
"subfactorial",
|
366
|
+
"subscript",
|
367
|
+
"sum",
|
368
|
+
"tan",
|
369
|
+
"tanh",
|
303
370
|
]
|
304
371
|
|
305
372
|
|
306
|
-
def __dir__():
|
373
|
+
def __dir__() -> list[str]:
|
307
374
|
return __all__
|
classiq/qmod/symbolic_expr.py
CHANGED
@@ -1,42 +1,66 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
|
+
import ast
|
4
|
+
from enum import Enum as PythonEnum
|
3
5
|
from typing import Any
|
4
6
|
|
7
|
+
from classiq.qmod.utilities import qmod_val_to_expr_str
|
8
|
+
|
5
9
|
|
6
10
|
class Symbolic:
|
7
|
-
def __init__(self, expr: str) -> None:
|
11
|
+
def __init__(self, expr: str, is_quantum: bool) -> None:
|
8
12
|
self._expr = expr
|
13
|
+
self.is_quantum = is_quantum
|
9
14
|
|
10
15
|
def __str__(self) -> str:
|
11
16
|
return self._expr
|
12
17
|
|
13
18
|
def __repr__(self) -> str:
|
14
|
-
return self.
|
19
|
+
return self.__str__()
|
20
|
+
|
21
|
+
def __bool__(self) -> bool:
|
22
|
+
try:
|
23
|
+
return bool(ast.literal_eval(self._expr))
|
24
|
+
except ValueError:
|
25
|
+
raise TypeError(
|
26
|
+
f"Symbolic expression {self._expr!r} cannot be converted to bool"
|
27
|
+
) from None
|
15
28
|
|
16
29
|
|
17
30
|
class SymbolicExpr(Symbolic):
|
18
|
-
def __init__(self, expr: str) -> None:
|
19
|
-
super().__init__(expr)
|
31
|
+
def __init__(self, expr: str, is_quantum: bool) -> None:
|
32
|
+
super().__init__(expr, is_quantum)
|
20
33
|
|
21
34
|
@staticmethod
|
22
35
|
def _binary_op(lhs: Any, rhs: Any, op: str) -> SymbolicExpr:
|
23
|
-
if not isinstance(lhs, (SymbolicExpr, int, float, bool)):
|
36
|
+
if not isinstance(lhs, (SymbolicExpr, int, float, bool, PythonEnum)):
|
24
37
|
raise TypeError(f"Invalid lhs argument {lhs!r} for binary operation {op!r}")
|
25
38
|
|
26
|
-
if not isinstance(rhs, (SymbolicExpr, int, float, bool)):
|
39
|
+
if not isinstance(rhs, (SymbolicExpr, int, float, bool, PythonEnum)):
|
27
40
|
raise TypeError(f"Invalid lhs argument {rhs!r} for binary operation {op!r}")
|
28
41
|
|
29
|
-
lhs_str =
|
30
|
-
|
42
|
+
lhs_str = qmod_val_to_expr_str(lhs)
|
43
|
+
if not isinstance(lhs, (int, float, bool, PythonEnum)):
|
44
|
+
lhs_str = f"({lhs_str})"
|
45
|
+
rhs_str = qmod_val_to_expr_str(rhs)
|
46
|
+
if not isinstance(rhs, (int, float, bool, PythonEnum)):
|
47
|
+
rhs_str = f"({rhs_str})"
|
31
48
|
|
32
|
-
|
49
|
+
lhs_is_quantum = isinstance(lhs, SymbolicExpr) and lhs.is_quantum
|
50
|
+
rhs_is_quantum = isinstance(rhs, SymbolicExpr) and rhs.is_quantum
|
51
|
+
|
52
|
+
return SymbolicExpr(
|
53
|
+
f"{lhs_str} {op} {rhs_str}", lhs_is_quantum or rhs_is_quantum
|
54
|
+
)
|
33
55
|
|
34
56
|
@staticmethod
|
35
57
|
def _unary_op(arg: Any, op: str) -> SymbolicExpr:
|
36
58
|
if not isinstance(arg, (SymbolicExpr, int, float, bool)):
|
37
59
|
raise TypeError(f"Invalid argument {arg!r} for unary operation {op!r}")
|
38
60
|
|
39
|
-
|
61
|
+
arg_is_quantum = isinstance(arg, SymbolicExpr) and arg.is_quantum
|
62
|
+
|
63
|
+
return SymbolicExpr(f"{op}({arg})", arg_is_quantum)
|
40
64
|
|
41
65
|
def __add__(self, other: Any) -> SymbolicExpr:
|
42
66
|
return SymbolicExpr._binary_op(self, other, "+")
|
@@ -143,7 +167,7 @@ class SymbolicExpr(Symbolic):
|
|
143
167
|
|
144
168
|
class SymbolicEquality(SymbolicExpr):
|
145
169
|
def __init__(self, lhs: Any, rhs: Any) -> None:
|
146
|
-
|
147
|
-
super().__init__(
|
170
|
+
sym_expr = SymbolicExpr._binary_op(lhs, rhs, "==")
|
171
|
+
super().__init__(sym_expr._expr, sym_expr.is_quantum)
|
148
172
|
self.lhs = lhs
|
149
173
|
self.rhs = rhs
|