classiq 0.93.0__py3-none-any.whl → 0.100.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- classiq/__init__.py +11 -19
- classiq/_analyzer_extras/_ipywidgets_async_extension.py +7 -7
- classiq/_analyzer_extras/interactive_hardware.py +19 -12
- classiq/_internals/api_wrapper.py +31 -142
- classiq/_internals/async_utils.py +4 -7
- classiq/_internals/authentication/auth0.py +41 -15
- classiq/_internals/authentication/authorization_code.py +9 -0
- classiq/_internals/authentication/authorization_flow.py +41 -0
- classiq/_internals/authentication/device.py +33 -52
- classiq/_internals/authentication/hybrid_flow.py +19 -0
- classiq/_internals/authentication/password_manager.py +13 -13
- classiq/_internals/authentication/token_manager.py +9 -9
- classiq/_internals/client.py +17 -44
- classiq/_internals/config.py +19 -5
- classiq/_internals/help.py +1 -2
- classiq/_internals/host_checker.py +3 -3
- classiq/_internals/jobs.py +14 -14
- classiq/_internals/type_validation.py +3 -3
- classiq/analyzer/analyzer.py +18 -18
- classiq/analyzer/rb.py +17 -8
- classiq/analyzer/show_interactive_hack.py +1 -1
- classiq/applications/__init__.py +2 -2
- classiq/applications/chemistry/__init__.py +0 -30
- classiq/applications/chemistry/op_utils.py +4 -4
- classiq/applications/chemistry/problems.py +3 -3
- classiq/applications/chemistry/ucc.py +1 -2
- classiq/applications/chemistry/z2_symmetries.py +4 -4
- classiq/applications/combinatorial_helpers/allowed_constraints.py +1 -3
- classiq/applications/combinatorial_helpers/arithmetic/arithmetic_expression.py +2 -1
- classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +2 -2
- classiq/applications/combinatorial_helpers/encoding_mapping.py +2 -3
- classiq/applications/combinatorial_helpers/encoding_utils.py +2 -2
- classiq/applications/combinatorial_helpers/optimization_model.py +3 -4
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_sparsing.py +2 -2
- classiq/applications/combinatorial_helpers/pyomo_utils.py +8 -8
- classiq/applications/combinatorial_helpers/sympy_utils.py +1 -3
- classiq/applications/combinatorial_helpers/transformations/encoding.py +3 -3
- classiq/applications/combinatorial_helpers/transformations/fixed_variables.py +1 -2
- classiq/applications/combinatorial_optimization/combinatorial_optimization_config.py +2 -3
- classiq/applications/combinatorial_optimization/combinatorial_optimization_model_constructor.py +4 -6
- classiq/applications/combinatorial_optimization/combinatorial_problem.py +15 -10
- classiq/applications/hamiltonian/pauli_decomposition.py +6 -4
- classiq/applications/iqae/iqae.py +14 -11
- classiq/applications/qnn/datasets/dataset_base_classes.py +6 -6
- classiq/applications/qnn/datasets/dataset_parity.py +6 -6
- classiq/applications/qnn/gradients/simple_quantum_gradient.py +1 -1
- classiq/applications/qnn/qlayer.py +9 -8
- classiq/applications/qnn/torch_utils.py +5 -6
- classiq/applications/qnn/types.py +2 -1
- classiq/applications/qsp/__init__.py +20 -2
- classiq/applications/qsp/qsp.py +238 -10
- classiq/applications/qsvm/qsvm_data_generation.py +1 -2
- classiq/evaluators/classical_expression.py +0 -4
- classiq/evaluators/parameter_types.py +10 -8
- classiq/evaluators/qmod_annotated_expression.py +31 -26
- classiq/evaluators/qmod_expression_visitors/qmod_expression_evaluator.py +14 -14
- classiq/evaluators/qmod_expression_visitors/qmod_expression_simplifier.py +2 -1
- classiq/evaluators/qmod_expression_visitors/sympy_wrappers.py +8 -8
- classiq/evaluators/qmod_node_evaluators/binary_op_evaluation.py +4 -4
- classiq/evaluators/qmod_node_evaluators/classical_function_evaluation.py +14 -4
- classiq/evaluators/qmod_node_evaluators/list_evaluation.py +2 -2
- classiq/evaluators/qmod_node_evaluators/numeric_attrs_utils.py +3 -3
- classiq/evaluators/qmod_node_evaluators/subscript_evaluation.py +9 -9
- classiq/evaluators/qmod_node_evaluators/utils.py +6 -6
- classiq/evaluators/qmod_type_inference/classical_type_inference.py +9 -10
- classiq/evaluators/qmod_type_inference/quantum_type_inference.py +5 -5
- classiq/execution/__init__.py +0 -3
- classiq/execution/execution_session.py +28 -21
- classiq/execution/jobs.py +26 -26
- classiq/execution/qnn.py +1 -2
- classiq/execution/user_budgets.py +71 -37
- classiq/executor.py +1 -3
- classiq/interface/_version.py +1 -1
- classiq/interface/analyzer/analysis_params.py +4 -4
- classiq/interface/analyzer/cytoscape_graph.py +3 -3
- classiq/interface/analyzer/result.py +4 -4
- classiq/interface/ast_node.py +3 -3
- classiq/interface/backend/backend_preferences.py +26 -50
- classiq/interface/backend/ionq/ionq_quantum_program.py +5 -5
- classiq/interface/backend/provider_config/__init__.py +0 -0
- classiq/interface/backend/provider_config/provider_config.py +8 -0
- classiq/interface/backend/provider_config/providers/__init__.py +0 -0
- classiq/interface/backend/provider_config/providers/alice_bob.py +47 -0
- classiq/interface/backend/provider_config/providers/aqt.py +16 -0
- classiq/interface/backend/provider_config/providers/azure.py +37 -0
- classiq/interface/backend/provider_config/providers/braket.py +39 -0
- classiq/interface/backend/provider_config/providers/ibm.py +26 -0
- classiq/interface/backend/provider_config/providers/ionq.py +22 -0
- classiq/interface/backend/quantum_backend_providers.py +20 -2
- classiq/interface/chemistry/ansatz_library.py +3 -5
- classiq/interface/chemistry/operator.py +3 -3
- classiq/interface/combinatorial_optimization/examples/knapsack.py +2 -4
- classiq/interface/combinatorial_optimization/examples/tsp_digraph.py +1 -2
- classiq/interface/compression_utils.py +2 -3
- classiq/interface/debug_info/debug_info.py +8 -7
- classiq/interface/exceptions.py +6 -7
- classiq/interface/execution/primitives.py +6 -6
- classiq/interface/executor/estimate_cost.py +1 -1
- classiq/interface/executor/execution_preferences.py +3 -5
- classiq/interface/executor/execution_request.py +10 -10
- classiq/interface/executor/execution_result.py +1 -2
- classiq/interface/executor/quantum_code.py +8 -8
- classiq/interface/executor/result.py +28 -18
- classiq/interface/executor/user_budget.py +21 -17
- classiq/interface/executor/vqe_result.py +5 -6
- classiq/interface/generator/ansatz_library.py +6 -8
- classiq/interface/generator/application_apis/__init__.py +0 -3
- classiq/interface/generator/arith/arithmetic.py +2 -2
- classiq/interface/generator/arith/arithmetic_arg_type_validator.py +2 -3
- classiq/interface/generator/arith/arithmetic_expression_abc.py +4 -5
- classiq/interface/generator/arith/arithmetic_expression_parser.py +11 -4
- classiq/interface/generator/arith/arithmetic_expression_validator.py +12 -15
- classiq/interface/generator/arith/arithmetic_operations.py +4 -6
- classiq/interface/generator/arith/arithmetic_param_getters.py +70 -107
- classiq/interface/generator/arith/arithmetic_result_builder.py +4 -4
- classiq/interface/generator/arith/ast_node_rewrite.py +8 -4
- classiq/interface/generator/arith/binary_ops.py +15 -40
- classiq/interface/generator/arith/logical_ops.py +2 -3
- classiq/interface/generator/arith/number_utils.py +2 -2
- classiq/interface/generator/arith/register_user_input.py +3 -3
- classiq/interface/generator/arith/unary_ops.py +2 -2
- classiq/interface/generator/circuit_code/circuit_code.py +8 -10
- classiq/interface/generator/circuit_code/types_and_constants.py +1 -1
- classiq/interface/generator/complex_type.py +2 -2
- classiq/interface/generator/copy.py +1 -3
- classiq/interface/generator/expressions/atomic_expression_functions.py +0 -5
- classiq/interface/generator/expressions/evaluated_expression.py +2 -3
- classiq/interface/generator/expressions/expression.py +2 -2
- classiq/interface/generator/expressions/proxies/classical/classical_array_proxy.py +4 -7
- classiq/interface/generator/function_param_list.py +0 -40
- classiq/interface/generator/function_params.py +5 -6
- classiq/interface/generator/functions/classical_function_declaration.py +2 -2
- classiq/interface/generator/functions/classical_type.py +3 -3
- classiq/interface/generator/functions/type_modifier.py +0 -15
- classiq/interface/generator/functions/type_name.py +2 -2
- classiq/interface/generator/generated_circuit_data.py +14 -18
- classiq/interface/generator/generation_request.py +35 -0
- classiq/interface/generator/hamiltonian_evolution/exponentiation.py +2 -4
- classiq/interface/generator/hardware/hardware_data.py +8 -8
- classiq/interface/generator/hardware_efficient_ansatz.py +9 -9
- classiq/interface/generator/mcu.py +3 -3
- classiq/interface/generator/mcx.py +3 -3
- classiq/interface/generator/model/constraints.py +34 -5
- classiq/interface/generator/model/preferences/preferences.py +15 -21
- classiq/interface/generator/model/quantum_register.py +7 -10
- classiq/interface/generator/noise_properties.py +3 -7
- classiq/interface/generator/parameters.py +1 -1
- classiq/interface/generator/partitioned_register.py +1 -2
- classiq/interface/generator/preferences/qasm_to_qmod_params.py +11 -0
- classiq/interface/generator/quantum_function_call.py +9 -12
- classiq/interface/generator/quantum_program.py +10 -23
- classiq/interface/generator/range_types.py +3 -3
- classiq/interface/generator/slice_parsing_utils.py +4 -5
- classiq/interface/generator/standard_gates/standard_gates.py +2 -4
- classiq/interface/generator/synthesis_execution_parameter.py +1 -3
- classiq/interface/generator/synthesis_metadata/synthesis_duration.py +9 -0
- classiq/interface/generator/synthesis_metadata/synthesis_execution_data.py +2 -3
- classiq/interface/generator/transpiler_basis_gates.py +10 -4
- classiq/interface/generator/types/builtin_enum_declarations.py +0 -145
- classiq/interface/generator/types/compilation_metadata.py +13 -2
- classiq/interface/generator/types/enum_declaration.py +2 -1
- classiq/interface/generator/validations/flow_graph.py +3 -3
- classiq/interface/generator/visitor.py +10 -12
- classiq/interface/hardware.py +2 -3
- classiq/interface/helpers/classproperty.py +2 -2
- classiq/interface/helpers/custom_encoders.py +2 -1
- classiq/interface/helpers/custom_pydantic_types.py +1 -1
- classiq/interface/helpers/text_utils.py +5 -4
- classiq/interface/ide/visual_model.py +6 -5
- classiq/interface/interface_version.py +1 -1
- classiq/interface/jobs.py +3 -3
- classiq/interface/model/allocate.py +4 -4
- classiq/interface/model/bind_operation.py +3 -0
- classiq/interface/model/block.py +6 -2
- classiq/interface/model/bounds.py +3 -3
- classiq/interface/model/classical_if.py +4 -0
- classiq/interface/model/control.py +8 -1
- classiq/interface/model/inplace_binary_operation.py +2 -2
- classiq/interface/model/invert.py +4 -0
- classiq/interface/model/model.py +4 -4
- classiq/interface/model/model_visitor.py +40 -1
- classiq/interface/model/parameter.py +1 -3
- classiq/interface/model/port_declaration.py +1 -1
- classiq/interface/model/power.py +4 -0
- classiq/interface/model/quantum_expressions/quantum_expression.py +1 -2
- classiq/interface/model/quantum_function_call.py +3 -6
- classiq/interface/model/quantum_function_declaration.py +1 -0
- classiq/interface/model/quantum_lambda_function.py +4 -4
- classiq/interface/model/quantum_statement.py +11 -4
- classiq/interface/model/quantum_type.py +14 -14
- classiq/interface/model/repeat.py +4 -0
- classiq/interface/model/skip_control.py +4 -0
- classiq/interface/model/validation_handle.py +2 -3
- classiq/interface/model/variable_declaration_statement.py +2 -2
- classiq/interface/model/within_apply_operation.py +4 -0
- classiq/interface/pretty_print/expression_to_qmod.py +3 -4
- classiq/interface/server/routes.py +0 -16
- classiq/interface/source_reference.py +3 -4
- classiq/model_expansions/arithmetic.py +11 -7
- classiq/model_expansions/arithmetic_compute_result_attrs.py +40 -28
- classiq/model_expansions/capturing/captured_vars.py +3 -3
- classiq/model_expansions/capturing/mangling_utils.py +1 -2
- classiq/model_expansions/closure.py +12 -11
- classiq/model_expansions/function_builder.py +14 -6
- classiq/model_expansions/generative_functions.py +7 -12
- classiq/model_expansions/interpreters/base_interpreter.py +3 -7
- classiq/model_expansions/interpreters/frontend_generative_interpreter.py +2 -1
- classiq/model_expansions/interpreters/generative_interpreter.py +5 -3
- classiq/model_expansions/quantum_operations/allocate.py +4 -4
- classiq/model_expansions/quantum_operations/assignment_result_processor.py +2 -4
- classiq/model_expansions/quantum_operations/call_emitter.py +31 -40
- classiq/model_expansions/quantum_operations/declarative_call_emitter.py +2 -2
- classiq/model_expansions/quantum_operations/emitter.py +3 -5
- classiq/model_expansions/quantum_operations/expression_evaluator.py +3 -3
- classiq/model_expansions/quantum_operations/skip_control_verifier.py +1 -2
- classiq/model_expansions/quantum_operations/variable_decleration.py +2 -2
- classiq/model_expansions/scope.py +7 -7
- classiq/model_expansions/scope_initialization.py +4 -0
- classiq/model_expansions/visitors/symbolic_param_inference.py +6 -6
- classiq/model_expansions/visitors/uncomputation_signature_inference.py +328 -0
- classiq/model_expansions/visitors/variable_references.py +15 -14
- classiq/open_library/functions/__init__.py +41 -11
- classiq/open_library/functions/amplitude_loading.py +81 -0
- classiq/open_library/functions/discrete_sine_cosine_transform.py +5 -5
- classiq/open_library/functions/encodings.py +182 -0
- classiq/open_library/functions/grover.py +8 -10
- classiq/open_library/functions/lcu.py +47 -18
- classiq/open_library/functions/modular_exponentiation.py +93 -8
- classiq/open_library/functions/qsvt.py +66 -79
- classiq/open_library/functions/qsvt_temp.py +536 -0
- classiq/open_library/functions/state_preparation.py +137 -31
- classiq/qmod/__init__.py +6 -4
- classiq/qmod/builtins/classical_execution_primitives.py +4 -23
- classiq/qmod/builtins/classical_functions.py +1 -42
- classiq/qmod/builtins/enums.py +15 -153
- classiq/qmod/builtins/functions/__init__.py +9 -18
- classiq/qmod/builtins/functions/allocation.py +25 -4
- classiq/qmod/builtins/functions/arithmetic.py +22 -27
- classiq/qmod/builtins/functions/exponentiation.py +51 -2
- classiq/qmod/builtins/functions/mcx_func.py +7 -0
- classiq/qmod/builtins/functions/standard_gates.py +46 -27
- classiq/qmod/builtins/operations.py +165 -79
- classiq/qmod/builtins/structs.py +24 -91
- classiq/qmod/cfunc.py +3 -2
- classiq/qmod/classical_function.py +2 -1
- classiq/qmod/cparam.py +2 -8
- classiq/qmod/create_model_function.py +7 -7
- classiq/qmod/declaration_inferrer.py +33 -30
- classiq/qmod/expression_query.py +7 -4
- classiq/qmod/model_state_container.py +2 -2
- classiq/qmod/native/pretty_printer.py +25 -14
- classiq/qmod/pretty_print/expression_to_python.py +5 -3
- classiq/qmod/pretty_print/pretty_printer.py +39 -17
- classiq/qmod/python_classical_type.py +40 -13
- classiq/qmod/qfunc.py +124 -19
- classiq/qmod/qmod_constant.py +2 -2
- classiq/qmod/qmod_parameter.py +5 -2
- classiq/qmod/qmod_variable.py +48 -47
- classiq/qmod/quantum_callable.py +18 -13
- classiq/qmod/quantum_expandable.py +31 -26
- classiq/qmod/quantum_function.py +84 -36
- classiq/qmod/semantics/annotation/call_annotation.py +5 -5
- classiq/qmod/semantics/error_manager.py +23 -15
- classiq/qmod/semantics/lambdas.py +1 -2
- classiq/qmod/semantics/validation/types_validation.py +1 -2
- classiq/qmod/symbolic.py +2 -4
- classiq/qmod/utilities.py +13 -20
- classiq/qmod/write_qmod.py +3 -4
- classiq/quantum_program.py +1 -3
- classiq/synthesis.py +11 -7
- {classiq-0.93.0.dist-info → classiq-0.100.0.dist-info}/METADATA +2 -3
- {classiq-0.93.0.dist-info → classiq-0.100.0.dist-info}/RECORD +274 -300
- {classiq-0.93.0.dist-info → classiq-0.100.0.dist-info}/WHEEL +1 -1
- classiq/applications/chemistry/ansatz_parameters.py +0 -29
- classiq/applications/chemistry/chemistry_execution_parameters.py +0 -16
- classiq/applications/chemistry/chemistry_model_constructor.py +0 -532
- classiq/applications/chemistry/ground_state_problem.py +0 -42
- classiq/applications/qsvm/__init__.py +0 -8
- classiq/applications/qsvm/qsvm.py +0 -11
- classiq/evaluators/qmod_expression_visitors/qmod_expression_bwc.py +0 -129
- classiq/execution/iqcc.py +0 -128
- classiq/interface/applications/qsvm.py +0 -117
- classiq/interface/chemistry/elements.py +0 -120
- classiq/interface/chemistry/fermionic_operator.py +0 -208
- classiq/interface/chemistry/ground_state_problem.py +0 -132
- classiq/interface/chemistry/ground_state_result.py +0 -8
- classiq/interface/chemistry/molecule.py +0 -71
- classiq/interface/execution/iqcc.py +0 -44
- classiq/interface/generator/application_apis/chemistry_declarations.py +0 -69
- classiq/interface/generator/application_apis/entangler_declarations.py +0 -29
- classiq/interface/generator/application_apis/qsvm_declarations.py +0 -6
- classiq/interface/generator/chemistry_function_params.py +0 -50
- classiq/interface/generator/entangler_params.py +0 -72
- classiq/interface/generator/entanglers.py +0 -14
- classiq/interface/generator/hamiltonian_evolution/qdrift.py +0 -27
- classiq/interface/generator/hartree_fock.py +0 -26
- classiq/interface/generator/hva.py +0 -22
- classiq/interface/generator/linear_pauli_rotations.py +0 -92
- classiq/interface/generator/qft.py +0 -37
- classiq/interface/generator/qsvm.py +0 -96
- classiq/interface/generator/state_preparation/__init__.py +0 -14
- classiq/interface/generator/state_preparation/bell_state_preparation.py +0 -27
- classiq/interface/generator/state_preparation/computational_basis_state_preparation.py +0 -28
- classiq/interface/generator/state_preparation/distributions.py +0 -53
- classiq/interface/generator/state_preparation/exponential_state_preparation.py +0 -14
- classiq/interface/generator/state_preparation/ghz_state_preparation.py +0 -14
- classiq/interface/generator/state_preparation/metrics.py +0 -41
- classiq/interface/generator/state_preparation/state_preparation.py +0 -113
- classiq/interface/generator/state_preparation/state_preparation_abc.py +0 -24
- classiq/interface/generator/state_preparation/uniform_distibution_state_preparation.py +0 -13
- classiq/interface/generator/state_preparation/w_state_preparation.py +0 -13
- classiq/interface/generator/ucc.py +0 -74
- classiq/interface/helpers/backward_compatibility.py +0 -9
- classiq/model_expansions/transformers/type_modifier_inference.py +0 -392
- classiq/open_library/functions/lookup_table.py +0 -58
- classiq/qmod/builtins/functions/chemistry.py +0 -123
- classiq/qmod/builtins/functions/qsvm.py +0 -24
- {classiq-0.93.0.dist-info → classiq-0.100.0.dist-info}/licenses/LICENSE.txt +0 -0
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import pydantic
|
|
2
|
-
|
|
3
|
-
from classiq.interface.generator.arith.register_user_input import RegisterArithmeticInfo
|
|
4
|
-
from classiq.interface.generator.function_params import (
|
|
5
|
-
DEFAULT_INPUT_NAME,
|
|
6
|
-
DEFAULT_OUTPUT_NAME,
|
|
7
|
-
FunctionParams,
|
|
8
|
-
)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class QFT(FunctionParams):
|
|
12
|
-
"""
|
|
13
|
-
Creates a quantum Fourier transform on a specified number of qubits.
|
|
14
|
-
"""
|
|
15
|
-
|
|
16
|
-
num_qubits: pydantic.PositiveInt = pydantic.Field(
|
|
17
|
-
description="The number of qubits on which the QFT acts."
|
|
18
|
-
)
|
|
19
|
-
approximation_degree: pydantic.NonNegativeInt = pydantic.Field(
|
|
20
|
-
default=0,
|
|
21
|
-
description="The degree of approximation (0 for no approximation). The smallest "
|
|
22
|
-
"'approximation_degree' rotation angles are dropped from the QFT.",
|
|
23
|
-
)
|
|
24
|
-
do_swaps: bool = pydantic.Field(
|
|
25
|
-
default=True, description="Whether to include the final swaps in the QFT."
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
def _create_ios(self) -> None:
|
|
29
|
-
self._inputs = {
|
|
30
|
-
DEFAULT_INPUT_NAME: RegisterArithmeticInfo(size=self.num_qubits)
|
|
31
|
-
}
|
|
32
|
-
self._outputs = {
|
|
33
|
-
DEFAULT_OUTPUT_NAME: RegisterArithmeticInfo(size=self.num_qubits)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
def get_power_order(self) -> int:
|
|
37
|
-
return 4
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
from typing import Literal, Optional, Union
|
|
2
|
-
|
|
3
|
-
import numpy as np
|
|
4
|
-
import pydantic
|
|
5
|
-
from pydantic import ConfigDict
|
|
6
|
-
|
|
7
|
-
from classiq.interface.enum_utils import StrEnum
|
|
8
|
-
from classiq.interface.exceptions import ClassiqQSVMError, ClassiqValueError
|
|
9
|
-
from classiq.interface.generator.arith.register_user_input import RegisterUserInput
|
|
10
|
-
from classiq.interface.generator.function_params import (
|
|
11
|
-
DEFAULT_INPUT_NAME,
|
|
12
|
-
DEFAULT_OUTPUT_NAME,
|
|
13
|
-
FunctionParams,
|
|
14
|
-
)
|
|
15
|
-
from classiq.interface.helpers.hashable_pydantic_base_model import (
|
|
16
|
-
HashablePydanticBaseModel,
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
VALID_PAULI_LETTERS = ("I", "X", "Y", "Z")
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class QSVMFeatureMapEntanglement(StrEnum):
|
|
23
|
-
FULL = "full"
|
|
24
|
-
LINEAR = "linear"
|
|
25
|
-
CIRCULAR = "circular"
|
|
26
|
-
SCA = "sca"
|
|
27
|
-
PAIRWISE = "pairwise"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class QSVMFeatureMapDimensional(HashablePydanticBaseModel):
|
|
31
|
-
feature_dimension: Optional[int] = None
|
|
32
|
-
model_config = ConfigDict(frozen=True)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
class QSVMFeatureMapPauli(QSVMFeatureMapDimensional):
|
|
36
|
-
map_type: Literal["pauli_feature_map"] = pydantic.Field(default="pauli_feature_map")
|
|
37
|
-
reps: int = 2
|
|
38
|
-
entanglement: QSVMFeatureMapEntanglement = QSVMFeatureMapEntanglement.LINEAR
|
|
39
|
-
alpha: float = 2.0
|
|
40
|
-
paulis: list[str] = ["Z", "ZZ"]
|
|
41
|
-
parameter_prefix: str = "x"
|
|
42
|
-
name: str = "PauliFeatureMap"
|
|
43
|
-
|
|
44
|
-
@pydantic.field_validator("paulis", mode="before")
|
|
45
|
-
@classmethod
|
|
46
|
-
def set_paulis(cls, paulis: list[str]) -> list[str]:
|
|
47
|
-
# iterate every letter in every string in the list of paulis
|
|
48
|
-
for s in paulis:
|
|
49
|
-
if not all(map(VALID_PAULI_LETTERS.__contains__, s.upper())):
|
|
50
|
-
raise ClassiqValueError(
|
|
51
|
-
f"Invalid pauli string given: {s!r}. Expecting a combination of {VALID_PAULI_LETTERS}"
|
|
52
|
-
)
|
|
53
|
-
return list(map(str.upper, paulis))
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
class QSVMFeatureMapBlochSphere(QSVMFeatureMapDimensional):
|
|
57
|
-
map_type: Literal["bloch_sphere_feature_map"] = pydantic.Field(
|
|
58
|
-
default="bloch_sphere_feature_map"
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
FeatureMapType = Union[QSVMFeatureMapBlochSphere, QSVMFeatureMapPauli]
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
class QSVMFeatureMap(FunctionParams):
|
|
66
|
-
"""
|
|
67
|
-
Feature map circuit used for QSVM
|
|
68
|
-
"""
|
|
69
|
-
|
|
70
|
-
feature_map: FeatureMapType = pydantic.Field(
|
|
71
|
-
description="The feature map for the qsvm",
|
|
72
|
-
discriminator="map_type",
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
@property
|
|
76
|
-
def num_qubits(self) -> int:
|
|
77
|
-
if not self.feature_map.feature_dimension:
|
|
78
|
-
raise ClassiqQSVMError(
|
|
79
|
-
"Feature dimension should be provided to create a circuit."
|
|
80
|
-
)
|
|
81
|
-
if isinstance(self.feature_map, QSVMFeatureMapPauli):
|
|
82
|
-
return self.feature_map.feature_dimension
|
|
83
|
-
else:
|
|
84
|
-
return int(np.ceil(self.feature_map.feature_dimension / 2))
|
|
85
|
-
|
|
86
|
-
def _create_ios(self) -> None:
|
|
87
|
-
self._inputs = {
|
|
88
|
-
DEFAULT_INPUT_NAME: RegisterUserInput(
|
|
89
|
-
name=DEFAULT_INPUT_NAME, size=self.num_qubits
|
|
90
|
-
)
|
|
91
|
-
}
|
|
92
|
-
self._outputs = {
|
|
93
|
-
DEFAULT_OUTPUT_NAME: RegisterUserInput(
|
|
94
|
-
name=DEFAULT_OUTPUT_NAME, size=self.num_qubits
|
|
95
|
-
)
|
|
96
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
from .bell_state_preparation import BellStatePreparation
|
|
2
|
-
from .computational_basis_state_preparation import ComputationalBasisStatePreparation
|
|
3
|
-
from .distributions import PMF, GaussianMixture, GaussianMoments
|
|
4
|
-
from .exponential_state_preparation import ExponentialStatePreparation
|
|
5
|
-
from .ghz_state_preparation import GHZStatePreparation
|
|
6
|
-
from .metrics import Metrics
|
|
7
|
-
from .state_preparation import StatePreparation
|
|
8
|
-
from .state_preparation_abc import (
|
|
9
|
-
DEFAULT_INPUT_NAME,
|
|
10
|
-
DEFAULT_OUTPUT_NAME,
|
|
11
|
-
StatePreparationABC,
|
|
12
|
-
)
|
|
13
|
-
from .uniform_distibution_state_preparation import UniformDistributionStatePreparation
|
|
14
|
-
from .w_state_preparation import WStatePreparation
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
from typing import Literal
|
|
2
|
-
|
|
3
|
-
import pydantic
|
|
4
|
-
|
|
5
|
-
from classiq.interface.generator.state_preparation.state_preparation_abc import (
|
|
6
|
-
StatePreparationABC,
|
|
7
|
-
)
|
|
8
|
-
|
|
9
|
-
BellStateName = Literal["psi+", "psi-", "phi+", "phi-"]
|
|
10
|
-
_ALIGNED_STATES: frozenset[BellStateName] = frozenset({"phi+", "phi-"})
|
|
11
|
-
_SIGNED_STATES: frozenset[BellStateName] = frozenset({"psi-", "phi-"})
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class BellStatePreparation(StatePreparationABC):
|
|
15
|
-
name: BellStateName = pydantic.Field(default="phi+")
|
|
16
|
-
|
|
17
|
-
@property
|
|
18
|
-
def aligned(self) -> bool:
|
|
19
|
-
return self.name in _ALIGNED_STATES
|
|
20
|
-
|
|
21
|
-
@property
|
|
22
|
-
def signed(self) -> bool:
|
|
23
|
-
return self.name in _SIGNED_STATES
|
|
24
|
-
|
|
25
|
-
@property
|
|
26
|
-
def num_state_qubits(self) -> int:
|
|
27
|
-
return 2
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import pydantic
|
|
2
|
-
|
|
3
|
-
from classiq.interface.generator.control_state import ControlState
|
|
4
|
-
from classiq.interface.generator.state_preparation.state_preparation_abc import (
|
|
5
|
-
StatePreparationABC,
|
|
6
|
-
)
|
|
7
|
-
from classiq.interface.helpers.custom_pydantic_types import PydanticNonEmptyString
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class ComputationalBasisStatePreparation(StatePreparationABC):
|
|
11
|
-
computational_state: PydanticNonEmptyString = pydantic.Field(
|
|
12
|
-
description="binary computational state to create"
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
@pydantic.field_validator("computational_state")
|
|
16
|
-
@classmethod
|
|
17
|
-
def _validate_computational_state(
|
|
18
|
-
cls, computational_state: PydanticNonEmptyString
|
|
19
|
-
) -> PydanticNonEmptyString:
|
|
20
|
-
ControlState.validate_control_string(computational_state)
|
|
21
|
-
return computational_state
|
|
22
|
-
|
|
23
|
-
@property
|
|
24
|
-
def num_state_qubits(self) -> int:
|
|
25
|
-
return len(self.computational_state)
|
|
26
|
-
|
|
27
|
-
def get_power_order(self) -> int:
|
|
28
|
-
return 2
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
from collections.abc import Collection, Sequence
|
|
2
|
-
from typing import Union
|
|
3
|
-
|
|
4
|
-
import pydantic
|
|
5
|
-
from numpy.typing import ArrayLike
|
|
6
|
-
from pydantic import ConfigDict
|
|
7
|
-
|
|
8
|
-
from classiq.interface.generator.validations.validator_functions import (
|
|
9
|
-
validate_probabilities,
|
|
10
|
-
)
|
|
11
|
-
from classiq.interface.helpers.custom_pydantic_types import PydanticProbabilityFloat
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class PMF(pydantic.BaseModel):
|
|
15
|
-
pmf: tuple[PydanticProbabilityFloat, ...]
|
|
16
|
-
|
|
17
|
-
@pydantic.field_validator("pmf")
|
|
18
|
-
@classmethod
|
|
19
|
-
def _validate_pmf(
|
|
20
|
-
cls, pmf: tuple[PydanticProbabilityFloat, ...]
|
|
21
|
-
) -> Sequence[PydanticProbabilityFloat]:
|
|
22
|
-
return validate_probabilities(cls, pmf)
|
|
23
|
-
|
|
24
|
-
model_config = ConfigDict(frozen=True)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
class GaussianMoments(pydantic.BaseModel):
|
|
28
|
-
mu: float
|
|
29
|
-
sigma: pydantic.PositiveFloat
|
|
30
|
-
model_config = ConfigDict(frozen=True)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
class GaussianMixture(pydantic.BaseModel):
|
|
34
|
-
gaussian_moment_list: tuple[GaussianMoments, ...]
|
|
35
|
-
num_qubits: pydantic.PositiveInt = pydantic.Field(
|
|
36
|
-
description="Number of qubits for the provided state."
|
|
37
|
-
)
|
|
38
|
-
model_config = ConfigDict(frozen=True)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
Probabilities = Union[PMF, GaussianMixture]
|
|
42
|
-
FlexibleProbabilities = Union[Probabilities, ArrayLike, dict, Collection[float]]
|
|
43
|
-
Amplitudes = tuple[float, ...]
|
|
44
|
-
FlexibleAmplitudes = Union[ArrayLike, Collection[float]]
|
|
45
|
-
Distribution = Union[Amplitudes, Probabilities]
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
def num_of_qubits(distribution: Distribution) -> int:
|
|
49
|
-
if isinstance(distribution, GaussianMixture):
|
|
50
|
-
return distribution.num_qubits
|
|
51
|
-
if isinstance(distribution, PMF):
|
|
52
|
-
return len(distribution.pmf).bit_length() - 1
|
|
53
|
-
return len(distribution).bit_length() - 1
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import pydantic
|
|
2
|
-
|
|
3
|
-
from classiq.interface.generator.state_preparation.state_preparation_abc import (
|
|
4
|
-
StatePreparationABC,
|
|
5
|
-
)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class ExponentialStatePreparation(StatePreparationABC):
|
|
9
|
-
num_qubits: pydantic.PositiveInt = pydantic.Field()
|
|
10
|
-
rate: float = pydantic.Field()
|
|
11
|
-
|
|
12
|
-
@property
|
|
13
|
-
def num_state_qubits(self) -> int:
|
|
14
|
-
return self.num_qubits
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import pydantic
|
|
2
|
-
|
|
3
|
-
from classiq.interface.generator.state_preparation.state_preparation_abc import (
|
|
4
|
-
StatePreparationABC,
|
|
5
|
-
)
|
|
6
|
-
from classiq.interface.helpers.custom_pydantic_types import PydanticLargerThanOneInteger
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class GHZStatePreparation(StatePreparationABC):
|
|
10
|
-
num_qubits: PydanticLargerThanOneInteger = pydantic.Field(default=3)
|
|
11
|
-
|
|
12
|
-
@property
|
|
13
|
-
def num_state_qubits(self) -> int:
|
|
14
|
-
return self.num_qubits
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
from classiq.interface.enum_utils import StrEnum
|
|
2
|
-
from classiq.interface.exceptions import ClassiqValueError
|
|
3
|
-
from classiq.interface.generator.preferences.optimization import (
|
|
4
|
-
StatePrepOptimizationMethod,
|
|
5
|
-
)
|
|
6
|
-
|
|
7
|
-
_AMPLITUDE_SUPPORTING_METRICS: frozenset = frozenset(
|
|
8
|
-
{"L2", "L1", "MAX_PROBABILITY", "TOTAL_VARIATION"}
|
|
9
|
-
)
|
|
10
|
-
|
|
11
|
-
_ZERO_DIVERGENT_METRICS: frozenset = frozenset({"KL", "BHATTACHARYYA"})
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class Metrics(StrEnum):
|
|
15
|
-
KL = "KL"
|
|
16
|
-
L2 = "L2"
|
|
17
|
-
L1 = "L1"
|
|
18
|
-
MAX_PROBABILITY = "MAX_PROBABILITY"
|
|
19
|
-
LOSS_OF_FIDELITY = "LOSS_OF_FIDELITY"
|
|
20
|
-
TOTAL_VARIATION = "TOTAL_VARIATION"
|
|
21
|
-
HELLINGER = "HELLINGER"
|
|
22
|
-
BHATTACHARYYA = "BHATTACHARYYA"
|
|
23
|
-
|
|
24
|
-
@classmethod
|
|
25
|
-
def from_sp_optimization_method(
|
|
26
|
-
cls, sp_opt_method: StatePrepOptimizationMethod
|
|
27
|
-
) -> "Metrics":
|
|
28
|
-
try:
|
|
29
|
-
return Metrics(sp_opt_method.value)
|
|
30
|
-
except ValueError:
|
|
31
|
-
raise ClassiqValueError(
|
|
32
|
-
f"Failed to convert {sp_opt_method} to an error metric"
|
|
33
|
-
) from None
|
|
34
|
-
|
|
35
|
-
@property
|
|
36
|
-
def supports_amplitudes(self) -> bool:
|
|
37
|
-
return self.value in _AMPLITUDE_SUPPORTING_METRICS
|
|
38
|
-
|
|
39
|
-
@property
|
|
40
|
-
def possibly_diverges(self) -> bool:
|
|
41
|
-
return self.value in _ZERO_DIVERGENT_METRICS
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
from typing import Optional, Union
|
|
2
|
-
|
|
3
|
-
import numpy as np
|
|
4
|
-
import pydantic
|
|
5
|
-
from pydantic_core.core_schema import ValidationInfo
|
|
6
|
-
from typing_extensions import Self
|
|
7
|
-
|
|
8
|
-
from classiq.interface.exceptions import ClassiqValueError
|
|
9
|
-
from classiq.interface.generator.range_types import NonNegativeFloatRange
|
|
10
|
-
from classiq.interface.generator.state_preparation.distributions import (
|
|
11
|
-
PMF,
|
|
12
|
-
Amplitudes,
|
|
13
|
-
FlexibleAmplitudes,
|
|
14
|
-
FlexibleProbabilities,
|
|
15
|
-
GaussianMixture,
|
|
16
|
-
Probabilities,
|
|
17
|
-
num_of_qubits,
|
|
18
|
-
)
|
|
19
|
-
from classiq.interface.generator.state_preparation.metrics import Metrics
|
|
20
|
-
from classiq.interface.generator.state_preparation.state_preparation_abc import (
|
|
21
|
-
StatePreparationABC,
|
|
22
|
-
)
|
|
23
|
-
from classiq.interface.generator.validations.validator_functions import (
|
|
24
|
-
validate_amplitudes,
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class StatePreparation(StatePreparationABC):
|
|
29
|
-
amplitudes: Optional[Amplitudes] = pydantic.Field(
|
|
30
|
-
description="vector of probabilities",
|
|
31
|
-
default=None,
|
|
32
|
-
validate_default=True,
|
|
33
|
-
)
|
|
34
|
-
probabilities: Optional[Probabilities] = pydantic.Field(
|
|
35
|
-
description="vector of amplitudes",
|
|
36
|
-
default=None,
|
|
37
|
-
validate_default=True,
|
|
38
|
-
)
|
|
39
|
-
error_metric: dict[Metrics, NonNegativeFloatRange] = pydantic.Field(
|
|
40
|
-
default_factory=lambda: {
|
|
41
|
-
Metrics.L2: NonNegativeFloatRange(lower_bound=0, upper_bound=1e-4)
|
|
42
|
-
}
|
|
43
|
-
)
|
|
44
|
-
# The order of validations is important: amplitudes, probabilities, error_metric
|
|
45
|
-
|
|
46
|
-
@pydantic.field_validator("amplitudes", mode="before")
|
|
47
|
-
@classmethod
|
|
48
|
-
def _initialize_amplitudes(
|
|
49
|
-
cls, amplitudes: Optional[FlexibleAmplitudes]
|
|
50
|
-
) -> Optional[Amplitudes]:
|
|
51
|
-
if amplitudes is None:
|
|
52
|
-
return None
|
|
53
|
-
amplitudes = np.array(amplitudes).squeeze()
|
|
54
|
-
if amplitudes.ndim == 1:
|
|
55
|
-
return validate_amplitudes(tuple(amplitudes))
|
|
56
|
-
|
|
57
|
-
raise ClassiqValueError(
|
|
58
|
-
"Invalid amplitudes were given, please ensure the amplitude is a vector of float in the form of either tuple or list or numpy array"
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
@pydantic.field_validator("probabilities", mode="before")
|
|
62
|
-
@classmethod
|
|
63
|
-
def _initialize_probabilities(
|
|
64
|
-
cls, probabilities: Optional[FlexibleProbabilities]
|
|
65
|
-
) -> Optional[Union[PMF, GaussianMixture, dict]]:
|
|
66
|
-
if probabilities is None:
|
|
67
|
-
return None
|
|
68
|
-
if isinstance(probabilities, Probabilities.__args__): # type: ignore[attr-defined]
|
|
69
|
-
return probabilities
|
|
70
|
-
if isinstance(probabilities, dict): # a pydantic object
|
|
71
|
-
return probabilities
|
|
72
|
-
probabilities = np.array(probabilities).squeeze()
|
|
73
|
-
if probabilities.ndim == 1:
|
|
74
|
-
return PMF(pmf=probabilities.tolist())
|
|
75
|
-
|
|
76
|
-
raise ClassiqValueError(
|
|
77
|
-
"Invalid probabilities were given, please ensure the probabilities is a vector of float in the form of either tuple or list or numpy array"
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
@pydantic.field_validator("error_metric", mode="before")
|
|
81
|
-
@classmethod
|
|
82
|
-
def _validate_error_metric(
|
|
83
|
-
cls, error_metric: dict[Metrics, NonNegativeFloatRange], info: ValidationInfo
|
|
84
|
-
) -> dict[Metrics, NonNegativeFloatRange]:
|
|
85
|
-
if not info.data.get("amplitudes"):
|
|
86
|
-
return error_metric
|
|
87
|
-
unsupported_metrics = {
|
|
88
|
-
Metrics(metric).value
|
|
89
|
-
for metric in error_metric
|
|
90
|
-
if not Metrics(metric).supports_amplitudes
|
|
91
|
-
}
|
|
92
|
-
if unsupported_metrics:
|
|
93
|
-
raise ClassiqValueError(
|
|
94
|
-
f"{unsupported_metrics} are not supported for amplitude preparation"
|
|
95
|
-
)
|
|
96
|
-
return error_metric
|
|
97
|
-
|
|
98
|
-
@pydantic.model_validator(mode="after")
|
|
99
|
-
def _validate_either_probabilities_or_amplitudes(self) -> Self:
|
|
100
|
-
amplitudes = self.amplitudes
|
|
101
|
-
probabilities = self.probabilities
|
|
102
|
-
if amplitudes is not None and probabilities is not None:
|
|
103
|
-
raise ClassiqValueError(
|
|
104
|
-
"StatePreparation can't get both probabilities and amplitudes"
|
|
105
|
-
)
|
|
106
|
-
return self
|
|
107
|
-
|
|
108
|
-
@property
|
|
109
|
-
def num_state_qubits(self) -> int:
|
|
110
|
-
distribution = self.probabilities or self.amplitudes
|
|
111
|
-
if distribution is None:
|
|
112
|
-
raise ClassiqValueError("Must have either probabilities or amplitudes")
|
|
113
|
-
return num_of_qubits(distribution)
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import abc
|
|
2
|
-
|
|
3
|
-
from classiq.interface.generator.arith.register_user_input import RegisterUserInput
|
|
4
|
-
from classiq.interface.generator.function_params import (
|
|
5
|
-
DEFAULT_INPUT_NAME,
|
|
6
|
-
DEFAULT_OUTPUT_NAME,
|
|
7
|
-
FunctionParams,
|
|
8
|
-
)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class StatePreparationABC(FunctionParams, abc.ABC):
|
|
12
|
-
@property
|
|
13
|
-
@abc.abstractmethod
|
|
14
|
-
def num_state_qubits(self) -> int:
|
|
15
|
-
pass
|
|
16
|
-
|
|
17
|
-
def _create_ios(self) -> None:
|
|
18
|
-
self._inputs = dict()
|
|
19
|
-
self._outputs = {
|
|
20
|
-
DEFAULT_OUTPUT_NAME: RegisterUserInput(
|
|
21
|
-
name=DEFAULT_OUTPUT_NAME, size=self.num_state_qubits
|
|
22
|
-
)
|
|
23
|
-
}
|
|
24
|
-
self._create_zero_input_registers({DEFAULT_INPUT_NAME: self.num_state_qubits})
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import pydantic
|
|
2
|
-
|
|
3
|
-
from classiq.interface.generator.state_preparation.state_preparation_abc import (
|
|
4
|
-
StatePreparationABC,
|
|
5
|
-
)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class UniformDistributionStatePreparation(StatePreparationABC):
|
|
9
|
-
num_qubits: pydantic.PositiveInt = pydantic.Field(default=2)
|
|
10
|
-
|
|
11
|
-
@property
|
|
12
|
-
def num_state_qubits(self) -> int:
|
|
13
|
-
return self.num_qubits
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import pydantic
|
|
2
|
-
|
|
3
|
-
from classiq.interface.generator.state_preparation.state_preparation_abc import (
|
|
4
|
-
StatePreparationABC,
|
|
5
|
-
)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class WStatePreparation(StatePreparationABC):
|
|
9
|
-
num_qubits: pydantic.PositiveInt = pydantic.Field(default=3)
|
|
10
|
-
|
|
11
|
-
@property
|
|
12
|
-
def num_state_qubits(self) -> int:
|
|
13
|
-
return self.num_qubits
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
from collections.abc import Iterable
|
|
2
|
-
from typing import Optional
|
|
3
|
-
|
|
4
|
-
import pydantic
|
|
5
|
-
|
|
6
|
-
from classiq.interface.exceptions import ClassiqValueError
|
|
7
|
-
from classiq.interface.generator.chemistry_function_params import (
|
|
8
|
-
ChemistryFunctionParams,
|
|
9
|
-
)
|
|
10
|
-
from classiq.interface.generator.excitations import (
|
|
11
|
-
EXCITATIONS_TYPE,
|
|
12
|
-
EXCITATIONS_TYPE_EXACT,
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
_EXCITATIONS_DICT = {"s": 1, "d": 2, "t": 3, "q": 4}
|
|
16
|
-
|
|
17
|
-
DEFAULT_EXCITATIONS = [1, 2]
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def default_excitation_factory() -> EXCITATIONS_TYPE_EXACT:
|
|
21
|
-
return DEFAULT_EXCITATIONS
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
class UCC(ChemistryFunctionParams):
|
|
25
|
-
"""
|
|
26
|
-
Ucc ansatz
|
|
27
|
-
"""
|
|
28
|
-
|
|
29
|
-
use_naive_evolution: bool = pydantic.Field(
|
|
30
|
-
default=False, description="Whether to evolve the operator naively"
|
|
31
|
-
)
|
|
32
|
-
excitations: EXCITATIONS_TYPE = pydantic.Field(
|
|
33
|
-
default_factory=default_excitation_factory,
|
|
34
|
-
description="type of excitation operators in the UCC ansatz",
|
|
35
|
-
)
|
|
36
|
-
max_depth: Optional[pydantic.PositiveInt] = pydantic.Field(
|
|
37
|
-
default=None,
|
|
38
|
-
description="Maximum depth of the generated quantum circuit ansatz",
|
|
39
|
-
)
|
|
40
|
-
parameter_prefix: str = pydantic.Field(
|
|
41
|
-
default="ucc_param_",
|
|
42
|
-
description="Prefix for the generated parameters",
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
@pydantic.field_validator("excitations")
|
|
46
|
-
@classmethod
|
|
47
|
-
def _validate_excitations(cls, excitations: EXCITATIONS_TYPE) -> EXCITATIONS_TYPE:
|
|
48
|
-
if isinstance(excitations, int):
|
|
49
|
-
if excitations not in _EXCITATIONS_DICT.values():
|
|
50
|
-
raise ClassiqValueError(
|
|
51
|
-
f"possible values of excitations are {list(_EXCITATIONS_DICT.values())}"
|
|
52
|
-
)
|
|
53
|
-
excitations = [excitations]
|
|
54
|
-
|
|
55
|
-
elif isinstance(excitations, Iterable):
|
|
56
|
-
excitations = list(excitations) # type: ignore[assignment]
|
|
57
|
-
if all(isinstance(idx, int) for idx in excitations):
|
|
58
|
-
if any(idx not in _EXCITATIONS_DICT.values() for idx in excitations):
|
|
59
|
-
raise ClassiqValueError(
|
|
60
|
-
f"possible values of excitations are {list(_EXCITATIONS_DICT.values())}"
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
elif all(isinstance(idx, str) for idx in excitations):
|
|
64
|
-
if any(idx not in _EXCITATIONS_DICT.keys() for idx in excitations):
|
|
65
|
-
raise ClassiqValueError(
|
|
66
|
-
f"possible values of excitations are {list(_EXCITATIONS_DICT.keys())}"
|
|
67
|
-
)
|
|
68
|
-
excitations = sorted(_EXCITATIONS_DICT[idx] for idx in excitations) # type: ignore[index]
|
|
69
|
-
|
|
70
|
-
else:
|
|
71
|
-
raise ClassiqValueError(
|
|
72
|
-
"excitations must be of the same type (all str or all int)"
|
|
73
|
-
)
|
|
74
|
-
return excitations
|