classiq 0.93.0__py3-none-any.whl → 0.99.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 +11 -19
- classiq/_analyzer_extras/_ipywidgets_async_extension.py +7 -7
- classiq/_analyzer_extras/interactive_hardware.py +19 -12
- classiq/_internals/api_wrapper.py +31 -142
- classiq/_internals/async_utils.py +4 -7
- classiq/_internals/authentication/auth0.py +41 -15
- classiq/_internals/authentication/authorization_code.py +9 -0
- classiq/_internals/authentication/authorization_flow.py +41 -0
- classiq/_internals/authentication/device.py +33 -52
- classiq/_internals/authentication/hybrid_flow.py +19 -0
- classiq/_internals/authentication/password_manager.py +13 -13
- classiq/_internals/authentication/token_manager.py +9 -9
- classiq/_internals/client.py +17 -44
- classiq/_internals/config.py +19 -5
- classiq/_internals/help.py +1 -2
- classiq/_internals/host_checker.py +3 -3
- classiq/_internals/jobs.py +14 -14
- classiq/_internals/type_validation.py +3 -3
- classiq/analyzer/analyzer.py +18 -18
- classiq/analyzer/rb.py +17 -8
- classiq/analyzer/show_interactive_hack.py +1 -1
- classiq/applications/__init__.py +2 -2
- classiq/applications/chemistry/__init__.py +0 -30
- classiq/applications/chemistry/op_utils.py +4 -4
- classiq/applications/chemistry/problems.py +3 -3
- classiq/applications/chemistry/ucc.py +1 -2
- classiq/applications/chemistry/z2_symmetries.py +4 -4
- classiq/applications/combinatorial_helpers/allowed_constraints.py +1 -3
- classiq/applications/combinatorial_helpers/arithmetic/arithmetic_expression.py +2 -1
- classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +2 -2
- classiq/applications/combinatorial_helpers/encoding_mapping.py +2 -3
- classiq/applications/combinatorial_helpers/encoding_utils.py +2 -2
- classiq/applications/combinatorial_helpers/optimization_model.py +3 -4
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_sparsing.py +2 -2
- classiq/applications/combinatorial_helpers/pyomo_utils.py +8 -8
- classiq/applications/combinatorial_helpers/sympy_utils.py +1 -3
- classiq/applications/combinatorial_helpers/transformations/encoding.py +3 -3
- classiq/applications/combinatorial_helpers/transformations/fixed_variables.py +1 -2
- classiq/applications/combinatorial_optimization/combinatorial_optimization_config.py +2 -3
- classiq/applications/combinatorial_optimization/combinatorial_optimization_model_constructor.py +4 -6
- classiq/applications/combinatorial_optimization/combinatorial_problem.py +15 -10
- classiq/applications/hamiltonian/pauli_decomposition.py +6 -4
- classiq/applications/iqae/iqae.py +14 -11
- classiq/applications/qnn/datasets/dataset_base_classes.py +6 -6
- classiq/applications/qnn/datasets/dataset_parity.py +6 -6
- classiq/applications/qnn/gradients/simple_quantum_gradient.py +1 -1
- classiq/applications/qnn/qlayer.py +9 -8
- classiq/applications/qnn/torch_utils.py +5 -6
- classiq/applications/qnn/types.py +2 -1
- classiq/applications/qsp/__init__.py +20 -2
- classiq/applications/qsp/qsp.py +238 -10
- classiq/applications/qsvm/qsvm_data_generation.py +1 -2
- classiq/evaluators/classical_expression.py +0 -4
- classiq/evaluators/parameter_types.py +10 -8
- classiq/evaluators/qmod_annotated_expression.py +31 -26
- classiq/evaluators/qmod_expression_visitors/qmod_expression_evaluator.py +14 -14
- classiq/evaluators/qmod_expression_visitors/qmod_expression_simplifier.py +2 -1
- classiq/evaluators/qmod_expression_visitors/sympy_wrappers.py +8 -8
- classiq/evaluators/qmod_node_evaluators/binary_op_evaluation.py +4 -4
- classiq/evaluators/qmod_node_evaluators/classical_function_evaluation.py +14 -4
- classiq/evaluators/qmod_node_evaluators/list_evaluation.py +2 -2
- classiq/evaluators/qmod_node_evaluators/numeric_attrs_utils.py +3 -3
- classiq/evaluators/qmod_node_evaluators/subscript_evaluation.py +9 -9
- classiq/evaluators/qmod_node_evaluators/utils.py +6 -6
- classiq/evaluators/qmod_type_inference/classical_type_inference.py +9 -10
- classiq/evaluators/qmod_type_inference/quantum_type_inference.py +5 -5
- classiq/execution/__init__.py +0 -3
- classiq/execution/execution_session.py +28 -21
- classiq/execution/jobs.py +26 -26
- classiq/execution/qnn.py +1 -2
- classiq/execution/user_budgets.py +71 -37
- classiq/executor.py +1 -3
- classiq/interface/_version.py +1 -1
- classiq/interface/analyzer/analysis_params.py +4 -4
- classiq/interface/analyzer/cytoscape_graph.py +3 -3
- classiq/interface/analyzer/result.py +4 -4
- classiq/interface/ast_node.py +3 -3
- classiq/interface/backend/backend_preferences.py +26 -50
- classiq/interface/backend/ionq/ionq_quantum_program.py +5 -5
- classiq/interface/backend/provider_config/__init__.py +0 -0
- classiq/interface/backend/provider_config/provider_config.py +8 -0
- classiq/interface/backend/provider_config/providers/__init__.py +0 -0
- classiq/interface/backend/provider_config/providers/alice_bob.py +47 -0
- classiq/interface/backend/provider_config/providers/aqt.py +16 -0
- classiq/interface/backend/provider_config/providers/azure.py +37 -0
- classiq/interface/backend/provider_config/providers/braket.py +39 -0
- classiq/interface/backend/provider_config/providers/ibm.py +26 -0
- classiq/interface/backend/provider_config/providers/ionq.py +22 -0
- classiq/interface/backend/quantum_backend_providers.py +20 -2
- classiq/interface/chemistry/ansatz_library.py +3 -5
- classiq/interface/chemistry/operator.py +3 -3
- classiq/interface/combinatorial_optimization/examples/knapsack.py +2 -4
- classiq/interface/combinatorial_optimization/examples/tsp_digraph.py +1 -2
- classiq/interface/compression_utils.py +2 -3
- classiq/interface/debug_info/debug_info.py +8 -7
- classiq/interface/exceptions.py +6 -7
- classiq/interface/execution/primitives.py +6 -6
- classiq/interface/executor/estimate_cost.py +1 -1
- classiq/interface/executor/execution_preferences.py +3 -5
- classiq/interface/executor/execution_request.py +10 -10
- classiq/interface/executor/execution_result.py +1 -2
- classiq/interface/executor/quantum_code.py +8 -8
- classiq/interface/executor/result.py +28 -18
- classiq/interface/executor/user_budget.py +25 -17
- classiq/interface/executor/vqe_result.py +5 -6
- classiq/interface/generator/ansatz_library.py +6 -8
- classiq/interface/generator/application_apis/__init__.py +0 -3
- classiq/interface/generator/arith/arithmetic.py +2 -2
- classiq/interface/generator/arith/arithmetic_arg_type_validator.py +2 -3
- classiq/interface/generator/arith/arithmetic_expression_abc.py +4 -5
- classiq/interface/generator/arith/arithmetic_expression_parser.py +11 -4
- classiq/interface/generator/arith/arithmetic_expression_validator.py +12 -15
- classiq/interface/generator/arith/arithmetic_operations.py +4 -6
- classiq/interface/generator/arith/arithmetic_param_getters.py +70 -107
- classiq/interface/generator/arith/arithmetic_result_builder.py +4 -4
- classiq/interface/generator/arith/ast_node_rewrite.py +8 -4
- classiq/interface/generator/arith/binary_ops.py +15 -40
- classiq/interface/generator/arith/logical_ops.py +2 -3
- classiq/interface/generator/arith/number_utils.py +2 -2
- classiq/interface/generator/arith/register_user_input.py +3 -3
- classiq/interface/generator/arith/unary_ops.py +2 -2
- classiq/interface/generator/circuit_code/circuit_code.py +8 -10
- classiq/interface/generator/circuit_code/types_and_constants.py +1 -1
- classiq/interface/generator/complex_type.py +2 -2
- classiq/interface/generator/copy.py +1 -3
- classiq/interface/generator/expressions/atomic_expression_functions.py +0 -5
- classiq/interface/generator/expressions/evaluated_expression.py +2 -3
- classiq/interface/generator/expressions/expression.py +2 -2
- classiq/interface/generator/expressions/proxies/classical/classical_array_proxy.py +4 -7
- classiq/interface/generator/function_param_list.py +0 -40
- classiq/interface/generator/function_params.py +5 -6
- classiq/interface/generator/functions/classical_function_declaration.py +2 -2
- classiq/interface/generator/functions/classical_type.py +3 -3
- classiq/interface/generator/functions/type_modifier.py +0 -15
- classiq/interface/generator/functions/type_name.py +2 -2
- classiq/interface/generator/generated_circuit_data.py +14 -18
- classiq/interface/generator/hamiltonian_evolution/exponentiation.py +2 -4
- classiq/interface/generator/hardware/hardware_data.py +8 -8
- classiq/interface/generator/hardware_efficient_ansatz.py +9 -9
- classiq/interface/generator/mcu.py +3 -3
- classiq/interface/generator/mcx.py +3 -3
- classiq/interface/generator/model/constraints.py +34 -5
- classiq/interface/generator/model/preferences/preferences.py +15 -21
- classiq/interface/generator/model/quantum_register.py +7 -10
- classiq/interface/generator/noise_properties.py +3 -7
- classiq/interface/generator/parameters.py +1 -1
- classiq/interface/generator/partitioned_register.py +1 -2
- classiq/interface/generator/preferences/qasm_to_qmod_params.py +11 -0
- classiq/interface/generator/quantum_function_call.py +9 -12
- classiq/interface/generator/quantum_program.py +10 -23
- classiq/interface/generator/range_types.py +3 -3
- classiq/interface/generator/slice_parsing_utils.py +4 -5
- classiq/interface/generator/standard_gates/standard_gates.py +2 -4
- classiq/interface/generator/synthesis_execution_parameter.py +1 -3
- classiq/interface/generator/synthesis_metadata/synthesis_duration.py +9 -0
- classiq/interface/generator/synthesis_metadata/synthesis_execution_data.py +2 -3
- classiq/interface/generator/transpiler_basis_gates.py +12 -4
- classiq/interface/generator/types/builtin_enum_declarations.py +0 -145
- classiq/interface/generator/types/compilation_metadata.py +12 -1
- classiq/interface/generator/types/enum_declaration.py +2 -1
- classiq/interface/generator/validations/flow_graph.py +3 -3
- classiq/interface/generator/visitor.py +10 -12
- classiq/interface/hardware.py +2 -3
- classiq/interface/helpers/classproperty.py +2 -2
- classiq/interface/helpers/custom_encoders.py +2 -1
- classiq/interface/helpers/custom_pydantic_types.py +1 -1
- classiq/interface/helpers/text_utils.py +1 -4
- classiq/interface/ide/visual_model.py +6 -5
- classiq/interface/interface_version.py +1 -1
- classiq/interface/jobs.py +3 -3
- classiq/interface/model/allocate.py +4 -4
- classiq/interface/model/block.py +6 -2
- classiq/interface/model/bounds.py +3 -3
- classiq/interface/model/classical_if.py +4 -0
- classiq/interface/model/control.py +8 -1
- classiq/interface/model/inplace_binary_operation.py +2 -2
- classiq/interface/model/invert.py +4 -0
- classiq/interface/model/model.py +4 -4
- classiq/interface/model/model_visitor.py +40 -1
- classiq/interface/model/parameter.py +1 -3
- classiq/interface/model/port_declaration.py +1 -1
- classiq/interface/model/power.py +4 -0
- classiq/interface/model/quantum_expressions/quantum_expression.py +1 -2
- classiq/interface/model/quantum_function_call.py +3 -6
- classiq/interface/model/quantum_function_declaration.py +1 -0
- classiq/interface/model/quantum_lambda_function.py +4 -4
- classiq/interface/model/quantum_statement.py +11 -4
- classiq/interface/model/quantum_type.py +14 -14
- classiq/interface/model/repeat.py +4 -0
- classiq/interface/model/skip_control.py +4 -0
- classiq/interface/model/validation_handle.py +2 -3
- classiq/interface/model/variable_declaration_statement.py +2 -2
- classiq/interface/model/within_apply_operation.py +4 -0
- classiq/interface/pretty_print/expression_to_qmod.py +3 -4
- classiq/interface/server/routes.py +0 -16
- classiq/interface/source_reference.py +3 -4
- classiq/model_expansions/arithmetic.py +11 -7
- classiq/model_expansions/arithmetic_compute_result_attrs.py +30 -27
- classiq/model_expansions/capturing/captured_vars.py +3 -3
- classiq/model_expansions/capturing/mangling_utils.py +1 -2
- classiq/model_expansions/closure.py +12 -11
- classiq/model_expansions/function_builder.py +14 -6
- classiq/model_expansions/generative_functions.py +7 -12
- classiq/model_expansions/interpreters/base_interpreter.py +3 -7
- classiq/model_expansions/interpreters/frontend_generative_interpreter.py +2 -1
- classiq/model_expansions/interpreters/generative_interpreter.py +5 -3
- classiq/model_expansions/quantum_operations/allocate.py +4 -4
- classiq/model_expansions/quantum_operations/assignment_result_processor.py +2 -4
- classiq/model_expansions/quantum_operations/call_emitter.py +31 -37
- classiq/model_expansions/quantum_operations/declarative_call_emitter.py +2 -2
- classiq/model_expansions/quantum_operations/emitter.py +3 -5
- classiq/model_expansions/quantum_operations/expression_evaluator.py +3 -3
- classiq/model_expansions/quantum_operations/skip_control_verifier.py +1 -2
- classiq/model_expansions/quantum_operations/variable_decleration.py +2 -2
- classiq/model_expansions/scope.py +7 -7
- classiq/model_expansions/scope_initialization.py +4 -0
- classiq/model_expansions/visitors/symbolic_param_inference.py +6 -6
- classiq/model_expansions/visitors/uncomputation_signature_inference.py +328 -0
- classiq/model_expansions/visitors/variable_references.py +15 -14
- classiq/open_library/functions/__init__.py +28 -11
- classiq/open_library/functions/amplitude_loading.py +81 -0
- classiq/open_library/functions/discrete_sine_cosine_transform.py +5 -5
- classiq/open_library/functions/grover.py +8 -10
- classiq/open_library/functions/lcu.py +47 -18
- classiq/open_library/functions/modular_exponentiation.py +93 -8
- classiq/open_library/functions/qsvt.py +66 -79
- classiq/open_library/functions/qsvt_temp.py +536 -0
- classiq/open_library/functions/state_preparation.py +130 -27
- classiq/qmod/__init__.py +6 -4
- classiq/qmod/builtins/classical_execution_primitives.py +4 -23
- classiq/qmod/builtins/classical_functions.py +1 -42
- classiq/qmod/builtins/enums.py +15 -153
- classiq/qmod/builtins/functions/__init__.py +9 -18
- classiq/qmod/builtins/functions/allocation.py +25 -4
- classiq/qmod/builtins/functions/arithmetic.py +22 -27
- classiq/qmod/builtins/functions/exponentiation.py +51 -2
- classiq/qmod/builtins/functions/mcx_func.py +7 -0
- classiq/qmod/builtins/functions/standard_gates.py +46 -27
- classiq/qmod/builtins/operations.py +165 -79
- classiq/qmod/builtins/structs.py +24 -91
- classiq/qmod/cfunc.py +3 -2
- classiq/qmod/classical_function.py +2 -1
- classiq/qmod/cparam.py +2 -8
- classiq/qmod/create_model_function.py +7 -7
- classiq/qmod/declaration_inferrer.py +33 -30
- classiq/qmod/expression_query.py +7 -4
- classiq/qmod/model_state_container.py +2 -2
- classiq/qmod/native/pretty_printer.py +25 -14
- classiq/qmod/pretty_print/expression_to_python.py +5 -3
- classiq/qmod/pretty_print/pretty_printer.py +39 -17
- classiq/qmod/python_classical_type.py +40 -13
- classiq/qmod/qfunc.py +124 -19
- classiq/qmod/qmod_constant.py +2 -2
- classiq/qmod/qmod_parameter.py +5 -2
- classiq/qmod/qmod_variable.py +47 -46
- classiq/qmod/quantum_callable.py +18 -13
- classiq/qmod/quantum_expandable.py +31 -26
- classiq/qmod/quantum_function.py +84 -36
- classiq/qmod/semantics/annotation/call_annotation.py +5 -5
- classiq/qmod/semantics/error_manager.py +12 -14
- classiq/qmod/semantics/lambdas.py +1 -2
- classiq/qmod/semantics/validation/types_validation.py +1 -2
- classiq/qmod/symbolic.py +2 -4
- classiq/qmod/utilities.py +13 -20
- classiq/qmod/write_qmod.py +3 -4
- classiq/quantum_program.py +1 -3
- classiq/synthesis.py +11 -7
- {classiq-0.93.0.dist-info → classiq-0.99.0.dist-info}/METADATA +2 -3
- {classiq-0.93.0.dist-info → classiq-0.99.0.dist-info}/RECORD +271 -299
- {classiq-0.93.0.dist-info → classiq-0.99.0.dist-info}/WHEEL +1 -1
- classiq/applications/chemistry/ansatz_parameters.py +0 -29
- classiq/applications/chemistry/chemistry_execution_parameters.py +0 -16
- classiq/applications/chemistry/chemistry_model_constructor.py +0 -532
- classiq/applications/chemistry/ground_state_problem.py +0 -42
- classiq/applications/qsvm/__init__.py +0 -8
- classiq/applications/qsvm/qsvm.py +0 -11
- classiq/evaluators/qmod_expression_visitors/qmod_expression_bwc.py +0 -129
- classiq/execution/iqcc.py +0 -128
- classiq/interface/applications/qsvm.py +0 -117
- classiq/interface/chemistry/elements.py +0 -120
- classiq/interface/chemistry/fermionic_operator.py +0 -208
- classiq/interface/chemistry/ground_state_problem.py +0 -132
- classiq/interface/chemistry/ground_state_result.py +0 -8
- classiq/interface/chemistry/molecule.py +0 -71
- classiq/interface/execution/iqcc.py +0 -44
- classiq/interface/generator/application_apis/chemistry_declarations.py +0 -69
- classiq/interface/generator/application_apis/entangler_declarations.py +0 -29
- classiq/interface/generator/application_apis/qsvm_declarations.py +0 -6
- classiq/interface/generator/chemistry_function_params.py +0 -50
- classiq/interface/generator/entangler_params.py +0 -72
- classiq/interface/generator/entanglers.py +0 -14
- classiq/interface/generator/hamiltonian_evolution/qdrift.py +0 -27
- classiq/interface/generator/hartree_fock.py +0 -26
- classiq/interface/generator/hva.py +0 -22
- classiq/interface/generator/linear_pauli_rotations.py +0 -92
- classiq/interface/generator/qft.py +0 -37
- classiq/interface/generator/qsvm.py +0 -96
- classiq/interface/generator/state_preparation/__init__.py +0 -14
- classiq/interface/generator/state_preparation/bell_state_preparation.py +0 -27
- classiq/interface/generator/state_preparation/computational_basis_state_preparation.py +0 -28
- classiq/interface/generator/state_preparation/distributions.py +0 -53
- classiq/interface/generator/state_preparation/exponential_state_preparation.py +0 -14
- classiq/interface/generator/state_preparation/ghz_state_preparation.py +0 -14
- classiq/interface/generator/state_preparation/metrics.py +0 -41
- classiq/interface/generator/state_preparation/state_preparation.py +0 -113
- classiq/interface/generator/state_preparation/state_preparation_abc.py +0 -24
- classiq/interface/generator/state_preparation/uniform_distibution_state_preparation.py +0 -13
- classiq/interface/generator/state_preparation/w_state_preparation.py +0 -13
- classiq/interface/generator/ucc.py +0 -74
- classiq/interface/helpers/backward_compatibility.py +0 -9
- classiq/model_expansions/transformers/type_modifier_inference.py +0 -392
- classiq/open_library/functions/lookup_table.py +0 -58
- classiq/qmod/builtins/functions/chemistry.py +0 -123
- classiq/qmod/builtins/functions/qsvm.py +0 -24
- {classiq-0.93.0.dist-info → classiq-0.99.0.dist-info}/licenses/LICENSE.txt +0 -0
|
@@ -0,0 +1,536 @@
|
|
|
1
|
+
import warnings
|
|
2
|
+
|
|
3
|
+
from classiq.interface.exceptions import ClassiqDeprecationWarning
|
|
4
|
+
|
|
5
|
+
from classiq.qmod.builtins.functions.standard_gates import IDENTITY, RZ, H
|
|
6
|
+
from classiq.qmod.builtins.operations import control, if_, invert, repeat, within_apply
|
|
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
|
+
from classiq.qmod.symbolic import floor, min as qmin
|
|
12
|
+
|
|
13
|
+
from .qsvt import (
|
|
14
|
+
projector_controlled_double_phase as projector_controlled_double_phase_new,
|
|
15
|
+
projector_controlled_phase as projector_controlled_phase_new,
|
|
16
|
+
qsvt as qsvt_new,
|
|
17
|
+
qsvt_inversion as qsvt_inversion_new,
|
|
18
|
+
qsvt_lcu as qsvt_lcu_new,
|
|
19
|
+
qsvt_lcu_step as qsvt_lcu_step_new,
|
|
20
|
+
qsvt_step as qsvt_step_new,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@qfunc
|
|
25
|
+
def qsvt_step_old(
|
|
26
|
+
phase1: CReal,
|
|
27
|
+
phase2: CReal,
|
|
28
|
+
proj_cnot_1: QCallable[QArray[QBit], QBit],
|
|
29
|
+
proj_cnot_2: QCallable[QArray[QBit], QBit],
|
|
30
|
+
u: QCallable[QArray[QBit]],
|
|
31
|
+
qvar: QArray[QBit],
|
|
32
|
+
aux: QBit,
|
|
33
|
+
) -> None:
|
|
34
|
+
"""
|
|
35
|
+
[Qmod Classiq-library function]
|
|
36
|
+
|
|
37
|
+
Applies a single QSVT step, composed of 2 projector-controlled-phase rotations, and applications of the block encoding unitary `u` and its inverse:
|
|
38
|
+
|
|
39
|
+
$$
|
|
40
|
+
\\Pi_{\\phi_2}U^{\\dagger}\\tilde{\\Pi}_{\\phi_{1}}U
|
|
41
|
+
$$
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
phase1: 1st rotation phase.
|
|
45
|
+
phase2: 2nd rotation phase.
|
|
46
|
+
proj_cnot_1: Projector-controlled-not unitary that locates the encoded matrix columns within U. Accepts a quantum variable of the same size as qvar, and a qubit that is set to |1> when the state is in the block.
|
|
47
|
+
proj_cnot_2: Projector-controlled-not unitary that locates the encoded matrix rows within U. Accepts a quantum variable of the same size as qvar, and a qubit that is set to |1> when the state is in the block.
|
|
48
|
+
u: A block encoding unitary matrix.
|
|
49
|
+
qvar: The quantum variable to which U is applied, which resides in the entire block encoding space.
|
|
50
|
+
aux: A zero auxilliary qubit, used for the projector-controlled-phase rotations. Given as an inout so that qsvt can be used as a building-block in a larger algorithm.
|
|
51
|
+
"""
|
|
52
|
+
u(qvar)
|
|
53
|
+
projector_controlled_phase_old(phase1, proj_cnot_2, qvar, aux)
|
|
54
|
+
invert(lambda: u(qvar))
|
|
55
|
+
projector_controlled_phase_old(phase2, proj_cnot_1, qvar, aux)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def qsvt_step(*args, **kwargs): # type: ignore[no-untyped-def]
|
|
59
|
+
"""
|
|
60
|
+
[Qmod Classiq-library function]
|
|
61
|
+
|
|
62
|
+
Applies a single QSVT step, composed of 2 projector-controlled-phase rotations, and applications of the block encoding unitary `u` and its inverse:
|
|
63
|
+
|
|
64
|
+
$$
|
|
65
|
+
\\Pi_{\\phi_2}U^{\\dagger}\\tilde{\\Pi}_{\\phi_{1}}U
|
|
66
|
+
$$
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
phase1: 1st rotation phase.
|
|
70
|
+
phase2: 2nd rotation phase.
|
|
71
|
+
proj_cnot_1: Projector-controlled-not unitary that locates the encoded matrix columns within U. Accepts a qubit that should be set to |1> when the state is in the block.
|
|
72
|
+
proj_cnot_2: Projector-controlled-not unitary that locates the encoded matrix rows within U. Accepts a qubit that should be set to |1> when the state is in the block.
|
|
73
|
+
u: A block encoding unitary matrix.
|
|
74
|
+
aux: A zero auxilliary qubit, used for the projector-controlled-phase rotations. Given as an inout so that qsvt can be used as a building-block in a larger algorithm.
|
|
75
|
+
"""
|
|
76
|
+
if len(args) + len(kwargs) == 7:
|
|
77
|
+
return qsvt_step_old(*args, **kwargs)
|
|
78
|
+
return qsvt_step_new(*args, **kwargs)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@qfunc
|
|
82
|
+
def qsvt_old(
|
|
83
|
+
phase_seq: CArray[CReal],
|
|
84
|
+
proj_cnot_1: QCallable[QArray[QBit], QBit],
|
|
85
|
+
proj_cnot_2: QCallable[QArray[QBit], QBit],
|
|
86
|
+
u: QCallable[QArray[QBit]],
|
|
87
|
+
qvar: QArray[QBit],
|
|
88
|
+
aux: QBit,
|
|
89
|
+
) -> None:
|
|
90
|
+
"""
|
|
91
|
+
[Qmod Classiq-library function]
|
|
92
|
+
|
|
93
|
+
Implements the Quantum Singular Value Transformation (QSVT) - an algorithmic framework, used to apply polynomial transformations of degree `d` on the singular values of a block encoded matrix, given as the unitary `u`. Given a unitary $U$, a list of phase angles $\\phi_1, \\phi_2, ..., \\phi_{d+1}$ and 2 projector-controlled-not operands $C_{\\Pi}NOT,C_{\\tilde{\\Pi}}NOT$, the QSVT sequence is as follows:
|
|
94
|
+
Given a unitary $U$, a list of phase angles $\\phi_1, \\phi_2, ..., \\phi_{d+1}$ and 2 projector-controlled-not operands $C_{\\Pi}NOT,C_{\\tilde{\\Pi}}NOT$, the QSVT sequence is as follows:
|
|
95
|
+
|
|
96
|
+
$$
|
|
97
|
+
\\tilde{\\Pi}_{\\phi_{d+1}}U \\prod_{k=1}^{(d-1)/2} (\\Pi_{\\phi_{d-2k}} U^{\\dagger}\\tilde{\\Pi}_{\\phi_{d - (2k+1)}}U)\\Pi_{\\phi_{1}}
|
|
98
|
+
$$
|
|
99
|
+
|
|
100
|
+
for odd $d$, and:
|
|
101
|
+
|
|
102
|
+
$$
|
|
103
|
+
\\prod_{k=1}^{d/2} (\\Pi_{\\phi_{d-(2k-1)}} U^{\\dagger}\\tilde{\\Pi}_{\\phi_{d-2k}}U)\\Pi_{\\phi_{1}}
|
|
104
|
+
$$
|
|
105
|
+
|
|
106
|
+
for even $d$.
|
|
107
|
+
|
|
108
|
+
Each of the $\\Pi$s is a projector-controlled-phase unitary, according to the given projectors.
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
phase_seq: A sequence of phase angles of length d+1.
|
|
112
|
+
proj_cnot_1: Projector-controlled-not unitary that locates the encoded matrix columns within U. Accepts a quantum variable of the same size as qvar, and a qubit that is set to |1> when the state is in the block.
|
|
113
|
+
proj_cnot_2: Projector-controlled-not unitary that locates the encoded matrix rows within U. Accepts a quantum variable of the same size as qvar, and a qubit that is set to |1> when the state is in the block.
|
|
114
|
+
u: A block encoding unitary matrix.
|
|
115
|
+
qvar: The quantum variable to which U is applied, which resides in the entire block encoding space.
|
|
116
|
+
aux: A zero auxilliary qubit, used for the projector-controlled-phase rotations. Given as an inout so that qsvt can be used as a building-block in a larger algorithm.
|
|
117
|
+
"""
|
|
118
|
+
H(aux)
|
|
119
|
+
|
|
120
|
+
projector_controlled_phase_old(phase_seq[0], proj_cnot_1, qvar, aux)
|
|
121
|
+
repeat(
|
|
122
|
+
count=floor((phase_seq.len - 1) / 2),
|
|
123
|
+
iteration=lambda index: qsvt_step_old(
|
|
124
|
+
phase_seq[2 * index + 1],
|
|
125
|
+
phase_seq[2 * index + 2],
|
|
126
|
+
proj_cnot_1,
|
|
127
|
+
proj_cnot_2,
|
|
128
|
+
u,
|
|
129
|
+
qvar,
|
|
130
|
+
aux,
|
|
131
|
+
),
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
if_(
|
|
135
|
+
condition=phase_seq.len % 2 == 1,
|
|
136
|
+
then=lambda: IDENTITY(qvar),
|
|
137
|
+
else_=lambda: (
|
|
138
|
+
u(qvar),
|
|
139
|
+
projector_controlled_phase_old(
|
|
140
|
+
phase_seq[phase_seq.len - 1],
|
|
141
|
+
proj_cnot_2,
|
|
142
|
+
qvar,
|
|
143
|
+
aux,
|
|
144
|
+
),
|
|
145
|
+
),
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
H(aux)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def qsvt(*args, **kwargs): # type: ignore[no-untyped-def]
|
|
152
|
+
"""
|
|
153
|
+
[Qmod Classiq-library function]
|
|
154
|
+
|
|
155
|
+
Implements the Quantum Singular Value Transformation (QSVT) - an algorithmic framework, used to apply polynomial transformations of degree `d` on the singular values of a block encoded matrix, given as the unitary `u`. Given a unitary $U$, a list of phase angles $\\phi_1, \\phi_2, ..., \\phi_{d+1}$ and 2 projector-controlled-not operands $C_{\\Pi}NOT,C_{\\tilde{\\Pi}}NOT$, the QSVT sequence is as follows:
|
|
156
|
+
Given a unitary $U$, a list of phase angles $\\phi_1, \\phi_2, ..., \\phi_{d+1}$ and 2 projector-controlled-not operands $C_{\\Pi}NOT,C_{\\tilde{\\Pi}}NOT$, the QSVT sequence is as follows:
|
|
157
|
+
|
|
158
|
+
$$
|
|
159
|
+
\\tilde{\\Pi}_{\\phi_{d+1}}U \\prod_{k=1}^{(d-1)/2} (\\Pi_{\\phi_{d-2k}} U^{\\dagger}\\tilde{\\Pi}_{\\phi_{d - (2k+1)}}U)\\Pi_{\\phi_{1}}
|
|
160
|
+
$$
|
|
161
|
+
|
|
162
|
+
for odd $d$, and:
|
|
163
|
+
|
|
164
|
+
$$
|
|
165
|
+
\\prod_{k=1}^{d/2} (\\Pi_{\\phi_{d-(2k-1)}} U^{\\dagger}\\tilde{\\Pi}_{\\phi_{d-2k}}U)\\Pi_{\\phi_{1}}
|
|
166
|
+
$$
|
|
167
|
+
|
|
168
|
+
for even $d$.
|
|
169
|
+
|
|
170
|
+
Each of the $\\Pi$s is a projector-controlled-phase unitary, according to the given projectors.
|
|
171
|
+
|
|
172
|
+
Args:
|
|
173
|
+
phase_seq: A sequence of phase angles of length d+1.
|
|
174
|
+
proj_cnot_1: Projector-controlled-not unitary that locates the encoded matrix columns within U. Accepts a qubit that should be set to |1> when the state is in the block.
|
|
175
|
+
proj_cnot_2: Projector-controlled-not unitary that locates the encoded matrix rows within U. Accepts a qubit that should be set to |1> when the state is in the block.
|
|
176
|
+
u: A block encoding unitary matrix.
|
|
177
|
+
aux: A zero auxilliary qubit, used for the projector-controlled-phase rotations. Given as an inout so that qsvt can be used as a building-block in a larger algorithm.
|
|
178
|
+
"""
|
|
179
|
+
if len(args) + len(kwargs) == 6:
|
|
180
|
+
warnings.warn(
|
|
181
|
+
"The 'qsvt' function signature has changed and the old version will be deprecated"
|
|
182
|
+
" starting on 2025-12-13 at the earliest",
|
|
183
|
+
ClassiqDeprecationWarning,
|
|
184
|
+
stacklevel=2,
|
|
185
|
+
)
|
|
186
|
+
return qsvt_old(*args, **kwargs)
|
|
187
|
+
return qsvt_new(*args, **kwargs)
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
@qfunc
|
|
191
|
+
def projector_controlled_phase_old(
|
|
192
|
+
phase: CReal,
|
|
193
|
+
proj_cnot: QCallable[QArray[QBit], QBit],
|
|
194
|
+
qvar: QArray[QBit],
|
|
195
|
+
aux: QBit,
|
|
196
|
+
) -> None:
|
|
197
|
+
"""
|
|
198
|
+
[Qmod Classiq-library function]
|
|
199
|
+
|
|
200
|
+
Assigns a phase to the entire subspace determined by the given projector. Corresponds to the operation:
|
|
201
|
+
|
|
202
|
+
$$
|
|
203
|
+
\\Pi_{\\phi} = (C_{\\Pi}NOT) e^{-i\frac{\\phi}{2}Z}(C_{\\Pi}NOT)
|
|
204
|
+
$$
|
|
205
|
+
|
|
206
|
+
Args:
|
|
207
|
+
phase: A rotation phase.
|
|
208
|
+
proj_cnot: Projector-controlled-not unitary that sets an auxilliary qubit to |1> when the state is in the projection.
|
|
209
|
+
qvar: The quantum variable to which the rotation applies, which resides in the entire block encoding space.
|
|
210
|
+
aux: A zero auxilliary qubit, used for the projector-controlled-phase rotation. Given as an inout so that qsvt can be used as a building-block in a larger algorithm.
|
|
211
|
+
"""
|
|
212
|
+
within_apply(lambda: proj_cnot(qvar, aux), lambda: RZ(phase, aux))
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def projector_controlled_phase(*args, **kwargs): # type: ignore[no-untyped-def]
|
|
216
|
+
"""
|
|
217
|
+
[Qmod Classiq-library function]
|
|
218
|
+
|
|
219
|
+
Assigns a phase to the entire subspace determined by the given projector. Corresponds to the operation:
|
|
220
|
+
|
|
221
|
+
$$
|
|
222
|
+
\\Pi_{\\phi} = (C_{\\Pi}NOT) e^{-i\frac{\\phi}{2}Z}(C_{\\Pi}NOT)
|
|
223
|
+
$$
|
|
224
|
+
|
|
225
|
+
Args:
|
|
226
|
+
phase: A rotation phase.
|
|
227
|
+
proj_cnot: Projector-controlled-not unitary that sets an auxilliary qubit to |1> when the state is in the projection.
|
|
228
|
+
aux: A zero auxilliary qubit, used for the projector-controlled-phase rotation.
|
|
229
|
+
"""
|
|
230
|
+
if len(args) + len(kwargs) == 4:
|
|
231
|
+
return projector_controlled_phase_old(*args, **kwargs)
|
|
232
|
+
return projector_controlled_phase_new(*args, **kwargs)
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
@qfunc
|
|
236
|
+
def qsvt_inversion_old(
|
|
237
|
+
phase_seq: CArray[CReal],
|
|
238
|
+
block_encoding_cnot: QCallable[QArray[QBit], QBit],
|
|
239
|
+
u: QCallable[QArray[QBit]],
|
|
240
|
+
qvar: QArray[QBit],
|
|
241
|
+
aux: QBit,
|
|
242
|
+
) -> None:
|
|
243
|
+
"""
|
|
244
|
+
[Qmod Classiq-library function]
|
|
245
|
+
|
|
246
|
+
Implements matrix inversion on a given block-encoding of a square matrix, using the QSVT framework. Applies a polynomial approximation
|
|
247
|
+
of the inverse of the singular values of the matrix encoded in `u`. The phases for the polynomial should be pre-calculated and passed into the function.
|
|
248
|
+
|
|
249
|
+
Args:
|
|
250
|
+
phase_seq: A sequence of phase angles of length d+1, corresponding to an odd polynomial approximation of the scaled inverse function.
|
|
251
|
+
block_encoding_cnot: Projector-controlled-not unitary that locates the encoded matrix columns within U. Accepts a quantum variable of the same size as qvar, and a qubit that is set to |1> when the state is in the block.
|
|
252
|
+
u: A block encoding unitary matrix.
|
|
253
|
+
qvar: The quantum variable to which U is applied, which resides in the entire block encoding space.
|
|
254
|
+
aux: A zero auxilliary qubit, used for the projector-controlled-phase rotations. Given as an inout so that qsvt can be used as a building-block in a larger algorithm.
|
|
255
|
+
"""
|
|
256
|
+
qsvt_old(
|
|
257
|
+
phase_seq,
|
|
258
|
+
block_encoding_cnot,
|
|
259
|
+
block_encoding_cnot,
|
|
260
|
+
lambda x: invert(lambda: u(x)),
|
|
261
|
+
qvar,
|
|
262
|
+
aux,
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def qsvt_inversion(*args, **kwargs): # type: ignore[no-untyped-def]
|
|
267
|
+
"""
|
|
268
|
+
[Qmod Classiq-library function]
|
|
269
|
+
|
|
270
|
+
Implements matrix inversion on a given block-encoding of a square matrix, using the QSVT framework. Applies a polynomial approximation
|
|
271
|
+
of the inverse of the singular values of the matrix encoded in `u`. The phases for the polynomial should be pre-calculated and passed into the function.
|
|
272
|
+
|
|
273
|
+
Args:
|
|
274
|
+
phase_seq: A sequence of phase angles of length d+1, corresponding to an odd polynomial approximation of the scaled inverse function.
|
|
275
|
+
block_encoding_cnot: Projector-controlled-not unitary that locates the encoded matrix columns within U. Accepts a quantum variable that should be set to |1> when the state is in the block.
|
|
276
|
+
u: A block encoding unitary matrix.
|
|
277
|
+
aux: A zero auxilliary qubit, used for the projector-controlled-phase rotations. Given as an inout so that qsvt can be used as a building-block in a larger algorithm.
|
|
278
|
+
"""
|
|
279
|
+
if len(args) + len(kwargs) == 5:
|
|
280
|
+
warnings.warn(
|
|
281
|
+
"The 'qsvt_inversion' function signature has changed and the old version will be deprecated"
|
|
282
|
+
" starting on 2025-12-13 at the earliest",
|
|
283
|
+
ClassiqDeprecationWarning,
|
|
284
|
+
stacklevel=2,
|
|
285
|
+
)
|
|
286
|
+
return qsvt_inversion_old(*args, **kwargs)
|
|
287
|
+
return qsvt_inversion_new(*args, **kwargs)
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
@qfunc
|
|
291
|
+
def projector_controlled_double_phase_old(
|
|
292
|
+
phase_even: CReal,
|
|
293
|
+
phase_odd: CReal,
|
|
294
|
+
proj_cnot: QCallable[QArray[QBit], QBit],
|
|
295
|
+
qvar: QArray[QBit],
|
|
296
|
+
aux: QBit,
|
|
297
|
+
lcu: QBit,
|
|
298
|
+
) -> None:
|
|
299
|
+
"""
|
|
300
|
+
[Qmod Classiq-library function]
|
|
301
|
+
|
|
302
|
+
Assigns 2 phases to the entire subspace determined by the given projector, each one is controlled differentely on a given `lcu` qvar.
|
|
303
|
+
Used in the context of the `qsvt_lcu` function. Corresponds to the operation:
|
|
304
|
+
|
|
305
|
+
$$
|
|
306
|
+
\\Pi_{\\phi_{odd}, \\phi_{even}} = (C_{\\Pi}NOT) (C_{lcu=1}e^{-i\\frac{\\phi_{even}}{2}Z}) (C_{lcu=0}e^{-i\\frac{\\phi_{odd}}{2}Z}) (C_{\\Pi}NOT)
|
|
307
|
+
$$
|
|
308
|
+
|
|
309
|
+
Args:
|
|
310
|
+
phase_even: Rotation phase, corresponds to 'lcu'=0.
|
|
311
|
+
phase_odd: Rotation phase, corresponds to 'lcu'=1.
|
|
312
|
+
proj_cnot: Projector-controlled-not unitary that sets an auxilliary qubit to |1> when the state is in the projection.
|
|
313
|
+
qvar: The quantum variable to which the rotation applies, which resides in the entire block encoding space.
|
|
314
|
+
aux: A zero auxilliary qubit, used for the projector-controlled-phase rotation. Given as an inout so that qsvt can be used as a building-block in a larger algorithm.
|
|
315
|
+
lcu: The quantum variable used for controlling the phase assignment.
|
|
316
|
+
"""
|
|
317
|
+
within_apply(
|
|
318
|
+
lambda: proj_cnot(qvar, aux),
|
|
319
|
+
lambda: control(lcu, lambda: RZ(phase_odd, aux), lambda: RZ(phase_even, aux)),
|
|
320
|
+
)
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
def projector_controlled_double_phase(*args, **kwargs): # type: ignore[no-untyped-def]
|
|
324
|
+
"""
|
|
325
|
+
[Qmod Classiq-library function]
|
|
326
|
+
|
|
327
|
+
Assigns 2 phases to the entire subspace determined by the given projector, each one is controlled differentely on a given `lcu` qvar.
|
|
328
|
+
Used in the context of the `qsvt_lcu` function. Corresponds to the operation:
|
|
329
|
+
|
|
330
|
+
$$
|
|
331
|
+
\\Pi_{\\phi_{odd}, \\phi_{even}} = (C_{\\Pi}NOT) (C_{lcu=1}e^{-i\\frac{\\phi_{even}}{2}Z}) (C_{lcu=0}e^{-i\\frac{\\phi_{odd}}{2}Z}) (C_{\\Pi}NOT)
|
|
332
|
+
$$
|
|
333
|
+
|
|
334
|
+
Args:
|
|
335
|
+
phase_even: Rotation phase, corresponds to 'lcu'=0.
|
|
336
|
+
phase_odd: Rotation phase, corresponds to 'lcu'=1.
|
|
337
|
+
proj_cnot: Projector-controlled-not unitary that sets an auxilliary qubit to |1> when the state is in the projection.
|
|
338
|
+
aux: A zero auxilliary qubit, used for the projector-controlled-phase rotation. Given as an inout so that qsvt can be used as a building-block in a larger algorithm.
|
|
339
|
+
lcu: The quantum variable used for controlling the phase assignment.
|
|
340
|
+
"""
|
|
341
|
+
if len(args) + len(kwargs) == 6:
|
|
342
|
+
return projector_controlled_double_phase_old(*args, **kwargs)
|
|
343
|
+
return projector_controlled_double_phase_new(*args, **kwargs)
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
@qfunc
|
|
347
|
+
def qsvt_lcu_step_old(
|
|
348
|
+
phases_even: CArray[CReal],
|
|
349
|
+
phases_odd: CArray[CReal],
|
|
350
|
+
proj_cnot_1: QCallable[QArray[QBit], QBit],
|
|
351
|
+
proj_cnot_2: QCallable[QArray[QBit], QBit],
|
|
352
|
+
u: QCallable[QArray[QBit]],
|
|
353
|
+
qvar: QArray[QBit],
|
|
354
|
+
aux: QBit,
|
|
355
|
+
lcu: QBit,
|
|
356
|
+
) -> None:
|
|
357
|
+
"""
|
|
358
|
+
[Qmod Classiq-library function]
|
|
359
|
+
|
|
360
|
+
Applies a single QSVT-lcu step, composed of 2 double phase projector-controlled-phase rotations, and applications of the block encoding unitary `u` and its inverse:
|
|
361
|
+
|
|
362
|
+
$$
|
|
363
|
+
(C_{lcu=1}\\Pi^{even}_{\\phi_2})(C_{lcu=0}\\Pi^{odd}_{\\phi_2})U^{\\dagger}(C_{lcu=1}\\tilde{\\Pi}^{even}_{\\phi_1})(C_{lcu=0}\\tilde{\\Pi}^{odd}_{\\phi_1})U
|
|
364
|
+
$$
|
|
365
|
+
|
|
366
|
+
Args:
|
|
367
|
+
phases_even: 2 rotation phases for the even polynomial
|
|
368
|
+
phases_odd: 2 rotation phases for the odd polynomial
|
|
369
|
+
proj_cnot_1: Projector-controlled-not unitary that locates the encoded matrix columns within U. Accepts a quantum variable of the same size as qvar, and a qubit that is set to |1> when the state is in the block.
|
|
370
|
+
proj_cnot_2: Projector-controlled-not unitary that locates the encoded matrix rows within U. Accepts a quantum variable of the same size as qvar, and a qubit that is set to |1> when the state is in the block.
|
|
371
|
+
u: A block encoding unitary matrix.
|
|
372
|
+
qvar: The quantum variable to which U is applied, which resides in the entire block encoding space.
|
|
373
|
+
aux: A zero auxilliary qubit, used for the projector-controlled-phase rotations. Given as an inout so that qsvt can be used as a building-block in a larger algorithm.
|
|
374
|
+
lcu: A qubit used for the combination of 2 polynomials within a single qsvt application
|
|
375
|
+
"""
|
|
376
|
+
u(qvar)
|
|
377
|
+
projector_controlled_double_phase_old(
|
|
378
|
+
phases_even[0], phases_odd[0], proj_cnot_2, qvar, aux, lcu
|
|
379
|
+
)
|
|
380
|
+
invert(lambda: u(qvar))
|
|
381
|
+
projector_controlled_double_phase_old(
|
|
382
|
+
phases_even[1], phases_odd[1], proj_cnot_1, qvar, aux, lcu
|
|
383
|
+
)
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
def qsvt_lcu_step(*args, **kwargs): # type: ignore[no-untyped-def]
|
|
387
|
+
"""
|
|
388
|
+
[Qmod Classiq-library function]
|
|
389
|
+
|
|
390
|
+
Applies a single QSVT-lcu step, composed of 2 double phase projector-controlled-phase rotations, and applications of the block encoding unitary `u` and its inverse:
|
|
391
|
+
|
|
392
|
+
$$
|
|
393
|
+
(C_{lcu=1}\\Pi^{even}_{\\phi_2})(C_{lcu=0}\\Pi^{odd}_{\\phi_2})U^{\\dagger}(C_{lcu=1}\\tilde{\\Pi}^{even}_{\\phi_1})(C_{lcu=0}\\tilde{\\Pi}^{odd}_{\\phi_1})U
|
|
394
|
+
$$
|
|
395
|
+
|
|
396
|
+
Args:
|
|
397
|
+
phases_even: 2 rotation phases for the even polynomial
|
|
398
|
+
phases_odd: 2 rotation phases for the odd polynomial
|
|
399
|
+
proj_cnot_1: Projector-controlled-not unitary that locates the encoded matrix columns within U. Accepts a qubit that should be set to |1> when the state is in the block.
|
|
400
|
+
proj_cnot_2: Projector-controlled-not unitary that locates the encoded matrix rows within U. Accepts a qubit that should be set to |1> when the state is in the block.
|
|
401
|
+
u: A block encoding unitary matrix.
|
|
402
|
+
aux: A zero auxilliary qubit, used for the projector-controlled-phase rotations. Given as an inout so that qsvt can be used as a building-block in a larger algorithm.
|
|
403
|
+
lcu: A qubit used for the combination of 2 polynomials within a single qsvt application
|
|
404
|
+
"""
|
|
405
|
+
if len(args) + len(kwargs) == 8:
|
|
406
|
+
return qsvt_lcu_step_old(*args, **kwargs)
|
|
407
|
+
return qsvt_lcu_step_new(*args, **kwargs)
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
@qfunc
|
|
411
|
+
def qsvt_lcu_old(
|
|
412
|
+
phase_seq_even: CArray[CReal],
|
|
413
|
+
phase_seq_odd: CArray[CReal],
|
|
414
|
+
proj_cnot_1: QCallable[QArray[QBit], QBit],
|
|
415
|
+
proj_cnot_2: QCallable[QArray[QBit], QBit],
|
|
416
|
+
u: QCallable[QArray[QBit]],
|
|
417
|
+
qvar: QArray[QBit],
|
|
418
|
+
aux: QBit,
|
|
419
|
+
lcu: QBit,
|
|
420
|
+
) -> None:
|
|
421
|
+
"""
|
|
422
|
+
[Qmod Classiq-library function]
|
|
423
|
+
|
|
424
|
+
Implements the Quantum Singular Value Transformation (QSVT) for a linear combination of odd and even polynomials, so that
|
|
425
|
+
it is possible to encode a polynomial of indefinite parity, such as approximation to exp(i*A) or exp(A). Should work
|
|
426
|
+
for Hermitian block encodings.
|
|
427
|
+
|
|
428
|
+
The function is equivalent to applying the `qsvt` function for odd and even polynomials with a LCU function, but
|
|
429
|
+
is more efficient as the two polynomials share the same applications of the given unitary.
|
|
430
|
+
|
|
431
|
+
The function is intended to be called within a context of LCU, where it is called as the SELECT operator, and wrapped
|
|
432
|
+
with initialization of the `lcu` qubit to get the desired combination coefficients.
|
|
433
|
+
The even polynomial corresponds to the case where the $lcu=|0\\rangle$, while the odd to $lcu=|1\\rangle$.
|
|
434
|
+
|
|
435
|
+
Note: the two polynomials should have the same degree up to a difference of 1.
|
|
436
|
+
|
|
437
|
+
Args:
|
|
438
|
+
phase_seq_odd: A sequence of phase angles of length d+(d%2) for the odd polynomial.
|
|
439
|
+
phase_seq_even: A sequence of phase angles of length d+(d+1)%2 for the even polynomial.
|
|
440
|
+
proj_cnot_1: Projector-controlled-not unitary that locates the encoded matrix columns within U. Accepts a quantum variable of the same size as qvar, and a qubit that is set to |1> when the state is in the block.
|
|
441
|
+
proj_cnot_2: Projector-controlled-not unitary that locates the encoded matrix rows within U. Accepts a quantum variable of the same size as qvar, and a qubit that is set to |1> when the state is in the block.
|
|
442
|
+
u: A block encoding unitary matrix.
|
|
443
|
+
qvar: The quantum variable to which U is applied, which resides in the entire block encoding space.
|
|
444
|
+
aux: A zero auxilliary qubit, used for the projector-controlled-phase rotations. Given as an inout so that qsvt can be used as a building-block in a larger algorithm.
|
|
445
|
+
lcu: A qubit used for the combination of 2 polynomials within a single qsvt application
|
|
446
|
+
"""
|
|
447
|
+
H(aux)
|
|
448
|
+
projector_controlled_double_phase_old(
|
|
449
|
+
phase_seq_even[0], phase_seq_odd[0], proj_cnot_1, qvar, aux, lcu
|
|
450
|
+
)
|
|
451
|
+
repeat(
|
|
452
|
+
count=floor((qmin(phase_seq_odd.len - 1, phase_seq_even.len - 1)) / 2),
|
|
453
|
+
iteration=lambda index: qsvt_lcu_step_old(
|
|
454
|
+
phase_seq_even[2 * index + 1 : 2 * index + 3],
|
|
455
|
+
phase_seq_odd[2 * index + 1 : 2 * index + 3],
|
|
456
|
+
proj_cnot_1,
|
|
457
|
+
proj_cnot_2,
|
|
458
|
+
u,
|
|
459
|
+
qvar,
|
|
460
|
+
aux,
|
|
461
|
+
lcu,
|
|
462
|
+
),
|
|
463
|
+
)
|
|
464
|
+
if_(
|
|
465
|
+
condition=phase_seq_odd.len > phase_seq_even.len,
|
|
466
|
+
then=lambda: control(
|
|
467
|
+
lcu,
|
|
468
|
+
lambda: [
|
|
469
|
+
u(qvar),
|
|
470
|
+
projector_controlled_phase_old(
|
|
471
|
+
phase_seq_odd[phase_seq_odd.len - 1], proj_cnot_2, qvar, aux
|
|
472
|
+
),
|
|
473
|
+
],
|
|
474
|
+
),
|
|
475
|
+
)
|
|
476
|
+
if_(
|
|
477
|
+
condition=phase_seq_odd.len < phase_seq_even.len,
|
|
478
|
+
then=lambda: (
|
|
479
|
+
u(qvar),
|
|
480
|
+
projector_controlled_double_phase_old(
|
|
481
|
+
phase_seq_even[phase_seq_even.len - 2],
|
|
482
|
+
phase_seq_odd[phase_seq_odd.len - 1],
|
|
483
|
+
proj_cnot_2,
|
|
484
|
+
qvar,
|
|
485
|
+
aux,
|
|
486
|
+
lcu,
|
|
487
|
+
),
|
|
488
|
+
control(
|
|
489
|
+
lcu == 0,
|
|
490
|
+
lambda: [
|
|
491
|
+
invert(lambda: u(qvar)),
|
|
492
|
+
projector_controlled_phase_old(
|
|
493
|
+
phase_seq_even[phase_seq_even.len - 1], proj_cnot_1, qvar, aux
|
|
494
|
+
),
|
|
495
|
+
],
|
|
496
|
+
),
|
|
497
|
+
),
|
|
498
|
+
)
|
|
499
|
+
H(aux)
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
def qsvt_lcu(*args, **kwargs): # type: ignore[no-untyped-def]
|
|
503
|
+
"""
|
|
504
|
+
[Qmod Classiq-library function]
|
|
505
|
+
|
|
506
|
+
Implements the Quantum Singular Value Transformation (QSVT) for a linear combination of odd and even polynomials, so that
|
|
507
|
+
it is possible to encode a polynomial of indefinite parity, such as approximation to exp(i*A) or exp(A). Should work
|
|
508
|
+
for Hermitian block encodings.
|
|
509
|
+
|
|
510
|
+
The function is equivalent to applying the `qsvt` function for odd and even polynomials with a LCU function, but
|
|
511
|
+
is more efficient as the two polynomials share the same applications of the given unitary.
|
|
512
|
+
|
|
513
|
+
The function is intended to be called within a context of LCU, where it is called as the SELECT operator, and wrapped
|
|
514
|
+
with initialization of the `lcu` qubit to get the desired combination coefficients.
|
|
515
|
+
The even polynomial corresponds to the case where the $lcu=|0\\rangle$, while the odd to $lcu=|1\\rangle$.
|
|
516
|
+
|
|
517
|
+
Note: the two polynomials should have the same degree up to a difference of 1.
|
|
518
|
+
|
|
519
|
+
Args:
|
|
520
|
+
phase_seq_odd: A sequence of phase angles of length d+(d%2) for the odd polynomial.
|
|
521
|
+
phase_seq_even: A sequence of phase angles of length d+(d+1)%2 for the even polynomial.
|
|
522
|
+
proj_cnot_1: Projector-controlled-not unitary that locates the encoded matrix columns within U. Accepts a qubit that should be set to |1> when the state is in the block.
|
|
523
|
+
proj_cnot_2: Projector-controlled-not unitary that locates the encoded matrix rows within U. Accepts a qubit that should be set to |1> when the state is in the block.
|
|
524
|
+
u: A block encoding unitary matrix.
|
|
525
|
+
aux: A zero auxilliary qubit, used for the projector-controlled-phase rotations. Given as an inout so that qsvt can be used as a building-block in a larger algorithm.
|
|
526
|
+
lcu: A qubit used for the combination of 2 polynomials within a single qsvt application
|
|
527
|
+
"""
|
|
528
|
+
if len(args) + len(kwargs) == 8:
|
|
529
|
+
warnings.warn(
|
|
530
|
+
"The 'qsvt_lcu' function signature has changed and the old version will be deprecated"
|
|
531
|
+
" starting on 2025-12-13 at the earliest",
|
|
532
|
+
ClassiqDeprecationWarning,
|
|
533
|
+
stacklevel=2,
|
|
534
|
+
)
|
|
535
|
+
return qsvt_lcu_old(*args, **kwargs)
|
|
536
|
+
return qsvt_lcu_new(*args, **kwargs)
|