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
@@ -405,7 +405,7 @@ def RZZ(theta: CReal, target: QArray[QBit, Literal[2]]) -> None:
|
|
405
405
|
|
406
406
|
|
407
407
|
@qfunc(external=True)
|
408
|
-
def CH(
|
408
|
+
def CH(ctrl: QBit, target: QBit) -> None:
|
409
409
|
"""
|
410
410
|
[Qmod core-library function]
|
411
411
|
|
@@ -423,7 +423,7 @@ def CH(control: QBit, target: QBit) -> None:
|
|
423
423
|
$$
|
424
424
|
|
425
425
|
Args:
|
426
|
-
|
426
|
+
ctrl: The control qubit.
|
427
427
|
target: The qubit to apply the Hadamard gate on.
|
428
428
|
|
429
429
|
Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
|
@@ -432,7 +432,7 @@ def CH(control: QBit, target: QBit) -> None:
|
|
432
432
|
|
433
433
|
|
434
434
|
@qfunc(external=True)
|
435
|
-
def CX(
|
435
|
+
def CX(ctrl: QBit, target: QBit) -> None:
|
436
436
|
"""
|
437
437
|
[Qmod core-library function]
|
438
438
|
|
@@ -450,7 +450,7 @@ def CX(control: QBit, target: QBit) -> None:
|
|
450
450
|
$$
|
451
451
|
|
452
452
|
Args:
|
453
|
-
|
453
|
+
ctrl: The control qubit.
|
454
454
|
target: The qubit to apply the Pauli-X gate on.
|
455
455
|
|
456
456
|
Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
|
@@ -459,7 +459,7 @@ def CX(control: QBit, target: QBit) -> None:
|
|
459
459
|
|
460
460
|
|
461
461
|
@qfunc(external=True)
|
462
|
-
def CY(
|
462
|
+
def CY(ctrl: QBit, target: QBit) -> None:
|
463
463
|
"""
|
464
464
|
[Qmod core-library function]
|
465
465
|
|
@@ -477,7 +477,7 @@ def CY(control: QBit, target: QBit) -> None:
|
|
477
477
|
$$
|
478
478
|
|
479
479
|
Args:
|
480
|
-
|
480
|
+
ctrl: The control qubit.
|
481
481
|
target: The qubit to apply the Pauli-Y gate on.
|
482
482
|
|
483
483
|
Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
|
@@ -486,7 +486,7 @@ def CY(control: QBit, target: QBit) -> None:
|
|
486
486
|
|
487
487
|
|
488
488
|
@qfunc(external=True)
|
489
|
-
def CZ(
|
489
|
+
def CZ(ctrl: QBit, target: QBit) -> None:
|
490
490
|
"""
|
491
491
|
[Qmod core-library function]
|
492
492
|
|
@@ -504,7 +504,7 @@ def CZ(control: QBit, target: QBit) -> None:
|
|
504
504
|
$$
|
505
505
|
|
506
506
|
Args:
|
507
|
-
|
507
|
+
ctrl: The control qubit.
|
508
508
|
target: The qubit to apply the Pauli-Z gate on.
|
509
509
|
|
510
510
|
Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
|
@@ -513,7 +513,7 @@ def CZ(control: QBit, target: QBit) -> None:
|
|
513
513
|
|
514
514
|
|
515
515
|
@qfunc(external=True)
|
516
|
-
def CRX(theta: CReal,
|
516
|
+
def CRX(theta: CReal, ctrl: QBit, target: QBit) -> None:
|
517
517
|
"""
|
518
518
|
[Qmod core-library function]
|
519
519
|
|
@@ -532,7 +532,7 @@ def CRX(theta: CReal, control: QBit, target: QBit) -> None:
|
|
532
532
|
|
533
533
|
Args:
|
534
534
|
theta: The rotation angle in radians.
|
535
|
-
|
535
|
+
ctrl: The control qubit.
|
536
536
|
target: The qubit to apply the RX gate on.
|
537
537
|
|
538
538
|
Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
|
@@ -541,7 +541,7 @@ def CRX(theta: CReal, control: QBit, target: QBit) -> None:
|
|
541
541
|
|
542
542
|
|
543
543
|
@qfunc(external=True)
|
544
|
-
def CRY(theta: CReal,
|
544
|
+
def CRY(theta: CReal, ctrl: QBit, target: QBit) -> None:
|
545
545
|
"""
|
546
546
|
[Qmod core-library function]
|
547
547
|
|
@@ -560,7 +560,7 @@ def CRY(theta: CReal, control: 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/)
|
@@ -569,7 +569,7 @@ def CRY(theta: CReal, control: QBit, target: QBit) -> None:
|
|
569
569
|
|
570
570
|
|
571
571
|
@qfunc(external=True)
|
572
|
-
def CRZ(theta: CReal,
|
572
|
+
def CRZ(theta: CReal, ctrl: QBit, target: QBit) -> None:
|
573
573
|
"""
|
574
574
|
[Qmod core-library function]
|
575
575
|
|
@@ -588,7 +588,7 @@ def CRZ(theta: CReal, control: 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/)
|
@@ -597,7 +597,7 @@ def CRZ(theta: CReal, control: QBit, target: QBit) -> None:
|
|
597
597
|
|
598
598
|
|
599
599
|
@qfunc(external=True)
|
600
|
-
def CPHASE(theta: CReal,
|
600
|
+
def CPHASE(theta: CReal, ctrl: QBit, target: QBit) -> None:
|
601
601
|
"""
|
602
602
|
[Qmod core-library function]
|
603
603
|
|
@@ -616,7 +616,7 @@ def CPHASE(theta: CReal, control: 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/)
|
@@ -707,7 +707,7 @@ def U(theta: CReal, phi: CReal, lam: CReal, gam: CReal, target: QBit) -> None:
|
|
707
707
|
|
708
708
|
|
709
709
|
@qfunc(external=True)
|
710
|
-
def CCX(
|
710
|
+
def CCX(ctrl: QArray[QBit, Literal[2]], target: QBit) -> None:
|
711
711
|
"""
|
712
712
|
[Qmod core-library function]
|
713
713
|
|
@@ -731,7 +731,7 @@ def CCX(control: 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)
|
@@ -0,0 +1,53 @@
|
|
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
|
4
|
+
from classiq.qmod.cparam import CReal
|
5
|
+
from classiq.qmod.qfunc import qfunc
|
6
|
+
from classiq.qmod.qmod_parameter import CArray
|
7
|
+
from classiq.qmod.qmod_variable import Output, QArray, QBit
|
8
|
+
from classiq.qmod.symbolic import ceiling, floor, pi
|
9
|
+
|
10
|
+
|
11
|
+
@qfunc(external=True)
|
12
|
+
def encode_in_angle(data: CArray[CReal], qba: Output[QArray[QBit]]) -> None:
|
13
|
+
"""
|
14
|
+
[Qmod Classiq-library function]
|
15
|
+
|
16
|
+
Creates an angle encoding of n data points on n qubits.
|
17
|
+
|
18
|
+
Applies RY($\\pi$data[i]) on qba[i].
|
19
|
+
|
20
|
+
Args:
|
21
|
+
data: A classical array representing the data to encode.
|
22
|
+
qba: The array of qubits on which the data is encoded.
|
23
|
+
"""
|
24
|
+
allocate(data.len, qba)
|
25
|
+
repeat(
|
26
|
+
count=data.len,
|
27
|
+
iteration=lambda index: RY(pi * data[index], qba[index]),
|
28
|
+
)
|
29
|
+
|
30
|
+
|
31
|
+
@qfunc(external=True)
|
32
|
+
def encode_on_bloch(data: CArray[CReal], qba: Output[QArray]) -> None:
|
33
|
+
"""
|
34
|
+
[Qmod Classiq-library function]
|
35
|
+
|
36
|
+
Creates a dense angle encoding of n data points on n//2 qubits.
|
37
|
+
|
38
|
+
Encodes pairs of data points on a Bloch sphere, via RX($\\pi$data[2*i])RZ($\\pi$data[2*i+1]) on qba[i].
|
39
|
+
If the length of the data is odd then RX($\\pi$data[i]) is applied on the last qubit.
|
40
|
+
|
41
|
+
Args:
|
42
|
+
data: A classical array representing the data to encode.
|
43
|
+
qba: The QArray of QBits on which the data is encoded.
|
44
|
+
"""
|
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,12 +1,11 @@
|
|
1
1
|
import inspect
|
2
2
|
import sys
|
3
|
+
from collections.abc import Mapping
|
3
4
|
from types import FrameType
|
4
5
|
from typing import (
|
5
6
|
Any,
|
6
7
|
Callable,
|
7
8
|
Final,
|
8
|
-
List,
|
9
|
-
Mapping,
|
10
9
|
Union,
|
11
10
|
)
|
12
11
|
|
@@ -48,8 +47,8 @@ _MISSING_VALUE: Final[int] = -1
|
|
48
47
|
|
49
48
|
|
50
49
|
def bind(
|
51
|
-
source: Union[Input[QVar],
|
52
|
-
destination: Union[Output[QVar],
|
50
|
+
source: Union[Input[QVar], list[Input[QVar]]],
|
51
|
+
destination: Union[Output[QVar], list[Output[QVar]]],
|
53
52
|
) -> None:
|
54
53
|
assert QCallable.CURRENT_EXPANDABLE is not None
|
55
54
|
source_ref = get_source_ref(sys._getframe(1))
|
@@ -311,5 +310,5 @@ __all__ = [
|
|
311
310
|
]
|
312
311
|
|
313
312
|
|
314
|
-
def __dir__() ->
|
313
|
+
def __dir__() -> list[str]:
|
315
314
|
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
|
|
@@ -1,8 +1,7 @@
|
|
1
1
|
import ast
|
2
2
|
import inspect
|
3
|
-
import sys
|
4
3
|
from textwrap import dedent
|
5
|
-
from typing import Any, Callable
|
4
|
+
from typing import Any, Callable
|
6
5
|
|
7
6
|
from classiq.interface.exceptions import ClassiqValueError
|
8
7
|
|
@@ -17,16 +16,13 @@ def _unparse_function_body(code: str, func: ast.FunctionDef) -> str:
|
|
17
16
|
|
18
17
|
|
19
18
|
class CFunc:
|
20
|
-
def __init__(self, py_callable: Callable[[], None], caller_locals:
|
19
|
+
def __init__(self, py_callable: Callable[[], None], caller_locals: dict[str, Any]):
|
21
20
|
code = dedent(inspect.getsource(py_callable))
|
22
21
|
func = ast.parse(code).body[0]
|
23
22
|
if not isinstance(func, ast.FunctionDef):
|
24
23
|
raise ClassiqValueError("Use @cfunc to decorate a function")
|
25
24
|
if len(func.args.args) > 0:
|
26
25
|
raise ClassiqValueError("A @cfunc must receive no arguments")
|
27
|
-
|
28
|
-
self.code = "\n".join([ast.unparse(statement) for statement in func.body])
|
29
|
-
else:
|
30
|
-
self.code = _unparse_function_body(code, func)
|
26
|
+
self.code = "\n".join([ast.unparse(statement) for statement in func.body])
|
31
27
|
|
32
28
|
self._caller_constants = caller_locals
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import TYPE_CHECKING,
|
1
|
+
from typing import TYPE_CHECKING, Optional, Union, cast
|
2
2
|
|
3
3
|
from classiq.interface.exceptions import ClassiqError
|
4
4
|
from classiq.interface.executor.execution_preferences import ExecutionPreferences
|
@@ -116,7 +116,7 @@ def _expand_generative_model(
|
|
116
116
|
|
117
117
|
def _get_generative_functions(
|
118
118
|
gen_main: QFunc, preferences: Optional[Preferences]
|
119
|
-
) ->
|
119
|
+
) -> list[NativeFunctionDefinition]:
|
120
120
|
# The Interpreter accepts a model and a list of generative functions.
|
121
121
|
# Since the main function is generative, it can only be expanded using the
|
122
122
|
# Interpreter.
|
@@ -154,10 +154,10 @@ def _get_wrapper_main(gen_main: QFunc, preferences: Optional[Preferences]) -> Mo
|
|
154
154
|
)
|
155
155
|
|
156
156
|
|
157
|
-
def _get_all_model_functions_as_generative_functions() ->
|
157
|
+
def _get_all_model_functions_as_generative_functions() -> list[GenerativeQFunc]:
|
158
|
+
|
158
159
|
gen_functions = list(GEN_QFUNCS) + [
|
159
|
-
|
160
|
-
for dec_func in DEC_QFUNCS
|
160
|
+
_get_gen_from_dec(dec_func) for dec_func in DEC_QFUNCS
|
161
161
|
]
|
162
162
|
return [
|
163
163
|
(
|
@@ -173,16 +173,27 @@ def _get_all_model_functions_as_generative_functions() -> List[GenerativeQFunc]:
|
|
173
173
|
]
|
174
174
|
|
175
175
|
|
176
|
+
def _get_gen_from_dec(dec_func: QFunc) -> GenerativeQFunc:
|
177
|
+
synthesis_data = dec_func.synthesis_data
|
178
|
+
if synthesis_data is not None and synthesis_data.should_synthesize_separately:
|
179
|
+
raise ClassiqError(
|
180
|
+
"""The model contains generative functions,
|
181
|
+
which cannot coexist with functions marked for separate synthesis"""
|
182
|
+
)
|
183
|
+
return GenerativeQFunc(dec_func._py_callable, dec_func.func_decl)
|
184
|
+
|
185
|
+
|
176
186
|
def _interpret_generative_model(
|
177
|
-
gen_model: Model, gen_functions:
|
178
|
-
) ->
|
187
|
+
gen_model: Model, gen_functions: list[GenerativeQFunc]
|
188
|
+
) -> dict[str, NativeFunctionDefinition]:
|
179
189
|
resolve_function_calls(
|
180
190
|
gen_model,
|
181
191
|
{gen_func.func_decl.name: gen_func.func_decl for gen_func in gen_functions},
|
182
192
|
)
|
183
193
|
interpreter = Interpreter(gen_model, gen_functions, is_frontend=True)
|
184
194
|
set_frontend_interpreter(interpreter)
|
185
|
-
|
195
|
+
expand_model, _ = interpreter.expand()
|
196
|
+
functions_dict = nameables_to_dict(expand_model.functions)
|
186
197
|
|
187
198
|
# Inline _gen_main call in main
|
188
199
|
expanded_gen_main_name = cast(
|
@@ -1,15 +1,12 @@
|
|
1
1
|
import dataclasses
|
2
2
|
import sys
|
3
|
+
from collections.abc import Sequence
|
3
4
|
from enum import EnumMeta
|
4
5
|
from typing import (
|
5
6
|
Any,
|
6
7
|
Callable,
|
7
|
-
List,
|
8
8
|
Literal,
|
9
9
|
Optional,
|
10
|
-
Sequence,
|
11
|
-
Tuple,
|
12
|
-
Type,
|
13
10
|
get_args,
|
14
11
|
get_origin,
|
15
12
|
overload,
|
@@ -91,7 +88,7 @@ def python_type_to_qmod(
|
|
91
88
|
|
92
89
|
def _extract_port_decl(name: Optional[str], py_type: Any) -> AnonPortDeclaration:
|
93
90
|
# FIXME: CAD-13409
|
94
|
-
qtype:
|
91
|
+
qtype: type[QVar] = QVar.from_type_hint(py_type) # type:ignore[assignment]
|
95
92
|
direction = qtype.port_direction(py_type)
|
96
93
|
if isinstance(py_type, _AnnotatedAlias):
|
97
94
|
py_type = py_type.__args__[0]
|
@@ -128,7 +125,7 @@ def _extract_operand_decl(
|
|
128
125
|
return param
|
129
126
|
|
130
127
|
|
131
|
-
def _extract_operand_param(py_type: Any) ->
|
128
|
+
def _extract_operand_param(py_type: Any) -> tuple[Optional[str], Any]:
|
132
129
|
if sys.version_info[0:2] < (3, 9) or get_origin(py_type) is not Annotated:
|
133
130
|
return None, py_type
|
134
131
|
args = get_args(py_type)
|
@@ -152,22 +149,22 @@ def _extract_operand_param(py_type: Any) -> Tuple[Optional[str], Any]:
|
|
152
149
|
|
153
150
|
@overload
|
154
151
|
def _extract_positional_args(
|
155
|
-
args: Sequence[
|
152
|
+
args: Sequence[tuple[str, Any]], qmodule: Optional[ModelStateContainer]
|
156
153
|
) -> Sequence[PositionalArg]:
|
157
154
|
pass
|
158
155
|
|
159
156
|
|
160
157
|
@overload
|
161
158
|
def _extract_positional_args(
|
162
|
-
args: Sequence[
|
159
|
+
args: Sequence[tuple[Optional[str], Any]], qmodule: Optional[ModelStateContainer]
|
163
160
|
) -> Sequence[AnonPositionalArg]:
|
164
161
|
pass
|
165
162
|
|
166
163
|
|
167
164
|
def _extract_positional_args(
|
168
|
-
args: Sequence[
|
165
|
+
args: Sequence[tuple[Optional[str], Any]], qmodule: Optional[ModelStateContainer]
|
169
166
|
) -> Sequence[AnonPositionalArg]:
|
170
|
-
result:
|
167
|
+
result: list[AnonPositionalArg] = []
|
171
168
|
for name, py_type in args:
|
172
169
|
if name == "return":
|
173
170
|
continue
|
classiq/qmod/expression_query.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import TYPE_CHECKING
|
1
|
+
from typing import TYPE_CHECKING
|
2
2
|
|
3
3
|
from classiq.interface.generator.arith.arithmetic import compute_arithmetic_result_type
|
4
4
|
from classiq.interface.generator.arith.number_utils import MAXIMAL_MACHINE_PRECISION
|
@@ -9,10 +9,10 @@ from classiq.qmod.symbolic_type import SymbolicTypes
|
|
9
9
|
|
10
10
|
|
11
11
|
def get_expression_numeric_attributes(
|
12
|
-
vars:
|
12
|
+
vars: list[QNum],
|
13
13
|
expr: SymbolicTypes,
|
14
14
|
machine_precision: int = MAXIMAL_MACHINE_PRECISION,
|
15
|
-
) ->
|
15
|
+
) -> tuple[int, bool, int]:
|
16
16
|
"""
|
17
17
|
Computes and returns the numeric attributes of a given symbolic expression.
|
18
18
|
|
classiq/qmod/generative.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
+
from collections.abc import Iterator
|
1
2
|
from contextlib import contextmanager
|
2
|
-
from typing import TYPE_CHECKING, Any,
|
3
|
+
from typing import TYPE_CHECKING, Any, Optional
|
3
4
|
|
4
5
|
from classiq.interface.exceptions import ClassiqError
|
5
6
|
from classiq.interface.generator.expressions.expression import Expression
|