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,6 +1,10 @@
|
|
1
|
+
from classiq.qmod.builtins.functions.qft_functions import qft
|
2
|
+
from classiq.qmod.builtins.functions.standard_gates import H
|
3
|
+
from classiq.qmod.builtins.functions.utility_functions import apply_to_all
|
4
|
+
from classiq.qmod.builtins.operations import bind, control, invert, power, repeat
|
5
|
+
from classiq.qmod.cparam import CInt
|
1
6
|
from classiq.qmod.qfunc import qfunc
|
2
|
-
from classiq.qmod.
|
3
|
-
from classiq.qmod.qmod_variable import QNum
|
7
|
+
from classiq.qmod.qmod_variable import QArray, QNum
|
4
8
|
from classiq.qmod.quantum_callable import QCallable
|
5
9
|
|
6
10
|
|
@@ -19,7 +23,19 @@ def qpe_flexible(unitary_with_power: QCallable[CInt], phase: QNum) -> None:
|
|
19
23
|
Further reading in Classiq Library:
|
20
24
|
Link: [qpe library reference](https://github.com/Classiq/classiq-library/blob/main/functions/qmod_library_reference/classiq_open_library/qpe/qpe.ipynb)
|
21
25
|
"""
|
22
|
-
|
26
|
+
phase_array: QArray = QArray("phase_array")
|
27
|
+
bind(phase, phase_array)
|
28
|
+
apply_to_all(H, phase_array)
|
29
|
+
|
30
|
+
repeat(
|
31
|
+
count=phase_array.len,
|
32
|
+
iteration=lambda index: control(
|
33
|
+
ctrl=phase_array[index], stmt_block=lambda: unitary_with_power(2**index)
|
34
|
+
),
|
35
|
+
)
|
36
|
+
|
37
|
+
invert(lambda: qft(phase_array))
|
38
|
+
bind(phase_array, phase)
|
23
39
|
|
24
40
|
|
25
41
|
@qfunc(external=True)
|
@@ -36,4 +52,4 @@ def qpe(unitary: QCallable, phase: QNum) -> None:
|
|
36
52
|
Further reading in Classiq Library:
|
37
53
|
Link: [qpe library reference](https://github.com/Classiq/classiq-library/blob/main/functions/qmod_library_reference/classiq_open_library/qpe/qpe.ipynb)
|
38
54
|
"""
|
39
|
-
|
55
|
+
qpe_flexible(unitary_with_power=lambda k: power(k, unitary), phase=phase)
|
@@ -1,7 +1,10 @@
|
|
1
|
+
from classiq.qmod.builtins.functions.standard_gates import IDENTITY, RZ, H
|
2
|
+
from classiq.qmod.builtins.operations import if_, invert, repeat
|
1
3
|
from classiq.qmod.qfunc import qfunc
|
2
4
|
from classiq.qmod.qmod_parameter import CArray, CReal
|
3
5
|
from classiq.qmod.qmod_variable import QArray, QBit
|
4
6
|
from classiq.qmod.quantum_callable import QCallable
|
7
|
+
from classiq.qmod.symbolic import floor
|
5
8
|
|
6
9
|
|
7
10
|
@qfunc(external=True)
|
@@ -35,7 +38,10 @@ def qsvt_step(
|
|
35
38
|
Further reading in Classiq Library:
|
36
39
|
[QSVT function usage example](https://docs.classiq.io/latest/explore/functions/qmod_library_reference/classiq_open_library/qsvt/qsvt/)
|
37
40
|
"""
|
38
|
-
|
41
|
+
u(qvar)
|
42
|
+
projector_controlled_phase(phase1, proj_cnot_2, qvar, aux)
|
43
|
+
invert(lambda: u(qvar))
|
44
|
+
projector_controlled_phase(phase2, proj_cnot_1, qvar, aux)
|
39
45
|
|
40
46
|
|
41
47
|
@qfunc(external=True)
|
@@ -78,7 +84,37 @@ def qsvt(
|
|
78
84
|
Further reading in Classiq Library:
|
79
85
|
[QSVT function usage example](https://docs.classiq.io/latest/explore/functions/qmod_library_reference/classiq_open_library/qsvt/qsvt/)
|
80
86
|
"""
|
81
|
-
|
87
|
+
H(aux)
|
88
|
+
|
89
|
+
projector_controlled_phase(phase_seq[0], proj_cnot_1, qvar, aux)
|
90
|
+
repeat(
|
91
|
+
count=floor((phase_seq.len - 1) / 2),
|
92
|
+
iteration=lambda index: qsvt_step(
|
93
|
+
phase_seq[2 * index + 1],
|
94
|
+
phase_seq[2 * index + 2],
|
95
|
+
proj_cnot_1,
|
96
|
+
proj_cnot_2,
|
97
|
+
u,
|
98
|
+
qvar,
|
99
|
+
aux,
|
100
|
+
),
|
101
|
+
)
|
102
|
+
|
103
|
+
if_(
|
104
|
+
condition=phase_seq.len % 2 == 1,
|
105
|
+
then=lambda: IDENTITY(qvar),
|
106
|
+
else_=lambda: ( # type:ignore[arg-type]
|
107
|
+
u(qvar), # type:ignore[func-returns-value]
|
108
|
+
projector_controlled_phase(
|
109
|
+
phase_seq[phase_seq.len - 1],
|
110
|
+
proj_cnot_2,
|
111
|
+
qvar,
|
112
|
+
aux,
|
113
|
+
),
|
114
|
+
),
|
115
|
+
)
|
116
|
+
|
117
|
+
H(aux)
|
82
118
|
|
83
119
|
|
84
120
|
@qfunc(external=True)
|
@@ -106,7 +142,9 @@ def projector_controlled_phase(
|
|
106
142
|
Further reading in Classiq Library:
|
107
143
|
[QSVT function usage example](https://docs.classiq.io/latest/explore/functions/qmod_library_reference/classiq_open_library/qsvt/qsvt/)
|
108
144
|
"""
|
109
|
-
|
145
|
+
proj_cnot(qvar, aux)
|
146
|
+
RZ(phase, aux)
|
147
|
+
proj_cnot(qvar, aux)
|
110
148
|
|
111
149
|
|
112
150
|
@qfunc(external=True)
|
@@ -133,4 +171,11 @@ def qsvt_inversion(
|
|
133
171
|
For usage example, see:
|
134
172
|
[QSVT matrix inversion example](https://docs.classiq.io/latest/explore/algorithms/qsvt/qsvt_matrix_inversion/qsvt_matrix_inversion)
|
135
173
|
"""
|
136
|
-
|
174
|
+
qsvt(
|
175
|
+
phase_seq,
|
176
|
+
block_encoding_cnot,
|
177
|
+
block_encoding_cnot,
|
178
|
+
lambda x: invert(lambda: u(x)),
|
179
|
+
qvar,
|
180
|
+
aux,
|
181
|
+
)
|
@@ -560,7 +560,7 @@ def CRY(theta: CReal, ctrl: QBit, target: QBit) -> None:
|
|
560
560
|
|
561
561
|
Args:
|
562
562
|
theta (CReal): The rotation angle in radians.
|
563
|
-
|
563
|
+
ctrl (QBit): The control qubit.
|
564
564
|
target (QBit): The qubit to apply the RY gate on.
|
565
565
|
|
566
566
|
Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
|
@@ -588,7 +588,7 @@ def CRZ(theta: CReal, ctrl: QBit, target: QBit) -> None:
|
|
588
588
|
|
589
589
|
Args:
|
590
590
|
theta (CReal): The rotation angle in radians.
|
591
|
-
|
591
|
+
ctrl (QBit): The control qubit.
|
592
592
|
target (QBit): The qubit to apply the RZ gate on.
|
593
593
|
|
594
594
|
Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
|
@@ -616,7 +616,7 @@ def CPHASE(theta: CReal, ctrl: QBit, target: QBit) -> None:
|
|
616
616
|
|
617
617
|
Args:
|
618
618
|
theta (CReal): The rotation angle in radians.
|
619
|
-
|
619
|
+
ctrl (QBit): The control qubit.
|
620
620
|
target (QBit): The qubit to apply the PHASE gate on.
|
621
621
|
|
622
622
|
Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
|
@@ -731,7 +731,7 @@ def CCX(ctrl: QArray[QBit, Literal[2]], target: QBit) -> None:
|
|
731
731
|
More information can be found on [Wikipedia](https://en.wikipedia.org/wiki/Toffoli_gate).
|
732
732
|
|
733
733
|
Args:
|
734
|
-
|
734
|
+
ctrl (QArray[QBit, Literal[2]]): The control qubits.
|
735
735
|
target (QBit): The qubit to apply the conditioned Pauli-X gate on.
|
736
736
|
|
737
737
|
Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
|
@@ -1,8 +1,24 @@
|
|
1
1
|
from typing import Literal
|
2
2
|
|
3
|
-
from classiq.qmod.
|
3
|
+
from classiq.qmod.builtins.functions.arithmetic import modular_increment
|
4
|
+
from classiq.qmod.builtins.functions.standard_gates import CX, IDENTITY, RY, H, X
|
5
|
+
from classiq.qmod.builtins.functions.utility_functions import hadamard_transform
|
6
|
+
from classiq.qmod.builtins.operations import control, if_, repeat
|
7
|
+
from classiq.qmod.cparam import CBool, CInt
|
4
8
|
from classiq.qmod.qfunc import qfunc
|
9
|
+
from classiq.qmod.qmod_parameter import CArray, CReal
|
5
10
|
from classiq.qmod.qmod_variable import Input, Output, QArray, QBit, QNum
|
11
|
+
from classiq.qmod.symbolic import (
|
12
|
+
asin,
|
13
|
+
atan,
|
14
|
+
exp,
|
15
|
+
floor,
|
16
|
+
log,
|
17
|
+
max as qmax,
|
18
|
+
min as qmin,
|
19
|
+
pi,
|
20
|
+
sqrt,
|
21
|
+
)
|
6
22
|
|
7
23
|
|
8
24
|
@qfunc(external=True)
|
@@ -53,7 +69,7 @@ def allocate_num(
|
|
53
69
|
Further reading is available on the [reference manual](https://docs.classiq.io/latest/reference-manual/qmod/language-reference/quantum-types#allocate-num)
|
54
70
|
|
55
71
|
"""
|
56
|
-
|
72
|
+
allocate(num_qubits, out)
|
57
73
|
|
58
74
|
|
59
75
|
@qfunc(external=True)
|
@@ -178,11 +194,31 @@ def inplace_prepare_amplitudes(
|
|
178
194
|
pass
|
179
195
|
|
180
196
|
|
197
|
+
def prepare_uniform_trimmed_state_apply_rotation(
|
198
|
+
size_lsb: CInt, lsbs_val: CInt, rotation_var: QBit
|
199
|
+
) -> None:
|
200
|
+
# max hold for the case where the value is on the left side
|
201
|
+
# the fraction in the sqrt is the wanted amount of probability
|
202
|
+
# in the left side divided by the total amount
|
203
|
+
RY(
|
204
|
+
-2 * (asin(sqrt(qmin((2 ** (size_lsb)) / lsbs_val, 1))) + pi / 4) + pi,
|
205
|
+
rotation_var,
|
206
|
+
)
|
207
|
+
|
208
|
+
|
181
209
|
@qfunc(external=True)
|
182
210
|
def _prepare_uniform_trimmed_state_step(
|
183
211
|
size_lsb: CInt, ctrl_val: CInt, lsbs_val: CInt, ctrl_var: QNum, rotation_var: QBit
|
184
212
|
) -> None:
|
185
|
-
|
213
|
+
if_(
|
214
|
+
lsbs_val != 0, # stop condition
|
215
|
+
lambda: control(
|
216
|
+
ctrl_var == ctrl_val,
|
217
|
+
lambda: prepare_uniform_trimmed_state_apply_rotation(
|
218
|
+
size_lsb, lsbs_val, rotation_var
|
219
|
+
),
|
220
|
+
),
|
221
|
+
)
|
186
222
|
|
187
223
|
|
188
224
|
@qfunc(external=True)
|
@@ -207,7 +243,28 @@ def prepare_uniform_trimmed_state(m: CInt, q: QArray[QBit]) -> None:
|
|
207
243
|
1. If the output variable has been declared with a specific number of qubits, it must match the number of allocated qubits.
|
208
244
|
2. The synthesis engine automatically handles the allocation, either by drawing new qubits from the available pool or by reusing existing ones.
|
209
245
|
"""
|
210
|
-
|
246
|
+
hadamard_transform(q)
|
247
|
+
|
248
|
+
if_(
|
249
|
+
m < 2**q.len,
|
250
|
+
# initial step without control
|
251
|
+
lambda: prepare_uniform_trimmed_state_apply_rotation(
|
252
|
+
q.len - 1, # type:ignore[arg-type]
|
253
|
+
m,
|
254
|
+
q[q.len - 1],
|
255
|
+
),
|
256
|
+
)
|
257
|
+
|
258
|
+
repeat(
|
259
|
+
qmax(q.len - 1, 0),
|
260
|
+
lambda i: _prepare_uniform_trimmed_state_step(
|
261
|
+
q.len - i - 2,
|
262
|
+
floor(m / (2 ** (q.len - i - 1))),
|
263
|
+
m % (2 ** (q.len - i - 1)),
|
264
|
+
q[q.len - i - 1 : q.len],
|
265
|
+
q[q.len - i - 2],
|
266
|
+
),
|
267
|
+
)
|
211
268
|
|
212
269
|
|
213
270
|
@qfunc(external=True)
|
@@ -232,7 +289,8 @@ def prepare_uniform_interval_state(start: CInt, end: CInt, q: QArray[QBit]) -> N
|
|
232
289
|
1. If the output variable has been declared with a specific number of qubits, it must match the number of allocated qubits.
|
233
290
|
2. The synthesis engine automatically handles the allocation, either by drawing new qubits from the available pool or by reusing existing ones.
|
234
291
|
"""
|
235
|
-
|
292
|
+
prepare_uniform_trimmed_state(end - start, q)
|
293
|
+
modular_increment(start, q)
|
236
294
|
|
237
295
|
|
238
296
|
@qfunc(external=True)
|
@@ -251,7 +309,20 @@ def prepare_ghz_state(size: CInt, q: Output[QArray[QBit]]) -> None:
|
|
251
309
|
|
252
310
|
|
253
311
|
"""
|
254
|
-
|
312
|
+
|
313
|
+
def inner_lop(step: CInt) -> None:
|
314
|
+
repeat(
|
315
|
+
count=2**step,
|
316
|
+
iteration=lambda control_index: if_(
|
317
|
+
condition=control_index + 2**step >= size,
|
318
|
+
then=lambda: IDENTITY(q[0]),
|
319
|
+
else_=lambda: CX(q[control_index], q[control_index + 2**step]),
|
320
|
+
),
|
321
|
+
)
|
322
|
+
|
323
|
+
allocate(size, q)
|
324
|
+
H(q[0])
|
325
|
+
repeat(floor(log(size - 1, 2)) + 1, inner_lop) # type:ignore[arg-type]
|
255
326
|
|
256
327
|
|
257
328
|
@qfunc(external=True)
|
@@ -272,7 +343,7 @@ def prepare_exponential_state(rate: CInt, q: QArray[QBit]) -> None:
|
|
272
343
|
|
273
344
|
Further reading is available on the [reference manual](https://docs.classiq.io/latest/explore/functions/qmod_library_reference/classiq_open_library/special_state_preparations/prepare_exponential_state)
|
274
345
|
"""
|
275
|
-
|
346
|
+
repeat(q.len, lambda i: RY(2.0 * atan(exp((-rate * 2.0**i) / 2.0)), q[i]))
|
276
347
|
|
277
348
|
|
278
349
|
@qfunc(external=True)
|
@@ -318,7 +389,10 @@ def prepare_bell_state(state_num: CInt, q: Output[QArray[QBit, Literal[2]]]) ->
|
|
318
389
|
|
319
390
|
|
320
391
|
"""
|
321
|
-
|
392
|
+
allocate(2, q)
|
393
|
+
inplace_prepare_int(state_num, q)
|
394
|
+
H(q[0])
|
395
|
+
CX(q[0], q[1])
|
322
396
|
|
323
397
|
|
324
398
|
@qfunc(external=True)
|
@@ -336,7 +410,14 @@ def inplace_prepare_int(value: CInt, target: QArray[QBit]) -> None:
|
|
336
410
|
Note:
|
337
411
|
If the value cannot fit into the quantum variable, it is truncated, i.e. treated as the value modulo $2^\\text{target.size}$.
|
338
412
|
"""
|
339
|
-
|
413
|
+
repeat(
|
414
|
+
target.len,
|
415
|
+
lambda index: if_(
|
416
|
+
(floor(value / (2**index)) % 2) == 1,
|
417
|
+
lambda: X(target[index]),
|
418
|
+
lambda: IDENTITY(target[index]),
|
419
|
+
),
|
420
|
+
)
|
340
421
|
|
341
422
|
|
342
423
|
@qfunc(external=True)
|
@@ -357,4 +438,5 @@ def prepare_int(
|
|
357
438
|
Note:
|
358
439
|
If the output variable has been declared with a specific number of qubits, it must match the number of allocated qubits.
|
359
440
|
"""
|
360
|
-
|
441
|
+
allocate(floor(log(value, 2)) + 1, out)
|
442
|
+
inplace_prepare_int(value, out)
|
@@ -1,3 +1,6 @@
|
|
1
|
+
from classiq.qmod.builtins.functions.standard_gates import SWAP, H
|
2
|
+
from classiq.qmod.builtins.functions.state_preparation import allocate
|
3
|
+
from classiq.qmod.builtins.operations import control, repeat
|
1
4
|
from classiq.qmod.qfunc import qfunc
|
2
5
|
from classiq.qmod.qmod_variable import Output, QArray, QBit
|
3
6
|
|
@@ -22,4 +25,7 @@ def swap_test(state1: QArray[QBit], state2: QArray[QBit], test: Output[QBit]) ->
|
|
22
25
|
Example:
|
23
26
|
Further reading in the Classiq library is found [here](https://docs.classiq.io/latest/explore/algorithms/swap_test/swap_test/).
|
24
27
|
"""
|
25
|
-
|
28
|
+
allocate(1, test)
|
29
|
+
H(test)
|
30
|
+
control(test, lambda: repeat(state1.len, lambda i: SWAP(state1[i], state2[i])))
|
31
|
+
H(test)
|
@@ -0,0 +1,43 @@
|
|
1
|
+
from typing import Annotated
|
2
|
+
|
3
|
+
from classiq.qmod.builtins.functions.standard_gates import H
|
4
|
+
from classiq.qmod.builtins.operations import repeat
|
5
|
+
from classiq.qmod.qfunc import qfunc
|
6
|
+
from classiq.qmod.qmod_variable import QArray, QBit, QCallable
|
7
|
+
|
8
|
+
|
9
|
+
@qfunc(external=True)
|
10
|
+
def apply_to_all(
|
11
|
+
gate_operand: QCallable[Annotated[QBit, "target"]], target: QArray[QBit]
|
12
|
+
) -> None:
|
13
|
+
"""
|
14
|
+
[Qmod Classiq-library function]
|
15
|
+
|
16
|
+
Applies the single-qubit operand `gate_operand` to each qubit in the qubit
|
17
|
+
array `target`.
|
18
|
+
|
19
|
+
Args:
|
20
|
+
gate_operand: The single-qubit gate to apply to each qubit in the array.
|
21
|
+
target: The qubit array to apply the gate to.
|
22
|
+
"""
|
23
|
+
repeat(target.len, lambda index: gate_operand(target[index]))
|
24
|
+
|
25
|
+
|
26
|
+
@qfunc(external=True)
|
27
|
+
def hadamard_transform(target: QArray[QBit]) -> None:
|
28
|
+
"""
|
29
|
+
[Qmod Classiq-library function]
|
30
|
+
|
31
|
+
Applies Hadamard transform to the target qubits.
|
32
|
+
|
33
|
+
Corresponds to the braket notation:
|
34
|
+
|
35
|
+
$$
|
36
|
+
H^{\\otimes n} |x\rangle = \frac{1}{\\sqrt{2^n}} \\sum_{y=0}^{2^n - 1} (-1)^{x \\cdot y} |y\rangle
|
37
|
+
$$
|
38
|
+
|
39
|
+
Args:
|
40
|
+
target: qubits to apply to Hadamard transform to.
|
41
|
+
|
42
|
+
"""
|
43
|
+
apply_to_all(H, target)
|
@@ -1,7 +1,11 @@
|
|
1
|
+
from classiq.qmod.builtins.functions.standard_gates import RX, RY, RZ
|
2
|
+
from classiq.qmod.builtins.functions.state_preparation import allocate
|
3
|
+
from classiq.qmod.builtins.operations import repeat
|
1
4
|
from classiq.qmod.cparam import CReal
|
2
5
|
from classiq.qmod.qfunc import qfunc
|
3
6
|
from classiq.qmod.qmod_parameter import CArray
|
4
7
|
from classiq.qmod.qmod_variable import Output, QArray, QBit
|
8
|
+
from classiq.qmod.symbolic import ceiling, floor, pi
|
5
9
|
|
6
10
|
|
7
11
|
@qfunc(external=True)
|
@@ -17,7 +21,11 @@ def encode_in_angle(data: CArray[CReal], qba: Output[QArray[QBit]]) -> None:
|
|
17
21
|
data: A classical array representing the data to encode.
|
18
22
|
qba: The array of qubits on which the data is encoded.
|
19
23
|
"""
|
20
|
-
|
24
|
+
allocate(data.len, qba)
|
25
|
+
repeat(
|
26
|
+
count=data.len,
|
27
|
+
iteration=lambda index: RY(pi * data[index], qba[index]),
|
28
|
+
)
|
21
29
|
|
22
30
|
|
23
31
|
@qfunc(external=True)
|
@@ -34,4 +42,12 @@ def encode_on_bloch(data: CArray[CReal], qba: Output[QArray]) -> None:
|
|
34
42
|
data: A classical array representing the data to encode.
|
35
43
|
qba: The QArray of QBits on which the data is encoded.
|
36
44
|
"""
|
37
|
-
|
45
|
+
allocate(ceiling(data.len / 2), qba)
|
46
|
+
repeat(
|
47
|
+
count=ceiling(data.len / 2),
|
48
|
+
iteration=lambda index: RX(pi * data[2 * index], qba[index]),
|
49
|
+
)
|
50
|
+
repeat(
|
51
|
+
count=floor(data.len / 2),
|
52
|
+
iteration=lambda index: RZ(pi * data[2 * index + 1], qba[index]),
|
53
|
+
)
|
@@ -1,13 +1,16 @@
|
|
1
1
|
import inspect
|
2
2
|
import sys
|
3
|
+
import warnings
|
4
|
+
from collections.abc import Mapping
|
3
5
|
from types import FrameType
|
4
6
|
from typing import (
|
7
|
+
TYPE_CHECKING,
|
5
8
|
Any,
|
6
9
|
Callable,
|
7
10
|
Final,
|
8
|
-
|
9
|
-
Mapping,
|
11
|
+
Optional,
|
10
12
|
Union,
|
13
|
+
overload,
|
11
14
|
)
|
12
15
|
|
13
16
|
from classiq.interface.exceptions import ClassiqValueError
|
@@ -22,13 +25,16 @@ from classiq.interface.model.classical_parameter_declaration import (
|
|
22
25
|
ClassicalParameterDeclaration,
|
23
26
|
)
|
24
27
|
from classiq.interface.model.control import Control
|
25
|
-
from classiq.interface.model.inplace_binary_operation import (
|
26
|
-
BinaryOperation,
|
27
|
-
InplaceBinaryOperation,
|
28
|
-
)
|
29
28
|
from classiq.interface.model.invert import Invert
|
30
29
|
from classiq.interface.model.phase_operation import PhaseOperation
|
31
30
|
from classiq.interface.model.power import Power
|
31
|
+
from classiq.interface.model.quantum_expressions.amplitude_loading_operation import (
|
32
|
+
AmplitudeLoadingOperation,
|
33
|
+
)
|
34
|
+
from classiq.interface.model.quantum_expressions.arithmetic_operation import (
|
35
|
+
ArithmeticOperation,
|
36
|
+
ArithmeticOperationKind,
|
37
|
+
)
|
32
38
|
from classiq.interface.model.quantum_function_call import QuantumFunctionCall
|
33
39
|
from classiq.interface.model.quantum_function_declaration import (
|
34
40
|
QuantumOperandDeclaration,
|
@@ -38,7 +44,7 @@ from classiq.interface.model.repeat import Repeat
|
|
38
44
|
from classiq.interface.model.statement_block import StatementBlock
|
39
45
|
from classiq.interface.model.within_apply_operation import WithinApply
|
40
46
|
|
41
|
-
from classiq.qmod.qmod_variable import Input, Output, QArray, QBit, QNum, QVar
|
47
|
+
from classiq.qmod.qmod_variable import Input, Output, QArray, QBit, QNum, QScalar, QVar
|
42
48
|
from classiq.qmod.quantum_callable import QCallable
|
43
49
|
from classiq.qmod.quantum_expandable import prepare_arg
|
44
50
|
from classiq.qmod.symbolic_expr import SymbolicExpr
|
@@ -48,8 +54,8 @@ _MISSING_VALUE: Final[int] = -1
|
|
48
54
|
|
49
55
|
|
50
56
|
def bind(
|
51
|
-
source: Union[Input[QVar],
|
52
|
-
destination: Union[Output[QVar],
|
57
|
+
source: Union[Input[QVar], list[Input[QVar]]],
|
58
|
+
destination: Union[Output[QVar], list[Output[QVar]]],
|
53
59
|
) -> None:
|
54
60
|
assert QCallable.CURRENT_EXPANDABLE is not None
|
55
61
|
source_ref = get_source_ref(sys._getframe(1))
|
@@ -92,6 +98,7 @@ def if_(
|
|
92
98
|
def control(
|
93
99
|
ctrl: Union[SymbolicExpr, QBit, QArray[QBit]],
|
94
100
|
stmt_block: Union[QCallable, Callable[[], None]],
|
101
|
+
else_block: Union[QCallable, Callable[[], None], None] = None,
|
95
102
|
) -> None:
|
96
103
|
_validate_operand(stmt_block)
|
97
104
|
assert QCallable.CURRENT_EXPANDABLE is not None
|
@@ -99,39 +106,125 @@ def control(
|
|
99
106
|
control_stmt = Control(
|
100
107
|
expression=Expression(expr=str(ctrl)),
|
101
108
|
body=_operand_to_body(stmt_block, "stmt_block"),
|
109
|
+
else_block=_operand_to_body(else_block, "else_block") if else_block else None,
|
102
110
|
source_ref=source_ref,
|
103
111
|
)
|
104
112
|
control_stmt.set_generative_block("body", stmt_block)
|
113
|
+
if else_block is not None:
|
114
|
+
control_stmt.set_generative_block("else_block", else_block)
|
105
115
|
QCallable.CURRENT_EXPANDABLE.append_statement_to_body(control_stmt)
|
106
116
|
|
107
117
|
|
118
|
+
def assign(expression: SymbolicExpr, target_var: QScalar) -> None:
|
119
|
+
assert QCallable.CURRENT_EXPANDABLE is not None
|
120
|
+
source_ref = get_source_ref(sys._getframe(1))
|
121
|
+
QCallable.CURRENT_EXPANDABLE.append_statement_to_body(
|
122
|
+
ArithmeticOperation(
|
123
|
+
expression=Expression(expr=str(expression)),
|
124
|
+
result_var=target_var.get_handle_binding(),
|
125
|
+
operation_kind=ArithmeticOperationKind.Assignment,
|
126
|
+
source_ref=source_ref,
|
127
|
+
)
|
128
|
+
)
|
129
|
+
|
130
|
+
|
131
|
+
def assign_amplitude(expression: SymbolicExpr, target_var: QScalar) -> None:
|
132
|
+
assert QCallable.CURRENT_EXPANDABLE is not None
|
133
|
+
source_ref = get_source_ref(sys._getframe(1))
|
134
|
+
QCallable.CURRENT_EXPANDABLE.append_statement_to_body(
|
135
|
+
AmplitudeLoadingOperation(
|
136
|
+
expression=Expression(expr=str(expression)),
|
137
|
+
result_var=target_var.get_handle_binding(),
|
138
|
+
source_ref=source_ref,
|
139
|
+
)
|
140
|
+
)
|
141
|
+
|
142
|
+
|
143
|
+
@overload
|
144
|
+
def inplace_add(expression: SymbolicExpr, target_var: QScalar) -> None:
|
145
|
+
pass
|
146
|
+
|
147
|
+
|
148
|
+
@overload
|
149
|
+
def inplace_add(*, value: QNum, target: QNum) -> None:
|
150
|
+
pass
|
151
|
+
|
152
|
+
|
108
153
|
def inplace_add(
|
109
|
-
|
110
|
-
|
154
|
+
expression: Optional[SymbolicExpr] = None,
|
155
|
+
target_var: Optional[QScalar] = None,
|
156
|
+
value: Optional[QNum] = None,
|
157
|
+
target: Optional[QNum] = None,
|
111
158
|
) -> None:
|
112
159
|
assert QCallable.CURRENT_EXPANDABLE is not None
|
160
|
+
if value is not None or target is not None:
|
161
|
+
warnings.warn(
|
162
|
+
"Parameters 'value' and 'target of function 'inplace_add' have "
|
163
|
+
"been renamed to 'expression' and 'target_var' respectively. Parameters "
|
164
|
+
"'value' and 'target' will no longer be supported starting on 02/12/24 at "
|
165
|
+
"the earliest.\nHint: Change `inplace_add(value=..., target=...)` to "
|
166
|
+
"`inplace_add(expression=..., target_var=...)` or `inplace_add(..., ...)`.",
|
167
|
+
category=DeprecationWarning,
|
168
|
+
stacklevel=2,
|
169
|
+
)
|
170
|
+
if value is not None:
|
171
|
+
expression = value
|
172
|
+
if target is not None:
|
173
|
+
target_var = target
|
174
|
+
if TYPE_CHECKING:
|
175
|
+
assert expression is not None
|
176
|
+
assert target_var is not None
|
113
177
|
source_ref = get_source_ref(sys._getframe(1))
|
114
178
|
QCallable.CURRENT_EXPANDABLE.append_statement_to_body(
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
179
|
+
ArithmeticOperation(
|
180
|
+
expression=Expression(expr=str(expression)),
|
181
|
+
result_var=target_var.get_handle_binding(),
|
182
|
+
operation_kind=ArithmeticOperationKind.InplaceAdd,
|
119
183
|
source_ref=source_ref,
|
120
184
|
)
|
121
185
|
)
|
122
186
|
|
123
187
|
|
188
|
+
@overload
|
189
|
+
def inplace_xor(expression: SymbolicExpr, target_var: QScalar) -> None:
|
190
|
+
pass
|
191
|
+
|
192
|
+
|
193
|
+
@overload
|
194
|
+
def inplace_xor(*, value: QNum, target: QNum) -> None:
|
195
|
+
pass
|
196
|
+
|
197
|
+
|
124
198
|
def inplace_xor(
|
125
|
-
|
126
|
-
|
199
|
+
expression: Optional[SymbolicExpr] = None,
|
200
|
+
target_var: Optional[QScalar] = None,
|
201
|
+
value: Optional[QNum] = None,
|
202
|
+
target: Optional[QNum] = None,
|
127
203
|
) -> None:
|
128
204
|
assert QCallable.CURRENT_EXPANDABLE is not None
|
205
|
+
if value is not None or target is not None:
|
206
|
+
warnings.warn(
|
207
|
+
"Parameters 'value' and 'target of function 'inplace_xor' have "
|
208
|
+
"been renamed to 'expression' and 'target_var' respectively. Parameters "
|
209
|
+
"'value' and 'target' will no longer be supported starting on 02/12/24 at "
|
210
|
+
"the earliest.\nHint: Change `inplace_xor(value=..., target=...)` to "
|
211
|
+
"`inplace_xor(expression=..., target_var=...)` or `inplace_xor(..., ...)`.",
|
212
|
+
category=DeprecationWarning,
|
213
|
+
stacklevel=2,
|
214
|
+
)
|
215
|
+
if value is not None:
|
216
|
+
expression = value
|
217
|
+
if target is not None:
|
218
|
+
target_var = target
|
219
|
+
if TYPE_CHECKING:
|
220
|
+
assert expression is not None
|
221
|
+
assert target_var is not None
|
129
222
|
source_ref = get_source_ref(sys._getframe(1))
|
130
223
|
QCallable.CURRENT_EXPANDABLE.append_statement_to_body(
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
224
|
+
ArithmeticOperation(
|
225
|
+
expression=Expression(expr=str(expression)),
|
226
|
+
result_var=target_var.get_handle_binding(),
|
227
|
+
operation_kind=ArithmeticOperationKind.InplaceXor,
|
135
228
|
source_ref=source_ref,
|
136
229
|
)
|
137
230
|
)
|
@@ -298,6 +391,8 @@ def _operand_to_body(
|
|
298
391
|
|
299
392
|
|
300
393
|
__all__ = [
|
394
|
+
"assign",
|
395
|
+
"assign_amplitude",
|
301
396
|
"bind",
|
302
397
|
"control",
|
303
398
|
"invert",
|
@@ -311,5 +406,5 @@ __all__ = [
|
|
311
406
|
]
|
312
407
|
|
313
408
|
|
314
|
-
def __dir__() ->
|
409
|
+
def __dir__() -> list[str]:
|
315
410
|
return __all__
|
classiq/qmod/cfunc.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
from typing import Any, Callable,
|
1
|
+
from typing import Any, Callable, Optional, Union, overload
|
2
2
|
|
3
3
|
from classiq.qmod.classical_function import CFunc
|
4
4
|
|
5
5
|
|
6
|
-
def get_caller_locals() ->
|
6
|
+
def get_caller_locals() -> dict[str, Any]:
|
7
7
|
"""Print the local variables in the caller's frame."""
|
8
8
|
import inspect
|
9
9
|
|