classiq 0.93.0__py3-none-any.whl → 0.99.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- classiq/__init__.py +11 -19
- classiq/_analyzer_extras/_ipywidgets_async_extension.py +7 -7
- classiq/_analyzer_extras/interactive_hardware.py +19 -12
- classiq/_internals/api_wrapper.py +31 -142
- classiq/_internals/async_utils.py +4 -7
- classiq/_internals/authentication/auth0.py +41 -15
- classiq/_internals/authentication/authorization_code.py +9 -0
- classiq/_internals/authentication/authorization_flow.py +41 -0
- classiq/_internals/authentication/device.py +33 -52
- classiq/_internals/authentication/hybrid_flow.py +19 -0
- classiq/_internals/authentication/password_manager.py +13 -13
- classiq/_internals/authentication/token_manager.py +9 -9
- classiq/_internals/client.py +17 -44
- classiq/_internals/config.py +19 -5
- classiq/_internals/help.py +1 -2
- classiq/_internals/host_checker.py +3 -3
- classiq/_internals/jobs.py +14 -14
- classiq/_internals/type_validation.py +3 -3
- classiq/analyzer/analyzer.py +18 -18
- classiq/analyzer/rb.py +17 -8
- classiq/analyzer/show_interactive_hack.py +1 -1
- classiq/applications/__init__.py +2 -2
- classiq/applications/chemistry/__init__.py +0 -30
- classiq/applications/chemistry/op_utils.py +4 -4
- classiq/applications/chemistry/problems.py +3 -3
- classiq/applications/chemistry/ucc.py +1 -2
- classiq/applications/chemistry/z2_symmetries.py +4 -4
- classiq/applications/combinatorial_helpers/allowed_constraints.py +1 -3
- classiq/applications/combinatorial_helpers/arithmetic/arithmetic_expression.py +2 -1
- classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +2 -2
- classiq/applications/combinatorial_helpers/encoding_mapping.py +2 -3
- classiq/applications/combinatorial_helpers/encoding_utils.py +2 -2
- classiq/applications/combinatorial_helpers/optimization_model.py +3 -4
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_sparsing.py +2 -2
- classiq/applications/combinatorial_helpers/pyomo_utils.py +8 -8
- classiq/applications/combinatorial_helpers/sympy_utils.py +1 -3
- classiq/applications/combinatorial_helpers/transformations/encoding.py +3 -3
- classiq/applications/combinatorial_helpers/transformations/fixed_variables.py +1 -2
- classiq/applications/combinatorial_optimization/combinatorial_optimization_config.py +2 -3
- classiq/applications/combinatorial_optimization/combinatorial_optimization_model_constructor.py +4 -6
- classiq/applications/combinatorial_optimization/combinatorial_problem.py +15 -10
- classiq/applications/hamiltonian/pauli_decomposition.py +6 -4
- classiq/applications/iqae/iqae.py +14 -11
- classiq/applications/qnn/datasets/dataset_base_classes.py +6 -6
- classiq/applications/qnn/datasets/dataset_parity.py +6 -6
- classiq/applications/qnn/gradients/simple_quantum_gradient.py +1 -1
- classiq/applications/qnn/qlayer.py +9 -8
- classiq/applications/qnn/torch_utils.py +5 -6
- classiq/applications/qnn/types.py +2 -1
- classiq/applications/qsp/__init__.py +20 -2
- classiq/applications/qsp/qsp.py +238 -10
- classiq/applications/qsvm/qsvm_data_generation.py +1 -2
- classiq/evaluators/classical_expression.py +0 -4
- classiq/evaluators/parameter_types.py +10 -8
- classiq/evaluators/qmod_annotated_expression.py +31 -26
- classiq/evaluators/qmod_expression_visitors/qmod_expression_evaluator.py +14 -14
- classiq/evaluators/qmod_expression_visitors/qmod_expression_simplifier.py +2 -1
- classiq/evaluators/qmod_expression_visitors/sympy_wrappers.py +8 -8
- classiq/evaluators/qmod_node_evaluators/binary_op_evaluation.py +4 -4
- classiq/evaluators/qmod_node_evaluators/classical_function_evaluation.py +14 -4
- classiq/evaluators/qmod_node_evaluators/list_evaluation.py +2 -2
- classiq/evaluators/qmod_node_evaluators/numeric_attrs_utils.py +3 -3
- classiq/evaluators/qmod_node_evaluators/subscript_evaluation.py +9 -9
- classiq/evaluators/qmod_node_evaluators/utils.py +6 -6
- classiq/evaluators/qmod_type_inference/classical_type_inference.py +9 -10
- classiq/evaluators/qmod_type_inference/quantum_type_inference.py +5 -5
- classiq/execution/__init__.py +0 -3
- classiq/execution/execution_session.py +28 -21
- classiq/execution/jobs.py +26 -26
- classiq/execution/qnn.py +1 -2
- classiq/execution/user_budgets.py +71 -37
- classiq/executor.py +1 -3
- classiq/interface/_version.py +1 -1
- classiq/interface/analyzer/analysis_params.py +4 -4
- classiq/interface/analyzer/cytoscape_graph.py +3 -3
- classiq/interface/analyzer/result.py +4 -4
- classiq/interface/ast_node.py +3 -3
- classiq/interface/backend/backend_preferences.py +26 -50
- classiq/interface/backend/ionq/ionq_quantum_program.py +5 -5
- classiq/interface/backend/provider_config/__init__.py +0 -0
- classiq/interface/backend/provider_config/provider_config.py +8 -0
- classiq/interface/backend/provider_config/providers/__init__.py +0 -0
- classiq/interface/backend/provider_config/providers/alice_bob.py +47 -0
- classiq/interface/backend/provider_config/providers/aqt.py +16 -0
- classiq/interface/backend/provider_config/providers/azure.py +37 -0
- classiq/interface/backend/provider_config/providers/braket.py +39 -0
- classiq/interface/backend/provider_config/providers/ibm.py +26 -0
- classiq/interface/backend/provider_config/providers/ionq.py +22 -0
- classiq/interface/backend/quantum_backend_providers.py +20 -2
- classiq/interface/chemistry/ansatz_library.py +3 -5
- classiq/interface/chemistry/operator.py +3 -3
- classiq/interface/combinatorial_optimization/examples/knapsack.py +2 -4
- classiq/interface/combinatorial_optimization/examples/tsp_digraph.py +1 -2
- classiq/interface/compression_utils.py +2 -3
- classiq/interface/debug_info/debug_info.py +8 -7
- classiq/interface/exceptions.py +6 -7
- classiq/interface/execution/primitives.py +6 -6
- classiq/interface/executor/estimate_cost.py +1 -1
- classiq/interface/executor/execution_preferences.py +3 -5
- classiq/interface/executor/execution_request.py +10 -10
- classiq/interface/executor/execution_result.py +1 -2
- classiq/interface/executor/quantum_code.py +8 -8
- classiq/interface/executor/result.py +28 -18
- classiq/interface/executor/user_budget.py +25 -17
- classiq/interface/executor/vqe_result.py +5 -6
- classiq/interface/generator/ansatz_library.py +6 -8
- classiq/interface/generator/application_apis/__init__.py +0 -3
- classiq/interface/generator/arith/arithmetic.py +2 -2
- classiq/interface/generator/arith/arithmetic_arg_type_validator.py +2 -3
- classiq/interface/generator/arith/arithmetic_expression_abc.py +4 -5
- classiq/interface/generator/arith/arithmetic_expression_parser.py +11 -4
- classiq/interface/generator/arith/arithmetic_expression_validator.py +12 -15
- classiq/interface/generator/arith/arithmetic_operations.py +4 -6
- classiq/interface/generator/arith/arithmetic_param_getters.py +70 -107
- classiq/interface/generator/arith/arithmetic_result_builder.py +4 -4
- classiq/interface/generator/arith/ast_node_rewrite.py +8 -4
- classiq/interface/generator/arith/binary_ops.py +15 -40
- classiq/interface/generator/arith/logical_ops.py +2 -3
- classiq/interface/generator/arith/number_utils.py +2 -2
- classiq/interface/generator/arith/register_user_input.py +3 -3
- classiq/interface/generator/arith/unary_ops.py +2 -2
- classiq/interface/generator/circuit_code/circuit_code.py +8 -10
- classiq/interface/generator/circuit_code/types_and_constants.py +1 -1
- classiq/interface/generator/complex_type.py +2 -2
- classiq/interface/generator/copy.py +1 -3
- classiq/interface/generator/expressions/atomic_expression_functions.py +0 -5
- classiq/interface/generator/expressions/evaluated_expression.py +2 -3
- classiq/interface/generator/expressions/expression.py +2 -2
- classiq/interface/generator/expressions/proxies/classical/classical_array_proxy.py +4 -7
- classiq/interface/generator/function_param_list.py +0 -40
- classiq/interface/generator/function_params.py +5 -6
- classiq/interface/generator/functions/classical_function_declaration.py +2 -2
- classiq/interface/generator/functions/classical_type.py +3 -3
- classiq/interface/generator/functions/type_modifier.py +0 -15
- classiq/interface/generator/functions/type_name.py +2 -2
- classiq/interface/generator/generated_circuit_data.py +14 -18
- classiq/interface/generator/hamiltonian_evolution/exponentiation.py +2 -4
- classiq/interface/generator/hardware/hardware_data.py +8 -8
- classiq/interface/generator/hardware_efficient_ansatz.py +9 -9
- classiq/interface/generator/mcu.py +3 -3
- classiq/interface/generator/mcx.py +3 -3
- classiq/interface/generator/model/constraints.py +34 -5
- classiq/interface/generator/model/preferences/preferences.py +15 -21
- classiq/interface/generator/model/quantum_register.py +7 -10
- classiq/interface/generator/noise_properties.py +3 -7
- classiq/interface/generator/parameters.py +1 -1
- classiq/interface/generator/partitioned_register.py +1 -2
- classiq/interface/generator/preferences/qasm_to_qmod_params.py +11 -0
- classiq/interface/generator/quantum_function_call.py +9 -12
- classiq/interface/generator/quantum_program.py +10 -23
- classiq/interface/generator/range_types.py +3 -3
- classiq/interface/generator/slice_parsing_utils.py +4 -5
- classiq/interface/generator/standard_gates/standard_gates.py +2 -4
- classiq/interface/generator/synthesis_execution_parameter.py +1 -3
- classiq/interface/generator/synthesis_metadata/synthesis_duration.py +9 -0
- classiq/interface/generator/synthesis_metadata/synthesis_execution_data.py +2 -3
- classiq/interface/generator/transpiler_basis_gates.py +12 -4
- classiq/interface/generator/types/builtin_enum_declarations.py +0 -145
- classiq/interface/generator/types/compilation_metadata.py +12 -1
- classiq/interface/generator/types/enum_declaration.py +2 -1
- classiq/interface/generator/validations/flow_graph.py +3 -3
- classiq/interface/generator/visitor.py +10 -12
- classiq/interface/hardware.py +2 -3
- classiq/interface/helpers/classproperty.py +2 -2
- classiq/interface/helpers/custom_encoders.py +2 -1
- classiq/interface/helpers/custom_pydantic_types.py +1 -1
- classiq/interface/helpers/text_utils.py +1 -4
- classiq/interface/ide/visual_model.py +6 -5
- classiq/interface/interface_version.py +1 -1
- classiq/interface/jobs.py +3 -3
- classiq/interface/model/allocate.py +4 -4
- classiq/interface/model/block.py +6 -2
- classiq/interface/model/bounds.py +3 -3
- classiq/interface/model/classical_if.py +4 -0
- classiq/interface/model/control.py +8 -1
- classiq/interface/model/inplace_binary_operation.py +2 -2
- classiq/interface/model/invert.py +4 -0
- classiq/interface/model/model.py +4 -4
- classiq/interface/model/model_visitor.py +40 -1
- classiq/interface/model/parameter.py +1 -3
- classiq/interface/model/port_declaration.py +1 -1
- classiq/interface/model/power.py +4 -0
- classiq/interface/model/quantum_expressions/quantum_expression.py +1 -2
- classiq/interface/model/quantum_function_call.py +3 -6
- classiq/interface/model/quantum_function_declaration.py +1 -0
- classiq/interface/model/quantum_lambda_function.py +4 -4
- classiq/interface/model/quantum_statement.py +11 -4
- classiq/interface/model/quantum_type.py +14 -14
- classiq/interface/model/repeat.py +4 -0
- classiq/interface/model/skip_control.py +4 -0
- classiq/interface/model/validation_handle.py +2 -3
- classiq/interface/model/variable_declaration_statement.py +2 -2
- classiq/interface/model/within_apply_operation.py +4 -0
- classiq/interface/pretty_print/expression_to_qmod.py +3 -4
- classiq/interface/server/routes.py +0 -16
- classiq/interface/source_reference.py +3 -4
- classiq/model_expansions/arithmetic.py +11 -7
- classiq/model_expansions/arithmetic_compute_result_attrs.py +30 -27
- classiq/model_expansions/capturing/captured_vars.py +3 -3
- classiq/model_expansions/capturing/mangling_utils.py +1 -2
- classiq/model_expansions/closure.py +12 -11
- classiq/model_expansions/function_builder.py +14 -6
- classiq/model_expansions/generative_functions.py +7 -12
- classiq/model_expansions/interpreters/base_interpreter.py +3 -7
- classiq/model_expansions/interpreters/frontend_generative_interpreter.py +2 -1
- classiq/model_expansions/interpreters/generative_interpreter.py +5 -3
- classiq/model_expansions/quantum_operations/allocate.py +4 -4
- classiq/model_expansions/quantum_operations/assignment_result_processor.py +2 -4
- classiq/model_expansions/quantum_operations/call_emitter.py +31 -37
- classiq/model_expansions/quantum_operations/declarative_call_emitter.py +2 -2
- classiq/model_expansions/quantum_operations/emitter.py +3 -5
- classiq/model_expansions/quantum_operations/expression_evaluator.py +3 -3
- classiq/model_expansions/quantum_operations/skip_control_verifier.py +1 -2
- classiq/model_expansions/quantum_operations/variable_decleration.py +2 -2
- classiq/model_expansions/scope.py +7 -7
- classiq/model_expansions/scope_initialization.py +4 -0
- classiq/model_expansions/visitors/symbolic_param_inference.py +6 -6
- classiq/model_expansions/visitors/uncomputation_signature_inference.py +328 -0
- classiq/model_expansions/visitors/variable_references.py +15 -14
- classiq/open_library/functions/__init__.py +28 -11
- classiq/open_library/functions/amplitude_loading.py +81 -0
- classiq/open_library/functions/discrete_sine_cosine_transform.py +5 -5
- classiq/open_library/functions/grover.py +8 -10
- classiq/open_library/functions/lcu.py +47 -18
- classiq/open_library/functions/modular_exponentiation.py +93 -8
- classiq/open_library/functions/qsvt.py +66 -79
- classiq/open_library/functions/qsvt_temp.py +536 -0
- classiq/open_library/functions/state_preparation.py +130 -27
- classiq/qmod/__init__.py +6 -4
- classiq/qmod/builtins/classical_execution_primitives.py +4 -23
- classiq/qmod/builtins/classical_functions.py +1 -42
- classiq/qmod/builtins/enums.py +15 -153
- classiq/qmod/builtins/functions/__init__.py +9 -18
- classiq/qmod/builtins/functions/allocation.py +25 -4
- classiq/qmod/builtins/functions/arithmetic.py +22 -27
- classiq/qmod/builtins/functions/exponentiation.py +51 -2
- classiq/qmod/builtins/functions/mcx_func.py +7 -0
- classiq/qmod/builtins/functions/standard_gates.py +46 -27
- classiq/qmod/builtins/operations.py +165 -79
- classiq/qmod/builtins/structs.py +24 -91
- classiq/qmod/cfunc.py +3 -2
- classiq/qmod/classical_function.py +2 -1
- classiq/qmod/cparam.py +2 -8
- classiq/qmod/create_model_function.py +7 -7
- classiq/qmod/declaration_inferrer.py +33 -30
- classiq/qmod/expression_query.py +7 -4
- classiq/qmod/model_state_container.py +2 -2
- classiq/qmod/native/pretty_printer.py +25 -14
- classiq/qmod/pretty_print/expression_to_python.py +5 -3
- classiq/qmod/pretty_print/pretty_printer.py +39 -17
- classiq/qmod/python_classical_type.py +40 -13
- classiq/qmod/qfunc.py +124 -19
- classiq/qmod/qmod_constant.py +2 -2
- classiq/qmod/qmod_parameter.py +5 -2
- classiq/qmod/qmod_variable.py +47 -46
- classiq/qmod/quantum_callable.py +18 -13
- classiq/qmod/quantum_expandable.py +31 -26
- classiq/qmod/quantum_function.py +84 -36
- classiq/qmod/semantics/annotation/call_annotation.py +5 -5
- classiq/qmod/semantics/error_manager.py +12 -14
- classiq/qmod/semantics/lambdas.py +1 -2
- classiq/qmod/semantics/validation/types_validation.py +1 -2
- classiq/qmod/symbolic.py +2 -4
- classiq/qmod/utilities.py +13 -20
- classiq/qmod/write_qmod.py +3 -4
- classiq/quantum_program.py +1 -3
- classiq/synthesis.py +11 -7
- {classiq-0.93.0.dist-info → classiq-0.99.0.dist-info}/METADATA +2 -3
- {classiq-0.93.0.dist-info → classiq-0.99.0.dist-info}/RECORD +271 -299
- {classiq-0.93.0.dist-info → classiq-0.99.0.dist-info}/WHEEL +1 -1
- classiq/applications/chemistry/ansatz_parameters.py +0 -29
- classiq/applications/chemistry/chemistry_execution_parameters.py +0 -16
- classiq/applications/chemistry/chemistry_model_constructor.py +0 -532
- classiq/applications/chemistry/ground_state_problem.py +0 -42
- classiq/applications/qsvm/__init__.py +0 -8
- classiq/applications/qsvm/qsvm.py +0 -11
- classiq/evaluators/qmod_expression_visitors/qmod_expression_bwc.py +0 -129
- classiq/execution/iqcc.py +0 -128
- classiq/interface/applications/qsvm.py +0 -117
- classiq/interface/chemistry/elements.py +0 -120
- classiq/interface/chemistry/fermionic_operator.py +0 -208
- classiq/interface/chemistry/ground_state_problem.py +0 -132
- classiq/interface/chemistry/ground_state_result.py +0 -8
- classiq/interface/chemistry/molecule.py +0 -71
- classiq/interface/execution/iqcc.py +0 -44
- classiq/interface/generator/application_apis/chemistry_declarations.py +0 -69
- classiq/interface/generator/application_apis/entangler_declarations.py +0 -29
- classiq/interface/generator/application_apis/qsvm_declarations.py +0 -6
- classiq/interface/generator/chemistry_function_params.py +0 -50
- classiq/interface/generator/entangler_params.py +0 -72
- classiq/interface/generator/entanglers.py +0 -14
- classiq/interface/generator/hamiltonian_evolution/qdrift.py +0 -27
- classiq/interface/generator/hartree_fock.py +0 -26
- classiq/interface/generator/hva.py +0 -22
- classiq/interface/generator/linear_pauli_rotations.py +0 -92
- classiq/interface/generator/qft.py +0 -37
- classiq/interface/generator/qsvm.py +0 -96
- classiq/interface/generator/state_preparation/__init__.py +0 -14
- classiq/interface/generator/state_preparation/bell_state_preparation.py +0 -27
- classiq/interface/generator/state_preparation/computational_basis_state_preparation.py +0 -28
- classiq/interface/generator/state_preparation/distributions.py +0 -53
- classiq/interface/generator/state_preparation/exponential_state_preparation.py +0 -14
- classiq/interface/generator/state_preparation/ghz_state_preparation.py +0 -14
- classiq/interface/generator/state_preparation/metrics.py +0 -41
- classiq/interface/generator/state_preparation/state_preparation.py +0 -113
- classiq/interface/generator/state_preparation/state_preparation_abc.py +0 -24
- classiq/interface/generator/state_preparation/uniform_distibution_state_preparation.py +0 -13
- classiq/interface/generator/state_preparation/w_state_preparation.py +0 -13
- classiq/interface/generator/ucc.py +0 -74
- classiq/interface/helpers/backward_compatibility.py +0 -9
- classiq/model_expansions/transformers/type_modifier_inference.py +0 -392
- classiq/open_library/functions/lookup_table.py +0 -58
- classiq/qmod/builtins/functions/chemistry.py +0 -123
- classiq/qmod/builtins/functions/qsvm.py +0 -24
- {classiq-0.93.0.dist-info → classiq-0.99.0.dist-info}/licenses/LICENSE.txt +0 -0
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import warnings
|
|
2
|
-
from typing import Annotated, Any, Literal, Optional, Union, cast
|
|
3
|
-
|
|
4
|
-
import pydantic
|
|
5
|
-
from pydantic import ConfigDict, Field
|
|
6
|
-
from pydantic_core.core_schema import ValidationInfo
|
|
7
|
-
|
|
8
|
-
from classiq.interface.chemistry.fermionic_operator import SummedFermionicOperator
|
|
9
|
-
from classiq.interface.chemistry.molecule import Molecule
|
|
10
|
-
from classiq.interface.enum_utils import StrEnum
|
|
11
|
-
from classiq.interface.exceptions import ClassiqDeprecationWarning, ClassiqValueError
|
|
12
|
-
from classiq.interface.helpers.hashable_pydantic_base_model import (
|
|
13
|
-
HashablePydanticBaseModel,
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
"""
|
|
17
|
-
The correct type hint is:
|
|
18
|
-
NumSpinUpParticles = pydantic.NonNegativeInt
|
|
19
|
-
NumSpinDownParticles = pydantic.NonNegativeInt
|
|
20
|
-
NumParticles = Tuple[NumSpinUpParticles, NumSpinDownParticles]
|
|
21
|
-
|
|
22
|
-
But:
|
|
23
|
-
A) the NonNegativeInt makes the ts-schemas have a `Minimum` object,
|
|
24
|
-
which is undefined, thus causing an error
|
|
25
|
-
B) a tuple of a specific size gives another, different error
|
|
26
|
-
|
|
27
|
-
Thus, we use `int` and manually check its value
|
|
28
|
-
And use a list, and manually check its length
|
|
29
|
-
"""
|
|
30
|
-
NumSpinUpParticles = pydantic.NonNegativeInt
|
|
31
|
-
NumSpinDownParticles = pydantic.NonNegativeInt
|
|
32
|
-
NumParticles = tuple[NumSpinUpParticles, NumSpinDownParticles]
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
class FermionMapping(StrEnum):
|
|
36
|
-
JORDAN_WIGNER = "jordan_wigner"
|
|
37
|
-
PARITY = "parity"
|
|
38
|
-
BRAVYI_KITAEV = "bravyi_kitaev"
|
|
39
|
-
FAST_BRAVYI_KITAEV = "fast_bravyi_kitaev"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
class GroundStateProblem(HashablePydanticBaseModel):
|
|
43
|
-
kind: str
|
|
44
|
-
|
|
45
|
-
mapping: FermionMapping = pydantic.Field(
|
|
46
|
-
default=FermionMapping.JORDAN_WIGNER,
|
|
47
|
-
description="Fermionic mapping type",
|
|
48
|
-
title="Fermion Mapping",
|
|
49
|
-
)
|
|
50
|
-
z2_symmetries: bool = pydantic.Field(
|
|
51
|
-
default=False,
|
|
52
|
-
description="whether to perform z2 symmetries reduction",
|
|
53
|
-
)
|
|
54
|
-
num_qubits: Optional[int] = pydantic.Field(default=None)
|
|
55
|
-
|
|
56
|
-
def __init__(self, /, **data: Any) -> None:
|
|
57
|
-
warnings.warn(
|
|
58
|
-
(
|
|
59
|
-
f"The class `{self.__class__.__name__}` is deprecated and will no "
|
|
60
|
-
"longer be supported starting on 2025-09-18 at the earliest. "
|
|
61
|
-
"For more information on Classiq's chemistry application, see "
|
|
62
|
-
"https://docs.classiq.io/latest/explore/applications/chemistry/classiq_chemistry_application/classiq_chemistry_application/."
|
|
63
|
-
),
|
|
64
|
-
category=ClassiqDeprecationWarning,
|
|
65
|
-
stacklevel=2,
|
|
66
|
-
)
|
|
67
|
-
super().__init__(**data)
|
|
68
|
-
|
|
69
|
-
@pydantic.field_validator("z2_symmetries")
|
|
70
|
-
@classmethod
|
|
71
|
-
def _validate_z2_symmetries(cls, z2_symmetries: bool, info: ValidationInfo) -> bool:
|
|
72
|
-
if (
|
|
73
|
-
z2_symmetries
|
|
74
|
-
and info.data.get("mapping") == FermionMapping.FAST_BRAVYI_KITAEV
|
|
75
|
-
):
|
|
76
|
-
raise ClassiqValueError(
|
|
77
|
-
"z2 symmetries reduction can not be used for fast_bravyi_kitaev mapping"
|
|
78
|
-
)
|
|
79
|
-
return z2_symmetries
|
|
80
|
-
|
|
81
|
-
model_config = ConfigDict(frozen=True)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
class MoleculeProblem(GroundStateProblem):
|
|
85
|
-
kind: Literal["molecule"] = pydantic.Field(default="molecule")
|
|
86
|
-
|
|
87
|
-
molecule: Molecule
|
|
88
|
-
basis: str = pydantic.Field(default="sto3g", description="Molecular basis set")
|
|
89
|
-
freeze_core: bool = pydantic.Field(default=False)
|
|
90
|
-
remove_orbitals: list[int] = pydantic.Field(
|
|
91
|
-
default_factory=list, description="list of orbitals to remove"
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
class HamiltonianProblem(GroundStateProblem):
|
|
96
|
-
kind: Literal["hamiltonian"] = pydantic.Field(default="hamiltonian")
|
|
97
|
-
|
|
98
|
-
hamiltonian: SummedFermionicOperator = pydantic.Field(
|
|
99
|
-
description="Hamiltonian as a fermionic operator"
|
|
100
|
-
)
|
|
101
|
-
num_particles: list[pydantic.PositiveInt] = pydantic.Field(
|
|
102
|
-
description="Tuple containing the numbers of alpha particles and beta particles"
|
|
103
|
-
)
|
|
104
|
-
|
|
105
|
-
@pydantic.field_validator("num_particles", mode="before")
|
|
106
|
-
@classmethod
|
|
107
|
-
def _validate_num_particles(
|
|
108
|
-
cls,
|
|
109
|
-
num_particles: Union[
|
|
110
|
-
list[Union[int, float]], tuple[Union[int, float], Union[int, float]]
|
|
111
|
-
],
|
|
112
|
-
) -> list[int]:
|
|
113
|
-
assert isinstance(num_particles, (list, tuple))
|
|
114
|
-
assert len(num_particles) == 2
|
|
115
|
-
|
|
116
|
-
num_particles = [int(x) for x in num_particles]
|
|
117
|
-
|
|
118
|
-
assert num_particles[0] >= 1
|
|
119
|
-
assert num_particles[1] >= 1
|
|
120
|
-
|
|
121
|
-
return cast(list[int], num_particles)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
CHEMISTRY_PROBLEMS = (MoleculeProblem, HamiltonianProblem)
|
|
125
|
-
CHEMISTRY_PROBLEMS_TYPE = Annotated[
|
|
126
|
-
Union[MoleculeProblem, HamiltonianProblem],
|
|
127
|
-
Field(
|
|
128
|
-
discriminator="kind",
|
|
129
|
-
description="Ground state problem object describing the system.",
|
|
130
|
-
),
|
|
131
|
-
]
|
|
132
|
-
CHEMISTRY_ANSATZ_NAMES = ["hw_efficient", "ucc", "hva"]
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
from typing import Literal, Union
|
|
2
|
-
|
|
3
|
-
import pydantic
|
|
4
|
-
from pydantic import ConfigDict
|
|
5
|
-
|
|
6
|
-
from classiq.interface.chemistry.elements import ELEMENTS
|
|
7
|
-
from classiq.interface.exceptions import ClassiqValueError
|
|
8
|
-
from classiq.interface.helpers.custom_pydantic_types import AtomType
|
|
9
|
-
from classiq.interface.helpers.hashable_pydantic_base_model import (
|
|
10
|
-
HashablePydanticBaseModel,
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class Atom(HashablePydanticBaseModel):
|
|
15
|
-
symbol: Literal[tuple(ELEMENTS)] = pydantic.Field(description="The atom symbol") # type: ignore[valid-type]
|
|
16
|
-
x: float = pydantic.Field(description="The x coordinate of the atom")
|
|
17
|
-
y: float = pydantic.Field(description="The y coordinate of the atom")
|
|
18
|
-
z: float = pydantic.Field(description="The z coordinate of the atom")
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class Molecule(HashablePydanticBaseModel):
|
|
22
|
-
atoms: list[Atom] = pydantic.Field(
|
|
23
|
-
description="A list of atoms each containing the atoms symbol and its (x,y,z) location",
|
|
24
|
-
min_length=1,
|
|
25
|
-
)
|
|
26
|
-
spin: pydantic.NonNegativeInt = pydantic.Field(
|
|
27
|
-
default=1, description="spin of the molecule"
|
|
28
|
-
)
|
|
29
|
-
charge: pydantic.NonNegativeInt = pydantic.Field(
|
|
30
|
-
default=0, description="charge of the molecule"
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
@property
|
|
34
|
-
def atoms_type(self) -> list[AtomType]:
|
|
35
|
-
return [(atom.symbol, [atom.x, atom.y, atom.z]) for atom in self.atoms]
|
|
36
|
-
|
|
37
|
-
@classmethod
|
|
38
|
-
def _validate_atom(cls, atom: Union[AtomType, Atom]) -> Atom:
|
|
39
|
-
if isinstance(atom, (list, tuple)):
|
|
40
|
-
return cls._validate_old_atoms_type(atom)
|
|
41
|
-
return atom
|
|
42
|
-
|
|
43
|
-
@pydantic.field_validator("atoms", mode="before")
|
|
44
|
-
@classmethod
|
|
45
|
-
def _validate_atoms(cls, atoms: list[Union[AtomType, Atom]]) -> list[Atom]:
|
|
46
|
-
return [cls._validate_atom(atom) for atom in atoms]
|
|
47
|
-
|
|
48
|
-
@staticmethod
|
|
49
|
-
def _validate_old_atoms_type(atom: AtomType) -> Atom:
|
|
50
|
-
if len(atom) != 2:
|
|
51
|
-
raise ClassiqValueError(
|
|
52
|
-
"each atom should be a list of two entries: 1) name pf the elemnt (str) 2) list of its (x,y,z) location"
|
|
53
|
-
)
|
|
54
|
-
if not isinstance(atom[0], str):
|
|
55
|
-
raise ClassiqValueError(
|
|
56
|
-
f"atom name should be a string. unknown element: {atom[0]}."
|
|
57
|
-
)
|
|
58
|
-
if len(atom[1]) != 3:
|
|
59
|
-
raise ClassiqValueError(
|
|
60
|
-
f"location of the atom is of length three, representing the (x,y,z) coordinates of the atom, error value: {atom[1]}"
|
|
61
|
-
)
|
|
62
|
-
for idx in atom[1]:
|
|
63
|
-
if not isinstance(idx, (float, int)):
|
|
64
|
-
raise ClassiqValueError(
|
|
65
|
-
f"coordinates of the atom should be of type float. error value: {idx}"
|
|
66
|
-
)
|
|
67
|
-
symbol, coordinate = atom
|
|
68
|
-
|
|
69
|
-
return Atom(symbol=symbol, x=coordinate[0], y=coordinate[1], z=coordinate[2])
|
|
70
|
-
|
|
71
|
-
model_config = ConfigDict(frozen=True)
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
from typing import Optional
|
|
2
|
-
|
|
3
|
-
from pydantic import BaseModel, Field
|
|
4
|
-
|
|
5
|
-
from classiq.interface.helpers.versioned_model import VersionedModel
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class IQCCInitAuthData(VersionedModel):
|
|
9
|
-
auth_scope_id: str
|
|
10
|
-
auth_method_id: str
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class IQCCInitAuthResponse(VersionedModel):
|
|
14
|
-
auth_url: str
|
|
15
|
-
token_id: str
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class IQCCProbeAuthData(IQCCInitAuthData):
|
|
19
|
-
token_id: str
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class IQCCProbeAuthResponse(VersionedModel):
|
|
23
|
-
auth_token: str
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class IQCCAuthItemDetails(BaseModel):
|
|
27
|
-
id: str
|
|
28
|
-
name: str
|
|
29
|
-
description: str
|
|
30
|
-
scope_id: Optional[str] = Field(default=None)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
class IQCCAuthItemsDetails(VersionedModel):
|
|
34
|
-
items: list[IQCCAuthItemDetails]
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
class IQCCListAuthMethods(VersionedModel):
|
|
38
|
-
auth_scope_id: str
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
class IQCCListAuthTargets(VersionedModel):
|
|
42
|
-
auth_scope_id: str
|
|
43
|
-
auth_method_id: str
|
|
44
|
-
auth_token: str
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
from enum import Enum
|
|
2
|
-
|
|
3
|
-
from classiq.interface.generator.functions.classical_function_declaration import (
|
|
4
|
-
ClassicalFunctionDeclaration,
|
|
5
|
-
)
|
|
6
|
-
from classiq.interface.generator.functions.classical_type import (
|
|
7
|
-
ClassicalArray,
|
|
8
|
-
VQEResult,
|
|
9
|
-
)
|
|
10
|
-
from classiq.interface.generator.functions.type_name import Struct
|
|
11
|
-
from classiq.interface.model.classical_parameter_declaration import (
|
|
12
|
-
ClassicalParameterDeclaration,
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
MOLECULE_PROBLEM_PARAM = ClassicalParameterDeclaration(
|
|
16
|
-
name="molecule_problem", classical_type=Struct(name="MoleculeProblem")
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
FOCK_HAMILTONIAN_PROBLEM_PARAM = ClassicalParameterDeclaration(
|
|
20
|
-
name="fock_hamiltonian_problem",
|
|
21
|
-
classical_type=Struct(name="FockHamiltonianProblem"),
|
|
22
|
-
)
|
|
23
|
-
FOCK_HAMILTONIAN_SIZE = (
|
|
24
|
-
"fock_hamiltonian_problem_to_hamiltonian(fock_hamiltonian_problem)[0].pauli.len"
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class ChemistryProblemType(Enum):
|
|
29
|
-
MoleculeProblem = "molecule_problem"
|
|
30
|
-
FockHamiltonianProblem = "fock_hamiltonian_problem"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
MOLECULE_PROBLEM_TO_HAMILTONIAN = ClassicalFunctionDeclaration(
|
|
34
|
-
name="molecule_problem_to_hamiltonian",
|
|
35
|
-
positional_parameters=[
|
|
36
|
-
ClassicalParameterDeclaration(
|
|
37
|
-
name="problem", classical_type=Struct(name="MoleculeProblem")
|
|
38
|
-
),
|
|
39
|
-
],
|
|
40
|
-
return_type=ClassicalArray(element_type=Struct(name="PauliTerm")),
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
FOCK_HAMILTONIAN_PROBLEM_TO_HAMILTONIAN = ClassicalFunctionDeclaration(
|
|
44
|
-
name="fock_hamiltonian_problem_to_hamiltonian",
|
|
45
|
-
positional_parameters=[
|
|
46
|
-
ClassicalParameterDeclaration(
|
|
47
|
-
name="problem", classical_type=Struct(name="FockHamiltonianProblem")
|
|
48
|
-
),
|
|
49
|
-
],
|
|
50
|
-
return_type=ClassicalArray(element_type=Struct(name="PauliTerm")),
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
MOLECULE_GROUND_STATE_SOLUTION_POST_PROCESS = ClassicalFunctionDeclaration(
|
|
55
|
-
name="molecule_ground_state_solution_post_process",
|
|
56
|
-
positional_parameters=[
|
|
57
|
-
ClassicalParameterDeclaration(
|
|
58
|
-
name="problem", classical_type=Struct(name="MoleculeProblem")
|
|
59
|
-
),
|
|
60
|
-
ClassicalParameterDeclaration(name="vqe_result", classical_type=VQEResult()),
|
|
61
|
-
],
|
|
62
|
-
return_type=Struct(name="MoleculeResult"),
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
__all__ = [
|
|
66
|
-
"FOCK_HAMILTONIAN_PROBLEM_TO_HAMILTONIAN",
|
|
67
|
-
"MOLECULE_GROUND_STATE_SOLUTION_POST_PROCESS",
|
|
68
|
-
"MOLECULE_PROBLEM_TO_HAMILTONIAN",
|
|
69
|
-
]
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
from classiq.interface.generator.functions.classical_function_declaration import (
|
|
2
|
-
ClassicalFunctionDeclaration,
|
|
3
|
-
)
|
|
4
|
-
from classiq.interface.generator.functions.classical_type import (
|
|
5
|
-
Bool,
|
|
6
|
-
ClassicalArray,
|
|
7
|
-
Integer,
|
|
8
|
-
)
|
|
9
|
-
from classiq.interface.model.classical_parameter_declaration import (
|
|
10
|
-
ClassicalParameterDeclaration,
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
GRID_ENTANGLER_GRAPH = ClassicalFunctionDeclaration(
|
|
14
|
-
name="grid_entangler_graph",
|
|
15
|
-
positional_parameters=[
|
|
16
|
-
ClassicalParameterDeclaration(name="num_qubits", classical_type=Integer()),
|
|
17
|
-
ClassicalParameterDeclaration(name="schmidt_rank", classical_type=Integer()),
|
|
18
|
-
ClassicalParameterDeclaration(name="grid_randomization", classical_type=Bool()),
|
|
19
|
-
],
|
|
20
|
-
return_type=ClassicalArray(element_type=ClassicalArray(element_type=Integer())),
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
HYPERCUBE_ENTANGLER_GRAPH = ClassicalFunctionDeclaration(
|
|
24
|
-
name="hypercube_entangler_graph",
|
|
25
|
-
positional_parameters=[
|
|
26
|
-
ClassicalParameterDeclaration(name="num_qubits", classical_type=Integer()),
|
|
27
|
-
],
|
|
28
|
-
return_type=ClassicalArray(element_type=ClassicalArray(element_type=Integer())),
|
|
29
|
-
)
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import pydantic
|
|
2
|
-
|
|
3
|
-
from classiq.interface.chemistry.ground_state_problem import (
|
|
4
|
-
CHEMISTRY_PROBLEMS_TYPE,
|
|
5
|
-
GroundStateProblem,
|
|
6
|
-
)
|
|
7
|
-
from classiq.interface.exceptions import ClassiqValueError
|
|
8
|
-
from classiq.interface.generator.arith.register_user_input import RegisterUserInput
|
|
9
|
-
from classiq.interface.generator.function_params import (
|
|
10
|
-
DEFAULT_INPUT_NAME,
|
|
11
|
-
DEFAULT_OUTPUT_NAME,
|
|
12
|
-
FunctionParams,
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class ChemistryFunctionParams(FunctionParams):
|
|
17
|
-
gs_problem: CHEMISTRY_PROBLEMS_TYPE
|
|
18
|
-
|
|
19
|
-
@pydantic.field_validator("gs_problem")
|
|
20
|
-
@classmethod
|
|
21
|
-
def validate_gs_problem_contains_num_qubits(
|
|
22
|
-
cls, gs_problem: CHEMISTRY_PROBLEMS_TYPE
|
|
23
|
-
) -> CHEMISTRY_PROBLEMS_TYPE:
|
|
24
|
-
if not gs_problem.num_qubits:
|
|
25
|
-
raise ClassiqValueError(
|
|
26
|
-
"Ground state problem doesn't contain num_qubits. "
|
|
27
|
-
"Use update_problem method."
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
return gs_problem
|
|
31
|
-
|
|
32
|
-
@property
|
|
33
|
-
def num_qubits(self) -> int:
|
|
34
|
-
assert isinstance(
|
|
35
|
-
self.gs_problem, GroundStateProblem
|
|
36
|
-
), "self.gs_problem is not from GroundStateProblem class"
|
|
37
|
-
assert isinstance(self.gs_problem.num_qubits, int)
|
|
38
|
-
return self.gs_problem.num_qubits
|
|
39
|
-
|
|
40
|
-
def _create_ios(self) -> None:
|
|
41
|
-
self._inputs = {
|
|
42
|
-
DEFAULT_INPUT_NAME: RegisterUserInput(
|
|
43
|
-
name=DEFAULT_INPUT_NAME, size=self.num_qubits
|
|
44
|
-
)
|
|
45
|
-
}
|
|
46
|
-
self._outputs = {
|
|
47
|
-
DEFAULT_OUTPUT_NAME: RegisterUserInput(
|
|
48
|
-
name=DEFAULT_OUTPUT_NAME, size=self.num_qubits
|
|
49
|
-
)
|
|
50
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import pydantic
|
|
2
|
-
|
|
3
|
-
from classiq.interface.generator.arith.register_user_input import RegisterUserInput
|
|
4
|
-
from classiq.interface.generator.function_params import FunctionParams
|
|
5
|
-
from classiq.interface.helpers.custom_pydantic_types import PydanticProbabilityFloat
|
|
6
|
-
|
|
7
|
-
IN_NAME: str = "IN"
|
|
8
|
-
OUT_NAME: str = "OUT"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class Entangler(FunctionParams):
|
|
12
|
-
"""
|
|
13
|
-
A Father class for all entangler classes
|
|
14
|
-
"""
|
|
15
|
-
|
|
16
|
-
qubit_count: pydantic.PositiveInt = pydantic.Field(
|
|
17
|
-
description="The number of qubits for the entangler."
|
|
18
|
-
)
|
|
19
|
-
schmidt_rank: pydantic.NonNegativeInt = pydantic.Field(
|
|
20
|
-
default=0, description="The required schmidt rank (log of schmidt number)."
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
def _create_ios(self) -> None:
|
|
24
|
-
self._inputs = {IN_NAME: RegisterUserInput(name=IN_NAME, size=self.qubit_count)}
|
|
25
|
-
self._outputs = {
|
|
26
|
-
OUT_NAME: RegisterUserInput(name=OUT_NAME, size=self.qubit_count)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class TwoDimensionalEntangler(Entangler):
|
|
31
|
-
"""
|
|
32
|
-
Creates a two dimensional cluster state with the specified number of qubits and schmidt rank
|
|
33
|
-
(log of schmidt number). When the desired schmidt rank is too high, a rectangular grid with schmidt rank
|
|
34
|
-
floor(sqrt(qubit_count))-1 is generated.
|
|
35
|
-
"""
|
|
36
|
-
|
|
37
|
-
pass
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
class HypercubeEntangler(Entangler):
|
|
41
|
-
"""
|
|
42
|
-
Creates a cluster/graph state in the form of a hypercube with the specified number of qubits. The hypercube is
|
|
43
|
-
constructed by building cubes of growing dimension therefore if the number of qubits is not a a power of 2 (n=2^k)
|
|
44
|
-
the last cube will not be completed. for example if n = 11 = 2^3 + 3 a three dimensional cube is constructed
|
|
45
|
-
connected to additional 3 qubits in the natural order
|
|
46
|
-
(that is, these qubits will be: 1000, 1001, 1010)
|
|
47
|
-
"""
|
|
48
|
-
|
|
49
|
-
pass
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
class GridEntangler(Entangler):
|
|
53
|
-
"""
|
|
54
|
-
creates a graph state in the form of multi-dimensional grid according to the specified number of qubits and Schmidt
|
|
55
|
-
rank. If possible the grid will include the exact Schmidt rank if not a smaller grid with a lower schmidt rank is
|
|
56
|
-
constructed - as close as possible to the specified parameters. if the specified Schmidt rank is too high a 'long'
|
|
57
|
-
grid with the maximal possible Schmidt rank width is constructed (that still obeys the condition that the largest
|
|
58
|
-
dimension minus 1 is larger then the sum of the (d_i - 1) -- d_i including all other dimensions)
|
|
59
|
-
"""
|
|
60
|
-
|
|
61
|
-
grid_randomization: bool = pydantic.Field(
|
|
62
|
-
default=True,
|
|
63
|
-
description="Boolean determining whether the grid structure is randomly selected out of all grids which provide"
|
|
64
|
-
"the same Schmidt rank width. If False the grid with maximal number of dimensions is selected.",
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
filling_factor: PydanticProbabilityFloat = pydantic.Field(
|
|
68
|
-
default=1,
|
|
69
|
-
description="float determining the fraction of cz gates that are included in a circuit for a given grid "
|
|
70
|
-
"structure. For example, for filling_factor=0.5 half of the cz gates required for the full grid structure are "
|
|
71
|
-
"included in the output circuit. The cz gates included in the circuit are chosen randomaly.",
|
|
72
|
-
)
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import pydantic
|
|
2
|
-
from pydantic import BaseModel
|
|
3
|
-
|
|
4
|
-
from classiq.interface.helpers.custom_pydantic_types import PydanticLargerThanOneInteger
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class SquareClusterEntanglerParameters(BaseModel):
|
|
8
|
-
num_of_qubits: PydanticLargerThanOneInteger
|
|
9
|
-
schmidt_rank: pydantic.NonNegativeInt
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class Open2DClusterEntanglerParameters(BaseModel):
|
|
13
|
-
qubit_count: PydanticLargerThanOneInteger
|
|
14
|
-
schmidt_rank: pydantic.NonNegativeInt
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import pydantic
|
|
2
|
-
|
|
3
|
-
from classiq.interface.chemistry import operator
|
|
4
|
-
from classiq.interface.chemistry.operator import PauliOperator
|
|
5
|
-
from classiq.interface.generator.function_params import FunctionParamsNumericParameter
|
|
6
|
-
from classiq.interface.generator.hamiltonian_evolution.hamiltonian_evolution import (
|
|
7
|
-
HamiltonianEvolution,
|
|
8
|
-
)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class QDrift(HamiltonianEvolution):
|
|
12
|
-
"""
|
|
13
|
-
qDrift trotterization of a Hermitian operator; see https://arxiv.org/abs/1811.08017
|
|
14
|
-
"""
|
|
15
|
-
|
|
16
|
-
evolution_coefficient: FunctionParamsNumericParameter = pydantic.Field(
|
|
17
|
-
default=1.0,
|
|
18
|
-
description="A global coefficient multiplying the operator.",
|
|
19
|
-
)
|
|
20
|
-
num_qdrift: pydantic.PositiveInt = pydantic.Field(
|
|
21
|
-
description="The number of elements in the qDrift product.",
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
@pydantic.field_validator("pauli_operator")
|
|
25
|
-
@classmethod
|
|
26
|
-
def _validate_is_hermitian(cls, pauli_operator: PauliOperator) -> PauliOperator:
|
|
27
|
-
return operator.validate_operator_is_hermitian(pauli_operator)
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
from typing import Any, Union
|
|
2
|
-
|
|
3
|
-
import pydantic
|
|
4
|
-
|
|
5
|
-
from classiq.interface.chemistry.ground_state_problem import (
|
|
6
|
-
CHEMISTRY_PROBLEMS,
|
|
7
|
-
HamiltonianProblem,
|
|
8
|
-
MoleculeProblem,
|
|
9
|
-
)
|
|
10
|
-
from classiq.interface.exceptions import ClassiqValueError
|
|
11
|
-
from classiq.interface.generator.chemistry_function_params import (
|
|
12
|
-
ChemistryFunctionParams,
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class HartreeFock(ChemistryFunctionParams):
|
|
17
|
-
@pydantic.field_validator("gs_problem")
|
|
18
|
-
@classmethod
|
|
19
|
-
def validate_gs_problem(
|
|
20
|
-
cls, gs_problem: Any
|
|
21
|
-
) -> Union[MoleculeProblem, HamiltonianProblem]:
|
|
22
|
-
if not isinstance(gs_problem, CHEMISTRY_PROBLEMS):
|
|
23
|
-
raise ClassiqValueError(
|
|
24
|
-
f"ground state problem must be of type {CHEMISTRY_PROBLEMS}"
|
|
25
|
-
)
|
|
26
|
-
return gs_problem
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import pydantic
|
|
2
|
-
|
|
3
|
-
from classiq.interface.generator.chemistry_function_params import (
|
|
4
|
-
ChemistryFunctionParams,
|
|
5
|
-
)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class HVA(ChemistryFunctionParams):
|
|
9
|
-
"""
|
|
10
|
-
Hamiltonian Variational Ansatz
|
|
11
|
-
"""
|
|
12
|
-
|
|
13
|
-
reps: pydantic.PositiveInt = pydantic.Field(
|
|
14
|
-
default=1, description="Number of layers in the Ansatz"
|
|
15
|
-
)
|
|
16
|
-
use_naive_evolution: bool = pydantic.Field(
|
|
17
|
-
default=False, description="Whether to evolve the operator naively"
|
|
18
|
-
)
|
|
19
|
-
parameter_prefix: str = pydantic.Field(
|
|
20
|
-
default="hva_param_",
|
|
21
|
-
description="Prefix for the generated parameters",
|
|
22
|
-
)
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
from typing import TYPE_CHECKING, Annotated, Any
|
|
2
|
-
|
|
3
|
-
import pydantic
|
|
4
|
-
from pydantic import StringConstraints
|
|
5
|
-
from typing_extensions import Self
|
|
6
|
-
|
|
7
|
-
from classiq.interface.exceptions import ClassiqValueError
|
|
8
|
-
from classiq.interface.generator import function_params
|
|
9
|
-
from classiq.interface.generator.arith.register_user_input import RegisterArithmeticInfo
|
|
10
|
-
|
|
11
|
-
STATE = "state"
|
|
12
|
-
TARGET = "target"
|
|
13
|
-
|
|
14
|
-
LENGTH_ERROR_MESSAGE = "Field required"
|
|
15
|
-
|
|
16
|
-
if TYPE_CHECKING:
|
|
17
|
-
PydanticPauliBasisStr = str
|
|
18
|
-
else:
|
|
19
|
-
PydanticPauliBasisStr = Annotated[
|
|
20
|
-
str,
|
|
21
|
-
StringConstraints(
|
|
22
|
-
to_lower=True,
|
|
23
|
-
pattern=r"[xyz]",
|
|
24
|
-
),
|
|
25
|
-
]
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class LinearPauliRotations(function_params.FunctionParams):
|
|
29
|
-
"""
|
|
30
|
-
Perform independent linear rotations on target qubits, each controlled by an identical
|
|
31
|
-
n-qubit state register |x>.
|
|
32
|
-
|
|
33
|
-
Each target qubit, indexed with k and denoted by q_k, undergoes the following transformation:
|
|
34
|
-
|x>|q_k> -> |x> * [cos(theta(x,k)/2) + i*sin(theta(x,k)/2)*sigma]|q_k>
|
|
35
|
-
with sigma being 'X', 'Y' or 'Z' Pauli matrix, and the angle is a linear function of the state,
|
|
36
|
-
theta(x,k)/2 = (slope(k)*x + offset(k))/2.
|
|
37
|
-
|
|
38
|
-
For example, a 'Y' rotation on one target qubit will result in a circuit implementing the following logic:
|
|
39
|
-
|x>|0> -> cos((slope*x + offset)/2)|x>|0> + sin((slope*x + offset)/2)|x>|1>
|
|
40
|
-
|
|
41
|
-
q_0: ─────────────────────────■───────── ... ──────────────────────
|
|
42
|
-
│
|
|
43
|
-
.
|
|
44
|
-
│
|
|
45
|
-
q_(n-1): ─────────────────────────┼───────── ... ───────────■──────────
|
|
46
|
-
┌────────────┐ ┌───────┴───────┐ ┌─────────┴─────────┐
|
|
47
|
-
target: ─┤ RY(offset) ├──┤ RY(2^0 slope) ├ ... ┤ RY(2^(n-1) slope) ├
|
|
48
|
-
└────────────┘ └───────────────┘ └───────────────────┘
|
|
49
|
-
"""
|
|
50
|
-
|
|
51
|
-
num_state_qubits: pydantic.PositiveInt = pydantic.Field(
|
|
52
|
-
description="The number of input qubits"
|
|
53
|
-
)
|
|
54
|
-
bases: list[PydanticPauliBasisStr] = pydantic.Field(
|
|
55
|
-
description="The types of Pauli rotations ('X', 'Y', 'Z')."
|
|
56
|
-
)
|
|
57
|
-
slopes: list[float] = pydantic.Field(
|
|
58
|
-
description="The slopes of the controlled rotations."
|
|
59
|
-
)
|
|
60
|
-
offsets: list[float] = pydantic.Field(
|
|
61
|
-
description="The offsets of the controlled rotations."
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
@pydantic.field_validator("bases", "slopes", "offsets", mode="before")
|
|
65
|
-
@classmethod
|
|
66
|
-
def as_list(cls, v: Any) -> list[Any]:
|
|
67
|
-
if not isinstance(v, list):
|
|
68
|
-
v = [v]
|
|
69
|
-
res = []
|
|
70
|
-
for x in v:
|
|
71
|
-
element = x
|
|
72
|
-
if isinstance(x, str):
|
|
73
|
-
res.append(element.lower())
|
|
74
|
-
else:
|
|
75
|
-
res.append(element)
|
|
76
|
-
return res
|
|
77
|
-
|
|
78
|
-
@pydantic.model_validator(mode="after")
|
|
79
|
-
def validate_lists(self) -> Self:
|
|
80
|
-
offsets = self.offsets or list()
|
|
81
|
-
bases = self.bases or list()
|
|
82
|
-
slopes = self.slopes or list()
|
|
83
|
-
if len(slopes) == len(offsets) and len(offsets) == len(bases):
|
|
84
|
-
return self
|
|
85
|
-
raise ClassiqValueError(LENGTH_ERROR_MESSAGE)
|
|
86
|
-
|
|
87
|
-
def _create_ios(self) -> None:
|
|
88
|
-
self._inputs = {
|
|
89
|
-
STATE: RegisterArithmeticInfo(size=self.num_state_qubits),
|
|
90
|
-
TARGET: RegisterArithmeticInfo(size=len(self.bases)),
|
|
91
|
-
}
|
|
92
|
-
self._outputs = {**self.inputs}
|