classiq 0.53.0__py3-none-any.whl → 0.55.0__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 +1 -3
- classiq/_analyzer_extras/_ipywidgets_async_extension.py +2 -1
- classiq/_internals/__init__.py +0 -20
- classiq/_internals/api_wrapper.py +8 -8
- classiq/_internals/async_utils.py +1 -3
- classiq/_internals/authentication/auth0.py +5 -5
- classiq/_internals/authentication/device.py +5 -4
- classiq/_internals/authentication/password_manager.py +3 -3
- classiq/_internals/authentication/token_manager.py +3 -2
- classiq/_internals/client.py +10 -12
- classiq/_internals/config.py +2 -2
- classiq/_internals/jobs.py +7 -6
- classiq/_internals/type_validation.py +9 -9
- classiq/analyzer/__init__.py +1 -3
- classiq/analyzer/analyzer.py +8 -7
- classiq/analyzer/analyzer_utilities.py +8 -8
- classiq/analyzer/rb.py +11 -11
- classiq/applications/__init__.py +1 -3
- classiq/applications/chemistry/__init__.py +1 -3
- classiq/applications/chemistry/ansatz_parameters.py +4 -4
- classiq/applications/chemistry/chemistry_model_constructor.py +10 -9
- classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +26 -9
- classiq/applications/combinatorial_helpers/encoding_mapping.py +10 -10
- classiq/applications/combinatorial_helpers/encoding_utils.py +4 -4
- classiq/applications/combinatorial_helpers/memory.py +5 -7
- classiq/applications/combinatorial_helpers/optimization_model.py +43 -24
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_utils.py +4 -6
- classiq/applications/combinatorial_helpers/pyomo_utils.py +95 -24
- classiq/applications/combinatorial_helpers/sympy_utils.py +2 -2
- classiq/applications/combinatorial_helpers/transformations/encoding.py +8 -8
- classiq/applications/combinatorial_helpers/transformations/fixed_variables.py +5 -5
- classiq/applications/combinatorial_helpers/transformations/ising_converter.py +7 -9
- classiq/applications/combinatorial_helpers/transformations/penalty.py +1 -2
- classiq/applications/combinatorial_helpers/transformations/sign_seperation.py +1 -2
- classiq/applications/combinatorial_helpers/transformations/slack_variables.py +1 -2
- classiq/applications/combinatorial_optimization/__init__.py +1 -3
- classiq/applications/combinatorial_optimization/combinatorial_optimization_config.py +2 -2
- classiq/applications/combinatorial_optimization/examples/__init__.py +1 -3
- classiq/applications/finance/__init__.py +1 -3
- classiq/applications/grover/__init__.py +1 -3
- classiq/applications/grover/grover_model_constructor.py +7 -9
- classiq/applications/hamiltonian/pauli_decomposition.py +6 -6
- classiq/applications/qnn/__init__.py +1 -3
- classiq/applications/qnn/circuit_utils.py +5 -5
- classiq/applications/qnn/datasets/__init__.py +1 -3
- classiq/applications/qnn/datasets/dataset_base_classes.py +5 -4
- classiq/applications/qnn/datasets/dataset_parity.py +2 -2
- classiq/applications/qnn/gradients/simple_quantum_gradient.py +2 -1
- classiq/applications/qnn/qlayer.py +3 -3
- classiq/applications/qnn/torch_utils.py +2 -2
- classiq/applications/qnn/types.py +5 -5
- classiq/applications/qsvm/qsvm.py +1 -3
- classiq/applications/qsvm/qsvm_data_generation.py +3 -3
- classiq/applications/qsvm/qsvm_model_constructor.py +5 -5
- classiq/execution/__init__.py +1 -3
- classiq/execution/all_hardware_devices.py +1 -3
- classiq/execution/execution_session.py +16 -16
- classiq/execution/jobs.py +4 -4
- classiq/execution/qaoa.py +3 -3
- classiq/execution/qnn.py +3 -3
- classiq/executor.py +3 -3
- classiq/interface/_version.py +1 -1
- classiq/interface/analyzer/analysis_params.py +9 -10
- classiq/interface/analyzer/cytoscape_graph.py +5 -5
- classiq/interface/analyzer/result.py +17 -17
- classiq/interface/applications/qsvm.py +6 -10
- classiq/interface/backend/backend_preferences.py +4 -3
- classiq/interface/backend/ionq/ionq_quantum_program.py +4 -5
- classiq/interface/backend/pydantic_backend.py +1 -2
- classiq/interface/chemistry/fermionic_operator.py +5 -5
- classiq/interface/chemistry/ground_state_problem.py +7 -8
- classiq/interface/chemistry/molecule.py +4 -4
- classiq/interface/chemistry/operator.py +11 -13
- classiq/interface/combinatorial_optimization/examples/ascending_sequence.py +1 -3
- classiq/interface/combinatorial_optimization/examples/integer_portfolio_optimization.py +2 -4
- classiq/interface/combinatorial_optimization/examples/knapsack.py +3 -3
- classiq/interface/combinatorial_optimization/examples/mht.py +2 -3
- classiq/interface/combinatorial_optimization/examples/portfolio_variations.py +2 -2
- classiq/interface/combinatorial_optimization/examples/set_cover.py +1 -2
- classiq/interface/combinatorial_optimization/mht_qaoa_input.py +5 -7
- classiq/interface/combinatorial_optimization/optimization_problem.py +2 -2
- classiq/interface/combinatorial_optimization/result.py +1 -3
- classiq/interface/debug_info/debug_info.py +8 -7
- classiq/interface/exceptions.py +8 -6
- classiq/interface/execution/jobs.py +2 -2
- classiq/interface/execution/primitives.py +3 -3
- classiq/interface/executor/aws_execution_cost.py +4 -4
- classiq/interface/executor/execution_request.py +2 -3
- classiq/interface/executor/execution_result.py +3 -3
- classiq/interface/executor/iqae_result.py +3 -5
- classiq/interface/executor/optimizer_preferences.py +2 -2
- classiq/interface/executor/quantum_code.py +6 -6
- classiq/interface/executor/register_initialization.py +2 -4
- classiq/interface/executor/result.py +23 -27
- classiq/interface/executor/vqe_result.py +8 -8
- classiq/interface/finance/function_input.py +2 -2
- classiq/interface/finance/gaussian_model_input.py +5 -5
- classiq/interface/finance/log_normal_model_input.py +2 -2
- classiq/interface/finance/model_input.py +1 -2
- classiq/interface/generator/adjacency.py +1 -3
- classiq/interface/generator/ansatz_library.py +4 -4
- classiq/interface/generator/application_apis/finance_declarations.py +1 -1
- classiq/interface/generator/arith/argument_utils.py +3 -3
- classiq/interface/generator/arith/arithmetic.py +7 -7
- classiq/interface/generator/arith/arithmetic_arg_type_validator.py +5 -5
- classiq/interface/generator/arith/arithmetic_expression_abc.py +11 -11
- classiq/interface/generator/arith/arithmetic_expression_parser.py +8 -7
- classiq/interface/generator/arith/arithmetic_expression_validator.py +8 -8
- classiq/interface/generator/arith/arithmetic_operations.py +4 -3
- classiq/interface/generator/arith/arithmetic_param_getters.py +6 -6
- classiq/interface/generator/arith/arithmetic_result_builder.py +9 -9
- classiq/interface/generator/arith/ast_node_rewrite.py +2 -1
- classiq/interface/generator/arith/binary_ops.py +10 -13
- classiq/interface/generator/arith/extremum_operations.py +3 -2
- classiq/interface/generator/arith/logical_ops.py +7 -6
- classiq/interface/generator/arith/number_utils.py +4 -4
- classiq/interface/generator/arith/register_user_input.py +4 -4
- classiq/interface/generator/arith/unary_ops.py +2 -1
- classiq/interface/generator/builtin_api_builder.py +2 -1
- classiq/interface/generator/circuit_code/circuit_code.py +4 -4
- classiq/interface/generator/circuit_code/types_and_constants.py +3 -5
- classiq/interface/generator/complex_type.py +1 -2
- classiq/interface/generator/control_state.py +2 -2
- classiq/interface/generator/custom_ansatz.py +1 -3
- classiq/interface/generator/distance.py +3 -5
- classiq/interface/generator/excitations.py +3 -2
- classiq/interface/generator/expressions/enums/finance_functions.py +1 -3
- classiq/interface/generator/expressions/evaluated_expression.py +4 -3
- classiq/interface/generator/expressions/expression.py +4 -5
- classiq/interface/generator/expressions/expression_constants.py +4 -4
- classiq/interface/generator/expressions/qmod_qarray_proxy.py +2 -1
- classiq/interface/generator/expressions/qmod_qscalar_proxy.py +2 -1
- classiq/interface/generator/expressions/qmod_qstruct_proxy.py +2 -1
- classiq/interface/generator/expressions/qmod_sized_proxy.py +2 -1
- classiq/interface/generator/expressions/qmod_struct_instance.py +2 -1
- classiq/interface/generator/expressions/sympy_supported_expressions.py +11 -13
- classiq/interface/generator/finance.py +2 -2
- classiq/interface/generator/function_param_library.py +6 -6
- classiq/interface/generator/function_params.py +13 -19
- classiq/interface/generator/functions/builtins/internal_operators.py +9 -1
- classiq/interface/generator/functions/classical_function_declaration.py +4 -3
- classiq/interface/generator/functions/classical_type.py +13 -13
- classiq/interface/generator/functions/concrete_types.py +1 -2
- classiq/interface/generator/functions/function_declaration.py +1 -1
- classiq/interface/generator/functions/qmod_python_interface.py +2 -1
- classiq/interface/generator/functions/type_name.py +3 -2
- classiq/interface/generator/generated_circuit_data.py +33 -22
- classiq/interface/generator/grover_diffuser.py +7 -7
- classiq/interface/generator/grover_operator.py +2 -2
- classiq/interface/generator/hardware/hardware_data.py +7 -6
- classiq/interface/generator/hardware_efficient_ansatz.py +8 -8
- classiq/interface/generator/identity.py +5 -6
- classiq/interface/generator/linear_pauli_rotations.py +6 -6
- classiq/interface/generator/mcu.py +2 -2
- classiq/interface/generator/mcx.py +6 -6
- classiq/interface/generator/model/__init__.py +1 -3
- classiq/interface/generator/model/constraints.py +2 -2
- classiq/interface/generator/model/model.py +5 -6
- classiq/interface/generator/model/preferences/preferences.py +11 -6
- classiq/interface/generator/model/quantum_register.py +6 -11
- classiq/interface/generator/oracles/arithmetic_oracle.py +1 -2
- classiq/interface/generator/oracles/custom_oracle.py +2 -2
- classiq/interface/generator/oracles/oracle_abc.py +6 -5
- classiq/interface/generator/partitioned_register.py +6 -5
- classiq/interface/generator/piecewise_linear_amplitude_loading.py +8 -7
- classiq/interface/generator/qpe.py +4 -4
- classiq/interface/generator/qsvm.py +3 -3
- classiq/interface/generator/quantum_function_call.py +24 -29
- classiq/interface/generator/quantum_program.py +9 -9
- classiq/interface/generator/register_role.py +2 -4
- classiq/interface/generator/slice_parsing_utils.py +4 -3
- classiq/interface/generator/standard_gates/standard_gates.py +3 -3
- classiq/interface/generator/state_preparation/bell_state_preparation.py +3 -3
- classiq/interface/generator/state_preparation/distributions.py +6 -5
- classiq/interface/generator/state_preparation/metrics.py +2 -4
- classiq/interface/generator/state_preparation/state_preparation.py +4 -4
- classiq/interface/generator/synthesis_metadata/synthesis_execution_data.py +3 -3
- classiq/interface/generator/transpiler_basis_gates.py +2 -2
- classiq/interface/generator/types/compilation_metadata.py +5 -0
- classiq/interface/generator/types/enum_declaration.py +2 -3
- classiq/interface/generator/types/qstruct_declaration.py +2 -1
- classiq/interface/generator/types/struct_declaration.py +3 -2
- classiq/interface/generator/ucc.py +2 -1
- classiq/interface/generator/unitary_gate.py +2 -2
- classiq/interface/generator/user_defined_function_params.py +1 -1
- classiq/interface/generator/validations/flow_graph.py +6 -5
- classiq/interface/generator/validations/validator_functions.py +3 -2
- classiq/interface/generator/visitor.py +9 -14
- classiq/interface/hardware.py +5 -6
- classiq/interface/helpers/custom_encoders.py +2 -2
- classiq/interface/helpers/custom_pydantic_types.py +8 -9
- 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 +4 -3
- classiq/interface/helpers/validation_helpers.py +2 -2
- classiq/interface/ide/ide_data.py +11 -15
- classiq/interface/ide/visual_model.py +22 -22
- classiq/interface/jobs.py +2 -2
- classiq/interface/model/bind_operation.py +5 -4
- classiq/interface/model/classical_parameter_declaration.py +2 -2
- classiq/interface/model/control.py +22 -1
- classiq/interface/model/handle_binding.py +3 -2
- classiq/interface/model/inplace_binary_operation.py +2 -1
- classiq/interface/model/model.py +16 -11
- classiq/interface/model/native_function_definition.py +1 -1
- classiq/interface/model/port_declaration.py +2 -2
- classiq/interface/model/quantum_expressions/amplitude_loading_operation.py +3 -2
- classiq/interface/model/quantum_expressions/arithmetic_operation.py +4 -27
- classiq/interface/model/quantum_expressions/quantum_expression.py +8 -7
- classiq/interface/model/quantum_function_call.py +9 -14
- classiq/interface/model/quantum_function_declaration.py +10 -12
- classiq/interface/model/quantum_lambda_function.py +3 -16
- classiq/interface/model/quantum_statement.py +7 -3
- classiq/interface/model/quantum_type.py +5 -5
- classiq/interface/model/statement_block.py +2 -3
- classiq/interface/model/validation_handle.py +5 -4
- classiq/interface/server/global_versions.py +3 -3
- classiq/model_expansions/atomic_expression_functions_defs.py +3 -2
- classiq/model_expansions/capturing/captured_var_manager.py +4 -6
- classiq/model_expansions/capturing/propagated_var_stack.py +7 -7
- classiq/model_expansions/closure.py +83 -12
- classiq/model_expansions/evaluators/arg_type_match.py +3 -2
- classiq/model_expansions/evaluators/argument_types.py +3 -3
- classiq/model_expansions/evaluators/control.py +3 -3
- classiq/model_expansions/evaluators/parameter_types.py +7 -7
- classiq/model_expansions/evaluators/quantum_type_utils.py +2 -1
- classiq/model_expansions/evaluators/type_type_match.py +1 -1
- classiq/model_expansions/expression_evaluator.py +10 -9
- classiq/model_expansions/expression_renamer.py +6 -6
- classiq/model_expansions/function_builder.py +13 -12
- classiq/model_expansions/generative_functions.py +5 -4
- classiq/model_expansions/interpreter.py +20 -11
- classiq/model_expansions/model_tables.py +14 -14
- classiq/model_expansions/quantum_operations/bind.py +2 -4
- classiq/model_expansions/quantum_operations/classicalif.py +1 -1
- classiq/model_expansions/quantum_operations/control.py +81 -24
- classiq/model_expansions/quantum_operations/emitter.py +33 -20
- classiq/model_expansions/quantum_operations/expression_operation.py +47 -16
- classiq/model_expansions/quantum_operations/inplace_binary_operation.py +160 -35
- classiq/model_expansions/quantum_operations/phase.py +6 -6
- classiq/model_expansions/quantum_operations/quantum_assignment_operation.py +28 -31
- classiq/model_expansions/quantum_operations/quantum_function_call.py +9 -0
- classiq/model_expansions/quantum_operations/repeat.py +1 -3
- classiq/model_expansions/quantum_operations/within_apply.py +0 -16
- classiq/model_expansions/scope.py +11 -10
- classiq/model_expansions/scope_initialization.py +5 -5
- classiq/model_expansions/sympy_conversion/expression_to_sympy.py +6 -6
- classiq/model_expansions/sympy_conversion/sympy_to_python.py +2 -2
- classiq/model_expansions/visitors/variable_references.py +5 -4
- classiq/qmod/builtins/classical_execution_primitives.py +9 -9
- classiq/qmod/builtins/functions/__init__.py +72 -55
- classiq/qmod/builtins/functions/amplitude_estimation.py +4 -1
- classiq/qmod/builtins/functions/arithmetic.py +14 -1
- classiq/qmod/builtins/functions/discrete_sine_cosine_transform.py +86 -6
- classiq/qmod/builtins/functions/grover.py +41 -45
- classiq/qmod/builtins/functions/hea.py +60 -4
- classiq/qmod/builtins/functions/linear_pauli_rotation.py +26 -4
- classiq/qmod/builtins/functions/modular_exponentiation.py +90 -29
- classiq/qmod/builtins/functions/operators.py +1 -1
- classiq/qmod/builtins/functions/qaoa_penalty.py +14 -5
- classiq/qmod/builtins/functions/qft_functions.py +57 -0
- classiq/qmod/builtins/functions/qpe.py +20 -4
- classiq/qmod/builtins/functions/qsvt.py +49 -4
- classiq/qmod/builtins/functions/standard_gates.py +4 -4
- classiq/qmod/builtins/functions/state_preparation.py +92 -10
- classiq/qmod/builtins/functions/swap_test.py +7 -1
- classiq/qmod/builtins/functions/utility_functions.py +43 -0
- classiq/qmod/builtins/functions/variational.py +18 -2
- classiq/qmod/builtins/operations.py +117 -22
- classiq/qmod/cfunc.py +2 -2
- classiq/qmod/classical_function.py +3 -7
- classiq/qmod/create_model_function.py +16 -17
- classiq/qmod/declaration_inferrer.py +7 -10
- classiq/qmod/expression_query.py +3 -3
- classiq/qmod/generative.py +2 -1
- classiq/qmod/model_state_container.py +10 -8
- classiq/qmod/native/__init__.py +1 -3
- classiq/qmod/native/expression_to_qmod.py +9 -8
- classiq/qmod/native/pretty_printer.py +12 -6
- classiq/qmod/pretty_print/__init__.py +1 -3
- classiq/qmod/pretty_print/expression_to_python.py +13 -12
- classiq/qmod/pretty_print/pretty_printer.py +38 -23
- classiq/qmod/python_classical_type.py +8 -4
- classiq/qmod/qfunc.py +4 -4
- classiq/qmod/qmod_variable.py +11 -10
- classiq/qmod/quantum_expandable.py +12 -15
- classiq/qmod/quantum_function.py +35 -22
- classiq/qmod/semantics/annotation.py +1 -1
- classiq/qmod/semantics/error_manager.py +8 -7
- classiq/qmod/semantics/static_semantics_visitor.py +19 -24
- classiq/qmod/semantics/validation/constants_validation.py +1 -1
- classiq/qmod/semantics/validation/func_call_validation.py +2 -2
- classiq/qmod/semantics/validation/main_validation.py +33 -0
- classiq/qmod/semantics/validation/types_validation.py +2 -1
- classiq/qmod/symbolic.py +5 -8
- classiq/qmod/symbolic_type.py +2 -2
- classiq/qmod/synthesize_separately.py +1 -2
- {classiq-0.53.0.dist-info → classiq-0.55.0.dist-info}/METADATA +1 -1
- {classiq-0.53.0.dist-info → classiq-0.55.0.dist-info}/RECORD +300 -297
- classiq/qmod/builtins/functions/qft.py +0 -23
- {classiq-0.53.0.dist-info → classiq-0.55.0.dist-info}/WHEEL +0 -0
@@ -1,15 +1,85 @@
|
|
1
|
+
from classiq.qmod.builtins.functions.arithmetic import modular_increment
|
2
|
+
from classiq.qmod.builtins.functions.qft_functions import qft
|
3
|
+
from classiq.qmod.builtins.functions.standard_gates import PHASE, H, S, X, Z
|
4
|
+
from classiq.qmod.builtins.functions.state_preparation import allocate
|
5
|
+
from classiq.qmod.builtins.functions.utility_functions import apply_to_all
|
6
|
+
from classiq.qmod.builtins.operations import bind, control, invert, repeat, within_apply
|
1
7
|
from classiq.qmod.qfunc import qfunc
|
2
8
|
from classiq.qmod.qmod_variable import QArray, QBit, QNum
|
9
|
+
from classiq.qmod.symbolic import pi
|
10
|
+
|
11
|
+
|
12
|
+
def _b_operator(q: QBit) -> None:
|
13
|
+
S(q)
|
14
|
+
H(q)
|
3
15
|
|
4
16
|
|
5
17
|
@qfunc(external=True)
|
6
18
|
def _qct_d_operator(x: QNum, q: QBit) -> None:
|
7
|
-
|
19
|
+
_b_operator(q)
|
20
|
+
control(x == 0, lambda: invert(lambda: _b_operator(q)))
|
8
21
|
|
9
22
|
|
10
23
|
@qfunc(external=True)
|
11
24
|
def _qct_pi_operator(x: QArray[QBit], q: QBit) -> None:
|
12
|
-
|
25
|
+
control(q == 1, lambda: apply_to_all(X, x))
|
26
|
+
control(q == 1, lambda: modular_increment(1, x))
|
27
|
+
|
28
|
+
|
29
|
+
def _t_operator(x: QArray) -> None:
|
30
|
+
_qct_d_operator(x[0 : x.len - 1], x[x.len - 1])
|
31
|
+
_qct_pi_operator(x[0 : x.len - 1], x[x.len - 1])
|
32
|
+
|
33
|
+
|
34
|
+
def _vn_operator(x: QArray[QBit], q: QBit) -> None:
|
35
|
+
H(q)
|
36
|
+
control(q == 1, lambda: apply_to_all(X, x))
|
37
|
+
|
38
|
+
|
39
|
+
def _d1_operator(x: QArray[QBit], q: QBit) -> None:
|
40
|
+
omega_exp = 2 * pi / (4 * 2**x.len)
|
41
|
+
|
42
|
+
# Li
|
43
|
+
control(q == 0, lambda: repeat(x.len, lambda k: PHASE(omega_exp * (2**k), x[k])))
|
44
|
+
# Ki
|
45
|
+
control(
|
46
|
+
q == 1,
|
47
|
+
lambda: repeat(
|
48
|
+
x.len,
|
49
|
+
lambda k: within_apply(
|
50
|
+
lambda: X(x[k]), lambda: PHASE(-omega_exp * (2**k), x[k])
|
51
|
+
),
|
52
|
+
),
|
53
|
+
)
|
54
|
+
PHASE(-omega_exp, q)
|
55
|
+
|
56
|
+
|
57
|
+
def _pi2_operator(x: QArray[QBit], q: QBit) -> None:
|
58
|
+
control(q == 1, lambda: modular_increment(1, x))
|
59
|
+
|
60
|
+
|
61
|
+
def _j_operator(q: QBit) -> None:
|
62
|
+
within_apply(lambda: Z(q), lambda: (S(q), H(q), S(q))) # type:ignore[arg-type]
|
63
|
+
|
64
|
+
|
65
|
+
def _b_t_operator(q: QBit) -> None:
|
66
|
+
H(q)
|
67
|
+
S(q)
|
68
|
+
|
69
|
+
|
70
|
+
def _d0dt_operator(x: QArray, q: QBit) -> None:
|
71
|
+
x_num: QNum = QNum("x_num", x.len, False, 0)
|
72
|
+
bind(x, x_num)
|
73
|
+
_b_t_operator(q)
|
74
|
+
control(x_num == 0, lambda: _j_operator(q))
|
75
|
+
bind(x_num, x)
|
76
|
+
|
77
|
+
|
78
|
+
def _un_dag_operator(x: QArray[QBit], q: QBit) -> None:
|
79
|
+
_d1_operator(x, q)
|
80
|
+
invert(lambda: _qct_pi_operator(x, q))
|
81
|
+
_d0dt_operator(x, q)
|
82
|
+
invert(lambda: _pi2_operator(x, q))
|
13
83
|
|
14
84
|
|
15
85
|
@qfunc(external=True)
|
@@ -39,7 +109,7 @@ def qct_qst_type1(x: QArray[QBit]) -> None:
|
|
39
109
|
Links:
|
40
110
|
- [Quantum Sine and Cosine Transforms](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/open-library-functions/qct_qst/qct_qst/)
|
41
111
|
"""
|
42
|
-
|
112
|
+
within_apply(lambda: _t_operator(x), lambda: qft(x))
|
43
113
|
|
44
114
|
|
45
115
|
@qfunc(external=True)
|
@@ -68,7 +138,12 @@ def qct_qst_type2(x: QArray[QBit], q: QBit) -> None:
|
|
68
138
|
Links:
|
69
139
|
- [Quantum Sine and Cosine Transforms](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/open-library-functions/qct_qst/qct_qst/)
|
70
140
|
"""
|
71
|
-
|
141
|
+
extended_state: QArray = QArray("extended_state")
|
142
|
+
_vn_operator(x, q)
|
143
|
+
bind([x, q], extended_state)
|
144
|
+
qft(extended_state)
|
145
|
+
bind(extended_state, [x, q])
|
146
|
+
_un_dag_operator(x, q)
|
72
147
|
|
73
148
|
|
74
149
|
@qfunc(external=True)
|
@@ -85,7 +160,8 @@ def qct_type2(x: QArray[QBit]) -> None:
|
|
85
160
|
Links:
|
86
161
|
- [Quantum Sine and Cosine Transforms](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/open-library-functions/qct_qst/qct_qst/)
|
87
162
|
"""
|
88
|
-
|
163
|
+
q = QBit("q")
|
164
|
+
within_apply(lambda: allocate(1, q), lambda: qct_qst_type2(x, q))
|
89
165
|
|
90
166
|
|
91
167
|
@qfunc(external=True)
|
@@ -102,4 +178,8 @@ def qst_type2(x: QArray[QBit]) -> None:
|
|
102
178
|
Links:
|
103
179
|
- [Quantum Sine and Cosine Transforms](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/open-library-functions/qct_qst/qct_qst/)
|
104
180
|
"""
|
105
|
-
|
181
|
+
q = QBit("q")
|
182
|
+
within_apply(
|
183
|
+
lambda: (allocate(1, q), X(q)), # type:ignore[arg-type]
|
184
|
+
lambda: qct_qst_type2(x, q),
|
185
|
+
)
|
@@ -1,9 +1,18 @@
|
|
1
|
-
from
|
2
|
-
|
1
|
+
from classiq.qmod.builtins.functions.standard_gates import H, U, X
|
2
|
+
from classiq.qmod.builtins.functions.state_preparation import allocate
|
3
|
+
from classiq.qmod.builtins.functions.utility_functions import hadamard_transform
|
4
|
+
from classiq.qmod.builtins.operations import (
|
5
|
+
bind,
|
6
|
+
control,
|
7
|
+
invert,
|
8
|
+
power,
|
9
|
+
within_apply,
|
10
|
+
)
|
3
11
|
from classiq.qmod.qfunc import qfunc
|
4
12
|
from classiq.qmod.qmod_parameter import CInt
|
5
|
-
from classiq.qmod.qmod_variable import QArray, QBit
|
13
|
+
from classiq.qmod.qmod_variable import QArray, QBit, QNum
|
6
14
|
from classiq.qmod.quantum_callable import QCallable
|
15
|
+
from classiq.qmod.symbolic import pi
|
7
16
|
|
8
17
|
|
9
18
|
@qfunc(external=True)
|
@@ -36,7 +45,11 @@ def phase_oracle(
|
|
36
45
|
|
37
46
|
[Hidden shift](https://docs.classiq.io/latest/explore/algorithms/algebraic/hidden_shift/hidden_shift/)
|
38
47
|
"""
|
39
|
-
|
48
|
+
aux = QBit("aux")
|
49
|
+
within_apply(
|
50
|
+
within=lambda: (allocate(1, aux), X(aux), H(aux)), # type:ignore[arg-type]
|
51
|
+
apply=lambda: predicate(target, aux),
|
52
|
+
)
|
40
53
|
|
41
54
|
|
42
55
|
@qfunc(external=True)
|
@@ -56,7 +69,14 @@ def reflect_about_zero(packed_vars: QArray[QBit]) -> None:
|
|
56
69
|
Args:
|
57
70
|
packed_vars: The quantum state to reflect.
|
58
71
|
"""
|
59
|
-
|
72
|
+
msbs: QNum = QNum("msbs", packed_vars.len - 1, False, 0)
|
73
|
+
lsb = QBit("lsb")
|
74
|
+
bind(packed_vars, [msbs, lsb])
|
75
|
+
within_apply(
|
76
|
+
lambda: (X(lsb), H(lsb)), # type:ignore[arg-type]
|
77
|
+
lambda: control(msbs == 0, lambda: X(lsb)),
|
78
|
+
)
|
79
|
+
bind([msbs, lsb], packed_vars)
|
60
80
|
|
61
81
|
|
62
82
|
@qfunc(external=True)
|
@@ -81,7 +101,10 @@ def grover_diffuser(
|
|
81
101
|
space_transform: The operator which encodes the axis of reflection.
|
82
102
|
packed_vars: The state to which to apply the diffuser.
|
83
103
|
"""
|
84
|
-
|
104
|
+
within_apply(
|
105
|
+
lambda: invert(lambda: space_transform(packed_vars)),
|
106
|
+
lambda: reflect_about_zero(packed_vars),
|
107
|
+
)
|
85
108
|
|
86
109
|
|
87
110
|
@qfunc(external=True)
|
@@ -115,7 +138,9 @@ def grover_operator(
|
|
115
138
|
- [Wikipedia page](https://en.wikipedia.org/wiki/Grover%27s_algorithm).
|
116
139
|
|
117
140
|
"""
|
118
|
-
|
141
|
+
oracle(packed_vars)
|
142
|
+
grover_diffuser(lambda qba: space_transform(qba), packed_vars)
|
143
|
+
U(0, 0, 0, pi, packed_vars[0])
|
119
144
|
|
120
145
|
|
121
146
|
@qfunc(external=True)
|
@@ -138,41 +163,12 @@ def grover_search(
|
|
138
163
|
[Grover Algorithm](https://docs.classiq.io/latest/explore/functions/qmod_library_reference/classiq_open_library/grover_operator/grover_operator/)
|
139
164
|
|
140
165
|
"""
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
Corresponds to the braket notation:
|
152
|
-
|
153
|
-
$$
|
154
|
-
H^{\\otimes n} |x\rangle = \frac{1}{\\sqrt{2^n}} \\sum_{y=0}^{2^n - 1} (-1)^{x \\cdot y} |y\rangle
|
155
|
-
$$
|
156
|
-
|
157
|
-
Args:
|
158
|
-
target: qubits to apply to Hadamard transform to.
|
159
|
-
|
160
|
-
"""
|
161
|
-
pass
|
162
|
-
|
163
|
-
|
164
|
-
@qfunc(external=True)
|
165
|
-
def apply_to_all(
|
166
|
-
gate_operand: QCallable[Annotated[QBit, "target"]], target: QArray[QBit]
|
167
|
-
) -> None:
|
168
|
-
"""
|
169
|
-
[Qmod Classiq-library function]
|
170
|
-
|
171
|
-
Applies the single-qubit operand `gate_operand` to each qubit in the qubit
|
172
|
-
array `target`.
|
173
|
-
|
174
|
-
Args:
|
175
|
-
gate_operand: The single-qubit gate to apply to each qubit in the array.
|
176
|
-
target: The qubit array to apply the gate to.
|
177
|
-
"""
|
178
|
-
pass
|
166
|
+
hadamard_transform(packed_vars)
|
167
|
+
power(
|
168
|
+
reps,
|
169
|
+
lambda: grover_operator(
|
170
|
+
lambda qba: oracle(qba),
|
171
|
+
lambda qba: hadamard_transform(qba),
|
172
|
+
packed_vars,
|
173
|
+
),
|
174
|
+
)
|
@@ -1,11 +1,11 @@
|
|
1
|
-
from typing import Literal
|
2
|
-
|
3
|
-
from typing_extensions import Annotated
|
1
|
+
from typing import Annotated, Literal
|
4
2
|
|
3
|
+
from classiq.qmod.builtins.operations import if_, repeat
|
5
4
|
from classiq.qmod.qfunc import qfunc
|
6
5
|
from classiq.qmod.qmod_parameter import CArray, CInt, CReal
|
7
6
|
from classiq.qmod.qmod_variable import QArray, QBit
|
8
7
|
from classiq.qmod.quantum_callable import QCallableList
|
8
|
+
from classiq.qmod.symbolic import floor, sum
|
9
9
|
|
10
10
|
|
11
11
|
@qfunc(external=True)
|
@@ -56,4 +56,60 @@ def full_hea(
|
|
56
56
|
operands_2qubit: A list of operations on two qubits
|
57
57
|
x: The quantum object to be transformed by the ansatz
|
58
58
|
"""
|
59
|
-
|
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
|
+
)
|
@@ -1,6 +1,9 @@
|
|
1
|
-
from
|
1
|
+
from typing import Annotated
|
2
2
|
|
3
3
|
from classiq.qmod.builtins.enums import Pauli
|
4
|
+
from classiq.qmod.builtins.functions.operators import switch
|
5
|
+
from classiq.qmod.builtins.functions.standard_gates import IDENTITY, RX, RY, RZ
|
6
|
+
from classiq.qmod.builtins.operations import control, repeat
|
4
7
|
from classiq.qmod.qfunc import qfunc
|
5
8
|
from classiq.qmod.qmod_parameter import CArray, CReal
|
6
9
|
from classiq.qmod.qmod_variable import QArray, QBit
|
@@ -15,7 +18,10 @@ def _single_pauli(
|
|
15
18
|
x: QArray[QBit],
|
16
19
|
q: QBit,
|
17
20
|
) -> None:
|
18
|
-
|
21
|
+
repeat(
|
22
|
+
x.len, lambda index: control(x[index], lambda: q1_qfunc(2**index * slope, q))
|
23
|
+
)
|
24
|
+
q1_qfunc(offset, q)
|
19
25
|
|
20
26
|
|
21
27
|
@qfunc(external=True)
|
@@ -61,5 +67,21 @@ def linear_pauli_rotations(
|
|
61
67
|
Links:
|
62
68
|
[linear_pauli_rotations](https://docs.classiq.io/latest/explore/functions/qmod_library_reference/classiq_open_library/linear_pauli_rotations/linear_pauli_rotations)
|
63
69
|
"""
|
64
|
-
|
65
|
-
|
70
|
+
repeat(
|
71
|
+
q.len,
|
72
|
+
lambda index: _single_pauli(
|
73
|
+
slope=slopes[index],
|
74
|
+
offset=offsets[index],
|
75
|
+
q1_qfunc=lambda theta, target: switch(
|
76
|
+
bases[index],
|
77
|
+
[
|
78
|
+
lambda: IDENTITY(target),
|
79
|
+
lambda: RX(theta, target),
|
80
|
+
lambda: RY(theta, target),
|
81
|
+
lambda: RZ(theta, target),
|
82
|
+
],
|
83
|
+
),
|
84
|
+
x=x,
|
85
|
+
q=q[index],
|
86
|
+
),
|
87
|
+
)
|
@@ -1,30 +1,26 @@
|
|
1
|
+
from classiq.qmod.builtins.classical_functions import qft_const_adder_phase
|
2
|
+
from classiq.qmod.builtins.functions.qft_functions import qft, qft_no_swap
|
3
|
+
from classiq.qmod.builtins.functions.standard_gates import PHASE, SWAP, X
|
4
|
+
from classiq.qmod.builtins.functions.state_preparation import allocate
|
5
|
+
from classiq.qmod.builtins.operations import bind, control, invert, repeat, within_apply
|
6
|
+
from classiq.qmod.cparam import CInt
|
1
7
|
from classiq.qmod.qfunc import qfunc
|
2
|
-
from classiq.qmod.qmod_parameter import CInt
|
3
8
|
from classiq.qmod.qmod_variable import QArray, QBit, QNum
|
4
|
-
|
5
|
-
|
6
|
-
@qfunc(external=True)
|
7
|
-
def qft_no_swap(qbv: QArray[QBit]) -> None:
|
8
|
-
"""
|
9
|
-
[Qmod Classiq-library function]
|
10
|
-
|
11
|
-
Applies the Quantum Fourier Transform (QFT) without the swap gates.
|
12
|
-
|
13
|
-
Args:
|
14
|
-
qbv: The quantum number to which the QFT is applied.
|
15
|
-
|
16
|
-
"""
|
17
|
-
pass
|
9
|
+
from classiq.qmod.symbolic import min, mod_inverse
|
18
10
|
|
19
11
|
|
20
12
|
@qfunc(external=True)
|
21
13
|
def _check_msb(ref: CInt, x: QArray[QBit], aux: QBit) -> None:
|
22
|
-
|
14
|
+
within_apply(
|
15
|
+
lambda: invert(lambda: qft_no_swap(x)), lambda: _ctrl_x(ref, x[0], aux)
|
16
|
+
)
|
23
17
|
|
24
18
|
|
25
19
|
@qfunc(external=True)
|
26
|
-
def _ctrl_x(
|
27
|
-
|
20
|
+
def _ctrl_x(
|
21
|
+
ref: CInt, ctrl: QNum, aux: QBit
|
22
|
+
) -> None: # TODO: remove qfunc when expressions of QBit is supported
|
23
|
+
control(ctrl == ref, lambda: X(aux))
|
28
24
|
|
29
25
|
|
30
26
|
@qfunc(external=True)
|
@@ -43,7 +39,15 @@ def qft_space_add_const(value: CInt, phi_b: QArray[QBit]) -> None:
|
|
43
39
|
phi_b: The quantum number (at the aft space) to which the constant is added.
|
44
40
|
|
45
41
|
"""
|
46
|
-
|
42
|
+
repeat(
|
43
|
+
count=phi_b.len,
|
44
|
+
iteration=lambda index: PHASE(
|
45
|
+
theta=qft_const_adder_phase(
|
46
|
+
index, value, phi_b.len # type:ignore[arg-type]
|
47
|
+
),
|
48
|
+
target=phi_b[index],
|
49
|
+
),
|
50
|
+
)
|
47
51
|
|
48
52
|
|
49
53
|
@qfunc(external=True)
|
@@ -62,7 +66,33 @@ def cc_modular_add(n: CInt, a: CInt, phi_b: QArray[QBit], c1: QBit, c2: QBit) ->
|
|
62
66
|
c2: a control qubit.
|
63
67
|
|
64
68
|
"""
|
65
|
-
|
69
|
+
ctrl: QArray[QBit] = QArray("ctrl")
|
70
|
+
aux = QBit("aux")
|
71
|
+
|
72
|
+
within_apply(
|
73
|
+
lambda: ( # type:ignore[arg-type]
|
74
|
+
allocate(1, aux),
|
75
|
+
bind([c1, c2], ctrl), # type:ignore[func-returns-value]
|
76
|
+
),
|
77
|
+
lambda: ( # type:ignore[arg-type]
|
78
|
+
control( # type:ignore[func-returns-value]
|
79
|
+
ctrl, lambda: qft_space_add_const(a, phi_b)
|
80
|
+
),
|
81
|
+
invert( # type:ignore[func-returns-value]
|
82
|
+
lambda: qft_space_add_const(n, phi_b)
|
83
|
+
),
|
84
|
+
_check_msb(1, phi_b, aux),
|
85
|
+
control( # type:ignore[func-returns-value]
|
86
|
+
aux, lambda: qft_space_add_const(n, phi_b)
|
87
|
+
),
|
88
|
+
within_apply(
|
89
|
+
lambda: invert( # type:ignore[func-returns-value]
|
90
|
+
lambda: control(ctrl, lambda: qft_space_add_const(a, phi_b))
|
91
|
+
),
|
92
|
+
lambda: _check_msb(0, phi_b, aux),
|
93
|
+
),
|
94
|
+
),
|
95
|
+
)
|
66
96
|
|
67
97
|
|
68
98
|
@qfunc(external=True)
|
@@ -82,7 +112,15 @@ def c_modular_multiply(
|
|
82
112
|
x: The quantum factor.
|
83
113
|
ctrl: The control bit.
|
84
114
|
"""
|
85
|
-
|
115
|
+
within_apply(
|
116
|
+
lambda: qft(b),
|
117
|
+
lambda: repeat(
|
118
|
+
count=x.len,
|
119
|
+
iteration=lambda index: cc_modular_add(
|
120
|
+
n, (a * (2**index)) % n, b, x[index], ctrl
|
121
|
+
),
|
122
|
+
),
|
123
|
+
)
|
86
124
|
|
87
125
|
|
88
126
|
@qfunc(external=True)
|
@@ -98,7 +136,10 @@ def multiswap(x: QArray[QBit], y: QArray[QBit]) -> None:
|
|
98
136
|
y: The second array
|
99
137
|
|
100
138
|
"""
|
101
|
-
|
139
|
+
repeat(
|
140
|
+
count=min(x.len, y.len),
|
141
|
+
iteration=lambda index: SWAP(x[index], y[index]),
|
142
|
+
)
|
102
143
|
|
103
144
|
|
104
145
|
@qfunc(external=True)
|
@@ -115,7 +156,20 @@ def inplace_c_modular_multiply(n: CInt, a: CInt, x: QArray[QBit], ctrl: QBit) ->
|
|
115
156
|
x: The quantum factor.
|
116
157
|
ctrl: The control bit.
|
117
158
|
"""
|
118
|
-
|
159
|
+
b: QArray[QBit] = QArray("b")
|
160
|
+
|
161
|
+
within_apply(
|
162
|
+
lambda: allocate(x.len + 1, b),
|
163
|
+
lambda: ( # type:ignore[arg-type]
|
164
|
+
c_modular_multiply(n, a, b, x, ctrl),
|
165
|
+
control( # type:ignore[func-returns-value]
|
166
|
+
ctrl, lambda: multiswap(x, b)
|
167
|
+
),
|
168
|
+
invert( # type:ignore[func-returns-value]
|
169
|
+
lambda: c_modular_multiply(n, mod_inverse(a, n), b, x, ctrl)
|
170
|
+
),
|
171
|
+
),
|
172
|
+
)
|
119
173
|
|
120
174
|
|
121
175
|
@qfunc(external=True)
|
@@ -123,15 +177,22 @@ def modular_exp(n: CInt, a: CInt, x: QArray[QBit], power: QArray[QBit]) -> None:
|
|
123
177
|
"""
|
124
178
|
[Qmod Classiq-library function]
|
125
179
|
|
126
|
-
Raises a classical integer `a` to the power of a quantum number `
|
127
|
-
times a quantum number `
|
128
|
-
(and specifically if at the input $
|
180
|
+
Raises a classical integer `a` to the power of a quantum number `power` modulo classical integer `n`
|
181
|
+
times a quantum number `x`. Performs $x=(a^{power} \\mod n)*x$ in-place.
|
182
|
+
(and specifically if at the input $x=1$, at the output $x=a^{power} \\mod n$).
|
129
183
|
|
130
184
|
Args:
|
131
185
|
n: The modulus number. Should be non-negative.
|
132
186
|
a: The base of the exponentiation. Should be non-negative.
|
133
|
-
x:
|
134
|
-
power:
|
187
|
+
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$.
|
188
|
+
power: The power of the exponentiation.
|
135
189
|
|
190
|
+
Usage Example:
|
191
|
+
[Modular Exponentiation](https://docs.classiq.io/latest/explore/functions/function_usage_examples/arithmetic/modular_exp/modular_exp_example)
|
136
192
|
"""
|
137
|
-
|
193
|
+
repeat(
|
194
|
+
count=power.len,
|
195
|
+
iteration=lambda index: inplace_c_modular_multiply(
|
196
|
+
n, (a ** (2**index)) % n, x, power[index]
|
197
|
+
),
|
198
|
+
)
|
@@ -1,5 +1,7 @@
|
|
1
1
|
from typing import Literal
|
2
2
|
|
3
|
+
from classiq.qmod.builtins.functions import RX, H, suzuki_trotter
|
4
|
+
from classiq.qmod.builtins.operations import repeat
|
3
5
|
from classiq.qmod.builtins.structs import PauliTerm
|
4
6
|
from classiq.qmod.qfunc import qfunc
|
5
7
|
from classiq.qmod.qmod_parameter import CArray, CInt, CReal
|
@@ -22,7 +24,7 @@ def qaoa_mixer_layer(b: CReal, target: QArray[QBit]) -> None:
|
|
22
24
|
b: The rotation parameter for the mixer layer.
|
23
25
|
target: The target quantum array.
|
24
26
|
"""
|
25
|
-
|
27
|
+
repeat(target.len, lambda index: RX(b, target[index]))
|
26
28
|
|
27
29
|
|
28
30
|
@qfunc(external=True)
|
@@ -44,7 +46,7 @@ def qaoa_cost_layer(
|
|
44
46
|
hamiltonian: The Hamiltonian terms for the QAOA model.
|
45
47
|
target: The target quantum array variable.
|
46
48
|
"""
|
47
|
-
|
49
|
+
suzuki_trotter(hamiltonian, g, 1, 1, target)
|
48
50
|
|
49
51
|
|
50
52
|
@qfunc(external=True)
|
@@ -68,7 +70,8 @@ def qaoa_layer(
|
|
68
70
|
target: The target quantum array variable.
|
69
71
|
|
70
72
|
"""
|
71
|
-
|
73
|
+
qaoa_cost_layer(g, hamiltonian, target)
|
74
|
+
qaoa_mixer_layer(b, target)
|
72
75
|
|
73
76
|
|
74
77
|
@qfunc(external=True)
|
@@ -85,7 +88,7 @@ def qaoa_init(target: QArray[QBit]) -> None:
|
|
85
88
|
Args:
|
86
89
|
target: The target quantum array variable.
|
87
90
|
"""
|
88
|
-
|
91
|
+
repeat(target.len, lambda index: H(target[index]))
|
89
92
|
|
90
93
|
|
91
94
|
@qfunc(external=True)
|
@@ -113,4 +116,10 @@ def qaoa_penalty(
|
|
113
116
|
hamiltonian: The Hamiltonian terms for the QAOA model.
|
114
117
|
target: The target quantum array variable.
|
115
118
|
"""
|
116
|
-
|
119
|
+
qaoa_init(target)
|
120
|
+
repeat(
|
121
|
+
params_list.len / 2, # type:ignore[arg-type]
|
122
|
+
lambda index: qaoa_layer(
|
123
|
+
params_list[2 * index], params_list[(2 * index) + 1], hamiltonian, target
|
124
|
+
),
|
125
|
+
)
|
@@ -0,0 +1,57 @@
|
|
1
|
+
from classiq.qmod.builtins.functions.standard_gates import CPHASE, SWAP, H
|
2
|
+
from classiq.qmod.builtins.operations import repeat
|
3
|
+
from classiq.qmod.qfunc import qfunc
|
4
|
+
from classiq.qmod.qmod_variable import QArray, QBit
|
5
|
+
from classiq.qmod.symbolic import pi
|
6
|
+
|
7
|
+
|
8
|
+
@qfunc(external=True)
|
9
|
+
def qft_no_swap(qbv: QArray[QBit]) -> None:
|
10
|
+
"""
|
11
|
+
[Qmod Classiq-library function]
|
12
|
+
|
13
|
+
Applies the Quantum Fourier Transform (QFT) without the swap gates.
|
14
|
+
|
15
|
+
Args:
|
16
|
+
qbv: The quantum number to which the QFT is applied.
|
17
|
+
|
18
|
+
"""
|
19
|
+
repeat(
|
20
|
+
qbv.len,
|
21
|
+
lambda i: ( # type:ignore[arg-type]
|
22
|
+
H(qbv[i]),
|
23
|
+
repeat( # type:ignore[func-returns-value]
|
24
|
+
qbv.len - i - 1,
|
25
|
+
lambda j: CPHASE(
|
26
|
+
theta=pi / (2 ** (j + 1)),
|
27
|
+
ctrl=qbv[i + j + 1],
|
28
|
+
target=qbv[i],
|
29
|
+
),
|
30
|
+
),
|
31
|
+
),
|
32
|
+
)
|
33
|
+
|
34
|
+
|
35
|
+
@qfunc(external=True)
|
36
|
+
def qft(target: QArray[QBit]) -> None:
|
37
|
+
"""
|
38
|
+
[Qmod Classiq-library function]
|
39
|
+
|
40
|
+
Performs the Quantum Fourier Transform (QFT) on `target` in-place.
|
41
|
+
Implements the following transformation:
|
42
|
+
|
43
|
+
$$
|
44
|
+
y_{k} = \\frac{1}{\\sqrt{N}} \\sum_{j=0}^{N-1} x_j e^{2\\pi i \\frac{jk}{N}}
|
45
|
+
$$
|
46
|
+
|
47
|
+
Args:
|
48
|
+
target: The quantum object to be transformed
|
49
|
+
|
50
|
+
Further reading in Classiq Library:
|
51
|
+
Link: [qft library reference](https://github.com/Classiq/classiq-library/blob/main/functions/qmod_library_reference/classiq_open_library/qft/qft.ipynb)
|
52
|
+
"""
|
53
|
+
repeat(
|
54
|
+
target.len / 2, # type:ignore[arg-type]
|
55
|
+
lambda index: SWAP(target[index], target[(target.len - 1) - index]),
|
56
|
+
)
|
57
|
+
qft_no_swap(target)
|