classiq 0.38.0__py3-none-any.whl → 0.65.4__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 +47 -32
- classiq/_analyzer_extras/_ipywidgets_async_extension.py +2 -1
- classiq/_internals/api_wrapper.py +235 -97
- classiq/_internals/async_utils.py +1 -3
- classiq/_internals/authentication/auth0.py +26 -10
- classiq/_internals/authentication/authentication.py +11 -0
- classiq/_internals/authentication/device.py +10 -5
- classiq/_internals/authentication/password_manager.py +18 -6
- classiq/_internals/authentication/token_manager.py +10 -5
- classiq/_internals/client.py +94 -33
- classiq/_internals/config.py +3 -4
- classiq/_internals/host_checker.py +38 -15
- classiq/_internals/jobs.py +60 -57
- classiq/_internals/type_validation.py +9 -9
- classiq/analyzer/__init__.py +1 -3
- classiq/analyzer/analyzer.py +24 -19
- classiq/analyzer/analyzer_utilities.py +10 -10
- classiq/analyzer/rb.py +15 -15
- classiq/analyzer/show_interactive_hack.py +27 -4
- 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 +165 -158
- classiq/applications/chemistry/ground_state_problem.py +1 -1
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/allowed_constraints.py +4 -1
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/arithmetic/arithmetic_expression.py +1 -1
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/arithmetic/isolation.py +1 -1
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/combinatorial_problem_utils.py +51 -15
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/encoding_mapping.py +12 -12
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/encoding_utils.py +8 -6
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/memory.py +7 -11
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/optimization_model.py +67 -40
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_utils.py +46 -0
- classiq/applications/combinatorial_helpers/pyomo_utils.py +447 -0
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/sympy_utils.py +2 -2
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/transformations/encoding.py +15 -20
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/transformations/fixed_variables.py +14 -15
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/transformations/ising_converter.py +11 -15
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/transformations/penalty.py +1 -2
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/transformations/penalty_support.py +3 -7
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/transformations/sign_seperation.py +2 -3
- classiq/{applications_model_constructors → applications}/combinatorial_helpers/transformations/slack_variables.py +5 -8
- classiq/applications/combinatorial_optimization/__init__.py +20 -6
- classiq/applications/combinatorial_optimization/combinatorial_optimization_config.py +2 -2
- classiq/{applications_model_constructors → applications/combinatorial_optimization}/combinatorial_optimization_model_constructor.py +35 -33
- 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 +48 -42
- classiq/applications/grover/__init__.py +9 -0
- classiq/{applications_model_constructors → applications/grover}/grover_model_constructor.py +52 -51
- classiq/applications/hamiltonian/pauli_decomposition.py +113 -0
- classiq/applications/libraries/qmci_library.py +22 -0
- classiq/applications/qnn/__init__.py +2 -4
- classiq/applications/qnn/circuit_utils.py +6 -6
- 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 +1 -1
- 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 +5 -5
- classiq/applications/qsvm/__init__.py +6 -4
- classiq/applications/qsvm/qsvm.py +3 -6
- classiq/applications/qsvm/qsvm_data_generation.py +3 -3
- 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 +20 -115
- classiq/interface/_version.py +1 -1
- classiq/interface/analyzer/analysis_params.py +43 -13
- classiq/interface/analyzer/cytoscape_graph.py +15 -9
- classiq/interface/analyzer/result.py +28 -32
- classiq/interface/applications/qsvm.py +20 -29
- classiq/interface/ast_node.py +16 -0
- classiq/interface/backend/backend_preferences.py +390 -121
- classiq/interface/backend/ionq/ionq_quantum_program.py +15 -23
- classiq/interface/backend/pydantic_backend.py +25 -22
- classiq/interface/backend/quantum_backend_providers.py +69 -16
- classiq/interface/chemistry/fermionic_operator.py +30 -21
- classiq/interface/chemistry/ground_state_problem.py +28 -25
- classiq/interface/chemistry/molecule.py +14 -10
- classiq/interface/chemistry/operator.py +64 -231
- classiq/interface/combinatorial_optimization/encoding_types.py +1 -1
- classiq/interface/combinatorial_optimization/examples/ascending_sequence.py +1 -3
- 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/mht.py +10 -6
- classiq/interface/combinatorial_optimization/examples/portfolio_variations.py +2 -2
- classiq/interface/combinatorial_optimization/examples/set_cover.py +1 -2
- classiq/interface/combinatorial_optimization/mht_qaoa_input.py +8 -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/debug_info.py +86 -0
- classiq/{exceptions.py → interface/exceptions.py} +37 -9
- 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/execution_preferences.py +26 -114
- classiq/interface/executor/execution_request.py +24 -46
- classiq/interface/executor/execution_result.py +30 -8
- classiq/interface/executor/iqae_result.py +4 -6
- classiq/interface/executor/optimizer_preferences.py +17 -14
- classiq/interface/executor/quantum_code.py +28 -24
- classiq/interface/executor/quantum_instruction_set.py +2 -2
- classiq/interface/executor/register_initialization.py +11 -14
- classiq/interface/executor/result.py +83 -56
- classiq/interface/executor/vqe_result.py +10 -10
- classiq/interface/finance/function_input.py +35 -25
- classiq/interface/finance/gaussian_model_input.py +5 -5
- classiq/interface/finance/log_normal_model_input.py +4 -4
- classiq/interface/finance/model_input.py +4 -4
- classiq/interface/generator/adjacency.py +1 -3
- classiq/interface/generator/amplitude_loading.py +22 -12
- classiq/interface/generator/ansatz_library.py +5 -5
- classiq/interface/generator/application_apis/arithmetic_declarations.py +8 -5
- 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 +46 -5
- classiq/interface/generator/arith/arithmetic.py +35 -16
- classiq/interface/generator/arith/arithmetic_arg_type_validator.py +6 -7
- classiq/interface/generator/arith/arithmetic_expression_abc.py +66 -25
- classiq/interface/generator/arith/arithmetic_expression_parser.py +11 -11
- classiq/interface/generator/arith/arithmetic_expression_validator.py +47 -43
- classiq/interface/generator/arith/arithmetic_operations.py +14 -6
- 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 +3 -2
- classiq/interface/generator/arith/binary_ops.py +218 -130
- classiq/interface/generator/arith/endianness.py +1 -1
- classiq/interface/generator/arith/extremum_operations.py +96 -25
- classiq/interface/generator/arith/logical_ops.py +14 -12
- classiq/interface/generator/arith/number_utils.py +12 -6
- classiq/interface/generator/arith/register_user_input.py +60 -37
- classiq/interface/generator/arith/unary_ops.py +49 -29
- 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 +3 -3
- 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 +7 -7
- classiq/interface/generator/compiler_keywords.py +5 -1
- classiq/interface/generator/complex_type.py +13 -18
- classiq/interface/generator/constant.py +3 -4
- classiq/interface/generator/control_state.py +34 -29
- 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 +21 -5
- 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 +5 -5
- classiq/interface/generator/expressions/expression.py +26 -14
- 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 +34 -8
- 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 +19 -11
- classiq/interface/generator/finance.py +2 -2
- 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 +36 -64
- classiq/interface/generator/functions/__init__.py +0 -22
- 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 +153 -20
- classiq/interface/generator/grover_diffuser.py +32 -25
- classiq/interface/generator/grover_operator.py +34 -25
- 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 +9 -9
- classiq/interface/generator/hardware/hardware_data.py +72 -34
- classiq/interface/generator/hardware_efficient_ansatz.py +20 -16
- classiq/interface/generator/hartree_fock.py +13 -5
- classiq/interface/generator/identity.py +10 -6
- classiq/interface/generator/linear_pauli_rotations.py +32 -20
- classiq/interface/generator/mcmt_method.py +1 -1
- classiq/interface/generator/mcu.py +17 -15
- classiq/interface/generator/mcx.py +24 -17
- classiq/interface/generator/model/__init__.py +2 -5
- classiq/interface/generator/model/constraints.py +26 -8
- classiq/interface/generator/model/model.py +27 -190
- classiq/interface/generator/model/preferences/preferences.py +115 -41
- classiq/{quantum_register.py → interface/generator/model/quantum_register.py} +14 -17
- classiq/interface/generator/oracles/arithmetic_oracle.py +2 -4
- classiq/interface/generator/oracles/custom_oracle.py +15 -13
- classiq/interface/generator/oracles/oracle_abc.py +7 -7
- 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 +41 -30
- classiq/interface/generator/qsvm.py +9 -10
- classiq/interface/generator/quantum_function_call.py +88 -73
- classiq/interface/generator/quantum_program.py +41 -24
- classiq/interface/generator/range_types.py +11 -12
- classiq/interface/generator/register_role.py +18 -6
- classiq/interface/generator/slice_parsing_utils.py +5 -5
- classiq/interface/generator/standard_gates/controlled_standard_gates.py +30 -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 +4 -7
- classiq/interface/generator/state_preparation/state_preparation.py +25 -20
- 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 +7 -11
- classiq/interface/generator/ucc.py +5 -4
- classiq/interface/generator/unitary_gate.py +5 -5
- classiq/interface/generator/user_defined_function_params.py +4 -1
- classiq/interface/generator/validations/flow_graph.py +7 -7
- classiq/interface/generator/validations/validator_functions.py +4 -4
- classiq/interface/generator/visitor.py +23 -16
- classiq/interface/hardware.py +29 -8
- classiq/interface/helpers/classproperty.py +8 -0
- classiq/interface/helpers/custom_encoders.py +2 -2
- 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 -5
- classiq/interface/helpers/validation_helpers.py +3 -20
- classiq/interface/helpers/versioned_model.py +1 -4
- 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 +29 -69
- classiq/interface/model/allocate.py +16 -0
- classiq/interface/model/bind_operation.py +32 -9
- 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 +29 -24
- classiq/interface/model/invert.py +12 -0
- classiq/interface/model/model.py +69 -61
- classiq/interface/model/native_function_definition.py +17 -20
- 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 +30 -18
- 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 +141 -343
- classiq/interface/model/quantum_function_declaration.py +190 -157
- classiq/interface/model/quantum_lambda_function.py +33 -32
- classiq/interface/model/quantum_statement.py +71 -12
- classiq/interface/model/quantum_type.py +177 -40
- classiq/interface/model/quantum_variable_declaration.py +3 -25
- classiq/interface/model/repeat.py +15 -0
- classiq/interface/model/statement_block.py +40 -14
- classiq/interface/model/validation_handle.py +13 -6
- classiq/interface/model/variable_declaration_statement.py +3 -1
- classiq/interface/model/within_apply_operation.py +7 -5
- classiq/interface/server/global_versions.py +6 -7
- classiq/interface/server/routes.py +17 -21
- classiq/interface/source_reference.py +59 -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 +10 -10
- classiq/qmod/builtins/__init__.py +19 -2
- classiq/qmod/builtins/classical_execution_primitives.py +36 -14
- classiq/qmod/builtins/classical_functions.py +39 -43
- 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 +373 -40
- classiq/qmod/builtins/structs.py +103 -80
- classiq/qmod/cfunc.py +2 -2
- classiq/qmod/classical_function.py +4 -8
- classiq/qmod/cparam.py +64 -0
- classiq/qmod/create_model_function.py +56 -0
- classiq/qmod/declaration_inferrer.py +143 -101
- classiq/qmod/expression_query.py +20 -4
- classiq/qmod/generative.py +42 -0
- classiq/qmod/model_state_container.py +18 -6
- classiq/qmod/native/__init__.py +7 -0
- classiq/qmod/native/expression_to_qmod.py +16 -11
- classiq/qmod/native/pretty_printer.py +187 -97
- 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 +60 -8
- classiq/qmod/qmod_constant.py +93 -26
- classiq/qmod/qmod_parameter.py +68 -59
- classiq/qmod/qmod_variable.py +468 -155
- classiq/qmod/quantum_callable.py +17 -7
- classiq/qmod/quantum_expandable.py +269 -96
- classiq/qmod/quantum_function.py +196 -41
- 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 +147 -123
- classiq/qmod/symbolic_expr.py +27 -12
- classiq/qmod/symbolic_type.py +2 -5
- classiq/qmod/type_attribute_remover.py +32 -0
- classiq/qmod/utilities.py +98 -4
- classiq/qmod/write_qmod.py +17 -3
- classiq/synthesis.py +210 -22
- {classiq-0.38.0.dist-info → classiq-0.65.4.dist-info}/METADATA +16 -9
- classiq-0.65.4.dist-info/RECORD +521 -0
- classiq/_internals/_qfunc_ext.py +0 -6
- classiq/applications/benchmarking/__init__.py +0 -9
- classiq/applications/benchmarking/mirror_benchmarking.py +0 -70
- classiq/applications/numpy_utils.py +0 -37
- classiq/applications_model_constructors/__init__.py +0 -25
- classiq/applications_model_constructors/combinatorial_helpers/multiple_comp_basis_sp.py +0 -34
- classiq/applications_model_constructors/combinatorial_helpers/pauli_helpers/pauli_utils.py +0 -65
- classiq/applications_model_constructors/combinatorial_helpers/pyomo_utils.py +0 -243
- classiq/applications_model_constructors/libraries/ampltitude_estimation_library.py +0 -11
- classiq/applications_model_constructors/libraries/qmci_library.py +0 -107
- 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/interface/executor/aws_execution_cost.py +0 -73
- classiq/interface/executor/error_mitigation.py +0 -6
- classiq/interface/generator/credit_risk_example/linear_gci.py +0 -122
- classiq/interface/generator/credit_risk_example/weighted_adder.py +0 -69
- 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/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 -1229
- classiq/interface/generator/functions/core_lib_declarations/quantum_operators.py +0 -95
- classiq/interface/generator/functions/foreign_function_definition.py +0 -114
- classiq/interface/generator/functions/function_implementation.py +0 -107
- classiq/interface/generator/functions/native_function_definition.py +0 -155
- classiq/interface/generator/functions/quantum_function_declaration.py +0 -69
- classiq/interface/generator/functions/register.py +0 -44
- classiq/interface/generator/functions/register_mapping_data.py +0 -106
- 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 -74
- classiq/interface/generator/types/builtin_struct_declarations/__init__.py +0 -1
- classiq/interface/generator/types/builtin_struct_declarations/pauli_struct_declarations.py +0 -22
- classiq/interface/ide/show.py +0 -34
- classiq/interface/model/call_synthesis_data.py +0 -68
- classiq/interface/model/common_model_types.py +0 -23
- classiq/interface/model/quantum_expressions/control_state.py +0 -38
- classiq/interface/model/quantum_if_operation.py +0 -94
- 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 -156
- 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 -462
- classiq/model/logic_flow.py +0 -149
- classiq/model/logic_flow_change_handler.py +0 -71
- classiq/model/model.py +0 -229
- classiq/qmod/builtins/functions.py +0 -913
- classiq/qmod/qmod_struct.py +0 -37
- classiq/quantum_functions/__init__.py +0 -17
- classiq/quantum_functions/annotation_parser.py +0 -205
- 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.38.0.dist-info/RECORD +0 -454
- /classiq/{applications_model_constructors → applications}/combinatorial_helpers/__init__.py +0 -0
- /classiq/{applications_model_constructors → applications}/combinatorial_helpers/arithmetic/__init__.py +0 -0
- /classiq/{applications_model_constructors → applications}/combinatorial_helpers/pauli_helpers/__init__.py +0 -0
- /classiq/{applications_model_constructors → applications}/combinatorial_helpers/pauli_helpers/pauli_sparsing.py +0 -0
- /classiq/{applications_model_constructors → applications}/combinatorial_helpers/py.typed +0 -0
- /classiq/{applications_model_constructors/combinatorial_helpers/transformations → applications/combinatorial_helpers/solvers}/__init__.py +0 -0
- /classiq/{applications_model_constructors/libraries → applications/combinatorial_helpers/transformations}/__init__.py +0 -0
- /classiq/{interface/generator/credit_risk_example → applications/hamiltonian}/__init__.py +0 -0
- /classiq/{interface/generator/functions/core_lib_declarations → applications/libraries}/__init__.py +0 -0
- /classiq/interface/{model/resolvers → debug_info}/__init__.py +0 -0
- /classiq/{_internals → interface}/enum_utils.py +0 -0
- /classiq/interface/{model/validations → generator/functions/builtins}/__init__.py +0 -0
- /classiq/{interface/generator/functions/core_lib_declarations/quantum_functions/chemistry_functions.py → model_expansions/__init__.py} +0 -0
- {classiq-0.38.0.dist-info → classiq-0.65.4.dist-info}/WHEEL +0 -0
@@ -1,41 +1,35 @@
|
|
1
1
|
import ast
|
2
2
|
import itertools
|
3
3
|
import re
|
4
|
+
from collections.abc import Collection, Iterable, Mapping
|
4
5
|
from typing import (
|
6
|
+
Annotated,
|
5
7
|
Any,
|
6
|
-
Collection,
|
7
|
-
Dict,
|
8
|
-
Iterable,
|
9
|
-
List,
|
10
|
-
Mapping,
|
11
8
|
Optional,
|
12
|
-
Set,
|
13
|
-
Type,
|
14
9
|
Union,
|
15
10
|
get_args,
|
16
11
|
)
|
17
12
|
|
18
13
|
import pydantic
|
19
14
|
import sympy
|
20
|
-
from pydantic
|
15
|
+
from pydantic import BeforeValidator, ConfigDict
|
21
16
|
|
17
|
+
from classiq.interface.enum_utils import StrEnum
|
18
|
+
from classiq.interface.exceptions import ClassiqValueError
|
22
19
|
from classiq.interface.generator.arith.arithmetic_expression_validator import (
|
23
20
|
validate_expression,
|
24
21
|
)
|
25
22
|
from classiq.interface.generator.arith.register_user_input import RegisterArithmeticInfo
|
26
|
-
from classiq.interface.generator.
|
23
|
+
from classiq.interface.generator.parameters import ParameterFloatType
|
27
24
|
from classiq.interface.helpers.custom_pydantic_types import PydanticNonEmptyString
|
28
25
|
from classiq.interface.helpers.hashable_pydantic_base_model import (
|
29
26
|
HashablePydanticBaseModel,
|
30
27
|
)
|
31
28
|
|
32
|
-
from classiq._internals.enum_utils import StrEnum
|
33
|
-
from classiq.exceptions import ClassiqValueError
|
34
|
-
|
35
29
|
FunctionParamsDiscriminator = str
|
36
30
|
|
37
31
|
IOName = PydanticNonEmptyString
|
38
|
-
ArithmeticIODict =
|
32
|
+
ArithmeticIODict = dict[IOName, RegisterArithmeticInfo]
|
39
33
|
|
40
34
|
DEFAULT_ZERO_NAME = "zero"
|
41
35
|
DEFAULT_OUTPUT_NAME = "OUT"
|
@@ -112,11 +106,9 @@ GenerationExpressionSupportedNodeTypes = Union[
|
|
112
106
|
ExecutionExpressionSupportedNodeTypes, GenerationOnlyExpressionSupportedNodeTypes
|
113
107
|
]
|
114
108
|
|
115
|
-
GenerationExpressionSupportedAttrSymbols = set(BUILTIN_ENUMS.keys())
|
116
|
-
|
117
109
|
|
118
110
|
def validate_expression_str(
|
119
|
-
expr_str: str, supported_functions: Optional[
|
111
|
+
expr_str: str, supported_functions: Optional[set[str]] = None
|
120
112
|
) -> None:
|
121
113
|
# By default, no functions are allowed.
|
122
114
|
supported_functions = supported_functions or set()
|
@@ -127,10 +119,25 @@ def validate_expression_str(
|
|
127
119
|
supported_nodes=get_args(GenerationExpressionSupportedNodeTypes),
|
128
120
|
expression_type="parameter",
|
129
121
|
supported_functions=supported_functions,
|
130
|
-
supported_attr_values=GenerationExpressionSupportedAttrSymbols,
|
131
122
|
)
|
132
123
|
|
133
124
|
|
125
|
+
def validate_parameters(value: Any) -> Any:
|
126
|
+
if isinstance(value, str):
|
127
|
+
validate_expression_str(value)
|
128
|
+
elif isinstance(value, sympy.Expr):
|
129
|
+
return str(value)
|
130
|
+
try:
|
131
|
+
return float(value)
|
132
|
+
except ValueError:
|
133
|
+
return value
|
134
|
+
|
135
|
+
|
136
|
+
FunctionParamsNumericParameter = Annotated[
|
137
|
+
ParameterFloatType, BeforeValidator(validate_parameters)
|
138
|
+
]
|
139
|
+
|
140
|
+
|
134
141
|
class PortDirection(StrEnum):
|
135
142
|
Input = "input"
|
136
143
|
Output = "output"
|
@@ -176,11 +183,11 @@ class FunctionParams(HashablePydanticBaseModel):
|
|
176
183
|
return sum(reg.size for reg in self.outputs.values())
|
177
184
|
|
178
185
|
@property
|
179
|
-
def _input_names(self) ->
|
186
|
+
def _input_names(self) -> list[IOName]:
|
180
187
|
return list(self._inputs.keys())
|
181
188
|
|
182
189
|
@property
|
183
|
-
def _output_names(self) ->
|
190
|
+
def _output_names(self) -> list[IOName]:
|
184
191
|
return list(self._outputs.keys())
|
185
192
|
|
186
193
|
def _create_zero_input_registers(self, names_and_sizes: Mapping[str, int]) -> None:
|
@@ -202,20 +209,6 @@ class FunctionParams(HashablePydanticBaseModel):
|
|
202
209
|
if self.discriminator() not in _UNVALIDATED_FUNCTIONS:
|
203
210
|
self._validate_total_io_sizes()
|
204
211
|
|
205
|
-
def is_field_param_type(self, name: str, param_type_signature: str) -> bool:
|
206
|
-
f = type(self).__fields__[name]
|
207
|
-
return isinstance(f, ModelField) and (
|
208
|
-
param_type_signature in f.field_info.extra
|
209
|
-
)
|
210
|
-
|
211
|
-
def is_field_gen_param(self, name: str) -> bool:
|
212
|
-
return self.is_field_param_type(
|
213
|
-
name, "is_gen_param"
|
214
|
-
) or self.is_field_exec_param(name)
|
215
|
-
|
216
|
-
def is_field_exec_param(self, name: str) -> bool:
|
217
|
-
return self.is_field_param_type(name, "is_exec_param")
|
218
|
-
|
219
212
|
def is_powerable(self, strict_zero_ios: bool = True) -> bool:
|
220
213
|
input_names = set(self.inputs_full(strict_zero_ios))
|
221
214
|
output_names = set(self._output_names)
|
@@ -239,7 +232,7 @@ class FunctionParams(HashablePydanticBaseModel):
|
|
239
232
|
return sum(reg.size if reg is not None else 0 for reg in registers)
|
240
233
|
|
241
234
|
def _validate_io_names(self) -> None:
|
242
|
-
error_msg:
|
235
|
+
error_msg: list[str] = []
|
243
236
|
error_msg += self._get_error_msg(self._inputs, BAD_INPUT_REGISTER_ERROR_MSG)
|
244
237
|
error_msg += self._get_error_msg(self._outputs, BAD_OUTPUT_REGISTER_ERROR_MSG)
|
245
238
|
if error_msg:
|
@@ -258,7 +251,7 @@ class FunctionParams(HashablePydanticBaseModel):
|
|
258
251
|
if total_inputs_size != total_outputs_size:
|
259
252
|
raise ClassiqValueError(REGISTER_SIZES_MISMATCH_ERROR_MSG)
|
260
253
|
|
261
|
-
def _get_error_msg(self, names: Iterable[IOName], msg: str) ->
|
254
|
+
def _get_error_msg(self, names: Iterable[IOName], msg: str) -> list[str]:
|
262
255
|
bad_names = [name for name in names if re.fullmatch(NAME_REGEX, name) is None]
|
263
256
|
return [f"{msg}: {bad_names}"] if bad_names else []
|
264
257
|
|
@@ -266,38 +259,17 @@ class FunctionParams(HashablePydanticBaseModel):
|
|
266
259
|
def discriminator(cls) -> FunctionParamsDiscriminator:
|
267
260
|
return cls.__name__
|
268
261
|
|
269
|
-
|
270
|
-
def _params(self) -> List[str]:
|
271
|
-
return [
|
272
|
-
name
|
273
|
-
for name, field in self.__fields__.items()
|
274
|
-
if field.field_info.extra.get("is_exec_param", False)
|
275
|
-
]
|
276
|
-
|
277
|
-
@pydantic.validator("*", pre=True)
|
278
|
-
def validate_parameters(cls, value: Any, field: pydantic.fields.ModelField) -> Any:
|
279
|
-
if (
|
280
|
-
"is_exec_param" in field.field_info.extra
|
281
|
-
or "is_gen_param" in field.field_info.extra
|
282
|
-
):
|
283
|
-
if isinstance(value, str):
|
284
|
-
validate_expression_str(value)
|
285
|
-
elif isinstance(value, sympy.Expr):
|
286
|
-
return str(value)
|
287
|
-
return value
|
288
|
-
|
289
|
-
class Config:
|
290
|
-
frozen = True
|
262
|
+
model_config = ConfigDict(frozen=True, extra="forbid")
|
291
263
|
|
292
264
|
|
293
265
|
def parse_function_params(
|
294
266
|
*,
|
295
267
|
params: Any,
|
296
268
|
discriminator: Optional[Any],
|
297
|
-
param_classes: Collection[
|
269
|
+
param_classes: Collection[type[FunctionParams]],
|
298
270
|
no_discriminator_error: Exception,
|
299
271
|
bad_function_error: Exception,
|
300
|
-
default_parser_class: Optional[
|
272
|
+
default_parser_class: Optional[type[FunctionParams]] = None,
|
301
273
|
) -> FunctionParams: # Any is for use in pydantic validators.
|
302
274
|
if not discriminator:
|
303
275
|
raise no_discriminator_error
|
@@ -311,21 +283,21 @@ def parse_function_params(
|
|
311
283
|
if len(matching_classes) != 1:
|
312
284
|
if default_parser_class is not None:
|
313
285
|
try:
|
314
|
-
return default_parser_class.
|
286
|
+
return default_parser_class.model_validate(params)
|
315
287
|
except Exception:
|
316
288
|
raise bad_function_error from None
|
317
289
|
raise bad_function_error
|
318
290
|
|
319
|
-
return matching_classes[0].
|
291
|
+
return matching_classes[0].model_validate(params)
|
320
292
|
|
321
293
|
|
322
294
|
def parse_function_params_values(
|
323
295
|
*,
|
324
|
-
values:
|
296
|
+
values: dict[str, Any],
|
325
297
|
params_key: str,
|
326
298
|
discriminator_key: str,
|
327
|
-
param_classes: Collection[
|
328
|
-
default_parser_class:
|
299
|
+
param_classes: Collection[type[FunctionParams]],
|
300
|
+
default_parser_class: type[FunctionParams],
|
329
301
|
) -> None:
|
330
302
|
params = values.get(params_key, dict())
|
331
303
|
if isinstance(params, FunctionParams):
|
@@ -1,23 +1 @@
|
|
1
|
-
from typing import List
|
2
|
-
|
3
|
-
import classiq.interface.generator.functions.core_lib_declarations.quantum_functions
|
4
|
-
import classiq.interface.generator.functions.core_lib_declarations.quantum_operators
|
5
|
-
from classiq.interface.generator.functions.foreign_function_definition import *
|
6
|
-
from classiq.interface.generator.functions.foreign_function_definition import (
|
7
|
-
SynthesisForeignFunctionDefinition as ForeignFunctionDefinition,
|
8
|
-
)
|
9
1
|
from classiq.interface.generator.functions.function_declaration import *
|
10
|
-
from classiq.interface.generator.functions.function_implementation import *
|
11
|
-
from classiq.interface.generator.functions.native_function_definition import *
|
12
|
-
from classiq.interface.generator.functions.register import *
|
13
|
-
|
14
|
-
__all__ = [ # noqa: F405
|
15
|
-
"ForeignFunctionDefinition",
|
16
|
-
"FunctionImplementation",
|
17
|
-
"Register",
|
18
|
-
"RegisterMappingData",
|
19
|
-
]
|
20
|
-
|
21
|
-
|
22
|
-
def __dir__() -> List[str]:
|
23
|
-
return __all__
|
@@ -0,0 +1,16 @@
|
|
1
|
+
CTRL_VAR_PREFIX = "ctrl__"
|
2
|
+
CONTROL_OPERATOR_NAME = "control"
|
3
|
+
INVERT_OPERATOR_NAME = "invert"
|
4
|
+
REPEAT_OPERATOR_NAME = "iteration"
|
5
|
+
POWER_OPERATOR_NAME = "power"
|
6
|
+
UNCOMPUTE_OPERATOR_NAME = "uncompute"
|
7
|
+
WITHIN_APPLY_NAME = "within_apply"
|
8
|
+
|
9
|
+
All_BUILTINS_OPERATORS = {
|
10
|
+
CONTROL_OPERATOR_NAME,
|
11
|
+
INVERT_OPERATOR_NAME,
|
12
|
+
REPEAT_OPERATOR_NAME,
|
13
|
+
POWER_OPERATOR_NAME,
|
14
|
+
UNCOMPUTE_OPERATOR_NAME,
|
15
|
+
WITHIN_APPLY_NAME,
|
16
|
+
}
|
@@ -1,11 +1,15 @@
|
|
1
|
-
from
|
1
|
+
from collections.abc import Sequence
|
2
|
+
from typing import ClassVar, Optional
|
2
3
|
|
3
4
|
import pydantic
|
4
5
|
|
5
|
-
from classiq.interface.generator.functions.
|
6
|
+
from classiq.interface.generator.functions.concrete_types import ConcreteClassicalType
|
6
7
|
from classiq.interface.generator.functions.function_declaration import (
|
7
8
|
FunctionDeclaration,
|
8
9
|
)
|
10
|
+
from classiq.interface.model.classical_parameter_declaration import (
|
11
|
+
ClassicalParameterDeclaration,
|
12
|
+
)
|
9
13
|
|
10
14
|
|
11
15
|
class ClassicalFunctionDeclaration(FunctionDeclaration):
|
@@ -13,23 +17,28 @@ class ClassicalFunctionDeclaration(FunctionDeclaration):
|
|
13
17
|
Facilitates the creation of a common classical function interface object.
|
14
18
|
"""
|
15
19
|
|
20
|
+
name: str
|
21
|
+
|
22
|
+
positional_parameters: Sequence[ClassicalParameterDeclaration] = pydantic.Field(
|
23
|
+
default_factory=list,
|
24
|
+
)
|
25
|
+
|
16
26
|
return_type: Optional[ConcreteClassicalType] = pydantic.Field(
|
17
27
|
description="The type of the classical value that is returned by the function (for classical functions)",
|
18
28
|
default=None,
|
19
29
|
)
|
20
30
|
|
21
31
|
BUILTIN_FUNCTION_DECLARATIONS: ClassVar[
|
22
|
-
|
32
|
+
dict[str, "ClassicalFunctionDeclaration"]
|
23
33
|
] = {}
|
24
34
|
|
25
35
|
FOREIGN_FUNCTION_DECLARATIONS: ClassVar[
|
26
|
-
|
36
|
+
dict[str, "ClassicalFunctionDeclaration"]
|
27
37
|
] = {}
|
28
38
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
pass
|
39
|
+
@property
|
40
|
+
def param_decls(self) -> Sequence[ClassicalParameterDeclaration]:
|
41
|
+
return self.positional_parameters
|
33
42
|
|
34
43
|
|
35
|
-
ClassicalFunctionDeclaration.
|
44
|
+
ClassicalFunctionDeclaration.model_rebuild()
|
@@ -1,43 +1,31 @@
|
|
1
|
-
from
|
2
|
-
from typing import Any, Dict, List, Literal, Union
|
1
|
+
from typing import TYPE_CHECKING, Any, Literal, Union
|
3
2
|
|
4
3
|
import pydantic
|
5
|
-
from pydantic import
|
4
|
+
from pydantic import ConfigDict
|
6
5
|
from sympy import IndexedBase, Symbol
|
7
|
-
from typing_extensions import Annotated
|
8
6
|
|
9
|
-
from classiq.interface.
|
10
|
-
LadderOperator as LadderOperatorEnum,
|
11
|
-
)
|
12
|
-
from classiq.interface.generator.expressions.enums.pauli import Pauli as PauliEnum
|
7
|
+
from classiq.interface.ast_node import HashableASTNode
|
13
8
|
from classiq.interface.generator.expressions.expression_types import RuntimeExpression
|
14
|
-
from classiq.interface.helpers.hashable_pydantic_base_model import (
|
15
|
-
HashablePydanticBaseModel,
|
16
|
-
)
|
17
9
|
from classiq.interface.helpers.pydantic_model_helpers import values_with_discriminator
|
18
10
|
|
11
|
+
if TYPE_CHECKING:
|
12
|
+
from classiq.interface.generator.functions.concrete_types import (
|
13
|
+
ConcreteClassicalType,
|
14
|
+
)
|
15
|
+
|
16
|
+
CLASSICAL_ATTRIBUTES = {"len", "size", "is_signed", "fraction_digits"}
|
17
|
+
|
19
18
|
NamedSymbol = Union[IndexedBase, Symbol]
|
20
19
|
|
21
20
|
|
22
|
-
class ClassicalType(
|
23
|
-
def as_symbolic(self, name: str) -> Union[NamedSymbol,
|
21
|
+
class ClassicalType(HashableASTNode):
|
22
|
+
def as_symbolic(self, name: str) -> Union[NamedSymbol, list[NamedSymbol]]:
|
24
23
|
return Symbol(name)
|
25
24
|
|
26
|
-
|
27
|
-
@abstractmethod
|
28
|
-
def default_value(self) -> Any:
|
29
|
-
raise NotImplementedError(
|
30
|
-
f"{self.__class__.__name__} type has no default value"
|
31
|
-
)
|
25
|
+
model_config = ConfigDict(extra="forbid")
|
32
26
|
|
33
|
-
|
34
|
-
|
35
|
-
raise NotImplementedError(
|
36
|
-
f"{self.__class__.__name__!r} has no Python SDK equivalent"
|
37
|
-
)
|
38
|
-
|
39
|
-
class Config:
|
40
|
-
extra = Extra.forbid
|
27
|
+
def __str__(self) -> str:
|
28
|
+
return str(type(self).__name__)
|
41
29
|
|
42
30
|
|
43
31
|
class Integer(ClassicalType):
|
@@ -46,18 +34,11 @@ class Integer(ClassicalType):
|
|
46
34
|
def as_symbolic(self, name: str) -> Symbol:
|
47
35
|
return Symbol(name, integer=True)
|
48
36
|
|
49
|
-
@
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
@pydantic.root_validator(pre=True)
|
54
|
-
def _set_kind(cls, values: Dict[str, Any]) -> Dict[str, Any]:
|
37
|
+
@pydantic.model_validator(mode="before")
|
38
|
+
@classmethod
|
39
|
+
def _set_kind(cls, values: Any) -> dict[str, Any]:
|
55
40
|
return values_with_discriminator(values, "kind", "int")
|
56
41
|
|
57
|
-
@property
|
58
|
-
def python_type(self) -> type:
|
59
|
-
return int
|
60
|
-
|
61
42
|
|
62
43
|
class Real(ClassicalType):
|
63
44
|
kind: Literal["real"]
|
@@ -65,34 +46,20 @@ class Real(ClassicalType):
|
|
65
46
|
def as_symbolic(self, name: str) -> Symbol:
|
66
47
|
return Symbol(name, real=True)
|
67
48
|
|
68
|
-
@
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
@pydantic.root_validator(pre=True)
|
73
|
-
def _set_kind(cls, values: Dict[str, Any]) -> Dict[str, Any]:
|
49
|
+
@pydantic.model_validator(mode="before")
|
50
|
+
@classmethod
|
51
|
+
def _set_kind(cls, values: Any) -> dict[str, Any]:
|
74
52
|
return values_with_discriminator(values, "kind", "real")
|
75
53
|
|
76
|
-
@property
|
77
|
-
def python_type(self) -> type:
|
78
|
-
return float
|
79
|
-
|
80
54
|
|
81
55
|
class Bool(ClassicalType):
|
82
56
|
kind: Literal["bool"]
|
83
57
|
|
84
|
-
@
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
@pydantic.root_validator(pre=True)
|
89
|
-
def _set_kind(cls, values: Dict[str, Any]) -> Dict[str, Any]:
|
58
|
+
@pydantic.model_validator(mode="before")
|
59
|
+
@classmethod
|
60
|
+
def _set_kind(cls, values: Any) -> dict[str, Any]:
|
90
61
|
return values_with_discriminator(values, "kind", "bool")
|
91
62
|
|
92
|
-
@property
|
93
|
-
def python_type(self) -> type:
|
94
|
-
return bool
|
95
|
-
|
96
63
|
|
97
64
|
class ClassicalList(ClassicalType):
|
98
65
|
kind: Literal["list"]
|
@@ -101,68 +68,21 @@ class ClassicalList(ClassicalType):
|
|
101
68
|
def as_symbolic(self, name: str) -> Symbol:
|
102
69
|
return IndexedBase(name)
|
103
70
|
|
104
|
-
@
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
@pydantic.root_validator(pre=True)
|
109
|
-
def _set_kind(cls, values: Dict[str, Any]) -> Dict[str, Any]:
|
71
|
+
@pydantic.model_validator(mode="before")
|
72
|
+
@classmethod
|
73
|
+
def _set_kind(cls, values: Any) -> dict[str, Any]:
|
110
74
|
return values_with_discriminator(values, "kind", "list")
|
111
75
|
|
112
|
-
@property
|
113
|
-
def python_type(self) -> type:
|
114
|
-
return List[self.element_type.python_type] # type:ignore[name-defined]
|
115
|
-
|
116
|
-
|
117
|
-
class Pauli(ClassicalType):
|
118
|
-
kind: Literal["pauli"]
|
119
|
-
|
120
|
-
@property
|
121
|
-
def default_value(self) -> PauliEnum:
|
122
|
-
return PauliEnum.I
|
123
|
-
|
124
|
-
@pydantic.root_validator(pre=True)
|
125
|
-
def _set_kind(cls, values: Dict[str, Any]) -> Dict[str, Any]:
|
126
|
-
return values_with_discriminator(values, "kind", "pauli")
|
127
|
-
|
128
|
-
@property
|
129
|
-
def python_type(self) -> type:
|
130
|
-
return int
|
131
|
-
|
132
76
|
|
133
77
|
class StructMetaType(ClassicalType):
|
134
78
|
kind: Literal["type_proxy"]
|
135
79
|
|
136
|
-
@
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
@pydantic.root_validator(pre=True)
|
141
|
-
def _set_kind(cls, values: Dict[str, Any]) -> Dict[str, Any]:
|
80
|
+
@pydantic.model_validator(mode="before")
|
81
|
+
@classmethod
|
82
|
+
def _set_kind(cls, values: Any) -> dict[str, Any]:
|
142
83
|
return values_with_discriminator(values, "kind", "type_proxy")
|
143
84
|
|
144
85
|
|
145
|
-
class QStructBase: # marker for Qmod structs in the Python SDK
|
146
|
-
pass
|
147
|
-
|
148
|
-
|
149
|
-
class Struct(ClassicalType):
|
150
|
-
kind: Literal["struct_instance"]
|
151
|
-
name: str = pydantic.Field(description="The struct type of the instance")
|
152
|
-
|
153
|
-
@property
|
154
|
-
def default_value(self) -> Any:
|
155
|
-
return super().default_value
|
156
|
-
|
157
|
-
@pydantic.root_validator(pre=True)
|
158
|
-
def _set_kind(cls, values: Dict[str, Any]) -> Dict[str, Any]:
|
159
|
-
return values_with_discriminator(values, "kind", "struct_instance")
|
160
|
-
|
161
|
-
@property
|
162
|
-
def python_type(self) -> type:
|
163
|
-
return type(self.name, (QStructBase,), dict())
|
164
|
-
|
165
|
-
|
166
86
|
class ClassicalArray(ClassicalType):
|
167
87
|
kind: Literal["array"]
|
168
88
|
element_type: "ConcreteClassicalType"
|
@@ -171,92 +91,53 @@ class ClassicalArray(ClassicalType):
|
|
171
91
|
def as_symbolic(self, name: str) -> list:
|
172
92
|
return [self.element_type.as_symbolic(f"{name}_{i}") for i in range(self.size)]
|
173
93
|
|
174
|
-
@
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
@pydantic.root_validator(pre=True)
|
179
|
-
def _set_kind(cls, values: Dict[str, Any]) -> Dict[str, Any]:
|
94
|
+
@pydantic.model_validator(mode="before")
|
95
|
+
@classmethod
|
96
|
+
def _set_kind(cls, values: Any) -> dict[str, Any]:
|
180
97
|
return values_with_discriminator(values, "kind", "array")
|
181
98
|
|
182
99
|
|
183
100
|
class OpaqueHandle(ClassicalType):
|
184
|
-
|
185
|
-
def default_value(self) -> int:
|
186
|
-
return 0
|
101
|
+
pass
|
187
102
|
|
188
103
|
|
189
104
|
class VQEResult(OpaqueHandle):
|
190
105
|
kind: Literal["vqe_result"]
|
191
106
|
|
192
|
-
@pydantic.
|
193
|
-
|
107
|
+
@pydantic.model_validator(mode="before")
|
108
|
+
@classmethod
|
109
|
+
def _set_kind(cls, values: Any) -> dict[str, Any]:
|
194
110
|
return values_with_discriminator(values, "kind", "vqe_result")
|
195
111
|
|
196
112
|
|
197
113
|
class Histogram(OpaqueHandle):
|
198
114
|
kind: Literal["histogram"]
|
199
115
|
|
200
|
-
@pydantic.
|
201
|
-
|
116
|
+
@pydantic.model_validator(mode="before")
|
117
|
+
@classmethod
|
118
|
+
def _set_kind(cls, values: Any) -> dict[str, Any]:
|
202
119
|
return values_with_discriminator(values, "kind", "histogram")
|
203
120
|
|
204
121
|
|
205
122
|
class Estimation(OpaqueHandle):
|
206
123
|
kind: Literal["estimation_result"]
|
207
124
|
|
208
|
-
@pydantic.
|
209
|
-
|
125
|
+
@pydantic.model_validator(mode="before")
|
126
|
+
@classmethod
|
127
|
+
def _set_kind(cls, values: Any) -> dict[str, Any]:
|
210
128
|
return values_with_discriminator(values, "kind", "estimation_result")
|
211
129
|
|
212
130
|
|
213
131
|
class IQAERes(OpaqueHandle):
|
214
132
|
kind: Literal["iqae_result"]
|
215
133
|
|
216
|
-
@pydantic.
|
217
|
-
|
134
|
+
@pydantic.model_validator(mode="before")
|
135
|
+
@classmethod
|
136
|
+
def _set_kind(cls, values: Any) -> dict[str, Any]:
|
218
137
|
return values_with_discriminator(values, "kind", "iqae_result")
|
219
138
|
|
220
139
|
|
221
|
-
|
222
|
-
kind: Literal["ladder_operator"]
|
223
|
-
|
224
|
-
@property
|
225
|
-
def default_value(self) -> LadderOperatorEnum:
|
226
|
-
return LadderOperatorEnum.PLUS
|
227
|
-
|
228
|
-
@pydantic.root_validator(pre=True)
|
229
|
-
def _set_kind(cls, values: Dict[str, Any]) -> Dict[str, Any]:
|
230
|
-
return values_with_discriminator(values, "kind", "ladder_operator")
|
231
|
-
|
232
|
-
@property
|
233
|
-
def python_type(self) -> type:
|
234
|
-
return int
|
235
|
-
|
236
|
-
|
237
|
-
ConcreteClassicalType = Annotated[
|
238
|
-
Union[
|
239
|
-
Integer,
|
240
|
-
Real,
|
241
|
-
Bool,
|
242
|
-
ClassicalList,
|
243
|
-
Pauli,
|
244
|
-
StructMetaType,
|
245
|
-
Struct,
|
246
|
-
ClassicalArray,
|
247
|
-
VQEResult,
|
248
|
-
Histogram,
|
249
|
-
Estimation,
|
250
|
-
LadderOperator,
|
251
|
-
IQAERes,
|
252
|
-
],
|
253
|
-
Field(discriminator="kind"),
|
254
|
-
]
|
255
|
-
ClassicalList.update_forward_refs()
|
256
|
-
ClassicalArray.update_forward_refs()
|
257
|
-
|
258
|
-
|
259
|
-
def as_symbolic(symbols: Dict[str, ClassicalType]) -> Dict[str, RuntimeExpression]:
|
140
|
+
def as_symbolic(symbols: dict[str, ClassicalType]) -> dict[str, RuntimeExpression]:
|
260
141
|
return {
|
261
142
|
param_name: param_type.as_symbolic(param_name)
|
262
143
|
for param_name, param_type in symbols.items()
|
@@ -0,0 +1,55 @@
|
|
1
|
+
from typing import Annotated, Union
|
2
|
+
|
3
|
+
from pydantic import Field
|
4
|
+
|
5
|
+
from classiq.interface.generator.functions.classical_type import (
|
6
|
+
Bool,
|
7
|
+
ClassicalArray,
|
8
|
+
ClassicalList,
|
9
|
+
Estimation,
|
10
|
+
Histogram,
|
11
|
+
Integer,
|
12
|
+
IQAERes,
|
13
|
+
Real,
|
14
|
+
StructMetaType,
|
15
|
+
VQEResult,
|
16
|
+
)
|
17
|
+
from classiq.interface.generator.functions.type_name import Enum, TypeName
|
18
|
+
from classiq.interface.generator.types.qstruct_declaration import QStructDeclaration
|
19
|
+
from classiq.interface.model.quantum_type import (
|
20
|
+
QuantumBit,
|
21
|
+
QuantumBitvector,
|
22
|
+
QuantumNumeric,
|
23
|
+
RegisterQuantumType,
|
24
|
+
)
|
25
|
+
|
26
|
+
ConcreteClassicalType = Annotated[
|
27
|
+
Union[
|
28
|
+
Integer,
|
29
|
+
Real,
|
30
|
+
Bool,
|
31
|
+
ClassicalList,
|
32
|
+
StructMetaType,
|
33
|
+
TypeName,
|
34
|
+
ClassicalArray,
|
35
|
+
VQEResult,
|
36
|
+
Histogram,
|
37
|
+
Estimation,
|
38
|
+
IQAERes,
|
39
|
+
],
|
40
|
+
Field(discriminator="kind"),
|
41
|
+
]
|
42
|
+
ClassicalList.model_rebuild()
|
43
|
+
ClassicalArray.model_rebuild()
|
44
|
+
|
45
|
+
NativePythonClassicalTypes = (int, float, bool, list)
|
46
|
+
PythonClassicalPydanticTypes = (Enum,)
|
47
|
+
|
48
|
+
ConcreteQuantumType = Annotated[
|
49
|
+
Union[QuantumBit, QuantumBitvector, QuantumNumeric, TypeName],
|
50
|
+
Field(discriminator="kind", default_factory=QuantumBitvector),
|
51
|
+
]
|
52
|
+
QuantumBitvector.model_rebuild()
|
53
|
+
TypeName.model_rebuild()
|
54
|
+
QStructDeclaration.model_rebuild()
|
55
|
+
RegisterQuantumType.model_rebuild()
|