classiq 0.37.1__py3-none-any.whl → 0.65.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- classiq/__init__.py +49 -34
- classiq/_analyzer_extras/_ipywidgets_async_extension.py +3 -2
- classiq/_analyzer_extras/interactive_hardware.py +3 -3
- classiq/_internals/api_wrapper.py +241 -95
- classiq/_internals/async_utils.py +2 -77
- classiq/_internals/authentication/auth0.py +26 -10
- classiq/_internals/authentication/authentication.py +11 -0
- classiq/_internals/authentication/device.py +18 -8
- classiq/_internals/authentication/password_manager.py +40 -13
- classiq/_internals/authentication/token_manager.py +11 -6
- classiq/_internals/client.py +106 -37
- classiq/_internals/config.py +3 -4
- classiq/_internals/host_checker.py +38 -15
- classiq/_internals/jobs.py +56 -50
- classiq/_internals/type_validation.py +9 -9
- classiq/analyzer/__init__.py +1 -3
- classiq/analyzer/analyzer.py +50 -47
- classiq/analyzer/analyzer_utilities.py +15 -15
- classiq/analyzer/rb.py +19 -20
- classiq/analyzer/show_interactive_hack.py +30 -7
- classiq/analyzer/url_utils.py +2 -3
- classiq/applications/__init__.py +3 -12
- classiq/applications/chemistry/__init__.py +14 -10
- classiq/applications/chemistry/ansatz_parameters.py +4 -4
- classiq/{applications_model_constructors → applications/chemistry}/chemistry_model_constructor.py +170 -170
- classiq/applications/chemistry/ground_state_problem.py +1 -1
- classiq/applications/combinatorial_helpers/allowed_constraints.py +23 -0
- classiq/applications/combinatorial_helpers/arithmetic/arithmetic_expression.py +35 -0
- classiq/applications/combinatorial_helpers/arithmetic/isolation.py +42 -0
- classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +166 -0
- classiq/applications/combinatorial_helpers/encoding_mapping.py +107 -0
- classiq/applications/combinatorial_helpers/encoding_utils.py +124 -0
- classiq/applications/combinatorial_helpers/memory.py +75 -0
- classiq/applications/combinatorial_helpers/optimization_model.py +193 -0
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_sparsing.py +31 -0
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_utils.py +46 -0
- classiq/applications/combinatorial_helpers/pyomo_utils.py +447 -0
- classiq/applications/combinatorial_helpers/sympy_utils.py +22 -0
- classiq/applications/combinatorial_helpers/transformations/encoding.py +189 -0
- classiq/applications/combinatorial_helpers/transformations/fixed_variables.py +143 -0
- classiq/applications/combinatorial_helpers/transformations/ising_converter.py +120 -0
- classiq/applications/combinatorial_helpers/transformations/penalty.py +31 -0
- classiq/applications/combinatorial_helpers/transformations/penalty_support.py +37 -0
- classiq/applications/combinatorial_helpers/transformations/sign_seperation.py +74 -0
- classiq/applications/combinatorial_helpers/transformations/slack_variables.py +87 -0
- classiq/applications/combinatorial_optimization/__init__.py +24 -5
- classiq/applications/combinatorial_optimization/combinatorial_optimization_config.py +2 -2
- classiq/applications/combinatorial_optimization/combinatorial_optimization_model_constructor.py +137 -0
- classiq/applications/combinatorial_optimization/combinatorial_problem.py +229 -0
- classiq/applications/combinatorial_optimization/examples/__init__.py +1 -3
- classiq/applications/finance/__init__.py +4 -5
- classiq/{applications_model_constructors → applications/finance}/finance_model_constructor.py +50 -57
- classiq/applications/grover/__init__.py +9 -0
- classiq/applications/grover/grover_model_constructor.py +157 -0
- classiq/applications/hamiltonian/__init__.py +0 -0
- classiq/applications/hamiltonian/pauli_decomposition.py +113 -0
- classiq/applications/libraries/__init__.py +0 -0
- classiq/applications/libraries/qmci_library.py +22 -0
- classiq/applications/qnn/__init__.py +2 -4
- classiq/applications/qnn/circuit_utils.py +8 -8
- classiq/applications/qnn/datasets/__init__.py +9 -11
- classiq/applications/qnn/datasets/dataset_base_classes.py +7 -5
- classiq/applications/qnn/datasets/dataset_not.py +2 -1
- classiq/applications/qnn/datasets/dataset_parity.py +2 -2
- classiq/applications/qnn/gradients/quantum_gradient.py +2 -2
- classiq/applications/qnn/gradients/simple_quantum_gradient.py +2 -1
- classiq/applications/qnn/qlayer.py +30 -10
- classiq/applications/qnn/torch_utils.py +4 -3
- classiq/applications/qnn/types.py +7 -7
- classiq/applications/qsvm/__init__.py +6 -4
- classiq/applications/qsvm/qsvm.py +4 -10
- classiq/applications/qsvm/qsvm_data_generation.py +5 -8
- classiq/{applications_model_constructors → applications/qsvm}/qsvm_model_constructor.py +30 -28
- classiq/execution/__init__.py +8 -3
- classiq/execution/all_hardware_devices.py +11 -0
- classiq/execution/execution_session.py +400 -0
- classiq/execution/iqcc.py +63 -0
- classiq/execution/jobs.py +197 -25
- classiq/execution/qnn.py +79 -0
- classiq/executor.py +23 -117
- classiq/interface/_version.py +1 -1
- classiq/interface/analyzer/analysis_params.py +49 -16
- classiq/interface/analyzer/cytoscape_graph.py +15 -9
- classiq/interface/analyzer/result.py +36 -32
- classiq/interface/applications/qsvm.py +28 -25
- classiq/interface/ast_node.py +16 -0
- classiq/interface/backend/backend_preferences.py +390 -119
- classiq/interface/backend/ionq/ionq_quantum_program.py +15 -23
- classiq/interface/backend/pydantic_backend.py +27 -22
- classiq/interface/backend/quantum_backend_providers.py +70 -16
- classiq/interface/chemistry/fermionic_operator.py +43 -32
- classiq/interface/chemistry/ground_state_problem.py +42 -24
- classiq/interface/chemistry/molecule.py +20 -14
- classiq/interface/chemistry/operator.py +75 -236
- classiq/interface/combinatorial_optimization/encoding_types.py +1 -1
- classiq/interface/combinatorial_optimization/examples/ascending_sequence.py +2 -4
- classiq/interface/combinatorial_optimization/examples/greater_than_ilp.py +1 -1
- classiq/interface/combinatorial_optimization/examples/ilp.py +2 -1
- classiq/interface/combinatorial_optimization/examples/integer_portfolio_optimization.py +2 -4
- classiq/interface/combinatorial_optimization/examples/knapsack.py +3 -3
- classiq/interface/combinatorial_optimization/examples/mds.py +2 -1
- classiq/interface/combinatorial_optimization/examples/mht.py +10 -6
- classiq/interface/combinatorial_optimization/examples/mis.py +4 -1
- classiq/interface/combinatorial_optimization/examples/mvc.py +2 -1
- classiq/interface/combinatorial_optimization/examples/portfolio_variations.py +2 -2
- classiq/interface/combinatorial_optimization/examples/set_cover.py +3 -3
- classiq/interface/combinatorial_optimization/examples/tsp.py +4 -3
- classiq/interface/combinatorial_optimization/examples/tsp_digraph.py +6 -2
- classiq/interface/combinatorial_optimization/mht_qaoa_input.py +14 -9
- classiq/interface/combinatorial_optimization/optimization_problem.py +2 -2
- classiq/interface/combinatorial_optimization/result.py +1 -3
- classiq/interface/combinatorial_optimization/solver_types.py +1 -1
- classiq/interface/debug_info/__init__.py +0 -0
- classiq/interface/debug_info/debug_info.py +86 -0
- classiq/interface/exceptions.py +201 -0
- classiq/interface/execution/iqcc.py +19 -0
- classiq/interface/execution/jobs.py +15 -12
- classiq/interface/execution/primitives.py +18 -0
- classiq/interface/executor/constants.py +1 -0
- classiq/interface/executor/estimation.py +2 -2
- classiq/interface/executor/execution_preferences.py +26 -143
- classiq/interface/executor/execution_request.py +36 -56
- classiq/interface/executor/execution_result.py +30 -8
- classiq/interface/executor/iqae_result.py +4 -6
- classiq/interface/executor/optimizer_preferences.py +34 -22
- classiq/interface/executor/{quantum_program.py → quantum_code.py} +44 -34
- classiq/interface/executor/quantum_instruction_set.py +3 -2
- classiq/interface/executor/register_initialization.py +12 -17
- classiq/interface/executor/result.py +122 -64
- classiq/interface/executor/vqe_result.py +11 -11
- classiq/interface/finance/function_input.py +42 -19
- classiq/interface/finance/gaussian_model_input.py +7 -5
- classiq/interface/finance/log_normal_model_input.py +6 -4
- classiq/interface/finance/model_input.py +6 -4
- classiq/interface/generator/adjacency.py +1 -3
- classiq/interface/generator/amplitude_loading.py +27 -14
- classiq/interface/generator/ansatz_library.py +5 -5
- classiq/interface/generator/application_apis/__init__.py +1 -0
- classiq/interface/generator/application_apis/arithmetic_declarations.py +17 -0
- classiq/interface/generator/application_apis/chemistry_declarations.py +27 -187
- classiq/interface/generator/application_apis/combinatorial_optimization_declarations.py +18 -21
- classiq/interface/generator/application_apis/entangler_declarations.py +11 -6
- classiq/interface/generator/application_apis/finance_declarations.py +48 -69
- classiq/interface/generator/application_apis/qsvm_declarations.py +0 -70
- classiq/interface/generator/arith/argument_utils.py +57 -6
- classiq/interface/generator/arith/arithmetic.py +37 -16
- classiq/interface/generator/arith/arithmetic_arg_type_validator.py +15 -17
- classiq/interface/generator/arith/arithmetic_expression_abc.py +70 -26
- classiq/interface/generator/arith/arithmetic_expression_parser.py +18 -12
- classiq/interface/generator/arith/arithmetic_expression_validator.py +61 -43
- classiq/interface/generator/arith/arithmetic_operations.py +19 -16
- classiq/interface/generator/arith/arithmetic_param_getters.py +7 -8
- classiq/interface/generator/arith/arithmetic_result_builder.py +21 -17
- classiq/interface/generator/arith/ast_node_rewrite.py +4 -3
- classiq/interface/generator/arith/binary_ops.py +375 -139
- classiq/interface/generator/arith/endianness.py +1 -1
- classiq/interface/generator/arith/extremum_operations.py +96 -23
- classiq/interface/generator/arith/logical_ops.py +16 -12
- classiq/interface/generator/arith/machine_precision.py +3 -0
- classiq/interface/generator/arith/number_utils.py +44 -48
- classiq/interface/generator/arith/register_user_input.py +70 -27
- classiq/interface/generator/arith/unary_ops.py +57 -46
- classiq/interface/generator/arith/uncomputation_methods.py +1 -1
- classiq/interface/generator/builtin_api_builder.py +2 -9
- classiq/interface/generator/chemistry_function_params.py +5 -5
- classiq/interface/generator/circuit_code/circuit_code.py +7 -7
- classiq/interface/generator/circuit_code/types_and_constants.py +4 -7
- classiq/interface/generator/commuting_pauli_exponentiation.py +8 -6
- classiq/interface/generator/compiler_keywords.py +8 -0
- classiq/interface/generator/complex_type.py +13 -25
- classiq/interface/generator/constant.py +3 -4
- classiq/interface/generator/control_state.py +35 -28
- classiq/interface/generator/copy.py +47 -0
- classiq/interface/generator/custom_ansatz.py +2 -5
- classiq/interface/generator/distance.py +3 -5
- classiq/interface/generator/excitations.py +3 -2
- classiq/interface/generator/expressions/atomic_expression_functions.py +26 -8
- classiq/interface/generator/expressions/enums/__init__.py +0 -10
- classiq/interface/generator/expressions/enums/finance_functions.py +12 -22
- classiq/interface/generator/expressions/evaluated_expression.py +21 -7
- classiq/interface/generator/expressions/expression.py +27 -15
- classiq/interface/generator/expressions/expression_constants.py +9 -3
- classiq/interface/generator/expressions/non_symbolic_expr.py +119 -0
- classiq/interface/generator/expressions/qmod_qarray_proxy.py +99 -0
- classiq/interface/generator/expressions/qmod_qscalar_proxy.py +59 -0
- classiq/interface/generator/expressions/qmod_qstruct_proxy.py +36 -0
- classiq/interface/generator/expressions/qmod_sized_proxy.py +30 -2
- classiq/interface/generator/expressions/qmod_struct_instance.py +14 -2
- classiq/interface/generator/expressions/sympy_supported_expressions.py +20 -11
- classiq/interface/generator/finance.py +3 -3
- classiq/interface/generator/function_param_library.py +6 -6
- classiq/interface/generator/function_param_list_without_self_reference.py +2 -10
- classiq/interface/generator/function_params.py +42 -69
- classiq/interface/generator/functions/__init__.py +0 -22
- classiq/interface/generator/functions/builtins/__init__.py +0 -0
- classiq/interface/generator/functions/builtins/internal_operators.py +16 -0
- classiq/interface/generator/functions/classical_function_declaration.py +18 -9
- classiq/interface/generator/functions/classical_type.py +47 -166
- classiq/interface/generator/functions/concrete_types.py +55 -0
- classiq/interface/generator/functions/function_declaration.py +13 -14
- classiq/interface/generator/functions/port_declaration.py +1 -13
- classiq/interface/generator/functions/qmod_python_interface.py +2 -1
- classiq/interface/generator/functions/type_name.py +90 -0
- classiq/interface/generator/generated_circuit_data.py +155 -22
- classiq/interface/generator/grover_diffuser.py +32 -25
- classiq/interface/generator/grover_operator.py +34 -23
- classiq/interface/generator/hamiltonian_evolution/exponentiation.py +4 -6
- classiq/interface/generator/hamiltonian_evolution/qdrift.py +4 -4
- classiq/interface/generator/hamiltonian_evolution/suzuki_trotter.py +12 -8
- classiq/interface/generator/hardware/hardware_data.py +76 -36
- classiq/interface/generator/hardware_efficient_ansatz.py +38 -17
- classiq/interface/generator/hartree_fock.py +14 -4
- classiq/interface/generator/identity.py +10 -6
- classiq/interface/generator/linear_pauli_rotations.py +33 -19
- classiq/interface/generator/mcmt_method.py +1 -1
- classiq/interface/generator/mcu.py +20 -16
- classiq/interface/generator/mcx.py +29 -20
- classiq/interface/generator/model/__init__.py +2 -5
- classiq/interface/generator/model/constraints.py +27 -8
- classiq/interface/generator/model/model.py +32 -203
- classiq/interface/generator/model/preferences/preferences.py +118 -43
- classiq/{quantum_register.py → interface/generator/model/quantum_register.py} +27 -22
- classiq/interface/generator/oracles/arithmetic_oracle.py +2 -4
- classiq/interface/generator/oracles/custom_oracle.py +17 -13
- classiq/interface/generator/oracles/oracle_abc.py +9 -9
- classiq/interface/generator/partitioned_register.py +7 -7
- classiq/interface/generator/piecewise_linear_amplitude_loading.py +45 -29
- classiq/interface/generator/preferences/optimization.py +1 -2
- classiq/interface/generator/qpe.py +47 -34
- classiq/interface/generator/qsvm.py +13 -17
- classiq/interface/generator/quantum_function_call.py +107 -87
- classiq/interface/generator/{generated_circuit.py → quantum_program.py} +50 -37
- classiq/interface/generator/range_types.py +13 -12
- classiq/interface/generator/register_role.py +18 -6
- classiq/interface/generator/slice_parsing_utils.py +11 -6
- classiq/interface/generator/standard_gates/controlled_standard_gates.py +32 -39
- classiq/interface/generator/standard_gates/standard_angle_metaclass.py +2 -6
- classiq/interface/generator/standard_gates/standard_gates.py +3 -3
- classiq/interface/generator/standard_gates/u_gate.py +7 -10
- classiq/interface/generator/state_preparation/bell_state_preparation.py +3 -3
- classiq/interface/generator/state_preparation/computational_basis_state_preparation.py +2 -1
- classiq/interface/generator/state_preparation/distributions.py +16 -15
- classiq/interface/generator/state_preparation/metrics.py +5 -7
- classiq/interface/generator/state_preparation/state_preparation.py +30 -23
- classiq/interface/generator/synthesis_metadata/synthesis_duration.py +0 -4
- classiq/interface/generator/synthesis_metadata/synthesis_execution_data.py +20 -6
- classiq/interface/generator/transpiler_basis_gates.py +7 -3
- classiq/interface/generator/types/builtin_enum_declarations.py +178 -0
- classiq/interface/generator/types/compilation_metadata.py +6 -0
- classiq/interface/generator/types/enum_declaration.py +54 -0
- classiq/interface/generator/types/qstruct_declaration.py +18 -0
- classiq/interface/generator/types/struct_declaration.py +15 -14
- classiq/interface/generator/ucc.py +9 -6
- classiq/interface/generator/unitary_gate.py +10 -6
- classiq/interface/generator/user_defined_function_params.py +4 -1
- classiq/interface/generator/validations/flow_graph.py +11 -9
- classiq/interface/generator/validations/validator_functions.py +8 -6
- classiq/interface/generator/visitor.py +23 -16
- classiq/interface/hardware.py +31 -10
- classiq/interface/helpers/classproperty.py +8 -0
- classiq/interface/helpers/custom_encoders.py +3 -0
- classiq/interface/helpers/custom_pydantic_types.py +40 -50
- classiq/interface/helpers/datastructures.py +26 -0
- classiq/interface/helpers/hashable_mixin.py +3 -2
- classiq/interface/helpers/hashable_pydantic_base_model.py +2 -1
- classiq/interface/helpers/pydantic_model_helpers.py +7 -11
- classiq/interface/helpers/validation_helpers.py +4 -21
- classiq/interface/helpers/versioned_model.py +1 -1
- classiq/interface/ide/ide_data.py +16 -20
- classiq/interface/ide/visual_model.py +130 -0
- classiq/interface/interface_version.py +1 -0
- classiq/interface/jobs.py +35 -6
- classiq/interface/model/allocate.py +16 -0
- classiq/interface/model/bind_operation.py +44 -14
- classiq/interface/model/classical_if.py +15 -0
- classiq/interface/model/classical_parameter_declaration.py +33 -3
- classiq/interface/model/control.py +45 -0
- classiq/interface/model/handle_binding.py +298 -20
- classiq/interface/model/inplace_binary_operation.py +31 -26
- classiq/interface/model/invert.py +12 -0
- classiq/interface/model/model.py +87 -73
- classiq/interface/model/native_function_definition.py +16 -21
- classiq/interface/model/parameter.py +13 -0
- classiq/interface/model/phase_operation.py +11 -0
- classiq/interface/model/port_declaration.py +27 -9
- classiq/interface/model/power.py +14 -0
- classiq/interface/model/quantum_expressions/amplitude_loading_operation.py +38 -21
- classiq/interface/model/quantum_expressions/arithmetic_operation.py +51 -14
- classiq/interface/model/quantum_expressions/quantum_expression.py +12 -35
- classiq/interface/model/quantum_function_call.py +146 -462
- classiq/interface/model/quantum_function_declaration.py +193 -152
- classiq/interface/model/quantum_lambda_function.py +65 -0
- classiq/interface/model/quantum_statement.py +71 -12
- classiq/interface/model/quantum_type.py +205 -67
- classiq/interface/model/quantum_variable_declaration.py +4 -26
- classiq/interface/model/repeat.py +15 -0
- classiq/interface/model/statement_block.py +58 -0
- classiq/interface/model/validation_handle.py +13 -6
- classiq/interface/model/variable_declaration_statement.py +3 -1
- classiq/interface/model/within_apply_operation.py +13 -0
- classiq/interface/pyomo_extension/pyomo_sympy_bimap.py +4 -1
- classiq/interface/server/global_versions.py +6 -7
- classiq/interface/server/routes.py +22 -21
- classiq/interface/source_reference.py +59 -0
- classiq/model_expansions/__init__.py +0 -0
- classiq/model_expansions/atomic_expression_functions_defs.py +253 -0
- classiq/model_expansions/capturing/__init__.py +0 -0
- classiq/model_expansions/capturing/captured_vars.py +435 -0
- classiq/model_expansions/capturing/mangling_utils.py +56 -0
- classiq/model_expansions/closure.py +171 -0
- classiq/model_expansions/debug_flag.py +3 -0
- classiq/model_expansions/evaluators/__init__.py +0 -0
- classiq/model_expansions/evaluators/arg_type_match.py +158 -0
- classiq/model_expansions/evaluators/argument_types.py +42 -0
- classiq/model_expansions/evaluators/classical_expression.py +36 -0
- classiq/model_expansions/evaluators/control.py +144 -0
- classiq/model_expansions/evaluators/parameter_types.py +226 -0
- classiq/model_expansions/evaluators/quantum_type_utils.py +239 -0
- classiq/model_expansions/evaluators/type_type_match.py +90 -0
- classiq/model_expansions/expression_evaluator.py +135 -0
- classiq/model_expansions/expression_renamer.py +76 -0
- classiq/model_expansions/function_builder.py +247 -0
- classiq/model_expansions/generative_functions.py +158 -0
- classiq/model_expansions/interpreters/__init__.py +0 -0
- classiq/model_expansions/interpreters/base_interpreter.py +263 -0
- classiq/model_expansions/interpreters/frontend_generative_interpreter.py +28 -0
- classiq/model_expansions/interpreters/generative_interpreter.py +249 -0
- classiq/model_expansions/model_tables.py +18 -0
- classiq/model_expansions/quantum_operations/__init__.py +9 -0
- classiq/model_expansions/quantum_operations/bind.py +60 -0
- classiq/model_expansions/quantum_operations/call_emitter.py +266 -0
- classiq/model_expansions/quantum_operations/classicalif.py +53 -0
- classiq/model_expansions/quantum_operations/declarative_call_emitter.py +87 -0
- classiq/model_expansions/quantum_operations/emitter.py +181 -0
- classiq/model_expansions/quantum_operations/quantum_function_call.py +33 -0
- classiq/model_expansions/quantum_operations/repeat.py +56 -0
- classiq/model_expansions/quantum_operations/shallow_emitter.py +180 -0
- classiq/model_expansions/quantum_operations/variable_decleration.py +28 -0
- classiq/model_expansions/scope.py +240 -0
- classiq/model_expansions/scope_initialization.py +150 -0
- classiq/model_expansions/sympy_conversion/__init__.py +0 -0
- classiq/model_expansions/sympy_conversion/arithmetics.py +49 -0
- classiq/model_expansions/sympy_conversion/expression_to_sympy.py +179 -0
- classiq/model_expansions/sympy_conversion/sympy_to_python.py +123 -0
- classiq/model_expansions/transformers/__init__.py +0 -0
- classiq/model_expansions/transformers/ast_renamer.py +26 -0
- classiq/model_expansions/transformers/var_splitter.py +299 -0
- classiq/model_expansions/utils/__init__.py +0 -0
- classiq/model_expansions/utils/counted_name_allocator.py +11 -0
- classiq/model_expansions/utils/handles_collector.py +33 -0
- classiq/model_expansions/visitors/__init__.py +0 -0
- classiq/model_expansions/visitors/boolean_expression_transformers.py +214 -0
- classiq/model_expansions/visitors/variable_references.py +144 -0
- classiq/open_library/__init__.py +4 -0
- classiq/open_library/functions/__init__.py +130 -0
- classiq/open_library/functions/amplitude_estimation.py +30 -0
- classiq/open_library/functions/discrete_sine_cosine_transform.py +181 -0
- classiq/open_library/functions/grover.py +157 -0
- classiq/open_library/functions/hea.py +115 -0
- classiq/open_library/functions/linear_pauli_rotation.py +82 -0
- classiq/open_library/functions/modular_exponentiation.py +201 -0
- classiq/open_library/functions/qaoa_penalty.py +117 -0
- classiq/open_library/functions/qft_functions.py +54 -0
- classiq/open_library/functions/qpe.py +46 -0
- classiq/open_library/functions/qsvt.py +331 -0
- classiq/open_library/functions/state_preparation.py +301 -0
- classiq/open_library/functions/swap_test.py +27 -0
- classiq/open_library/functions/utility_functions.py +81 -0
- classiq/open_library/functions/variational.py +52 -0
- classiq/qmod/__init__.py +17 -10
- classiq/qmod/builtins/__init__.py +19 -2
- classiq/qmod/builtins/classical_execution_primitives.py +60 -47
- classiq/qmod/builtins/classical_functions.py +44 -38
- classiq/qmod/builtins/constants.py +10 -0
- classiq/qmod/builtins/enums.py +208 -0
- classiq/qmod/builtins/functions/__init__.py +137 -0
- classiq/qmod/builtins/functions/allocation.py +150 -0
- classiq/qmod/builtins/functions/arithmetic.py +55 -0
- classiq/qmod/builtins/functions/benchmarking.py +8 -0
- classiq/qmod/builtins/functions/chemistry.py +91 -0
- classiq/qmod/builtins/functions/exponentiation.py +105 -0
- classiq/qmod/builtins/functions/finance.py +34 -0
- classiq/qmod/builtins/functions/operators.py +16 -0
- classiq/qmod/builtins/functions/qsvm.py +24 -0
- classiq/qmod/builtins/functions/standard_gates.py +651 -0
- classiq/qmod/builtins/operations.py +379 -57
- classiq/qmod/builtins/structs.py +103 -80
- classiq/qmod/cfunc.py +42 -0
- classiq/qmod/classical_function.py +8 -20
- classiq/qmod/cparam.py +64 -0
- classiq/qmod/create_model_function.py +56 -0
- classiq/qmod/declaration_inferrer.py +145 -112
- classiq/qmod/expression_query.py +39 -0
- classiq/qmod/generative.py +42 -0
- classiq/qmod/model_state_container.py +19 -5
- classiq/qmod/native/__init__.py +7 -0
- classiq/qmod/native/expression_to_qmod.py +194 -0
- classiq/qmod/native/pretty_printer.py +401 -0
- classiq/qmod/pretty_print/__init__.py +7 -0
- classiq/qmod/pretty_print/expression_to_python.py +222 -0
- classiq/qmod/pretty_print/pretty_printer.py +572 -0
- classiq/qmod/python_classical_type.py +67 -0
- classiq/qmod/qfunc.py +79 -0
- classiq/qmod/qmod_constant.py +143 -0
- classiq/qmod/qmod_parameter.py +84 -53
- classiq/qmod/qmod_variable.py +497 -100
- classiq/qmod/quantum_callable.py +17 -7
- classiq/qmod/quantum_expandable.py +278 -105
- classiq/qmod/quantum_function.py +232 -48
- classiq/qmod/semantics/__init__.py +0 -0
- classiq/qmod/semantics/annotation/__init__.py +0 -0
- classiq/qmod/semantics/annotation/call_annotation.py +92 -0
- classiq/qmod/semantics/annotation/qstruct_annotator.py +23 -0
- classiq/qmod/semantics/error_manager.py +88 -0
- classiq/qmod/semantics/lambdas.py +25 -0
- classiq/qmod/semantics/static_semantics_visitor.py +384 -0
- classiq/qmod/semantics/validation/__init__.py +0 -0
- classiq/qmod/semantics/validation/constants_validation.py +16 -0
- classiq/qmod/semantics/validation/func_call_validation.py +99 -0
- classiq/qmod/semantics/validation/function_name_collisions_validation.py +23 -0
- classiq/qmod/semantics/validation/handle_validation.py +85 -0
- classiq/qmod/semantics/validation/main_validation.py +33 -0
- classiq/qmod/semantics/validation/types_validation.py +128 -0
- classiq/qmod/symbolic.py +178 -111
- classiq/qmod/symbolic_expr.py +36 -12
- classiq/qmod/symbolic_type.py +2 -5
- classiq/qmod/type_attribute_remover.py +32 -0
- classiq/qmod/utilities.py +108 -1
- classiq/qmod/write_qmod.py +53 -0
- classiq/synthesis.py +210 -22
- {classiq-0.37.1.dist-info → classiq-0.65.3.dist-info}/METADATA +16 -8
- classiq-0.65.3.dist-info/RECORD +521 -0
- {classiq-0.37.1.dist-info → classiq-0.65.3.dist-info}/WHEEL +1 -1
- classiq/_internals/_qfunc_ext.py +0 -6
- classiq/applications/benchmarking/__init__.py +0 -9
- classiq/applications/benchmarking/mirror_benchmarking.py +0 -67
- classiq/applications/numpy_utils.py +0 -37
- classiq/applications_model_constructors/__init__.py +0 -17
- classiq/applications_model_constructors/combinatorial_optimization_model_constructor.py +0 -178
- classiq/applications_model_constructors/grover_model_constructor.py +0 -227
- classiq/applications_model_constructors/libraries/ampltitude_estimation_library.py +0 -11
- classiq/applications_model_constructors/libraries/qmci_library.py +0 -109
- classiq/builtin_functions/__init__.py +0 -43
- classiq/builtin_functions/amplitude_loading.py +0 -3
- classiq/builtin_functions/binary_ops.py +0 -1
- classiq/builtin_functions/exponentiation.py +0 -5
- classiq/builtin_functions/qpe.py +0 -4
- classiq/builtin_functions/qsvm.py +0 -7
- classiq/builtin_functions/range_types.py +0 -5
- classiq/builtin_functions/standard_gates.py +0 -1
- classiq/builtin_functions/state_preparation.py +0 -6
- classiq/builtin_functions/suzuki_trotter.py +0 -3
- classiq/exceptions.py +0 -131
- classiq/interface/executor/aws_execution_cost.py +0 -72
- classiq/interface/executor/error_mitigation.py +0 -6
- classiq/interface/generator/credit_risk_example/linear_gci.py +0 -115
- classiq/interface/generator/credit_risk_example/weighted_adder.py +0 -59
- classiq/interface/generator/expressions/enums/chemistry.py +0 -28
- classiq/interface/generator/expressions/enums/classical_enum.py +0 -5
- classiq/interface/generator/expressions/enums/ladder_operator.py +0 -16
- classiq/interface/generator/expressions/enums/optimizers.py +0 -9
- classiq/interface/generator/expressions/enums/pauli.py +0 -8
- classiq/interface/generator/expressions/enums/qsvm_feature_map_entanglement.py +0 -9
- classiq/interface/generator/expressions/qmod_qnum_proxy.py +0 -22
- classiq/interface/generator/functions/core_lib_declarations/quantum_functions/__init__.py +0 -18
- classiq/interface/generator/functions/core_lib_declarations/quantum_functions/atomic_quantum_functions.py +0 -641
- classiq/interface/generator/functions/core_lib_declarations/quantum_functions/exponentiation_functions.py +0 -89
- classiq/interface/generator/functions/core_lib_declarations/quantum_functions/std_lib_functions.py +0 -862
- classiq/interface/generator/functions/core_lib_declarations/quantum_operators.py +0 -169
- classiq/interface/generator/functions/foreign_function_definition.py +0 -106
- classiq/interface/generator/functions/function_implementation.py +0 -103
- classiq/interface/generator/functions/native_function_definition.py +0 -153
- classiq/interface/generator/functions/quantum_function_declaration.py +0 -69
- classiq/interface/generator/functions/register.py +0 -42
- classiq/interface/generator/functions/register_mapping_data.py +0 -102
- classiq/interface/generator/inequality_mixer.py +0 -51
- classiq/interface/generator/model/classical_main_validator.py +0 -106
- classiq/interface/generator/range_mixer.py +0 -56
- classiq/interface/generator/state_propagator.py +0 -63
- classiq/interface/generator/types/builtin_struct_declarations/__init__.py +0 -2
- classiq/interface/generator/types/builtin_struct_declarations/pauli_struct_declarations.py +0 -22
- classiq/interface/generator/types/builtin_struct_declarations/qaoa_declarations.py +0 -23
- classiq/interface/generator/types/combinatorial_problem.py +0 -26
- classiq/interface/ide/show.py +0 -34
- classiq/interface/model/common_model_types.py +0 -23
- classiq/interface/model/numeric_reinterpretation.py +0 -25
- classiq/interface/model/operator_synthesis_data.py +0 -48
- classiq/interface/model/quantum_expressions/control_state.py +0 -38
- classiq/interface/model/quantum_if_operation.py +0 -95
- classiq/interface/model/resolvers/function_call_resolver.py +0 -43
- classiq/interface/model/validations/handle_validation_base.py +0 -55
- classiq/interface/model/validations/handles_validator.py +0 -154
- classiq/interface/model/validations/port_to_wire_name_generator.py +0 -12
- classiq/model/__init__.py +0 -14
- classiq/model/composite_function_generator.py +0 -33
- classiq/model/function_handler.py +0 -466
- classiq/model/function_handler.pyi +0 -152
- classiq/model/logic_flow.py +0 -149
- classiq/model/logic_flow_change_handler.py +0 -71
- classiq/model/model.py +0 -246
- classiq/qmod/builtins/functions.py +0 -896
- classiq/qmod/qmod_struct.py +0 -37
- classiq/quantum_functions/__init__.py +0 -17
- classiq/quantum_functions/annotation_parser.py +0 -207
- classiq/quantum_functions/decorators.py +0 -22
- classiq/quantum_functions/function_library.py +0 -181
- classiq/quantum_functions/function_parser.py +0 -74
- classiq/quantum_functions/quantum_function.py +0 -236
- classiq-0.37.1.dist-info/RECORD +0 -418
- /classiq/{applications_model_constructors/libraries → applications/combinatorial_helpers}/__init__.py +0 -0
- /classiq/{interface/generator/credit_risk_example → applications/combinatorial_helpers/arithmetic}/__init__.py +0 -0
- /classiq/{interface/generator/functions/core_lib_declarations → applications/combinatorial_helpers/pauli_helpers}/__init__.py +0 -0
- /classiq/{interface/generator/functions/core_lib_declarations/quantum_functions/chemistry_functions.py → applications/combinatorial_helpers/py.typed} +0 -0
- /classiq/{interface/model/resolvers → applications/combinatorial_helpers/solvers}/__init__.py +0 -0
- /classiq/{interface/model/validations → applications/combinatorial_helpers/transformations}/__init__.py +0 -0
- /classiq/{_internals → interface}/enum_utils.py +0 -0
@@ -0,0 +1,157 @@
|
|
1
|
+
from classiq.open_library.functions.utility_functions import hadamard_transform
|
2
|
+
from classiq.qmod.builtins.functions.standard_gates import H, U, X
|
3
|
+
from classiq.qmod.builtins.operations import (
|
4
|
+
allocate,
|
5
|
+
bind,
|
6
|
+
control,
|
7
|
+
invert,
|
8
|
+
power,
|
9
|
+
within_apply,
|
10
|
+
)
|
11
|
+
from classiq.qmod.qfunc import qfunc
|
12
|
+
from classiq.qmod.qmod_parameter import CInt
|
13
|
+
from classiq.qmod.qmod_variable import QArray, QBit, QNum
|
14
|
+
from classiq.qmod.quantum_callable import QCallable
|
15
|
+
from classiq.qmod.symbolic import pi
|
16
|
+
|
17
|
+
|
18
|
+
@qfunc
|
19
|
+
def phase_oracle(
|
20
|
+
predicate: QCallable[QArray[QBit], QBit], target: QArray[QBit]
|
21
|
+
) -> None:
|
22
|
+
"""
|
23
|
+
[Qmod Classiq-library function]
|
24
|
+
|
25
|
+
Creates a phase oracle operator based on a predicate function.
|
26
|
+
|
27
|
+
Applies a predicate function and marks "good" and "bad" states with a phase flip.
|
28
|
+
If the predicate is marked as $\\chi$, and the oracle is marked as $S_\\chi$, then:
|
29
|
+
|
30
|
+
|
31
|
+
$$
|
32
|
+
S_\\chi\\lvert x \rangle =
|
33
|
+
\begin{cases}
|
34
|
+
-\\lvert x \rangle & \text{if } \\chi(x) = 1 \\
|
35
|
+
\\phantom{-} \\lvert x \rangle & \text{if } \\chi(x) = 0
|
36
|
+
\\end{cases}
|
37
|
+
$$
|
38
|
+
|
39
|
+
Args:
|
40
|
+
predicate: A predicate function that takes a QArray of QBits and sets a single QBit |1> if the predicate is true, and |0> otherwise.
|
41
|
+
target: The target QArray of QBits to apply the phase oracle to.
|
42
|
+
"""
|
43
|
+
aux = QBit("aux")
|
44
|
+
within_apply(
|
45
|
+
within=lambda: (allocate(1, aux), X(aux), H(aux)), # type:ignore[arg-type]
|
46
|
+
apply=lambda: predicate(target, aux),
|
47
|
+
)
|
48
|
+
|
49
|
+
|
50
|
+
@qfunc
|
51
|
+
def reflect_about_zero(packed_vars: QArray[QBit]) -> None:
|
52
|
+
"""
|
53
|
+
[Qmod Classiq-library function]
|
54
|
+
|
55
|
+
Reflects the state about the |0> state (i.e. applies a (-1) phase to all states
|
56
|
+
besides the |0> state). Implements the operator $S_0$:
|
57
|
+
|
58
|
+
$$
|
59
|
+
\begin{equation}
|
60
|
+
S_0|{x}\rangle = (-1)^{(x\ne0)}|{x}\rangle= (2|{0}\rangle\\langle{0}|-I)|{x}\rangle
|
61
|
+
\\end{equation}
|
62
|
+
$$
|
63
|
+
|
64
|
+
Args:
|
65
|
+
packed_vars: The quantum state to reflect.
|
66
|
+
"""
|
67
|
+
msbs: QNum = QNum("msbs", packed_vars.len - 1, False, 0)
|
68
|
+
lsb = QBit("lsb")
|
69
|
+
bind(packed_vars, [msbs, lsb])
|
70
|
+
within_apply(
|
71
|
+
lambda: (X(lsb), H(lsb)), # type:ignore[arg-type]
|
72
|
+
lambda: control(msbs == 0, lambda: X(lsb)),
|
73
|
+
)
|
74
|
+
bind([msbs, lsb], packed_vars)
|
75
|
+
|
76
|
+
|
77
|
+
@qfunc
|
78
|
+
def grover_diffuser(
|
79
|
+
space_transform: QCallable[QArray[QBit]], packed_vars: QArray[QBit]
|
80
|
+
) -> None:
|
81
|
+
"""
|
82
|
+
[Qmod Classiq-library function]
|
83
|
+
|
84
|
+
Reflects the given state about the A|0> state, where A
|
85
|
+
is the `space_transform` parameter. It is defined as:
|
86
|
+
|
87
|
+
$$
|
88
|
+
\begin{equation}
|
89
|
+
D = A S_0 A^{\\dagger}
|
90
|
+
\\end{equation}
|
91
|
+
$$
|
92
|
+
|
93
|
+
where $S_0$ is the reflection about the |0> state (see `reflect_about_zero`).
|
94
|
+
|
95
|
+
Args:
|
96
|
+
space_transform: The operator which encodes the axis of reflection.
|
97
|
+
packed_vars: The state to which to apply the diffuser.
|
98
|
+
"""
|
99
|
+
within_apply(
|
100
|
+
lambda: invert(lambda: space_transform(packed_vars)),
|
101
|
+
lambda: reflect_about_zero(packed_vars),
|
102
|
+
)
|
103
|
+
|
104
|
+
|
105
|
+
@qfunc
|
106
|
+
def grover_operator(
|
107
|
+
oracle: QCallable[QArray[QBit]],
|
108
|
+
space_transform: QCallable[QArray[QBit]],
|
109
|
+
packed_vars: QArray[QBit],
|
110
|
+
) -> None:
|
111
|
+
"""
|
112
|
+
[Qmod Classiq-library function]
|
113
|
+
|
114
|
+
Applies the grover operator, defined by:
|
115
|
+
|
116
|
+
$$
|
117
|
+
Q=S_{\\psi_0}S_{\\psi_1}
|
118
|
+
$$
|
119
|
+
|
120
|
+
where $S_{\\psi_1}$ is a reflection about marked states, and $S_{\\psi_0}$ is a reflection
|
121
|
+
about a given state defined by $|\\psi_0\rangle = A|0\rangle$.
|
122
|
+
|
123
|
+
Args:
|
124
|
+
oracle: A unitary operator which adds a phase of (-1) to marked states.
|
125
|
+
space_transform: The operator which creates $|\\psi_0\rangle$, the initial state, used by the diffuser to reflect about it.
|
126
|
+
packed_vars: The state to which to apply the grover operator.
|
127
|
+
"""
|
128
|
+
oracle(packed_vars)
|
129
|
+
grover_diffuser(lambda qba: space_transform(qba), packed_vars)
|
130
|
+
U(0, 0, 0, pi, packed_vars[0])
|
131
|
+
|
132
|
+
|
133
|
+
@qfunc
|
134
|
+
def grover_search(
|
135
|
+
reps: CInt, oracle: QCallable[QArray[QBit]], packed_vars: QArray[QBit]
|
136
|
+
) -> None:
|
137
|
+
"""
|
138
|
+
[Qmod Classiq-library function]
|
139
|
+
|
140
|
+
Applies Grover search algorithm.
|
141
|
+
|
142
|
+
Args:
|
143
|
+
reps: Number of repetitions of the grover operator.
|
144
|
+
oracle: An oracle that marks the solution.
|
145
|
+
packed_vars: Packed form of the variable to apply the grover operator on.
|
146
|
+
|
147
|
+
Returns: None
|
148
|
+
"""
|
149
|
+
hadamard_transform(packed_vars)
|
150
|
+
power(
|
151
|
+
reps,
|
152
|
+
lambda: grover_operator(
|
153
|
+
lambda qba: oracle(qba),
|
154
|
+
lambda qba: hadamard_transform(qba),
|
155
|
+
packed_vars,
|
156
|
+
),
|
157
|
+
)
|
@@ -0,0 +1,115 @@
|
|
1
|
+
from typing import Annotated, Literal
|
2
|
+
|
3
|
+
from classiq.qmod.builtins.operations import if_, repeat
|
4
|
+
from classiq.qmod.qfunc import qfunc
|
5
|
+
from classiq.qmod.qmod_parameter import CArray, CInt, CReal
|
6
|
+
from classiq.qmod.qmod_variable import QArray, QBit
|
7
|
+
from classiq.qmod.quantum_callable import QCallableList
|
8
|
+
from classiq.qmod.symbolic import floor, sum
|
9
|
+
|
10
|
+
|
11
|
+
@qfunc
|
12
|
+
def full_hea(
|
13
|
+
num_qubits: CInt,
|
14
|
+
is_parametrized: CArray[CInt],
|
15
|
+
angle_params: CArray[CReal],
|
16
|
+
connectivity_map: CArray[CArray[CInt]],
|
17
|
+
reps: CInt,
|
18
|
+
operands_1qubit: QCallableList[Annotated[CReal, "angle"], Annotated[QBit, "q"]],
|
19
|
+
operands_2qubit: QCallableList[
|
20
|
+
Annotated[CReal, "angle"], Annotated[QBit, "q1"], Annotated[QBit, "q2"]
|
21
|
+
],
|
22
|
+
x: QArray[QBit, Literal["num_qubits"]],
|
23
|
+
) -> None:
|
24
|
+
"""
|
25
|
+
[Qmod Classiq-library function]
|
26
|
+
|
27
|
+
Implements an ansatz on a qubit array `x` with the given 1-qubit and 2-qubit operations.
|
28
|
+
|
29
|
+
The number of ansatz layers is given in argument `reps`.
|
30
|
+
Each layer applies the 1-qubit operands in `operands_1qubit` to all the qubits in `x`.
|
31
|
+
Next, it applies the 2-qubit operands in `operands_2qubit` to qubits (i, j) for each
|
32
|
+
pair of indices (i, j) in `connectivity_map`.
|
33
|
+
|
34
|
+
The list `is_parametrized` specifies whether the operands in `operands_1qubit` and
|
35
|
+
`operands_2qubit` are parametric (expect a classical argument).
|
36
|
+
`is_parametrized` is a list of flags (0 and 1 integers) of length
|
37
|
+
`len(operands_1qubit) + len(operands_2qubit)`.
|
38
|
+
The first `len(operands_1qubit)` flags refer to the `operands_1qubit` operands and
|
39
|
+
the next `len(operands_2qubit)` flags refer to the `operands_2qubit` operands.
|
40
|
+
|
41
|
+
The classical arguments to the parametric operands are given in argument
|
42
|
+
`angle_params`.
|
43
|
+
`angle_params` concatenates a set of arguments for each ansatz layer.
|
44
|
+
Each set contains an argument for each qubit in `x` times the number
|
45
|
+
of parametric operands in `operands_1qubit`.
|
46
|
+
These are followed by an argument for each mapping pair in `connectivity_map` times
|
47
|
+
the number of parametric operands in `operands_2qubit`.
|
48
|
+
|
49
|
+
Args:
|
50
|
+
num_qubits: The length of qubit array x
|
51
|
+
is_parametrized: A list of 0 and 1 flags
|
52
|
+
angle_params A list of arguments to gate
|
53
|
+
connectivity_map: A list of pairs of qubit indices
|
54
|
+
reps: The number of ansatz layers
|
55
|
+
operands_1qubit: A list of operations on a single qubit
|
56
|
+
operands_2qubit: A list of operations on two qubits
|
57
|
+
x: The quantum object to be transformed by the ansatz
|
58
|
+
"""
|
59
|
+
repeat(
|
60
|
+
reps,
|
61
|
+
lambda r: [ # type:ignore[arg-type]
|
62
|
+
repeat( # type:ignore[func-returns-value]
|
63
|
+
operands_1qubit.len,
|
64
|
+
lambda i1: repeat(
|
65
|
+
num_qubits,
|
66
|
+
lambda index: if_(
|
67
|
+
condition=is_parametrized[i1] == 1,
|
68
|
+
then=lambda: operands_1qubit[i1](
|
69
|
+
angle_params[
|
70
|
+
sum(is_parametrized[0:i1]) # type:ignore[index]
|
71
|
+
+ floor((angle_params.len / reps) * r)
|
72
|
+
+ index
|
73
|
+
],
|
74
|
+
x[index],
|
75
|
+
),
|
76
|
+
else_=lambda: operands_1qubit[i1](0, x[index]),
|
77
|
+
),
|
78
|
+
),
|
79
|
+
),
|
80
|
+
repeat( # type:ignore[func-returns-value]
|
81
|
+
operands_2qubit.len,
|
82
|
+
lambda i2: repeat(
|
83
|
+
connectivity_map.len,
|
84
|
+
lambda index: if_(
|
85
|
+
condition=is_parametrized[operands_1qubit.len + i2] == 1,
|
86
|
+
then=lambda: operands_2qubit[i2](
|
87
|
+
angle_params[
|
88
|
+
num_qubits
|
89
|
+
* sum(
|
90
|
+
is_parametrized[
|
91
|
+
0 : operands_1qubit.len
|
92
|
+
] # type:ignore[index]
|
93
|
+
)
|
94
|
+
+ connectivity_map.len
|
95
|
+
* sum(
|
96
|
+
is_parametrized[
|
97
|
+
operands_1qubit.len : operands_1qubit.len + i2
|
98
|
+
]
|
99
|
+
)
|
100
|
+
+ floor((angle_params.len / reps) * r)
|
101
|
+
+ index
|
102
|
+
],
|
103
|
+
x[connectivity_map[index][0]],
|
104
|
+
x[connectivity_map[index][1]],
|
105
|
+
),
|
106
|
+
else_=lambda: operands_2qubit[i2](
|
107
|
+
0,
|
108
|
+
x[connectivity_map[index][0]],
|
109
|
+
x[connectivity_map[index][1]],
|
110
|
+
),
|
111
|
+
),
|
112
|
+
),
|
113
|
+
),
|
114
|
+
],
|
115
|
+
)
|
@@ -0,0 +1,82 @@
|
|
1
|
+
from typing import Annotated
|
2
|
+
|
3
|
+
from classiq.open_library.functions.utility_functions import switch
|
4
|
+
from classiq.qmod.builtins.enums import Pauli
|
5
|
+
from classiq.qmod.builtins.functions.standard_gates import IDENTITY, RX, RY, RZ
|
6
|
+
from classiq.qmod.builtins.operations import control, repeat
|
7
|
+
from classiq.qmod.qfunc import qfunc
|
8
|
+
from classiq.qmod.qmod_parameter import CArray, CReal
|
9
|
+
from classiq.qmod.qmod_variable import QArray, QBit
|
10
|
+
from classiq.qmod.quantum_callable import QCallable
|
11
|
+
|
12
|
+
|
13
|
+
@qfunc
|
14
|
+
def _single_pauli(
|
15
|
+
slope: CReal,
|
16
|
+
offset: CReal,
|
17
|
+
q1_qfunc: QCallable[Annotated[CReal, "theta"], Annotated[QBit, "target"]],
|
18
|
+
x: QArray[QBit],
|
19
|
+
q: QBit,
|
20
|
+
) -> None:
|
21
|
+
repeat(
|
22
|
+
x.len, lambda index: control(x[index], lambda: q1_qfunc(2**index * slope, q))
|
23
|
+
)
|
24
|
+
q1_qfunc(offset, q)
|
25
|
+
|
26
|
+
|
27
|
+
@qfunc
|
28
|
+
def linear_pauli_rotations(
|
29
|
+
bases: CArray[Pauli],
|
30
|
+
slopes: CArray[CReal],
|
31
|
+
offsets: CArray[CReal],
|
32
|
+
x: QArray[QBit],
|
33
|
+
q: QArray[QBit],
|
34
|
+
) -> None:
|
35
|
+
"""
|
36
|
+
[Qmod Classiq-library function]
|
37
|
+
|
38
|
+
Performs a rotation on a series of $m$ target qubits,
|
39
|
+
where the rotation angle is a linear function of an $n$-qubit
|
40
|
+
control register.
|
41
|
+
|
42
|
+
Corresponds to the braket notation:
|
43
|
+
|
44
|
+
$$
|
45
|
+
\\left|x\right\rangle _{n}\\left|q\right\rangle
|
46
|
+
_{m}\rightarrow\\left|x\right\rangle
|
47
|
+
_{n}\\prod_{k=1}^{m}\\left(\\cos\\left(\frac{a_{k}}{2}x+\frac{b_{k}}{2}\right)-
|
48
|
+
i\\sin\\left(\frac{a_{k}}{2}x+\frac{b_{k}}{2}\right)P_{k}\right)\\left|q_{k}\right\rangle
|
49
|
+
$$
|
50
|
+
|
51
|
+
where $\\left|x\right\rangle$ is the control register,
|
52
|
+
$\\left|q\right\rangle$ is the target register, each $P_{k}$ is one of
|
53
|
+
the three Pauli matrices $X$, $Y$, or $Z$, and $a_{k}$, $b_{k}$ are
|
54
|
+
the user given slopes and offsets, respectively.
|
55
|
+
|
56
|
+
Args:
|
57
|
+
bases: List of Pauli Enums.
|
58
|
+
slopes: Rotation slopes for each of the given Pauli bases.
|
59
|
+
offsets: Rotation offsets for each of the given Pauli bases.
|
60
|
+
x: Quantum state to apply the rotation based on its value.
|
61
|
+
q: List of indicator qubits for each of the given Pauli bases.
|
62
|
+
|
63
|
+
Notice that bases, slopes, offset and q should be of the same size.
|
64
|
+
"""
|
65
|
+
repeat(
|
66
|
+
q.len,
|
67
|
+
lambda index: _single_pauli(
|
68
|
+
slope=slopes[index],
|
69
|
+
offset=offsets[index],
|
70
|
+
q1_qfunc=lambda theta, target: switch(
|
71
|
+
bases[index],
|
72
|
+
[
|
73
|
+
lambda: IDENTITY(target),
|
74
|
+
lambda: RX(theta, target),
|
75
|
+
lambda: RY(theta, target),
|
76
|
+
lambda: RZ(theta, target),
|
77
|
+
],
|
78
|
+
),
|
79
|
+
x=x,
|
80
|
+
q=q[index],
|
81
|
+
),
|
82
|
+
)
|
@@ -0,0 +1,201 @@
|
|
1
|
+
from classiq.open_library.functions.qft_functions import qft, qft_no_swap
|
2
|
+
from classiq.qmod.builtins.classical_functions import qft_const_adder_phase
|
3
|
+
from classiq.qmod.builtins.functions.standard_gates import PHASE, SWAP, X
|
4
|
+
from classiq.qmod.builtins.operations import (
|
5
|
+
allocate,
|
6
|
+
bind,
|
7
|
+
control,
|
8
|
+
invert,
|
9
|
+
repeat,
|
10
|
+
within_apply,
|
11
|
+
)
|
12
|
+
from classiq.qmod.cparam import CInt
|
13
|
+
from classiq.qmod.qfunc import qfunc
|
14
|
+
from classiq.qmod.qmod_variable import QArray, QBit, QNum
|
15
|
+
from classiq.qmod.symbolic import min, mod_inverse
|
16
|
+
|
17
|
+
|
18
|
+
@qfunc
|
19
|
+
def _check_msb(ref: CInt, x: QArray[QBit], aux: QBit) -> None:
|
20
|
+
within_apply(
|
21
|
+
lambda: invert(lambda: qft_no_swap(x)), lambda: _ctrl_x(ref, x[0], aux)
|
22
|
+
)
|
23
|
+
|
24
|
+
|
25
|
+
@qfunc
|
26
|
+
def _ctrl_x(
|
27
|
+
ref: CInt, ctrl: QNum, aux: QBit
|
28
|
+
) -> None: # TODO: remove qfunc when expressions of QBit is supported
|
29
|
+
control(ctrl == ref, lambda: X(aux))
|
30
|
+
|
31
|
+
|
32
|
+
@qfunc
|
33
|
+
def qft_space_add_const(value: CInt, phi_b: QArray[QBit]) -> None:
|
34
|
+
"""
|
35
|
+
[Qmod Classiq-library function]
|
36
|
+
|
37
|
+
Adds a constant to a quantum number (in the Fourier space) using the Quantum Fourier Transform (QFT) Adder algorithm.
|
38
|
+
Assuming that the input `phi_b` has `n` qubits, the result will be $\\phi_b+=value \\mod 2^n$.
|
39
|
+
|
40
|
+
To perform the full algorithm, use:
|
41
|
+
within_apply(lambda: QFT(phi_b), qft_space_add_const(value, phi_b))
|
42
|
+
|
43
|
+
Args:
|
44
|
+
value: The constant to add to the quantum number.
|
45
|
+
phi_b: The quantum number (at the aft space) to which the constant is added.
|
46
|
+
|
47
|
+
"""
|
48
|
+
repeat(
|
49
|
+
count=phi_b.len,
|
50
|
+
iteration=lambda index: PHASE(
|
51
|
+
theta=qft_const_adder_phase(
|
52
|
+
index, value, phi_b.len # type:ignore[arg-type]
|
53
|
+
),
|
54
|
+
target=phi_b[index],
|
55
|
+
),
|
56
|
+
)
|
57
|
+
|
58
|
+
|
59
|
+
@qfunc
|
60
|
+
def cc_modular_add(n: CInt, a: CInt, phi_b: QArray[QBit], c1: QBit, c2: QBit) -> None:
|
61
|
+
"""
|
62
|
+
[Qmod Classiq-library function]
|
63
|
+
|
64
|
+
Adds a constant `a` to a quantum number `phi_b` modulo the constant `n`, controlled by 2 qubits.
|
65
|
+
The quantum number `phi_b` and the constant `a` are assumed to be in the QFT space.
|
66
|
+
|
67
|
+
Args:
|
68
|
+
n: The modulo number.
|
69
|
+
a: The constant to add to the quantum number.
|
70
|
+
phi_b: The quantum number to which the constant is added.
|
71
|
+
c1: a control qubit.
|
72
|
+
c2: a control qubit.
|
73
|
+
|
74
|
+
"""
|
75
|
+
ctrl: QArray[QBit] = QArray("ctrl")
|
76
|
+
aux = QBit("aux")
|
77
|
+
|
78
|
+
within_apply(
|
79
|
+
lambda: ( # type:ignore[arg-type]
|
80
|
+
allocate(1, aux),
|
81
|
+
bind([c1, c2], ctrl), # type:ignore[func-returns-value]
|
82
|
+
),
|
83
|
+
lambda: ( # type:ignore[arg-type]
|
84
|
+
control( # type:ignore[func-returns-value]
|
85
|
+
ctrl, lambda: qft_space_add_const(a, phi_b)
|
86
|
+
),
|
87
|
+
invert( # type:ignore[func-returns-value]
|
88
|
+
lambda: qft_space_add_const(n, phi_b)
|
89
|
+
),
|
90
|
+
_check_msb(1, phi_b, aux),
|
91
|
+
control( # type:ignore[func-returns-value]
|
92
|
+
aux, lambda: qft_space_add_const(n, phi_b)
|
93
|
+
),
|
94
|
+
within_apply(
|
95
|
+
lambda: invert( # type:ignore[func-returns-value]
|
96
|
+
lambda: control(ctrl, lambda: qft_space_add_const(a, phi_b))
|
97
|
+
),
|
98
|
+
lambda: _check_msb(0, phi_b, aux),
|
99
|
+
),
|
100
|
+
),
|
101
|
+
)
|
102
|
+
|
103
|
+
|
104
|
+
@qfunc
|
105
|
+
def c_modular_multiply(
|
106
|
+
n: CInt, a: CInt, b: QArray[QBit], x: QArray[QBit], ctrl: QBit
|
107
|
+
) -> None:
|
108
|
+
"""
|
109
|
+
[Qmod Classiq-library function]
|
110
|
+
|
111
|
+
Performs out-of-place multiplication of a quantum number `x` by a classical number `a` modulo classical number `n`,
|
112
|
+
controlled by a quantum bit `ctrl` and adds the result to a quantum array `b`. Applies $b += xa \\mod n$ if `ctrl=1`, and the identity otherwise.
|
113
|
+
|
114
|
+
Args:
|
115
|
+
n: The modulo number. Should be non-negative.
|
116
|
+
a: The classical factor. Should be non-negative.
|
117
|
+
b: The quantum number added to the multiplication result. Stores the result of the multiplication.
|
118
|
+
x: The quantum factor.
|
119
|
+
ctrl: The control bit.
|
120
|
+
"""
|
121
|
+
within_apply(
|
122
|
+
lambda: qft(b),
|
123
|
+
lambda: repeat(
|
124
|
+
count=x.len,
|
125
|
+
iteration=lambda index: cc_modular_add(
|
126
|
+
n, (a * (2**index)) % n, b, x[index], ctrl
|
127
|
+
),
|
128
|
+
),
|
129
|
+
)
|
130
|
+
|
131
|
+
|
132
|
+
@qfunc
|
133
|
+
def multiswap(x: QArray[QBit], y: QArray[QBit]) -> None:
|
134
|
+
"""
|
135
|
+
[Qmod Classiq-library function]
|
136
|
+
|
137
|
+
Swaps the qubit states between two arrays.
|
138
|
+
Qubits of respective indices are swapped, and additional qubits in the longer array are left unchanged.
|
139
|
+
|
140
|
+
Args:
|
141
|
+
x: The first array
|
142
|
+
y: The second array
|
143
|
+
|
144
|
+
"""
|
145
|
+
repeat(
|
146
|
+
count=min(x.len, y.len),
|
147
|
+
iteration=lambda index: SWAP(x[index], y[index]),
|
148
|
+
)
|
149
|
+
|
150
|
+
|
151
|
+
@qfunc
|
152
|
+
def inplace_c_modular_multiply(n: CInt, a: CInt, x: QArray[QBit], ctrl: QBit) -> None:
|
153
|
+
"""
|
154
|
+
[Qmod Classiq-library function]
|
155
|
+
|
156
|
+
Performs multiplication of a quantum number `x` by a classical number `a` modulo classical number `n`,
|
157
|
+
controlled by a quantum bit `ctrl`. Applies $x=xa \\mod n$ if `ctrl=1`, and the identity otherwise.
|
158
|
+
|
159
|
+
Args:
|
160
|
+
n: The modulo number. Should be non-negative.
|
161
|
+
a: The classical factor. Should be non-negative.
|
162
|
+
x: The quantum factor.
|
163
|
+
ctrl: The control bit.
|
164
|
+
"""
|
165
|
+
b: QArray[QBit] = QArray("b")
|
166
|
+
|
167
|
+
within_apply(
|
168
|
+
lambda: allocate(x.len + 1, b),
|
169
|
+
lambda: ( # type:ignore[arg-type]
|
170
|
+
c_modular_multiply(n, a, b, x, ctrl),
|
171
|
+
control( # type:ignore[func-returns-value]
|
172
|
+
ctrl, lambda: multiswap(x, b)
|
173
|
+
),
|
174
|
+
invert( # type:ignore[func-returns-value]
|
175
|
+
lambda: c_modular_multiply(n, mod_inverse(a, n), b, x, ctrl)
|
176
|
+
),
|
177
|
+
),
|
178
|
+
)
|
179
|
+
|
180
|
+
|
181
|
+
@qfunc
|
182
|
+
def modular_exp(n: CInt, a: CInt, x: QArray[QBit], power: QArray[QBit]) -> None:
|
183
|
+
"""
|
184
|
+
[Qmod Classiq-library function]
|
185
|
+
|
186
|
+
Raises a classical integer `a` to the power of a quantum number `power` modulo classical integer `n`
|
187
|
+
times a quantum number `x`. Performs $x=(a^{power} \\mod n)*x$ in-place.
|
188
|
+
(and specifically if at the input $x=1$, at the output $x=a^{power} \\mod n$).
|
189
|
+
|
190
|
+
Args:
|
191
|
+
n: The modulus number. Should be non-negative.
|
192
|
+
a: The base of the exponentiation. Should be non-negative.
|
193
|
+
x: A quantum number that multiplies the modular exponentiation and holds the output. It should be at least the size of $\\lceil \\log(n) \rceil$.
|
194
|
+
power: The power of the exponentiation.
|
195
|
+
"""
|
196
|
+
repeat(
|
197
|
+
count=power.len,
|
198
|
+
iteration=lambda index: inplace_c_modular_multiply(
|
199
|
+
n, (a ** (2**index)) % n, x, power[index]
|
200
|
+
),
|
201
|
+
)
|
@@ -0,0 +1,117 @@
|
|
1
|
+
from typing import Literal
|
2
|
+
|
3
|
+
from classiq.qmod.builtins.functions import RX, H, suzuki_trotter
|
4
|
+
from classiq.qmod.builtins.operations import repeat
|
5
|
+
from classiq.qmod.builtins.structs import PauliTerm
|
6
|
+
from classiq.qmod.qfunc import qfunc
|
7
|
+
from classiq.qmod.qmod_parameter import CArray, CInt, CReal
|
8
|
+
from classiq.qmod.qmod_variable import QArray, QBit
|
9
|
+
|
10
|
+
|
11
|
+
@qfunc
|
12
|
+
def qaoa_mixer_layer(b: CReal, target: QArray[QBit]) -> None:
|
13
|
+
"""
|
14
|
+
[Qmod Classiq-library function]
|
15
|
+
|
16
|
+
Applies the mixer layer for the QAOA algorithm.
|
17
|
+
The mixer layer is a sequence of `X` gates applied to each qubit in the target quantum
|
18
|
+
array variable.
|
19
|
+
|
20
|
+
Args:
|
21
|
+
b: The rotation parameter for the mixer layer.
|
22
|
+
target: The target quantum array.
|
23
|
+
"""
|
24
|
+
repeat(target.len, lambda index: RX(b, target[index]))
|
25
|
+
|
26
|
+
|
27
|
+
@qfunc
|
28
|
+
def qaoa_cost_layer(
|
29
|
+
g: CReal, hamiltonian: CArray[PauliTerm], target: QArray[QBit]
|
30
|
+
) -> None:
|
31
|
+
"""
|
32
|
+
[Qmod Classiq-library function]
|
33
|
+
|
34
|
+
Applies the cost layer to the QAOA model.
|
35
|
+
|
36
|
+
This function integrates the problem-specific cost function into the QAOA model's objective function.
|
37
|
+
The cost layer represents the primary objective that the QAOA algorithm seeks to optimize, such as
|
38
|
+
minimizing energy or maximizing profit, depending on the application.
|
39
|
+
|
40
|
+
Args:
|
41
|
+
g: The rotation parameter for the cost layer (prefactor).
|
42
|
+
hamiltonian: The Hamiltonian terms for the QAOA model.
|
43
|
+
target: The target quantum array variable.
|
44
|
+
"""
|
45
|
+
suzuki_trotter(hamiltonian, g, 1, 1, target)
|
46
|
+
|
47
|
+
|
48
|
+
@qfunc
|
49
|
+
def qaoa_layer(
|
50
|
+
g: CReal, b: CReal, hamiltonian: CArray[PauliTerm], target: QArray[QBit]
|
51
|
+
) -> None:
|
52
|
+
"""
|
53
|
+
[Qmod Classiq-library function]
|
54
|
+
|
55
|
+
Applies the QAOA layer, which concatenates the cost layer and the mixer layer.
|
56
|
+
|
57
|
+
The `qaoa_layer` function integrates both the cost and mixer layers, essential components of the
|
58
|
+
Quantum Approximate Optimization Algorithm (QAOA). The cost layer encodes the problem's objective,
|
59
|
+
while the mixer layer introduces quantum superposition and drives the search across the solution space.
|
60
|
+
|
61
|
+
Args:
|
62
|
+
g: The rotation parameter for the cost layer.
|
63
|
+
b: The rotation parameter for the mixer layer.
|
64
|
+
hamiltonian: The Hamiltonian terms for the QAOA model.
|
65
|
+
target: The target quantum array variable.
|
66
|
+
|
67
|
+
"""
|
68
|
+
qaoa_cost_layer(g, hamiltonian, target)
|
69
|
+
qaoa_mixer_layer(b, target)
|
70
|
+
|
71
|
+
|
72
|
+
@qfunc
|
73
|
+
def qaoa_init(target: QArray[QBit]) -> None:
|
74
|
+
"""
|
75
|
+
[Qmod Classiq-library function]
|
76
|
+
|
77
|
+
Initializes the QAOA circuit by applying the Hadamard gate to all qubits.
|
78
|
+
|
79
|
+
In the Quantum Approximate Optimization Algorithm (QAOA), the initial state is a uniform superposition
|
80
|
+
created by applying the Hadamard gate to each qubit. This function prepares the qubits for the subsequent
|
81
|
+
application of the cost and mixer layers by preparing them in an equal superposition state.
|
82
|
+
|
83
|
+
Args:
|
84
|
+
target: The target quantum array variable.
|
85
|
+
"""
|
86
|
+
repeat(target.len, lambda index: H(target[index]))
|
87
|
+
|
88
|
+
|
89
|
+
@qfunc
|
90
|
+
def qaoa_penalty(
|
91
|
+
num_qubits: CInt,
|
92
|
+
params_list: CArray[CReal],
|
93
|
+
hamiltonian: CArray[PauliTerm],
|
94
|
+
target: QArray[QBit, Literal["num_qubits"]],
|
95
|
+
) -> None:
|
96
|
+
"""
|
97
|
+
[Qmod Classiq-library function]
|
98
|
+
|
99
|
+
Applies the penalty layer to the QAOA model.
|
100
|
+
|
101
|
+
This function adds a penalty term to the objective function of the QAOA model to
|
102
|
+
enforce certain constraints (e.g., binary or integer variables) during the
|
103
|
+
optimization process.
|
104
|
+
|
105
|
+
Args:
|
106
|
+
num_qubits: The number of qubits in the quantum circuit.
|
107
|
+
params_list The list of QAOA parameters.
|
108
|
+
hamiltonian: The Hamiltonian terms for the QAOA model.
|
109
|
+
target: The target quantum array variable.
|
110
|
+
"""
|
111
|
+
qaoa_init(target)
|
112
|
+
repeat(
|
113
|
+
params_list.len / 2, # type:ignore[arg-type]
|
114
|
+
lambda index: qaoa_layer(
|
115
|
+
params_list[2 * index], params_list[(2 * index) + 1], hamiltonian, target
|
116
|
+
),
|
117
|
+
)
|