classiq 0.37.1__py3-none-any.whl → 0.65.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- classiq/__init__.py +49 -34
- classiq/_analyzer_extras/_ipywidgets_async_extension.py +3 -2
- classiq/_analyzer_extras/interactive_hardware.py +3 -3
- classiq/_internals/api_wrapper.py +241 -95
- classiq/_internals/async_utils.py +2 -77
- classiq/_internals/authentication/auth0.py +26 -10
- classiq/_internals/authentication/authentication.py +11 -0
- classiq/_internals/authentication/device.py +18 -8
- classiq/_internals/authentication/password_manager.py +40 -13
- classiq/_internals/authentication/token_manager.py +11 -6
- classiq/_internals/client.py +106 -37
- classiq/_internals/config.py +3 -4
- classiq/_internals/host_checker.py +38 -15
- classiq/_internals/jobs.py +56 -50
- classiq/_internals/type_validation.py +9 -9
- classiq/analyzer/__init__.py +1 -3
- classiq/analyzer/analyzer.py +50 -47
- classiq/analyzer/analyzer_utilities.py +15 -15
- classiq/analyzer/rb.py +19 -20
- classiq/analyzer/show_interactive_hack.py +30 -7
- classiq/analyzer/url_utils.py +2 -3
- classiq/applications/__init__.py +3 -12
- classiq/applications/chemistry/__init__.py +14 -10
- classiq/applications/chemistry/ansatz_parameters.py +4 -4
- classiq/{applications_model_constructors → applications/chemistry}/chemistry_model_constructor.py +170 -170
- classiq/applications/chemistry/ground_state_problem.py +1 -1
- classiq/applications/combinatorial_helpers/allowed_constraints.py +23 -0
- classiq/applications/combinatorial_helpers/arithmetic/arithmetic_expression.py +35 -0
- classiq/applications/combinatorial_helpers/arithmetic/isolation.py +42 -0
- classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +166 -0
- classiq/applications/combinatorial_helpers/encoding_mapping.py +107 -0
- classiq/applications/combinatorial_helpers/encoding_utils.py +124 -0
- classiq/applications/combinatorial_helpers/memory.py +75 -0
- classiq/applications/combinatorial_helpers/optimization_model.py +193 -0
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_sparsing.py +31 -0
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_utils.py +46 -0
- classiq/applications/combinatorial_helpers/pyomo_utils.py +447 -0
- classiq/applications/combinatorial_helpers/sympy_utils.py +22 -0
- classiq/applications/combinatorial_helpers/transformations/encoding.py +189 -0
- classiq/applications/combinatorial_helpers/transformations/fixed_variables.py +143 -0
- classiq/applications/combinatorial_helpers/transformations/ising_converter.py +120 -0
- classiq/applications/combinatorial_helpers/transformations/penalty.py +31 -0
- classiq/applications/combinatorial_helpers/transformations/penalty_support.py +37 -0
- classiq/applications/combinatorial_helpers/transformations/sign_seperation.py +74 -0
- classiq/applications/combinatorial_helpers/transformations/slack_variables.py +87 -0
- classiq/applications/combinatorial_optimization/__init__.py +24 -5
- classiq/applications/combinatorial_optimization/combinatorial_optimization_config.py +2 -2
- classiq/applications/combinatorial_optimization/combinatorial_optimization_model_constructor.py +137 -0
- classiq/applications/combinatorial_optimization/combinatorial_problem.py +229 -0
- classiq/applications/combinatorial_optimization/examples/__init__.py +1 -3
- classiq/applications/finance/__init__.py +4 -5
- classiq/{applications_model_constructors → applications/finance}/finance_model_constructor.py +50 -57
- classiq/applications/grover/__init__.py +9 -0
- classiq/applications/grover/grover_model_constructor.py +157 -0
- classiq/applications/hamiltonian/__init__.py +0 -0
- classiq/applications/hamiltonian/pauli_decomposition.py +113 -0
- classiq/applications/libraries/__init__.py +0 -0
- classiq/applications/libraries/qmci_library.py +22 -0
- classiq/applications/qnn/__init__.py +2 -4
- classiq/applications/qnn/circuit_utils.py +8 -8
- classiq/applications/qnn/datasets/__init__.py +9 -11
- classiq/applications/qnn/datasets/dataset_base_classes.py +7 -5
- classiq/applications/qnn/datasets/dataset_not.py +2 -1
- classiq/applications/qnn/datasets/dataset_parity.py +2 -2
- classiq/applications/qnn/gradients/quantum_gradient.py +2 -2
- classiq/applications/qnn/gradients/simple_quantum_gradient.py +2 -1
- classiq/applications/qnn/qlayer.py +30 -10
- classiq/applications/qnn/torch_utils.py +4 -3
- classiq/applications/qnn/types.py +7 -7
- classiq/applications/qsvm/__init__.py +6 -4
- classiq/applications/qsvm/qsvm.py +4 -10
- classiq/applications/qsvm/qsvm_data_generation.py +5 -8
- classiq/{applications_model_constructors → applications/qsvm}/qsvm_model_constructor.py +30 -28
- classiq/execution/__init__.py +8 -3
- classiq/execution/all_hardware_devices.py +11 -0
- classiq/execution/execution_session.py +400 -0
- classiq/execution/iqcc.py +63 -0
- classiq/execution/jobs.py +197 -25
- classiq/execution/qnn.py +79 -0
- classiq/executor.py +23 -117
- classiq/interface/_version.py +1 -1
- classiq/interface/analyzer/analysis_params.py +49 -16
- classiq/interface/analyzer/cytoscape_graph.py +15 -9
- classiq/interface/analyzer/result.py +36 -32
- classiq/interface/applications/qsvm.py +28 -25
- classiq/interface/ast_node.py +16 -0
- classiq/interface/backend/backend_preferences.py +390 -119
- classiq/interface/backend/ionq/ionq_quantum_program.py +15 -23
- classiq/interface/backend/pydantic_backend.py +27 -22
- classiq/interface/backend/quantum_backend_providers.py +70 -16
- classiq/interface/chemistry/fermionic_operator.py +43 -32
- classiq/interface/chemistry/ground_state_problem.py +42 -24
- classiq/interface/chemistry/molecule.py +20 -14
- classiq/interface/chemistry/operator.py +75 -236
- classiq/interface/combinatorial_optimization/encoding_types.py +1 -1
- classiq/interface/combinatorial_optimization/examples/ascending_sequence.py +2 -4
- classiq/interface/combinatorial_optimization/examples/greater_than_ilp.py +1 -1
- classiq/interface/combinatorial_optimization/examples/ilp.py +2 -1
- classiq/interface/combinatorial_optimization/examples/integer_portfolio_optimization.py +2 -4
- classiq/interface/combinatorial_optimization/examples/knapsack.py +3 -3
- classiq/interface/combinatorial_optimization/examples/mds.py +2 -1
- classiq/interface/combinatorial_optimization/examples/mht.py +10 -6
- classiq/interface/combinatorial_optimization/examples/mis.py +4 -1
- classiq/interface/combinatorial_optimization/examples/mvc.py +2 -1
- classiq/interface/combinatorial_optimization/examples/portfolio_variations.py +2 -2
- classiq/interface/combinatorial_optimization/examples/set_cover.py +3 -3
- classiq/interface/combinatorial_optimization/examples/tsp.py +4 -3
- classiq/interface/combinatorial_optimization/examples/tsp_digraph.py +6 -2
- classiq/interface/combinatorial_optimization/mht_qaoa_input.py +14 -9
- classiq/interface/combinatorial_optimization/optimization_problem.py +2 -2
- classiq/interface/combinatorial_optimization/result.py +1 -3
- classiq/interface/combinatorial_optimization/solver_types.py +1 -1
- classiq/interface/debug_info/__init__.py +0 -0
- classiq/interface/debug_info/debug_info.py +86 -0
- classiq/interface/exceptions.py +201 -0
- classiq/interface/execution/iqcc.py +19 -0
- classiq/interface/execution/jobs.py +15 -12
- classiq/interface/execution/primitives.py +18 -0
- classiq/interface/executor/constants.py +1 -0
- classiq/interface/executor/estimation.py +2 -2
- classiq/interface/executor/execution_preferences.py +26 -143
- classiq/interface/executor/execution_request.py +36 -56
- classiq/interface/executor/execution_result.py +30 -8
- classiq/interface/executor/iqae_result.py +4 -6
- classiq/interface/executor/optimizer_preferences.py +34 -22
- classiq/interface/executor/{quantum_program.py → quantum_code.py} +44 -34
- classiq/interface/executor/quantum_instruction_set.py +3 -2
- classiq/interface/executor/register_initialization.py +12 -17
- classiq/interface/executor/result.py +122 -64
- classiq/interface/executor/vqe_result.py +11 -11
- classiq/interface/finance/function_input.py +42 -19
- classiq/interface/finance/gaussian_model_input.py +7 -5
- classiq/interface/finance/log_normal_model_input.py +6 -4
- classiq/interface/finance/model_input.py +6 -4
- classiq/interface/generator/adjacency.py +1 -3
- classiq/interface/generator/amplitude_loading.py +27 -14
- classiq/interface/generator/ansatz_library.py +5 -5
- classiq/interface/generator/application_apis/__init__.py +1 -0
- classiq/interface/generator/application_apis/arithmetic_declarations.py +17 -0
- classiq/interface/generator/application_apis/chemistry_declarations.py +27 -187
- classiq/interface/generator/application_apis/combinatorial_optimization_declarations.py +18 -21
- classiq/interface/generator/application_apis/entangler_declarations.py +11 -6
- classiq/interface/generator/application_apis/finance_declarations.py +48 -69
- classiq/interface/generator/application_apis/qsvm_declarations.py +0 -70
- classiq/interface/generator/arith/argument_utils.py +57 -6
- classiq/interface/generator/arith/arithmetic.py +37 -16
- classiq/interface/generator/arith/arithmetic_arg_type_validator.py +15 -17
- classiq/interface/generator/arith/arithmetic_expression_abc.py +70 -26
- classiq/interface/generator/arith/arithmetic_expression_parser.py +18 -12
- classiq/interface/generator/arith/arithmetic_expression_validator.py +61 -43
- classiq/interface/generator/arith/arithmetic_operations.py +19 -16
- classiq/interface/generator/arith/arithmetic_param_getters.py +7 -8
- classiq/interface/generator/arith/arithmetic_result_builder.py +21 -17
- classiq/interface/generator/arith/ast_node_rewrite.py +4 -3
- classiq/interface/generator/arith/binary_ops.py +375 -139
- classiq/interface/generator/arith/endianness.py +1 -1
- classiq/interface/generator/arith/extremum_operations.py +96 -23
- classiq/interface/generator/arith/logical_ops.py +16 -12
- classiq/interface/generator/arith/machine_precision.py +3 -0
- classiq/interface/generator/arith/number_utils.py +44 -48
- classiq/interface/generator/arith/register_user_input.py +70 -27
- classiq/interface/generator/arith/unary_ops.py +57 -46
- classiq/interface/generator/arith/uncomputation_methods.py +1 -1
- classiq/interface/generator/builtin_api_builder.py +2 -9
- classiq/interface/generator/chemistry_function_params.py +5 -5
- classiq/interface/generator/circuit_code/circuit_code.py +7 -7
- classiq/interface/generator/circuit_code/types_and_constants.py +4 -7
- classiq/interface/generator/commuting_pauli_exponentiation.py +8 -6
- classiq/interface/generator/compiler_keywords.py +8 -0
- classiq/interface/generator/complex_type.py +13 -25
- classiq/interface/generator/constant.py +3 -4
- classiq/interface/generator/control_state.py +35 -28
- classiq/interface/generator/copy.py +47 -0
- classiq/interface/generator/custom_ansatz.py +2 -5
- classiq/interface/generator/distance.py +3 -5
- classiq/interface/generator/excitations.py +3 -2
- classiq/interface/generator/expressions/atomic_expression_functions.py +26 -8
- classiq/interface/generator/expressions/enums/__init__.py +0 -10
- classiq/interface/generator/expressions/enums/finance_functions.py +12 -22
- classiq/interface/generator/expressions/evaluated_expression.py +21 -7
- classiq/interface/generator/expressions/expression.py +27 -15
- classiq/interface/generator/expressions/expression_constants.py +9 -3
- classiq/interface/generator/expressions/non_symbolic_expr.py +119 -0
- classiq/interface/generator/expressions/qmod_qarray_proxy.py +99 -0
- classiq/interface/generator/expressions/qmod_qscalar_proxy.py +59 -0
- classiq/interface/generator/expressions/qmod_qstruct_proxy.py +36 -0
- classiq/interface/generator/expressions/qmod_sized_proxy.py +30 -2
- classiq/interface/generator/expressions/qmod_struct_instance.py +14 -2
- classiq/interface/generator/expressions/sympy_supported_expressions.py +20 -11
- classiq/interface/generator/finance.py +3 -3
- classiq/interface/generator/function_param_library.py +6 -6
- classiq/interface/generator/function_param_list_without_self_reference.py +2 -10
- classiq/interface/generator/function_params.py +42 -69
- classiq/interface/generator/functions/__init__.py +0 -22
- classiq/interface/generator/functions/builtins/__init__.py +0 -0
- classiq/interface/generator/functions/builtins/internal_operators.py +16 -0
- classiq/interface/generator/functions/classical_function_declaration.py +18 -9
- classiq/interface/generator/functions/classical_type.py +47 -166
- classiq/interface/generator/functions/concrete_types.py +55 -0
- classiq/interface/generator/functions/function_declaration.py +13 -14
- classiq/interface/generator/functions/port_declaration.py +1 -13
- classiq/interface/generator/functions/qmod_python_interface.py +2 -1
- classiq/interface/generator/functions/type_name.py +90 -0
- classiq/interface/generator/generated_circuit_data.py +155 -22
- classiq/interface/generator/grover_diffuser.py +32 -25
- classiq/interface/generator/grover_operator.py +34 -23
- classiq/interface/generator/hamiltonian_evolution/exponentiation.py +4 -6
- classiq/interface/generator/hamiltonian_evolution/qdrift.py +4 -4
- classiq/interface/generator/hamiltonian_evolution/suzuki_trotter.py +12 -8
- classiq/interface/generator/hardware/hardware_data.py +76 -36
- classiq/interface/generator/hardware_efficient_ansatz.py +38 -17
- classiq/interface/generator/hartree_fock.py +14 -4
- classiq/interface/generator/identity.py +10 -6
- classiq/interface/generator/linear_pauli_rotations.py +33 -19
- classiq/interface/generator/mcmt_method.py +1 -1
- classiq/interface/generator/mcu.py +20 -16
- classiq/interface/generator/mcx.py +29 -20
- classiq/interface/generator/model/__init__.py +2 -5
- classiq/interface/generator/model/constraints.py +27 -8
- classiq/interface/generator/model/model.py +32 -203
- classiq/interface/generator/model/preferences/preferences.py +118 -43
- classiq/{quantum_register.py → interface/generator/model/quantum_register.py} +27 -22
- classiq/interface/generator/oracles/arithmetic_oracle.py +2 -4
- classiq/interface/generator/oracles/custom_oracle.py +17 -13
- classiq/interface/generator/oracles/oracle_abc.py +9 -9
- classiq/interface/generator/partitioned_register.py +7 -7
- classiq/interface/generator/piecewise_linear_amplitude_loading.py +45 -29
- classiq/interface/generator/preferences/optimization.py +1 -2
- classiq/interface/generator/qpe.py +47 -34
- classiq/interface/generator/qsvm.py +13 -17
- classiq/interface/generator/quantum_function_call.py +107 -87
- classiq/interface/generator/{generated_circuit.py → quantum_program.py} +50 -37
- classiq/interface/generator/range_types.py +13 -12
- classiq/interface/generator/register_role.py +18 -6
- classiq/interface/generator/slice_parsing_utils.py +11 -6
- classiq/interface/generator/standard_gates/controlled_standard_gates.py +32 -39
- classiq/interface/generator/standard_gates/standard_angle_metaclass.py +2 -6
- classiq/interface/generator/standard_gates/standard_gates.py +3 -3
- classiq/interface/generator/standard_gates/u_gate.py +7 -10
- classiq/interface/generator/state_preparation/bell_state_preparation.py +3 -3
- classiq/interface/generator/state_preparation/computational_basis_state_preparation.py +2 -1
- classiq/interface/generator/state_preparation/distributions.py +16 -15
- classiq/interface/generator/state_preparation/metrics.py +5 -7
- classiq/interface/generator/state_preparation/state_preparation.py +30 -23
- classiq/interface/generator/synthesis_metadata/synthesis_duration.py +0 -4
- classiq/interface/generator/synthesis_metadata/synthesis_execution_data.py +20 -6
- classiq/interface/generator/transpiler_basis_gates.py +7 -3
- classiq/interface/generator/types/builtin_enum_declarations.py +178 -0
- classiq/interface/generator/types/compilation_metadata.py +6 -0
- classiq/interface/generator/types/enum_declaration.py +54 -0
- classiq/interface/generator/types/qstruct_declaration.py +18 -0
- classiq/interface/generator/types/struct_declaration.py +15 -14
- classiq/interface/generator/ucc.py +9 -6
- classiq/interface/generator/unitary_gate.py +10 -6
- classiq/interface/generator/user_defined_function_params.py +4 -1
- classiq/interface/generator/validations/flow_graph.py +11 -9
- classiq/interface/generator/validations/validator_functions.py +8 -6
- classiq/interface/generator/visitor.py +23 -16
- classiq/interface/hardware.py +31 -10
- classiq/interface/helpers/classproperty.py +8 -0
- classiq/interface/helpers/custom_encoders.py +3 -0
- classiq/interface/helpers/custom_pydantic_types.py +40 -50
- classiq/interface/helpers/datastructures.py +26 -0
- classiq/interface/helpers/hashable_mixin.py +3 -2
- classiq/interface/helpers/hashable_pydantic_base_model.py +2 -1
- classiq/interface/helpers/pydantic_model_helpers.py +7 -11
- classiq/interface/helpers/validation_helpers.py +4 -21
- classiq/interface/helpers/versioned_model.py +1 -1
- classiq/interface/ide/ide_data.py +16 -20
- classiq/interface/ide/visual_model.py +130 -0
- classiq/interface/interface_version.py +1 -0
- classiq/interface/jobs.py +35 -6
- classiq/interface/model/allocate.py +16 -0
- classiq/interface/model/bind_operation.py +44 -14
- classiq/interface/model/classical_if.py +15 -0
- classiq/interface/model/classical_parameter_declaration.py +33 -3
- classiq/interface/model/control.py +45 -0
- classiq/interface/model/handle_binding.py +298 -20
- classiq/interface/model/inplace_binary_operation.py +31 -26
- classiq/interface/model/invert.py +12 -0
- classiq/interface/model/model.py +87 -73
- classiq/interface/model/native_function_definition.py +16 -21
- classiq/interface/model/parameter.py +13 -0
- classiq/interface/model/phase_operation.py +11 -0
- classiq/interface/model/port_declaration.py +27 -9
- classiq/interface/model/power.py +14 -0
- classiq/interface/model/quantum_expressions/amplitude_loading_operation.py +38 -21
- classiq/interface/model/quantum_expressions/arithmetic_operation.py +51 -14
- classiq/interface/model/quantum_expressions/quantum_expression.py +12 -35
- classiq/interface/model/quantum_function_call.py +146 -462
- classiq/interface/model/quantum_function_declaration.py +193 -152
- classiq/interface/model/quantum_lambda_function.py +65 -0
- classiq/interface/model/quantum_statement.py +71 -12
- classiq/interface/model/quantum_type.py +205 -67
- classiq/interface/model/quantum_variable_declaration.py +4 -26
- classiq/interface/model/repeat.py +15 -0
- classiq/interface/model/statement_block.py +58 -0
- classiq/interface/model/validation_handle.py +13 -6
- classiq/interface/model/variable_declaration_statement.py +3 -1
- classiq/interface/model/within_apply_operation.py +13 -0
- classiq/interface/pyomo_extension/pyomo_sympy_bimap.py +4 -1
- classiq/interface/server/global_versions.py +6 -7
- classiq/interface/server/routes.py +22 -21
- classiq/interface/source_reference.py +59 -0
- classiq/model_expansions/__init__.py +0 -0
- classiq/model_expansions/atomic_expression_functions_defs.py +253 -0
- classiq/model_expansions/capturing/__init__.py +0 -0
- classiq/model_expansions/capturing/captured_vars.py +435 -0
- classiq/model_expansions/capturing/mangling_utils.py +56 -0
- classiq/model_expansions/closure.py +171 -0
- classiq/model_expansions/debug_flag.py +3 -0
- classiq/model_expansions/evaluators/__init__.py +0 -0
- classiq/model_expansions/evaluators/arg_type_match.py +158 -0
- classiq/model_expansions/evaluators/argument_types.py +42 -0
- classiq/model_expansions/evaluators/classical_expression.py +36 -0
- classiq/model_expansions/evaluators/control.py +144 -0
- classiq/model_expansions/evaluators/parameter_types.py +226 -0
- classiq/model_expansions/evaluators/quantum_type_utils.py +239 -0
- classiq/model_expansions/evaluators/type_type_match.py +90 -0
- classiq/model_expansions/expression_evaluator.py +135 -0
- classiq/model_expansions/expression_renamer.py +76 -0
- classiq/model_expansions/function_builder.py +247 -0
- classiq/model_expansions/generative_functions.py +158 -0
- classiq/model_expansions/interpreters/__init__.py +0 -0
- classiq/model_expansions/interpreters/base_interpreter.py +263 -0
- classiq/model_expansions/interpreters/frontend_generative_interpreter.py +28 -0
- classiq/model_expansions/interpreters/generative_interpreter.py +249 -0
- classiq/model_expansions/model_tables.py +18 -0
- classiq/model_expansions/quantum_operations/__init__.py +9 -0
- classiq/model_expansions/quantum_operations/bind.py +60 -0
- classiq/model_expansions/quantum_operations/call_emitter.py +266 -0
- classiq/model_expansions/quantum_operations/classicalif.py +53 -0
- classiq/model_expansions/quantum_operations/declarative_call_emitter.py +87 -0
- classiq/model_expansions/quantum_operations/emitter.py +181 -0
- classiq/model_expansions/quantum_operations/quantum_function_call.py +33 -0
- classiq/model_expansions/quantum_operations/repeat.py +56 -0
- classiq/model_expansions/quantum_operations/shallow_emitter.py +180 -0
- classiq/model_expansions/quantum_operations/variable_decleration.py +28 -0
- classiq/model_expansions/scope.py +240 -0
- classiq/model_expansions/scope_initialization.py +150 -0
- classiq/model_expansions/sympy_conversion/__init__.py +0 -0
- classiq/model_expansions/sympy_conversion/arithmetics.py +49 -0
- classiq/model_expansions/sympy_conversion/expression_to_sympy.py +179 -0
- classiq/model_expansions/sympy_conversion/sympy_to_python.py +123 -0
- classiq/model_expansions/transformers/__init__.py +0 -0
- classiq/model_expansions/transformers/ast_renamer.py +26 -0
- classiq/model_expansions/transformers/var_splitter.py +299 -0
- classiq/model_expansions/utils/__init__.py +0 -0
- classiq/model_expansions/utils/counted_name_allocator.py +11 -0
- classiq/model_expansions/utils/handles_collector.py +33 -0
- classiq/model_expansions/visitors/__init__.py +0 -0
- classiq/model_expansions/visitors/boolean_expression_transformers.py +214 -0
- classiq/model_expansions/visitors/variable_references.py +144 -0
- classiq/open_library/__init__.py +4 -0
- classiq/open_library/functions/__init__.py +130 -0
- classiq/open_library/functions/amplitude_estimation.py +30 -0
- classiq/open_library/functions/discrete_sine_cosine_transform.py +181 -0
- classiq/open_library/functions/grover.py +157 -0
- classiq/open_library/functions/hea.py +115 -0
- classiq/open_library/functions/linear_pauli_rotation.py +82 -0
- classiq/open_library/functions/modular_exponentiation.py +201 -0
- classiq/open_library/functions/qaoa_penalty.py +117 -0
- classiq/open_library/functions/qft_functions.py +54 -0
- classiq/open_library/functions/qpe.py +46 -0
- classiq/open_library/functions/qsvt.py +331 -0
- classiq/open_library/functions/state_preparation.py +301 -0
- classiq/open_library/functions/swap_test.py +27 -0
- classiq/open_library/functions/utility_functions.py +81 -0
- classiq/open_library/functions/variational.py +52 -0
- classiq/qmod/__init__.py +17 -10
- classiq/qmod/builtins/__init__.py +19 -2
- classiq/qmod/builtins/classical_execution_primitives.py +60 -47
- classiq/qmod/builtins/classical_functions.py +44 -38
- classiq/qmod/builtins/constants.py +10 -0
- classiq/qmod/builtins/enums.py +208 -0
- classiq/qmod/builtins/functions/__init__.py +137 -0
- classiq/qmod/builtins/functions/allocation.py +150 -0
- classiq/qmod/builtins/functions/arithmetic.py +55 -0
- classiq/qmod/builtins/functions/benchmarking.py +8 -0
- classiq/qmod/builtins/functions/chemistry.py +91 -0
- classiq/qmod/builtins/functions/exponentiation.py +105 -0
- classiq/qmod/builtins/functions/finance.py +34 -0
- classiq/qmod/builtins/functions/operators.py +16 -0
- classiq/qmod/builtins/functions/qsvm.py +24 -0
- classiq/qmod/builtins/functions/standard_gates.py +651 -0
- classiq/qmod/builtins/operations.py +379 -57
- classiq/qmod/builtins/structs.py +103 -80
- classiq/qmod/cfunc.py +42 -0
- classiq/qmod/classical_function.py +8 -20
- classiq/qmod/cparam.py +64 -0
- classiq/qmod/create_model_function.py +56 -0
- classiq/qmod/declaration_inferrer.py +145 -112
- classiq/qmod/expression_query.py +39 -0
- classiq/qmod/generative.py +42 -0
- classiq/qmod/model_state_container.py +19 -5
- classiq/qmod/native/__init__.py +7 -0
- classiq/qmod/native/expression_to_qmod.py +194 -0
- classiq/qmod/native/pretty_printer.py +401 -0
- classiq/qmod/pretty_print/__init__.py +7 -0
- classiq/qmod/pretty_print/expression_to_python.py +222 -0
- classiq/qmod/pretty_print/pretty_printer.py +572 -0
- classiq/qmod/python_classical_type.py +67 -0
- classiq/qmod/qfunc.py +79 -0
- classiq/qmod/qmod_constant.py +143 -0
- classiq/qmod/qmod_parameter.py +84 -53
- classiq/qmod/qmod_variable.py +497 -100
- classiq/qmod/quantum_callable.py +17 -7
- classiq/qmod/quantum_expandable.py +278 -105
- classiq/qmod/quantum_function.py +232 -48
- classiq/qmod/semantics/__init__.py +0 -0
- classiq/qmod/semantics/annotation/__init__.py +0 -0
- classiq/qmod/semantics/annotation/call_annotation.py +92 -0
- classiq/qmod/semantics/annotation/qstruct_annotator.py +23 -0
- classiq/qmod/semantics/error_manager.py +88 -0
- classiq/qmod/semantics/lambdas.py +25 -0
- classiq/qmod/semantics/static_semantics_visitor.py +384 -0
- classiq/qmod/semantics/validation/__init__.py +0 -0
- classiq/qmod/semantics/validation/constants_validation.py +16 -0
- classiq/qmod/semantics/validation/func_call_validation.py +99 -0
- classiq/qmod/semantics/validation/function_name_collisions_validation.py +23 -0
- classiq/qmod/semantics/validation/handle_validation.py +85 -0
- classiq/qmod/semantics/validation/main_validation.py +33 -0
- classiq/qmod/semantics/validation/types_validation.py +128 -0
- classiq/qmod/symbolic.py +178 -111
- classiq/qmod/symbolic_expr.py +36 -12
- classiq/qmod/symbolic_type.py +2 -5
- classiq/qmod/type_attribute_remover.py +32 -0
- classiq/qmod/utilities.py +108 -1
- classiq/qmod/write_qmod.py +53 -0
- classiq/synthesis.py +210 -22
- {classiq-0.37.1.dist-info → classiq-0.65.3.dist-info}/METADATA +16 -8
- classiq-0.65.3.dist-info/RECORD +521 -0
- {classiq-0.37.1.dist-info → classiq-0.65.3.dist-info}/WHEEL +1 -1
- classiq/_internals/_qfunc_ext.py +0 -6
- classiq/applications/benchmarking/__init__.py +0 -9
- classiq/applications/benchmarking/mirror_benchmarking.py +0 -67
- classiq/applications/numpy_utils.py +0 -37
- classiq/applications_model_constructors/__init__.py +0 -17
- classiq/applications_model_constructors/combinatorial_optimization_model_constructor.py +0 -178
- classiq/applications_model_constructors/grover_model_constructor.py +0 -227
- classiq/applications_model_constructors/libraries/ampltitude_estimation_library.py +0 -11
- classiq/applications_model_constructors/libraries/qmci_library.py +0 -109
- classiq/builtin_functions/__init__.py +0 -43
- classiq/builtin_functions/amplitude_loading.py +0 -3
- classiq/builtin_functions/binary_ops.py +0 -1
- classiq/builtin_functions/exponentiation.py +0 -5
- classiq/builtin_functions/qpe.py +0 -4
- classiq/builtin_functions/qsvm.py +0 -7
- classiq/builtin_functions/range_types.py +0 -5
- classiq/builtin_functions/standard_gates.py +0 -1
- classiq/builtin_functions/state_preparation.py +0 -6
- classiq/builtin_functions/suzuki_trotter.py +0 -3
- classiq/exceptions.py +0 -131
- classiq/interface/executor/aws_execution_cost.py +0 -72
- classiq/interface/executor/error_mitigation.py +0 -6
- classiq/interface/generator/credit_risk_example/linear_gci.py +0 -115
- classiq/interface/generator/credit_risk_example/weighted_adder.py +0 -59
- classiq/interface/generator/expressions/enums/chemistry.py +0 -28
- classiq/interface/generator/expressions/enums/classical_enum.py +0 -5
- classiq/interface/generator/expressions/enums/ladder_operator.py +0 -16
- classiq/interface/generator/expressions/enums/optimizers.py +0 -9
- classiq/interface/generator/expressions/enums/pauli.py +0 -8
- classiq/interface/generator/expressions/enums/qsvm_feature_map_entanglement.py +0 -9
- classiq/interface/generator/expressions/qmod_qnum_proxy.py +0 -22
- classiq/interface/generator/functions/core_lib_declarations/quantum_functions/__init__.py +0 -18
- classiq/interface/generator/functions/core_lib_declarations/quantum_functions/atomic_quantum_functions.py +0 -641
- classiq/interface/generator/functions/core_lib_declarations/quantum_functions/exponentiation_functions.py +0 -89
- classiq/interface/generator/functions/core_lib_declarations/quantum_functions/std_lib_functions.py +0 -862
- classiq/interface/generator/functions/core_lib_declarations/quantum_operators.py +0 -169
- classiq/interface/generator/functions/foreign_function_definition.py +0 -106
- classiq/interface/generator/functions/function_implementation.py +0 -103
- classiq/interface/generator/functions/native_function_definition.py +0 -153
- classiq/interface/generator/functions/quantum_function_declaration.py +0 -69
- classiq/interface/generator/functions/register.py +0 -42
- classiq/interface/generator/functions/register_mapping_data.py +0 -102
- classiq/interface/generator/inequality_mixer.py +0 -51
- classiq/interface/generator/model/classical_main_validator.py +0 -106
- classiq/interface/generator/range_mixer.py +0 -56
- classiq/interface/generator/state_propagator.py +0 -63
- classiq/interface/generator/types/builtin_struct_declarations/__init__.py +0 -2
- classiq/interface/generator/types/builtin_struct_declarations/pauli_struct_declarations.py +0 -22
- classiq/interface/generator/types/builtin_struct_declarations/qaoa_declarations.py +0 -23
- classiq/interface/generator/types/combinatorial_problem.py +0 -26
- classiq/interface/ide/show.py +0 -34
- classiq/interface/model/common_model_types.py +0 -23
- classiq/interface/model/numeric_reinterpretation.py +0 -25
- classiq/interface/model/operator_synthesis_data.py +0 -48
- classiq/interface/model/quantum_expressions/control_state.py +0 -38
- classiq/interface/model/quantum_if_operation.py +0 -95
- classiq/interface/model/resolvers/function_call_resolver.py +0 -43
- classiq/interface/model/validations/handle_validation_base.py +0 -55
- classiq/interface/model/validations/handles_validator.py +0 -154
- classiq/interface/model/validations/port_to_wire_name_generator.py +0 -12
- classiq/model/__init__.py +0 -14
- classiq/model/composite_function_generator.py +0 -33
- classiq/model/function_handler.py +0 -466
- classiq/model/function_handler.pyi +0 -152
- classiq/model/logic_flow.py +0 -149
- classiq/model/logic_flow_change_handler.py +0 -71
- classiq/model/model.py +0 -246
- classiq/qmod/builtins/functions.py +0 -896
- classiq/qmod/qmod_struct.py +0 -37
- classiq/quantum_functions/__init__.py +0 -17
- classiq/quantum_functions/annotation_parser.py +0 -207
- classiq/quantum_functions/decorators.py +0 -22
- classiq/quantum_functions/function_library.py +0 -181
- classiq/quantum_functions/function_parser.py +0 -74
- classiq/quantum_functions/quantum_function.py +0 -236
- classiq-0.37.1.dist-info/RECORD +0 -418
- /classiq/{applications_model_constructors/libraries → applications/combinatorial_helpers}/__init__.py +0 -0
- /classiq/{interface/generator/credit_risk_example → applications/combinatorial_helpers/arithmetic}/__init__.py +0 -0
- /classiq/{interface/generator/functions/core_lib_declarations → applications/combinatorial_helpers/pauli_helpers}/__init__.py +0 -0
- /classiq/{interface/generator/functions/core_lib_declarations/quantum_functions/chemistry_functions.py → applications/combinatorial_helpers/py.typed} +0 -0
- /classiq/{interface/model/resolvers → applications/combinatorial_helpers/solvers}/__init__.py +0 -0
- /classiq/{interface/model/validations → applications/combinatorial_helpers/transformations}/__init__.py +0 -0
- /classiq/{_internals → interface}/enum_utils.py +0 -0
@@ -1,17 +1,24 @@
|
|
1
|
-
from
|
1
|
+
from collections.abc import Sequence
|
2
|
+
from enum import IntEnum
|
3
|
+
from typing import TYPE_CHECKING, Annotated, Any, Optional, Union
|
2
4
|
|
3
5
|
import pydantic
|
4
|
-
from
|
6
|
+
from pydantic import Field
|
7
|
+
from pydantic_core.core_schema import ValidationInfo
|
8
|
+
from typing_extensions import Self, TypeAlias
|
5
9
|
|
6
10
|
from classiq.interface.backend.backend_preferences import (
|
7
11
|
BackendPreferences,
|
8
|
-
validate_backend_service_provider,
|
9
12
|
)
|
10
13
|
from classiq.interface.backend.quantum_backend_providers import (
|
11
14
|
AllBackendsNameByVendor,
|
12
15
|
ProviderVendor,
|
13
16
|
)
|
14
|
-
from classiq.interface.
|
17
|
+
from classiq.interface.enum_utils import StrEnum
|
18
|
+
from classiq.interface.exceptions import ClassiqValueError
|
19
|
+
from classiq.interface.generator.arith.machine_precision import (
|
20
|
+
DEFAULT_MACHINE_PRECISION,
|
21
|
+
)
|
15
22
|
from classiq.interface.generator.hardware.hardware_data import (
|
16
23
|
BACKEND_VALIDATION_ERROR_MESSAGE,
|
17
24
|
CustomHardwareSettings,
|
@@ -20,19 +27,17 @@ from classiq.interface.generator.model.preferences.randomness import create_rand
|
|
20
27
|
from classiq.interface.hardware import Provider
|
21
28
|
from classiq.interface.helpers.custom_pydantic_types import PydanticMachinePrecision
|
22
29
|
|
23
|
-
from classiq._internals.enum_utils import StrEnum
|
24
|
-
|
25
30
|
if TYPE_CHECKING:
|
26
31
|
VisualizationLevel: TypeAlias = Optional[int]
|
27
32
|
else:
|
28
|
-
VisualizationLevel: TypeAlias = Optional[
|
33
|
+
VisualizationLevel: TypeAlias = Optional[Annotated[int, Field(ge=-1)]]
|
29
34
|
|
30
35
|
if TYPE_CHECKING:
|
31
36
|
PydanticBackendName = str
|
32
37
|
else:
|
33
|
-
PydanticBackendName =
|
34
|
-
strict=True, min_length=1,
|
35
|
-
|
38
|
+
PydanticBackendName = Annotated[
|
39
|
+
str, Field(strict=True, min_length=1, pattern="^([.A-Za-z0-9_-]*)$")
|
40
|
+
]
|
36
41
|
|
37
42
|
|
38
43
|
class QuantumFormat(StrEnum):
|
@@ -44,7 +49,7 @@ class QuantumFormat(StrEnum):
|
|
44
49
|
QASM_CIRQ_COMPATIBLE = "qasm_cirq_compatible"
|
45
50
|
|
46
51
|
|
47
|
-
_SERVICE_PROVIDER_TO_FORMAT:
|
52
|
+
_SERVICE_PROVIDER_TO_FORMAT: dict[Provider, QuantumFormat] = {
|
48
53
|
Provider.CLASSIQ: QuantumFormat.QASM,
|
49
54
|
Provider.IONQ: QuantumFormat.IONQ,
|
50
55
|
Provider.AZURE_QUANTUM: QuantumFormat.QSHARP,
|
@@ -53,11 +58,18 @@ _SERVICE_PROVIDER_TO_FORMAT: Dict[Provider, QuantumFormat] = {
|
|
53
58
|
}
|
54
59
|
|
55
60
|
if TYPE_CHECKING:
|
56
|
-
PydanticConstrainedQuantumFormatList =
|
61
|
+
PydanticConstrainedQuantumFormatList = list[QuantumFormat]
|
57
62
|
else:
|
58
|
-
PydanticConstrainedQuantumFormatList =
|
59
|
-
QuantumFormat,
|
60
|
-
|
63
|
+
PydanticConstrainedQuantumFormatList = Annotated[
|
64
|
+
list[QuantumFormat], Field(min_length=1, max_length=len(QuantumFormat))
|
65
|
+
]
|
66
|
+
|
67
|
+
|
68
|
+
class OptimizationLevel(IntEnum):
|
69
|
+
NONE = 0
|
70
|
+
LIGHT = 1
|
71
|
+
MEDIUM = 2
|
72
|
+
HIGH = 3
|
61
73
|
|
62
74
|
|
63
75
|
class TranspilationOption(StrEnum):
|
@@ -73,11 +85,60 @@ class TranspilationOption(StrEnum):
|
|
73
85
|
return self != TranspilationOption.NONE
|
74
86
|
|
75
87
|
|
76
|
-
class Preferences(pydantic.BaseModel, extra=
|
88
|
+
class Preferences(pydantic.BaseModel, extra="forbid"):
|
89
|
+
"""
|
90
|
+
Preferences for synthesizing a quantum circuit.
|
91
|
+
|
92
|
+
Attributes:
|
93
|
+
machine_precision (int): Specifies the precision used for quantum operations.
|
94
|
+
Defaults to `DEFAULT_MACHINE_PRECISION`.
|
95
|
+
backend_service_provider (str): The provider company or cloud service for the
|
96
|
+
requested backend. Defaults to `None`.
|
97
|
+
backend_name (str): The name of the requested backend or target. Defaults to `None`.
|
98
|
+
custom_hardware_settings (CustomHardwareSettings): Defines custom hardware
|
99
|
+
settings for optimization. This field is ignored if backend preferences are
|
100
|
+
specified.
|
101
|
+
debug_mode (bool): If `True`, debug information is added to the
|
102
|
+
synthesized result, potentially slowing down the synthesis. Useful for
|
103
|
+
executing interactive algorithms. Defaults to `True`.
|
104
|
+
output_format (List[QuantumFormat]): Lists the output format(s)
|
105
|
+
for the quantum circuit. Defaults to `[QuantumFormat.QASM]`.
|
106
|
+
`QuantumFormat` Options:
|
107
|
+
- QASM = "qasm"
|
108
|
+
- QSHARP = "qsharp"
|
109
|
+
- QIR = "qir"
|
110
|
+
- IONQ = "ionq"
|
111
|
+
- CIRQ_JSON = "cirq_json"
|
112
|
+
- QASM_CIRQ_COMPATIBLE = "qasm_cirq_compatible"
|
113
|
+
pretty_qasm (bool): If `True`, formats OpenQASM 2 outputs with line breaks
|
114
|
+
inside gate declarations, improving readability. Defaults to `True`.
|
115
|
+
qasm3 (Optional[bool]): If `True`, outputs OpenQASM 3.0 in addition to 2.0,
|
116
|
+
applicable to relevant attributes in `GeneratedCircuit`. Defaults to `None`.
|
117
|
+
transpilation_option (TranspilationOption): Sets the transpilation option to
|
118
|
+
optimize the circuit. Defaults to `AUTO_OPTIMIZE`. See `TranspilationOption`
|
119
|
+
solovay_kitaev_max_iterations (Optional[int]): Specifies the
|
120
|
+
maximum number of iterations for the Solovay-Kitaev algorithm, if used.
|
121
|
+
Defaults to `None`.
|
122
|
+
timeout_seconds (int): Timeout setting for circuit synthesis
|
123
|
+
in seconds. Defaults to `300`.
|
124
|
+
optimization_timeout_seconds (Optional[int]): Specifies the
|
125
|
+
timeout for optimization in seconds, or `None` for no optimization timeout.
|
126
|
+
This will still adhere to the overall synthesis timeout. Defaults to `None`.
|
127
|
+
random_seed (int): Random seed for circuit synthesis.
|
128
|
+
|
129
|
+
Raises:
|
130
|
+
ClassiqValueError:
|
131
|
+
- If the optimization timeout is greater than or equal to the synthesis timeout.
|
132
|
+
- If the `output_format` contains duplicate entries.
|
133
|
+
- If `backend_name` is provided without `backend_service_provider` or vice versa.
|
134
|
+
ValueError:
|
135
|
+
- If `backend_service_provider` is not valid.
|
136
|
+
"""
|
137
|
+
|
77
138
|
_backend_preferences: Optional[BackendPreferences] = pydantic.PrivateAttr(
|
78
139
|
default=None
|
79
140
|
)
|
80
|
-
machine_precision: PydanticMachinePrecision =
|
141
|
+
machine_precision: PydanticMachinePrecision = DEFAULT_MACHINE_PRECISION
|
81
142
|
|
82
143
|
backend_service_provider: Optional[Union[Provider, ProviderVendor, str]] = (
|
83
144
|
pydantic.Field(
|
@@ -101,6 +162,15 @@ class Preferences(pydantic.BaseModel, extra=pydantic.Extra.forbid):
|
|
101
162
|
"Setting this option to False can potentially speed up the synthesis, and is "
|
102
163
|
"recommended for executing iterative algorithms.",
|
103
164
|
)
|
165
|
+
synthesize_all_separately: bool = pydantic.Field(
|
166
|
+
default=False,
|
167
|
+
description="If true, a heuristic is used to determine if a function should be synthesized separately",
|
168
|
+
deprecated=True,
|
169
|
+
)
|
170
|
+
optimization_level: OptimizationLevel = pydantic.Field(
|
171
|
+
default=OptimizationLevel.HIGH,
|
172
|
+
description="The optimization level used during synthesis; determines the trade-off between synthesis speed and the quality of the results",
|
173
|
+
)
|
104
174
|
output_format: PydanticConstrainedQuantumFormatList = pydantic.Field(
|
105
175
|
default=[QuantumFormat.QASM],
|
106
176
|
description="The quantum circuit output format(s). ",
|
@@ -124,6 +194,11 @@ class Preferences(pydantic.BaseModel, extra=pydantic.Extra.forbid):
|
|
124
194
|
"transpiled circuit and its depth",
|
125
195
|
)
|
126
196
|
|
197
|
+
solovay_kitaev_max_iterations: Optional[pydantic.PositiveInt] = pydantic.Field(
|
198
|
+
None,
|
199
|
+
description="Maximum iterations for the Solovay-Kitaev algorithm (if applied).",
|
200
|
+
)
|
201
|
+
|
127
202
|
timeout_seconds: pydantic.PositiveInt = pydantic.Field(
|
128
203
|
default=300, description="Generation timeout in seconds"
|
129
204
|
)
|
@@ -133,55 +208,51 @@ class Preferences(pydantic.BaseModel, extra=pydantic.Extra.forbid):
|
|
133
208
|
description="Optimization timeout in seconds, or None for no "
|
134
209
|
"optimization timeout (will still timeout when the generation timeout is over)",
|
135
210
|
)
|
136
|
-
|
137
211
|
random_seed: int = pydantic.Field(
|
138
212
|
default_factory=create_random_seed,
|
139
213
|
description="The random seed used for the generation",
|
140
214
|
)
|
141
215
|
|
142
|
-
@pydantic.
|
143
|
-
|
144
|
-
cls, backend_service_provider: Any
|
145
|
-
) -> Optional[Provider]:
|
146
|
-
if backend_service_provider is None:
|
147
|
-
return None
|
148
|
-
return validate_backend_service_provider(backend_service_provider)
|
149
|
-
|
150
|
-
@pydantic.validator("optimization_timeout_seconds")
|
216
|
+
@pydantic.field_validator("optimization_timeout_seconds", mode="before")
|
217
|
+
@classmethod
|
151
218
|
def optimization_timeout_less_than_generation_timeout(
|
152
219
|
cls,
|
153
220
|
optimization_timeout_seconds: Optional[pydantic.PositiveInt],
|
154
|
-
|
221
|
+
info: ValidationInfo,
|
155
222
|
) -> Optional[pydantic.PositiveInt]:
|
156
|
-
generation_timeout_seconds =
|
223
|
+
generation_timeout_seconds = info.data.get("timeout_seconds")
|
157
224
|
if generation_timeout_seconds is None or optimization_timeout_seconds is None:
|
158
225
|
return optimization_timeout_seconds
|
159
226
|
if optimization_timeout_seconds >= generation_timeout_seconds:
|
160
|
-
raise
|
227
|
+
raise ClassiqValueError(
|
161
228
|
f"Generation timeout ({generation_timeout_seconds})"
|
162
229
|
f"is greater than or equal to "
|
163
230
|
f"optimization timeout ({optimization_timeout_seconds}) "
|
164
231
|
)
|
165
232
|
return optimization_timeout_seconds
|
166
233
|
|
167
|
-
@pydantic.
|
168
|
-
|
169
|
-
|
234
|
+
@pydantic.field_validator("output_format", mode="before")
|
235
|
+
@classmethod
|
236
|
+
def make_output_format_list(cls, output_format: Any) -> list:
|
237
|
+
if not isinstance(output_format, Sequence) or isinstance(output_format, str):
|
170
238
|
output_format = [output_format]
|
171
239
|
|
172
240
|
return output_format
|
173
241
|
|
174
|
-
@pydantic.
|
242
|
+
@pydantic.field_validator("output_format", mode="before")
|
243
|
+
@classmethod
|
175
244
|
def validate_output_format(
|
176
|
-
cls,
|
245
|
+
cls,
|
246
|
+
output_format: PydanticConstrainedQuantumFormatList,
|
247
|
+
info: ValidationInfo,
|
177
248
|
) -> PydanticConstrainedQuantumFormatList:
|
178
249
|
if len(output_format) != len(set(output_format)):
|
179
|
-
raise
|
250
|
+
raise ClassiqValueError(
|
180
251
|
f"output_format={output_format}\n"
|
181
252
|
"has at least one format that appears twice or more"
|
182
253
|
)
|
183
254
|
|
184
|
-
service_provider =
|
255
|
+
service_provider = info.data.get("backend_service_provider")
|
185
256
|
if service_provider is None:
|
186
257
|
return output_format
|
187
258
|
|
@@ -191,16 +262,20 @@ class Preferences(pydantic.BaseModel, extra=pydantic.Extra.forbid):
|
|
191
262
|
|
192
263
|
return output_format
|
193
264
|
|
194
|
-
@pydantic.
|
195
|
-
def validate_backend(
|
196
|
-
backend_name =
|
197
|
-
backend_service_provider =
|
265
|
+
@pydantic.model_validator(mode="after")
|
266
|
+
def validate_backend(self) -> Self:
|
267
|
+
backend_name = self.backend_name
|
268
|
+
backend_service_provider = self.backend_service_provider
|
198
269
|
if (backend_name is None) != (backend_service_provider is None):
|
199
|
-
raise
|
200
|
-
return
|
270
|
+
raise ClassiqValueError(BACKEND_VALIDATION_ERROR_MESSAGE)
|
271
|
+
return self
|
201
272
|
|
202
273
|
@property
|
203
274
|
def backend_preferences(self) -> Optional[BackendPreferences]:
|
275
|
+
"""
|
276
|
+
Returns the backend preferences. If the backend preferences are not provided, the function sets the backend preferences according to backend name and provider.
|
277
|
+
|
278
|
+
"""
|
204
279
|
if self.backend_name is None or self.backend_service_provider is None:
|
205
280
|
return None
|
206
281
|
if self._backend_preferences is None:
|
@@ -1,8 +1,15 @@
|
|
1
1
|
import itertools
|
2
2
|
import sys
|
3
|
-
from
|
4
|
-
from
|
3
|
+
from collections.abc import Iterator
|
4
|
+
from types import GenericAlias as TypesGenericAlias
|
5
|
+
from typing import ( # type: ignore[attr-defined]
|
6
|
+
Any,
|
7
|
+
Optional,
|
8
|
+
Union,
|
9
|
+
_GenericAlias,
|
10
|
+
)
|
5
11
|
|
12
|
+
from classiq.interface.exceptions import ClassiqQRegError
|
6
13
|
from classiq.interface.generator.arith.register_user_input import (
|
7
14
|
RegisterArithmeticInfo,
|
8
15
|
RegisterUserInput,
|
@@ -10,16 +17,11 @@ from classiq.interface.generator.arith.register_user_input import (
|
|
10
17
|
from classiq.interface.generator.function_params import ArithmeticIODict, IOName
|
11
18
|
from classiq.interface.generator.register_role import RegisterRole
|
12
19
|
|
13
|
-
from classiq.exceptions import ClassiqQRegError
|
14
|
-
|
15
|
-
if sys.version_info >= (3, 9):
|
16
|
-
from types import GenericAlias as TypesGenericAlias
|
17
|
-
|
18
20
|
|
19
21
|
# This class is used for QReg, to support type-hint initialization
|
20
22
|
# Due to the `size` property of QReg
|
21
23
|
class QRegGenericAlias(_GenericAlias, _root=True): # type: ignore[call-arg]
|
22
|
-
def __call__(self, *args, **kwargs):
|
24
|
+
def __call__(self, *args: Any, **kwargs: Any) -> Any:
|
23
25
|
arith_info = {}
|
24
26
|
if self.size is not None:
|
25
27
|
arith_info["size"] = self.size
|
@@ -48,13 +50,13 @@ class QRegGenericAlias(_GenericAlias, _root=True): # type: ignore[call-arg]
|
|
48
50
|
|
49
51
|
@property
|
50
52
|
def integer_places(self) -> Optional[int]:
|
51
|
-
if len(self.__args__) in (1, 2) and
|
53
|
+
if len(self.__args__) in (1, 2) and isinstance(self.__args__[0], int):
|
52
54
|
return self.__args__[0]
|
53
55
|
return None
|
54
56
|
|
55
57
|
@property
|
56
58
|
def fraction_places(self) -> Optional[int]:
|
57
|
-
if len(self.__args__) == 2 and
|
59
|
+
if len(self.__args__) == 2 and isinstance(self.__args__[1], int):
|
58
60
|
return self.__args__[1]
|
59
61
|
return None
|
60
62
|
|
@@ -73,14 +75,17 @@ class QReg:
|
|
73
75
|
"""Initializes a new QReg with the specified number of qubits.
|
74
76
|
|
75
77
|
Args:
|
76
|
-
size
|
78
|
+
size: The number of qubits in the QReg.
|
77
79
|
"""
|
78
80
|
if size <= 0:
|
79
81
|
raise ClassiqQRegError(f"Cannot create {size} new qubits")
|
80
82
|
self._qubits = [Qubit() for _ in range(size)]
|
81
83
|
|
84
|
+
def __hash__(self) -> int:
|
85
|
+
return super.__hash__(self)
|
86
|
+
|
82
87
|
@classmethod
|
83
|
-
def _from_qubits(cls, qubits:
|
88
|
+
def _from_qubits(cls, qubits: list[Qubit]) -> "QReg":
|
84
89
|
if (
|
85
90
|
not isinstance(qubits, list)
|
86
91
|
or not all(isinstance(qubit, Qubit) for qubit in qubits)
|
@@ -102,7 +107,7 @@ class QReg:
|
|
102
107
|
)
|
103
108
|
self._qubits[key] = value._qubits[0] if isinstance(key, int) else value._qubits # type: ignore[call-overload]
|
104
109
|
|
105
|
-
def __iter__(self):
|
110
|
+
def __iter__(self) -> Iterator["QReg"]:
|
106
111
|
return iter([self[idx] for idx in range(len(self))])
|
107
112
|
|
108
113
|
def __eq__(self, other: Any) -> bool:
|
@@ -131,12 +136,12 @@ class QReg:
|
|
131
136
|
return len(self._qubits)
|
132
137
|
|
133
138
|
@property
|
134
|
-
def qubits(self) ->
|
139
|
+
def qubits(self) -> list[Qubit]:
|
135
140
|
return self._qubits
|
136
141
|
|
137
142
|
def __class_getitem__(cls, params: Any) -> QRegGenericAlias:
|
138
143
|
# Supporting python 3.7+, thus returning `typing._GenericAlias` instead of `types.GenericAlias`
|
139
|
-
if
|
144
|
+
if isinstance(params, int):
|
140
145
|
return QRegGenericAlias(cls, params)
|
141
146
|
|
142
147
|
raise ClassiqQRegError(f"Invalid size: {params} ; int required")
|
@@ -171,8 +176,8 @@ class QSFixed(QReg):
|
|
171
176
|
if (
|
172
177
|
type(params) is tuple
|
173
178
|
and len(params) == 2
|
174
|
-
and
|
175
|
-
and
|
179
|
+
and isinstance(params[0], int)
|
180
|
+
and isinstance(params[1], int)
|
176
181
|
):
|
177
182
|
return QRegGenericAlias(cls, params)
|
178
183
|
|
@@ -221,7 +226,7 @@ _PROP_TO_QREG_TYPE = {
|
|
221
226
|
}
|
222
227
|
|
223
228
|
|
224
|
-
def _get_qreg_type_from_arithmetic_info(info: RegisterArithmeticInfo) ->
|
229
|
+
def _get_qreg_type_from_arithmetic_info(info: RegisterArithmeticInfo) -> type["QReg"]:
|
225
230
|
return _PROP_TO_QREG_TYPE[(info.is_signed, info.is_frac)]
|
226
231
|
|
227
232
|
|
@@ -237,7 +242,7 @@ def _get_qreg_generic_alias_from_arithmetic_info(
|
|
237
242
|
|
238
243
|
def get_type_and_size_dict(
|
239
244
|
arithmetic_info_dict: ArithmeticIODict,
|
240
|
-
) ->
|
245
|
+
) -> dict[IOName, QRegGenericAlias]:
|
241
246
|
return {
|
242
247
|
io_name: _get_qreg_generic_alias_from_arithmetic_info(info)
|
243
248
|
for io_name, info in arithmetic_info_dict.items()
|
@@ -245,11 +250,11 @@ def get_type_and_size_dict(
|
|
245
250
|
|
246
251
|
|
247
252
|
__all__ = [
|
253
|
+
"AuxQReg",
|
248
254
|
"QReg",
|
249
|
-
"QSInt",
|
250
|
-
"QUInt",
|
251
255
|
"QSFixed",
|
256
|
+
"QSInt",
|
252
257
|
"QUFixed",
|
258
|
+
"QUInt",
|
253
259
|
"ZeroQReg",
|
254
|
-
"AuxQReg",
|
255
260
|
]
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import ast
|
2
2
|
import re
|
3
|
-
from typing import Dict
|
4
3
|
|
5
4
|
import numexpr # type: ignore[import]
|
6
5
|
|
6
|
+
from classiq.interface.exceptions import ClassiqArithmeticError, ClassiqValueError
|
7
7
|
from classiq.interface.generator.arith import number_utils
|
8
8
|
from classiq.interface.generator.arith.arithmetic import Arithmetic
|
9
9
|
from classiq.interface.generator.arith.arithmetic_expression_abc import (
|
@@ -17,8 +17,6 @@ from classiq.interface.generator.oracles.oracle_abc import (
|
|
17
17
|
VariableTypedResultMap,
|
18
18
|
)
|
19
19
|
|
20
|
-
from classiq.exceptions import ClassiqArithmeticError, ClassiqValueError
|
21
|
-
|
22
20
|
|
23
21
|
class ArithmeticOracle(OracleABC[float], ArithmeticExpressionABC):
|
24
22
|
@staticmethod
|
@@ -62,7 +60,7 @@ class ArithmeticOracle(OracleABC[float], ArithmeticExpressionABC):
|
|
62
60
|
|
63
61
|
@staticmethod
|
64
62
|
def _simplify_negations_of_boolean_variables(
|
65
|
-
expression: str, input_definitions:
|
63
|
+
expression: str, input_definitions: dict[str, RegisterArithmeticInfo]
|
66
64
|
) -> str:
|
67
65
|
for var_name in input_definitions:
|
68
66
|
if getattr(input_definitions[var_name], "size", 0) == 1:
|
@@ -1,7 +1,8 @@
|
|
1
|
-
from typing import Any
|
1
|
+
from typing import Any
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
|
5
|
+
from classiq.interface.exceptions import ClassiqValueError
|
5
6
|
from classiq.interface.generator.function_params import parse_function_params_values
|
6
7
|
from classiq.interface.generator.oracles.oracle_abc import (
|
7
8
|
ArithmeticIODict,
|
@@ -21,30 +22,33 @@ class CustomOracle(OracleABC[QubitState]):
|
|
21
22
|
default_factory=CustomFunction,
|
22
23
|
)
|
23
24
|
|
24
|
-
@pydantic.
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
25
|
+
@pydantic.model_validator(mode="before")
|
26
|
+
@classmethod
|
27
|
+
def _parse_oracle(cls, values: Any) -> dict[str, Any]:
|
28
|
+
if isinstance(values, dict):
|
29
|
+
parse_function_params_values(
|
30
|
+
values=values,
|
31
|
+
params_key="custom_oracle_params",
|
32
|
+
discriminator_key="custom_oracle",
|
33
|
+
param_classes={CustomFunction},
|
34
|
+
default_parser_class=CustomFunction,
|
35
|
+
)
|
33
36
|
return values
|
34
37
|
|
35
|
-
@pydantic.
|
38
|
+
@pydantic.field_validator("custom_oracle_params")
|
39
|
+
@classmethod
|
36
40
|
def _validate_names_match_oracle(
|
37
41
|
cls, custom_oracle_params: CustomFunction
|
38
42
|
) -> CustomFunction:
|
39
43
|
if set(custom_oracle_params.input_decls.keys()) != set(
|
40
44
|
custom_oracle_params.output_decls.keys()
|
41
45
|
):
|
42
|
-
raise
|
46
|
+
raise ClassiqValueError("Oracle IO names must be identical")
|
43
47
|
if any(
|
44
48
|
custom_oracle_params.output_decls[name].size != input_decl.size
|
45
49
|
for name, input_decl in custom_oracle_params.input_decls.items()
|
46
50
|
):
|
47
|
-
raise
|
51
|
+
raise ClassiqValueError("Oracle IO sizes must be identical")
|
48
52
|
return custom_oracle_params
|
49
53
|
|
50
54
|
def _get_register_transputs(self) -> ArithmeticIODict:
|
@@ -1,19 +1,19 @@
|
|
1
1
|
import abc
|
2
|
-
from
|
2
|
+
from collections.abc import Sequence
|
3
|
+
from typing import Generic, Optional, TypeVar
|
3
4
|
|
4
5
|
import numpy as np
|
5
6
|
|
7
|
+
from classiq.interface.exceptions import ClassiqOracleError
|
6
8
|
from classiq.interface.executor.result import State
|
7
9
|
from classiq.interface.generator.arith.register_user_input import RegisterUserInput
|
8
10
|
from classiq.interface.generator.function_params import ArithmeticIODict, FunctionParams
|
9
11
|
from classiq.interface.generator.generated_circuit_data import IOQubitMapping
|
10
12
|
|
11
|
-
from classiq.exceptions import ClassiqOracleError
|
12
|
-
|
13
13
|
ProblemResultType = TypeVar("ProblemResultType")
|
14
14
|
|
15
|
-
VariableBinResultMap =
|
16
|
-
VariableTypedResultMap =
|
15
|
+
VariableBinResultMap = dict[str, State]
|
16
|
+
VariableTypedResultMap = dict[str, ProblemResultType]
|
17
17
|
|
18
18
|
|
19
19
|
class OracleABC(abc.ABC, FunctionParams, Generic[ProblemResultType]):
|
@@ -59,11 +59,11 @@ class OracleABC(abc.ABC, FunctionParams, Generic[ProblemResultType]):
|
|
59
59
|
) -> bool:
|
60
60
|
pass
|
61
61
|
|
62
|
-
def variables(self) ->
|
63
|
-
return
|
62
|
+
def variables(self) -> list[RegisterUserInput]:
|
63
|
+
return [
|
64
64
|
RegisterUserInput.from_arithmetic_info(info=info, name=name)
|
65
65
|
for name, info in self._inputs.items()
|
66
|
-
|
66
|
+
]
|
67
67
|
|
68
68
|
def _check_indices(self, indices: IOQubitMapping) -> None:
|
69
69
|
if set(indices.keys()) != {reg.name for reg in self.variables()}:
|
@@ -72,5 +72,5 @@ class OracleABC(abc.ABC, FunctionParams, Generic[ProblemResultType]):
|
|
72
72
|
)
|
73
73
|
|
74
74
|
|
75
|
-
def _reverse_endianness(indices: Sequence[int], state_length: int) ->
|
75
|
+
def _reverse_endianness(indices: Sequence[int], state_length: int) -> list[int]:
|
76
76
|
return [state_length - 1 - index for index in indices]
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import itertools
|
2
|
+
from collections.abc import Iterator
|
2
3
|
from dataclasses import dataclass
|
3
|
-
from typing import
|
4
|
+
from typing import Optional
|
4
5
|
|
6
|
+
from classiq.interface.exceptions import ClassiqValueError
|
5
7
|
from classiq.interface.generator.slice_parsing_utils import parse_io_slicing
|
6
8
|
|
7
|
-
from classiq.exceptions import ClassiqValueError
|
8
|
-
|
9
9
|
|
10
10
|
@dataclass(frozen=True)
|
11
11
|
class PartitionedRegister:
|
@@ -13,7 +13,7 @@ class PartitionedRegister:
|
|
13
13
|
|
14
14
|
# There are up to num_qubits qubits within the partitions, with unique values from 0 to num_qubits-1
|
15
15
|
num_qubits: int
|
16
|
-
partitions:
|
16
|
+
partitions: tuple[tuple[int, ...], ...]
|
17
17
|
|
18
18
|
def __post_init__(self) -> None:
|
19
19
|
if not self.partitions:
|
@@ -48,7 +48,7 @@ class PartitionedRegister:
|
|
48
48
|
return RegisterPartition(self, _index=None)
|
49
49
|
|
50
50
|
@property
|
51
|
-
def _leftover_qubits(self) ->
|
51
|
+
def _leftover_qubits(self) -> tuple[int, ...]:
|
52
52
|
total_qubits = set(itertools.chain.from_iterable(self.partitions))
|
53
53
|
return tuple(
|
54
54
|
qubit for qubit in range(self.num_qubits) if qubit not in total_qubits
|
@@ -60,7 +60,7 @@ class PartitionedRegister:
|
|
60
60
|
|
61
61
|
def all_register_partitions(
|
62
62
|
self, include_leftover_partition: bool = False
|
63
|
-
) ->
|
63
|
+
) -> list["RegisterPartition"]:
|
64
64
|
all_partitions = [self.get_partition(i) for i in range(len(self.partitions))]
|
65
65
|
if include_leftover_partition:
|
66
66
|
all_partitions.append(self.leftover_partition)
|
@@ -83,7 +83,7 @@ class RegisterPartition:
|
|
83
83
|
raise ClassiqValueError(message)
|
84
84
|
|
85
85
|
@property
|
86
|
-
def qubits(self) ->
|
86
|
+
def qubits(self) -> tuple[int, ...]:
|
87
87
|
if self._index is None:
|
88
88
|
return self.partitioned_register._leftover_qubits
|
89
89
|
return self.partitioned_register.partitions[self._index]
|