classiq 0.52.0__py3-none-any.whl → 0.54.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 +23 -17
- 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 +11 -13
- 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 +25 -6
- 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 +3 -3
- classiq/execution/all_hardware_devices.py +1 -3
- classiq/execution/execution_session.py +57 -16
- classiq/execution/iqcc.py +1 -1
- classiq/execution/jobs.py +4 -4
- classiq/execution/qaoa.py +84 -0
- classiq/execution/qnn.py +3 -3
- classiq/executor.py +4 -4
- 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 +11 -7
- classiq/interface/execution/iqcc.py +1 -3
- 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 +35 -28
- 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/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 +34 -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 +7 -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/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/dotdict.py +18 -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 +4 -3
- classiq/interface/helpers/validation_helpers.py +2 -2
- classiq/interface/ide/ide_data.py +11 -15
- classiq/interface/ide/visual_model.py +33 -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/handle_binding.py +3 -2
- classiq/interface/model/inplace_binary_operation.py +2 -1
- classiq/interface/model/model.py +12 -11
- classiq/interface/model/native_function_definition.py +10 -0
- 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 +3 -2
- 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 +4 -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/call_to_model_converter.py +190 -0
- 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 +17 -9
- 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 +19 -12
- classiq/model_expansions/generative_functions.py +3 -2
- classiq/model_expansions/interpreter.py +31 -19
- 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 +2 -4
- classiq/model_expansions/quantum_operations/emitter.py +10 -13
- classiq/model_expansions/quantum_operations/expression_operation.py +23 -16
- classiq/model_expansions/quantum_operations/inplace_binary_operation.py +164 -38
- classiq/model_expansions/quantum_operations/phase.py +6 -6
- classiq/model_expansions/quantum_operations/quantum_assignment_operation.py +25 -5
- classiq/model_expansions/quantum_operations/quantum_function_call.py +41 -2
- classiq/model_expansions/quantum_operations/repeat.py +1 -3
- classiq/model_expansions/scope.py +11 -10
- classiq/model_expansions/scope_initialization.py +6 -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/__init__.py +2 -0
- classiq/qmod/builtins/classical_execution_primitives.py +9 -9
- classiq/qmod/builtins/functions/__init__.py +75 -53
- 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 +18 -18
- 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 +53 -0
- classiq/qmod/builtins/operations.py +4 -5
- classiq/qmod/cfunc.py +2 -2
- classiq/qmod/classical_function.py +3 -7
- classiq/qmod/create_model_function.py +19 -8
- 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 +5 -7
- classiq/qmod/native/__init__.py +1 -3
- classiq/qmod/native/expression_to_qmod.py +9 -8
- classiq/qmod/native/pretty_printer.py +6 -5
- 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 +13 -12
- classiq/qmod/python_classical_type.py +8 -4
- classiq/qmod/qfunc.py +4 -4
- classiq/qmod/qmod_parameter.py +3 -1
- classiq/qmod/qmod_variable.py +11 -10
- classiq/qmod/quantum_expandable.py +32 -15
- classiq/qmod/quantum_function.py +34 -5
- 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 +16 -0
- {classiq-0.52.0.dist-info → classiq-0.54.0.dist-info}/METADATA +1 -1
- {classiq-0.52.0.dist-info → classiq-0.54.0.dist-info}/RECORD +302 -295
- classiq/qmod/builtins/functions/qft.py +0 -23
- {classiq-0.52.0.dist-info → classiq-0.54.0.dist-info}/WHEEL +0 -0
@@ -1,15 +1,54 @@
|
|
1
|
+
from typing import TYPE_CHECKING
|
2
|
+
|
1
3
|
from classiq.interface.model.quantum_function_call import QuantumFunctionCall
|
2
4
|
|
5
|
+
from classiq.model_expansions.call_to_model_converter import (
|
6
|
+
BlockFunctionInfo,
|
7
|
+
CallToModelConverter,
|
8
|
+
)
|
3
9
|
from classiq.model_expansions.closure import FunctionClosure
|
4
10
|
from classiq.model_expansions.quantum_operations.emitter import Emitter
|
5
11
|
from classiq.qmod.semantics.error_manager import ErrorManager
|
6
12
|
|
13
|
+
if TYPE_CHECKING:
|
14
|
+
from classiq.model_expansions.interpreter import Interpreter
|
15
|
+
|
7
16
|
|
8
17
|
class QuantumFunctionCallEmitter(Emitter[QuantumFunctionCall]):
|
18
|
+
def __init__(self, interpreter: "Interpreter") -> None:
|
19
|
+
super().__init__(interpreter)
|
20
|
+
self._model = self._interpreter._model
|
21
|
+
self._synthesized_separately_blocks = (
|
22
|
+
self._interpreter._synthesized_separately_blocks
|
23
|
+
)
|
24
|
+
|
9
25
|
def emit(self, call: QuantumFunctionCall, /) -> None:
|
10
|
-
function = self._interpreter.evaluate(call.function).as_type(
|
26
|
+
function: FunctionClosure = self._interpreter.evaluate(call.function).as_type(
|
27
|
+
FunctionClosure
|
28
|
+
)
|
11
29
|
args = call.positional_args
|
12
30
|
with ErrorManager().call(
|
13
31
|
function.name
|
14
32
|
), function.scope.freeze(), self._propagated_var_stack.capture_variables(call):
|
15
|
-
self._emit_quantum_function_call(function, args)
|
33
|
+
new_call = self._emit_quantum_function_call(function, args)
|
34
|
+
if function.synthesis_data.should_synthesize_separately:
|
35
|
+
interpreted_call_converter = CallToModelConverter(
|
36
|
+
call,
|
37
|
+
function.positional_arg_declarations,
|
38
|
+
function.scope.data,
|
39
|
+
self._model,
|
40
|
+
)
|
41
|
+
self._update_synthesized_separately_models(
|
42
|
+
interpreted_call_converter, new_call.func_name
|
43
|
+
)
|
44
|
+
|
45
|
+
def _update_synthesized_separately_models(
|
46
|
+
self, call_converter: CallToModelConverter, call_name: str
|
47
|
+
) -> None:
|
48
|
+
synthesized_separately_blocks = self._synthesized_separately_blocks
|
49
|
+
block_id = call_converter.block_id
|
50
|
+
block_function = synthesized_separately_blocks.get(block_id)
|
51
|
+
if block_function is None:
|
52
|
+
block_function = BlockFunctionInfo.from_call_converter(call_converter)
|
53
|
+
synthesized_separately_blocks[block_id] = block_function
|
54
|
+
block_function.calls.add(call_name)
|
@@ -1,5 +1,3 @@
|
|
1
|
-
from typing import Type
|
2
|
-
|
3
1
|
from classiq.interface.generator.expressions.expression import Expression
|
4
2
|
from classiq.interface.generator.functions.builtins.internal_operators import (
|
5
3
|
REPEAT_OPERATOR_NAME,
|
@@ -24,7 +22,7 @@ class RepeatEmitter(Emitter[Repeat]):
|
|
24
22
|
self._emit_propagated(repeat, i)
|
25
23
|
|
26
24
|
def _emit_propagated(self, repeat: Repeat, i: int) -> None:
|
27
|
-
closure_constructor:
|
25
|
+
closure_constructor: type[FunctionClosure]
|
28
26
|
extra_args: dict
|
29
27
|
if repeat.is_generative():
|
30
28
|
closure_constructor = GenerativeFunctionClosure
|
@@ -1,9 +1,10 @@
|
|
1
1
|
import itertools
|
2
2
|
from collections import UserDict
|
3
|
+
from collections.abc import Iterator
|
3
4
|
from contextlib import contextmanager
|
4
5
|
from dataclasses import dataclass
|
5
6
|
from functools import singledispatch
|
6
|
-
from typing import TYPE_CHECKING, Any,
|
7
|
+
from typing import TYPE_CHECKING, Any, Optional, TypeVar, Union
|
7
8
|
|
8
9
|
from classiq.interface.exceptions import (
|
9
10
|
ClassiqExpansionError,
|
@@ -104,7 +105,7 @@ class QuantumSymbol:
|
|
104
105
|
)
|
105
106
|
|
106
107
|
@property
|
107
|
-
def fields(self) ->
|
108
|
+
def fields(self) -> dict[str, "QuantumSymbol"]:
|
108
109
|
quantum_type = self.quantum_type
|
109
110
|
if not isinstance(quantum_type, TypeName):
|
110
111
|
raise ClassiqExpansionError(
|
@@ -120,18 +121,18 @@ class QuantumSymbol:
|
|
120
121
|
|
121
122
|
|
122
123
|
@singledispatch
|
123
|
-
def
|
124
|
+
def evaluated_to_str(value: Any) -> str:
|
124
125
|
return str(value)
|
125
126
|
|
126
127
|
|
127
|
-
@
|
128
|
+
@evaluated_to_str.register
|
128
129
|
def _evaluated_to_str_list(value: list) -> str:
|
129
|
-
return f"[{', '.join(
|
130
|
+
return f"[{', '.join(evaluated_to_str(x) for x in value)}]"
|
130
131
|
|
131
132
|
|
132
|
-
@
|
133
|
+
@evaluated_to_str.register
|
133
134
|
def _evaluated_to_str_struct_literal(value: QmodStructInstance) -> str:
|
134
|
-
return f"struct_literal({value.struct_declaration.name}, {', '.join(f'{k}={
|
135
|
+
return f"struct_literal({value.struct_declaration.name}, {', '.join(f'{k}={evaluated_to_str(v)}' for k, v in value.fields.items())})"
|
135
136
|
|
136
137
|
|
137
138
|
@dataclass(frozen=True)
|
@@ -139,7 +140,7 @@ class Evaluated: # FIXME: Merge with EvaluatedExpression if possible
|
|
139
140
|
value: Any
|
140
141
|
defining_function: Optional["Closure"] = None
|
141
142
|
|
142
|
-
def as_type(self, t:
|
143
|
+
def as_type(self, t: type[T]) -> T:
|
143
144
|
if t is int:
|
144
145
|
return self._as_int() # type: ignore[return-value]
|
145
146
|
|
@@ -162,7 +163,7 @@ class Evaluated: # FIXME: Merge with EvaluatedExpression if possible
|
|
162
163
|
if isinstance(self.value, QuantumSymbol):
|
163
164
|
return self.value.emit()
|
164
165
|
|
165
|
-
ret = Expression(expr=
|
166
|
+
ret = Expression(expr=evaluated_to_str(self.value))
|
166
167
|
ret._evaluated_expr = EvaluatedExpression(value=self.value)
|
167
168
|
return ret
|
168
169
|
|
@@ -176,7 +177,7 @@ else:
|
|
176
177
|
class Scope(EvaluatedUserDict):
|
177
178
|
def __init__(
|
178
179
|
self,
|
179
|
-
data: Optional[
|
180
|
+
data: Optional[dict[str, Evaluated]] = None,
|
180
181
|
/,
|
181
182
|
*,
|
182
183
|
parent: Optional["Scope"] = None,
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from
|
1
|
+
from collections.abc import Sequence
|
2
2
|
|
3
3
|
from classiq.interface.exceptions import ClassiqError
|
4
4
|
from classiq.interface.generator.constant import Constant
|
@@ -43,7 +43,7 @@ def get_main_renamer(
|
|
43
43
|
return ExpressionRenamer(var_mapping={})
|
44
44
|
|
45
45
|
|
46
|
-
def _add_constants_to_scope(constants:
|
46
|
+
def _add_constants_to_scope(constants: list[Constant], scope: Scope) -> None:
|
47
47
|
for constant in constants:
|
48
48
|
scope[constant.name] = Evaluated(
|
49
49
|
value=evaluate_classical_expression(constant.value, scope).value
|
@@ -51,7 +51,7 @@ def _add_constants_to_scope(constants: List[Constant], scope: Scope) -> None:
|
|
51
51
|
|
52
52
|
|
53
53
|
def _add_functions_to_scope(
|
54
|
-
functions:
|
54
|
+
functions: list[NativeFunctionDefinition], scope: Scope
|
55
55
|
) -> None:
|
56
56
|
for function in functions:
|
57
57
|
scope[function.name] = Evaluated(
|
@@ -60,12 +60,13 @@ def _add_functions_to_scope(
|
|
60
60
|
positional_arg_declarations=function.positional_arg_declarations,
|
61
61
|
body=function.body,
|
62
62
|
scope=Scope(parent=scope),
|
63
|
+
synthesis_data=function.synthesis_data,
|
63
64
|
)
|
64
65
|
)
|
65
66
|
|
66
67
|
|
67
68
|
def _add_generative_functions_to_scope(
|
68
|
-
functions:
|
69
|
+
functions: list[GenerativeQFunc], scope: Scope
|
69
70
|
) -> None:
|
70
71
|
for function in functions:
|
71
72
|
scope[function.func_decl.name] = Evaluated(
|
@@ -138,7 +139,7 @@ def add_entry_point_params_to_scope(
|
|
138
139
|
|
139
140
|
|
140
141
|
def init_top_level_scope(
|
141
|
-
model: Model, generative_functions:
|
142
|
+
model: Model, generative_functions: list[GenerativeQFunc], scope: Scope
|
142
143
|
) -> None:
|
143
144
|
_add_functions_to_scope(model.functions, scope)
|
144
145
|
_add_generative_functions_to_scope(generative_functions, scope)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import ast
|
2
|
-
from typing import TYPE_CHECKING,
|
2
|
+
from typing import TYPE_CHECKING, cast
|
3
3
|
|
4
4
|
from classiq.interface.exceptions import ClassiqExpansionError
|
5
5
|
|
@@ -18,29 +18,29 @@ def translate_to_sympy(expr: str) -> str:
|
|
18
18
|
|
19
19
|
|
20
20
|
class ExpressionSympyTranslator(ast.NodeTransformer):
|
21
|
-
BINARY_OPERATORS:
|
21
|
+
BINARY_OPERATORS: dict[type[ast.AST], str] = {
|
22
22
|
ast.BitOr: "BitwiseOr",
|
23
23
|
ast.BitAnd: "BitwiseAnd",
|
24
24
|
ast.BitXor: "BitwiseXor",
|
25
25
|
ast.Div: "do_div",
|
26
26
|
}
|
27
27
|
|
28
|
-
UNARY_OPERATORS:
|
28
|
+
UNARY_OPERATORS: dict[type[ast.AST], str] = {
|
29
29
|
ast.Invert: "BitwiseNot",
|
30
30
|
ast.Not: "Not",
|
31
31
|
}
|
32
32
|
|
33
|
-
BOOLEAN_OPERATORS:
|
33
|
+
BOOLEAN_OPERATORS: dict[type[ast.AST], str] = {
|
34
34
|
ast.Or: "Or",
|
35
35
|
ast.And: "And",
|
36
36
|
}
|
37
37
|
|
38
|
-
COMPARE_OPERATORS:
|
38
|
+
COMPARE_OPERATORS: dict[type[ast.AST], str] = {
|
39
39
|
ast.Eq: "Eq",
|
40
40
|
ast.NotEq: "Ne",
|
41
41
|
}
|
42
42
|
|
43
|
-
SPECIAL_FUNCTIONS:
|
43
|
+
SPECIAL_FUNCTIONS: dict[str, str] = {
|
44
44
|
"max": "Max",
|
45
45
|
"min": "Min",
|
46
46
|
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import functools
|
2
|
-
from typing import Any,
|
2
|
+
from typing import Any, Optional, get_args
|
3
3
|
|
4
4
|
from sympy import (
|
5
5
|
Array,
|
@@ -22,7 +22,7 @@ from classiq.model_expansions.sympy_conversion.arithmetics import LogicalXor
|
|
22
22
|
|
23
23
|
|
24
24
|
def sympy_to_python(
|
25
|
-
value: Any, locals: Optional[
|
25
|
+
value: Any, locals: Optional[dict[str, ExpressionValue]] = None
|
26
26
|
) -> ExpressionValue:
|
27
27
|
if isinstance(value, Integer):
|
28
28
|
value = int(value)
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import ast
|
2
|
+
from collections.abc import Iterator
|
2
3
|
from contextlib import contextmanager
|
3
|
-
from typing import
|
4
|
+
from typing import Optional, Union
|
4
5
|
|
5
6
|
from classiq.interface.exceptions import (
|
6
7
|
ClassiqExpansionError,
|
@@ -23,12 +24,12 @@ from classiq.interface.model.handle_binding import (
|
|
23
24
|
|
24
25
|
class VarRefCollector(ast.NodeVisitor):
|
25
26
|
def __init__(self, ignore_duplicated_handles: bool = False) -> None:
|
26
|
-
self._var_handles:
|
27
|
+
self._var_handles: dict[HandleBinding, bool] = {}
|
27
28
|
self._ignore_duplicated_handles = ignore_duplicated_handles
|
28
29
|
self._is_nested = False
|
29
30
|
|
30
31
|
@property
|
31
|
-
def var_handles(self) ->
|
32
|
+
def var_handles(self) -> list[HandleBinding]:
|
32
33
|
return list(self._var_handles)
|
33
34
|
|
34
35
|
def visit(self, node: ast.AST) -> Union[
|
@@ -110,7 +111,7 @@ class VarRefCollector(ast.NodeVisitor):
|
|
110
111
|
|
111
112
|
|
112
113
|
class VarRefTransformer(ast.NodeTransformer):
|
113
|
-
def __init__(self, var_mapping:
|
114
|
+
def __init__(self, var_mapping: dict[str, str]) -> None:
|
114
115
|
self.var_mapping = var_mapping
|
115
116
|
|
116
117
|
def visit_Name(self, node: ast.Name) -> ast.Name:
|
classiq/qmod/__init__.py
CHANGED
@@ -8,6 +8,7 @@ from .qmod_constant import QConstant
|
|
8
8
|
from .qmod_parameter import Array, CArray, CBool, CInt, CReal
|
9
9
|
from .qmod_variable import Input, Output, QArray, QBit, QNum, QStruct
|
10
10
|
from .quantum_callable import QCallable, QCallableList
|
11
|
+
from .synthesize_separately import synthesize_separately
|
11
12
|
from .write_qmod import write_qmod
|
12
13
|
|
13
14
|
__all__ = [
|
@@ -30,4 +31,5 @@ __all__ = [
|
|
30
31
|
"get_expression_numeric_attributes",
|
31
32
|
"qfunc",
|
32
33
|
"write_qmod",
|
34
|
+
"synthesize_separately",
|
33
35
|
] + _builtins_all
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import
|
1
|
+
from typing import Final, Optional, Union
|
2
2
|
|
3
3
|
from classiq.interface.exceptions import ClassiqError
|
4
4
|
from classiq.interface.executor.execution_preferences import QaeWithQpeEstimationMethod
|
@@ -15,7 +15,7 @@ from classiq.interface.generator.functions.qmod_python_interface import QmodPySt
|
|
15
15
|
from classiq.applications.qsvm.qsvm import Data, Labels
|
16
16
|
from classiq.qmod.builtins.enums import Optimizer
|
17
17
|
|
18
|
-
ExecutionParams =
|
18
|
+
ExecutionParams = dict[str, Union[float, int, list[int], list[float]]]
|
19
19
|
|
20
20
|
_CALL_IN_QFUNC_ERROR = (
|
21
21
|
'Cannot call "{}" in a quantum context. "{}" is a classical execution primitive.'
|
@@ -39,28 +39,28 @@ def sample( # type: ignore[return]
|
|
39
39
|
|
40
40
|
|
41
41
|
def batch_sample( # type: ignore[return]
|
42
|
-
batch_execution_params:
|
42
|
+
batch_execution_params: list[ExecutionParams],
|
43
43
|
) -> MultipleExecutionDetails:
|
44
44
|
_raise_error("batch_sample")
|
45
45
|
|
46
46
|
|
47
47
|
def estimate( # type: ignore[return]
|
48
|
-
hamiltonian:
|
48
|
+
hamiltonian: list[QmodPyStruct], execution_params: Optional[ExecutionParams] = None
|
49
49
|
) -> EstimationResult:
|
50
50
|
_raise_error("estimate")
|
51
51
|
|
52
52
|
|
53
53
|
def batch_estimate( # type: ignore[return]
|
54
|
-
hamiltonian:
|
55
|
-
batch_execution_params:
|
54
|
+
hamiltonian: list[QmodPyStruct],
|
55
|
+
batch_execution_params: list[ExecutionParams],
|
56
56
|
) -> EstimationResults:
|
57
57
|
_raise_error("batch_estimate")
|
58
58
|
|
59
59
|
|
60
60
|
def vqe( # type: ignore[return]
|
61
|
-
hamiltonian:
|
61
|
+
hamiltonian: list[QmodPyStruct],
|
62
62
|
maximize: bool,
|
63
|
-
initial_point:
|
63
|
+
initial_point: list[float],
|
64
64
|
optimizer: Optimizer,
|
65
65
|
max_iteration: int,
|
66
66
|
tolerance: float,
|
@@ -118,5 +118,5 @@ __all__ = [
|
|
118
118
|
]
|
119
119
|
|
120
120
|
|
121
|
-
def __dir__() ->
|
121
|
+
def __dir__() -> list[str]:
|
122
122
|
return __all__
|
@@ -1,3 +1,6 @@
|
|
1
|
+
from classiq.interface.model.native_function_definition import NativeFunctionDefinition
|
2
|
+
|
3
|
+
from ...quantum_function import GenerativeQFunc
|
1
4
|
from .amplitude_estimation import *
|
2
5
|
from .arithmetic import *
|
3
6
|
from .benchmarking import *
|
@@ -14,7 +17,7 @@ from .modular_exponentiation import *
|
|
14
17
|
from .modular_exponentiation import _check_msb, _ctrl_x
|
15
18
|
from .operators import *
|
16
19
|
from .qaoa_penalty import *
|
17
|
-
from .
|
20
|
+
from .qft_functions import *
|
18
21
|
from .qpe import *
|
19
22
|
from .qsvm import *
|
20
23
|
from .qsvt import *
|
@@ -22,6 +25,8 @@ from .standard_gates import *
|
|
22
25
|
from .state_preparation import *
|
23
26
|
from .state_preparation import _prepare_uniform_trimmed_state_step
|
24
27
|
from .swap_test import *
|
28
|
+
from .utility_functions import *
|
29
|
+
from .variational import *
|
25
30
|
|
26
31
|
CORE_LIB_DECLS = [
|
27
32
|
func.func_decl
|
@@ -85,60 +90,75 @@ CORE_LIB_DECLS = [
|
|
85
90
|
)
|
86
91
|
]
|
87
92
|
|
93
|
+
OPEN_LIBRARY_UNPROCESSED_FUNCTIONS = [
|
94
|
+
qpe_flexible,
|
95
|
+
qpe,
|
96
|
+
_single_pauli,
|
97
|
+
linear_pauli_rotations,
|
98
|
+
amplitude_estimation,
|
99
|
+
phase_oracle,
|
100
|
+
reflect_about_zero,
|
101
|
+
grover_diffuser,
|
102
|
+
grover_operator,
|
103
|
+
grover_search,
|
104
|
+
hadamard_transform,
|
105
|
+
apply_to_all,
|
106
|
+
qft_no_swap,
|
107
|
+
qft_space_add_const,
|
108
|
+
cc_modular_add,
|
109
|
+
c_modular_multiply,
|
110
|
+
multiswap,
|
111
|
+
inplace_c_modular_multiply,
|
112
|
+
modular_exp,
|
113
|
+
qsvt_step,
|
114
|
+
qsvt,
|
115
|
+
projector_controlled_phase,
|
116
|
+
qsvt_inversion,
|
117
|
+
allocate_num,
|
118
|
+
qaoa_mixer_layer,
|
119
|
+
qaoa_cost_layer,
|
120
|
+
qaoa_layer,
|
121
|
+
qaoa_init,
|
122
|
+
qaoa_penalty,
|
123
|
+
full_hea,
|
124
|
+
swap_test,
|
125
|
+
prepare_uniform_trimmed_state,
|
126
|
+
prepare_uniform_interval_state,
|
127
|
+
prepare_ghz_state,
|
128
|
+
prepare_exponential_state,
|
129
|
+
prepare_bell_state,
|
130
|
+
inplace_prepare_int,
|
131
|
+
prepare_int,
|
132
|
+
switch,
|
133
|
+
qct_qst_type1,
|
134
|
+
qct_qst_type2,
|
135
|
+
qct_type2,
|
136
|
+
qst_type2,
|
137
|
+
modular_increment,
|
138
|
+
qft,
|
139
|
+
_ctrl_x,
|
140
|
+
_prepare_uniform_trimmed_state_step,
|
141
|
+
_qct_d_operator,
|
142
|
+
_qct_pi_operator,
|
143
|
+
_check_msb,
|
144
|
+
encode_in_angle,
|
145
|
+
encode_on_bloch,
|
146
|
+
]
|
147
|
+
|
148
|
+
OPEN_LIBRARY_FUNCTIONS: list[NativeFunctionDefinition] = []
|
149
|
+
|
150
|
+
|
151
|
+
def load_open_library_implementations() -> None:
|
152
|
+
OPEN_LIBRARY_FUNCTIONS.extend(
|
153
|
+
[func.get_implementation() for func in OPEN_LIBRARY_UNPROCESSED_FUNCTIONS]
|
154
|
+
)
|
155
|
+
|
156
|
+
|
157
|
+
OPEN_LIBRARY_GENERATIVE_FUNCTIONS: list[GenerativeQFunc] = []
|
158
|
+
|
88
159
|
OPEN_LIB_DECLS = [
|
89
160
|
func.func_decl
|
90
|
-
for func in
|
91
|
-
qpe_flexible,
|
92
|
-
qpe,
|
93
|
-
_single_pauli,
|
94
|
-
linear_pauli_rotations,
|
95
|
-
amplitude_estimation,
|
96
|
-
phase_oracle,
|
97
|
-
reflect_about_zero,
|
98
|
-
grover_diffuser,
|
99
|
-
grover_operator,
|
100
|
-
grover_search,
|
101
|
-
hadamard_transform,
|
102
|
-
apply_to_all,
|
103
|
-
qft_no_swap,
|
104
|
-
qft_space_add_const,
|
105
|
-
cc_modular_add,
|
106
|
-
c_modular_multiply,
|
107
|
-
multiswap,
|
108
|
-
inplace_c_modular_multiply,
|
109
|
-
modular_exp,
|
110
|
-
qsvt_step,
|
111
|
-
qsvt,
|
112
|
-
projector_controlled_phase,
|
113
|
-
qsvt_inversion,
|
114
|
-
allocate_num,
|
115
|
-
qaoa_mixer_layer,
|
116
|
-
qaoa_cost_layer,
|
117
|
-
qaoa_layer,
|
118
|
-
qaoa_init,
|
119
|
-
qaoa_penalty,
|
120
|
-
full_hea,
|
121
|
-
swap_test,
|
122
|
-
prepare_uniform_trimmed_state,
|
123
|
-
prepare_uniform_interval_state,
|
124
|
-
prepare_ghz_state,
|
125
|
-
prepare_exponential_state,
|
126
|
-
prepare_bell_state,
|
127
|
-
inplace_prepare_int,
|
128
|
-
prepare_int,
|
129
|
-
switch,
|
130
|
-
qct_qst_type1,
|
131
|
-
qct_qst_type2,
|
132
|
-
qct_type2,
|
133
|
-
qst_type2,
|
134
|
-
modular_increment,
|
135
|
-
qft,
|
136
|
-
_ctrl_x,
|
137
|
-
_prepare_uniform_trimmed_state_step,
|
138
|
-
_qct_d_operator,
|
139
|
-
_qct_pi_operator,
|
140
|
-
_check_msb,
|
141
|
-
)
|
161
|
+
for func in OPEN_LIBRARY_GENERATIVE_FUNCTIONS + OPEN_LIBRARY_UNPROCESSED_FUNCTIONS
|
142
162
|
]
|
143
163
|
|
144
164
|
STD_QMOD_OPERATORS = [func.func_decl for func in (apply, permute)]
|
@@ -252,4 +272,6 @@ __all__ = [
|
|
252
272
|
"qst_type2",
|
253
273
|
"modular_increment",
|
254
274
|
"qft",
|
275
|
+
"encode_in_angle",
|
276
|
+
"encode_on_bloch",
|
255
277
|
]
|
@@ -1,3 +1,5 @@
|
|
1
|
+
from classiq.qmod.builtins.functions.grover import grover_operator
|
2
|
+
from classiq.qmod.builtins.functions.qpe import qpe
|
1
3
|
from classiq.qmod.qfunc import qfunc
|
2
4
|
from classiq.qmod.qmod_variable import QArray, QBit, QNum
|
3
5
|
from classiq.qmod.quantum_callable import QCallable
|
@@ -24,4 +26,5 @@ def amplitude_estimation(
|
|
24
26
|
phase: Assuming this variable starts from the zero state -this variable output holds the $phase=\\theta$ result in the [0,1] domain, which relates to the estimated probability $a$ through $a=\\sin^2(\\pi \\theta)$.
|
25
27
|
packed_vars: The variable that holds the state to be estimated. Assumed to be in the zero state at the beginning of the algorithm.
|
26
28
|
"""
|
27
|
-
|
29
|
+
space_transform(packed_vars)
|
30
|
+
qpe(lambda: grover_operator(oracle, space_transform, packed_vars), phase)
|
@@ -1,9 +1,13 @@
|
|
1
1
|
from typing import Literal
|
2
2
|
|
3
|
+
from classiq.qmod.builtins.functions.qft_functions import qft
|
4
|
+
from classiq.qmod.builtins.functions.standard_gates import PHASE
|
5
|
+
from classiq.qmod.builtins.operations import bind, repeat, within_apply
|
3
6
|
from classiq.qmod.cparam import CInt
|
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 Output, QArray, QBit, QNum
|
10
|
+
from classiq.qmod.symbolic import pi
|
7
11
|
|
8
12
|
|
9
13
|
@qfunc(external=True)
|
@@ -75,4 +79,13 @@ def modular_increment(a: CInt, x: QNum) -> None:
|
|
75
79
|
x: A quantum number that is assumed to be non-negative integer.
|
76
80
|
|
77
81
|
"""
|
78
|
-
|
82
|
+
array_cast: QArray = QArray("array_cast")
|
83
|
+
within_apply(
|
84
|
+
lambda: ( # type:ignore[arg-type]
|
85
|
+
bind(x, array_cast), # type:ignore[func-returns-value]
|
86
|
+
qft(array_cast),
|
87
|
+
),
|
88
|
+
lambda: repeat(
|
89
|
+
x.size, lambda i: PHASE(a * 2 * pi * 2**i / (2**x.size), array_cast[i])
|
90
|
+
),
|
91
|
+
)
|
@@ -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
|
+
)
|