classiq 0.43.3__py3-none-any.whl → 0.45.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 +8 -3
- classiq/_internals/api_wrapper.py +2 -2
- classiq/_internals/authentication/auth0.py +1 -1
- classiq/_internals/authentication/device.py +5 -1
- classiq/_internals/authentication/token_manager.py +5 -4
- classiq/_internals/client.py +5 -8
- classiq/_internals/config.py +1 -2
- classiq/_internals/host_checker.py +34 -13
- classiq/_internals/jobs.py +3 -3
- classiq/analyzer/analyzer.py +1 -1
- classiq/analyzer/analyzer_utilities.py +1 -1
- classiq/analyzer/rb.py +1 -1
- classiq/applications/chemistry/chemistry_model_constructor.py +13 -7
- classiq/applications/combinatorial_helpers/allowed_constraints.py +4 -1
- classiq/applications/combinatorial_helpers/arithmetic/isolation.py +1 -1
- classiq/applications/combinatorial_helpers/encoding_mapping.py +1 -1
- classiq/applications/combinatorial_helpers/encoding_utils.py +2 -1
- classiq/applications/combinatorial_helpers/optimization_model.py +1 -1
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_utils.py +1 -1
- classiq/applications/combinatorial_helpers/pyomo_utils.py +1 -2
- classiq/applications/combinatorial_helpers/transformations/encoding.py +1 -1
- classiq/applications/combinatorial_helpers/transformations/fixed_variables.py +5 -4
- classiq/applications/combinatorial_helpers/transformations/ising_converter.py +1 -1
- classiq/applications/combinatorial_helpers/transformations/sign_seperation.py +1 -1
- classiq/applications/combinatorial_optimization/combinatorial_optimization_model_constructor.py +1 -1
- classiq/applications/finance/finance_model_constructor.py +4 -3
- classiq/applications/grover/grover_model_constructor.py +7 -5
- classiq/applications/hamiltonian/__init__.py +0 -0
- classiq/applications/hamiltonian/pauli_decomposition.py +113 -0
- classiq/applications/qnn/circuit_utils.py +1 -1
- classiq/applications/qnn/datasets/dataset_base_classes.py +2 -1
- classiq/applications/qnn/datasets/dataset_not.py +2 -1
- classiq/applications/qnn/qlayer.py +3 -2
- classiq/applications/qnn/torch_utils.py +2 -1
- classiq/applications/qsvm/qsvm_model_constructor.py +1 -1
- classiq/execution/execution_session.py +1 -1
- classiq/execution/jobs.py +5 -2
- classiq/interface/_version.py +1 -1
- classiq/interface/analyzer/cytoscape_graph.py +1 -2
- classiq/interface/analyzer/result.py +2 -3
- classiq/interface/ast_node.py +1 -18
- classiq/interface/backend/backend_preferences.py +11 -18
- classiq/interface/backend/ionq/ionq_quantum_program.py +1 -1
- classiq/interface/backend/pydantic_backend.py +0 -5
- classiq/interface/backend/quantum_backend_providers.py +4 -3
- classiq/interface/chemistry/fermionic_operator.py +1 -2
- classiq/interface/chemistry/ground_state_problem.py +2 -3
- classiq/interface/chemistry/molecule.py +1 -2
- classiq/interface/chemistry/operator.py +8 -10
- classiq/interface/combinatorial_optimization/encoding_types.py +1 -1
- classiq/interface/combinatorial_optimization/mht_qaoa_input.py +1 -1
- classiq/interface/combinatorial_optimization/solver_types.py +1 -1
- classiq/interface/debug_info/__init__.py +0 -0
- classiq/interface/debug_info/debug_info.py +32 -0
- classiq/{exceptions.py → interface/exceptions.py} +4 -0
- classiq/interface/executor/aws_execution_cost.py +2 -2
- classiq/interface/executor/execution_preferences.py +2 -47
- classiq/interface/executor/execution_result.py +1 -2
- classiq/interface/executor/optimizer_preferences.py +2 -3
- classiq/interface/executor/quantum_code.py +1 -2
- classiq/interface/executor/quantum_instruction_set.py +2 -2
- classiq/interface/executor/register_initialization.py +1 -2
- classiq/interface/executor/result.py +29 -14
- classiq/interface/finance/function_input.py +6 -11
- classiq/interface/generator/amplitude_loading.py +2 -3
- classiq/interface/generator/ansatz_library.py +1 -1
- classiq/interface/generator/application_apis/arithmetic_declarations.py +8 -5
- classiq/interface/generator/application_apis/chemistry_declarations.py +78 -60
- classiq/interface/generator/application_apis/combinatorial_optimization_declarations.py +19 -10
- classiq/interface/generator/application_apis/entangler_declarations.py +11 -6
- classiq/interface/generator/application_apis/finance_declarations.py +37 -44
- classiq/interface/generator/application_apis/qsvm_declarations.py +21 -15
- classiq/interface/generator/arith/arithmetic.py +10 -8
- classiq/interface/generator/arith/arithmetic_arg_type_validator.py +1 -2
- classiq/interface/generator/arith/arithmetic_expression_abc.py +22 -3
- classiq/interface/generator/arith/arithmetic_expression_parser.py +3 -4
- classiq/interface/generator/arith/arithmetic_expression_validator.py +1 -2
- classiq/interface/generator/arith/arithmetic_param_getters.py +1 -2
- classiq/interface/generator/arith/arithmetic_result_builder.py +15 -11
- classiq/interface/generator/arith/ast_node_rewrite.py +1 -1
- classiq/interface/generator/arith/binary_ops.py +7 -7
- classiq/interface/generator/arith/endianness.py +1 -1
- classiq/interface/generator/arith/extremum_operations.py +44 -21
- classiq/interface/generator/arith/logical_ops.py +1 -2
- classiq/interface/generator/arith/register_user_input.py +1 -2
- classiq/interface/generator/arith/unary_ops.py +1 -2
- classiq/interface/generator/arith/uncomputation_methods.py +1 -1
- classiq/interface/generator/chemistry_function_params.py +1 -2
- classiq/interface/generator/circuit_code/circuit_code.py +1 -2
- classiq/interface/generator/circuit_code/types_and_constants.py +1 -2
- classiq/interface/generator/commuting_pauli_exponentiation.py +1 -2
- classiq/interface/generator/constant.py +1 -1
- classiq/interface/generator/control_state.py +1 -2
- classiq/interface/generator/custom_ansatz.py +1 -2
- classiq/interface/generator/expressions/atomic_expression_functions.py +1 -0
- classiq/interface/generator/expressions/enums/finance_functions.py +4 -5
- classiq/interface/generator/expressions/evaluated_expression.py +1 -2
- classiq/interface/generator/expressions/expression.py +1 -2
- classiq/interface/generator/expressions/expression_constants.py +3 -1
- classiq/interface/generator/expressions/non_symbolic_expr.py +1 -1
- classiq/interface/generator/expressions/qmod_qarray_proxy.py +53 -70
- classiq/interface/generator/expressions/qmod_qscalar_proxy.py +2 -7
- classiq/interface/generator/expressions/qmod_qstruct_proxy.py +35 -0
- classiq/interface/generator/expressions/qmod_sized_proxy.py +1 -1
- classiq/interface/generator/expressions/sympy_supported_expressions.py +2 -1
- classiq/interface/generator/function_params.py +2 -3
- classiq/interface/generator/functions/builtins/core_library/__init__.py +4 -2
- classiq/interface/generator/functions/builtins/core_library/atomic_quantum_functions.py +41 -41
- classiq/interface/generator/functions/builtins/core_library/exponentiation_functions.py +52 -42
- classiq/interface/generator/functions/builtins/open_lib_functions.py +1095 -3347
- classiq/interface/generator/functions/builtins/quantum_operators.py +9 -22
- classiq/interface/generator/functions/classical_function_declaration.py +14 -6
- classiq/interface/generator/functions/classical_type.py +7 -114
- classiq/interface/generator/functions/concrete_types.py +55 -0
- classiq/interface/generator/functions/function_declaration.py +10 -10
- classiq/interface/generator/functions/port_declaration.py +1 -2
- classiq/interface/generator/functions/type_name.py +80 -0
- classiq/interface/generator/generated_circuit_data.py +3 -3
- classiq/interface/generator/grover_diffuser.py +1 -2
- classiq/interface/generator/grover_operator.py +1 -2
- classiq/interface/generator/hamiltonian_evolution/exponentiation.py +1 -2
- classiq/interface/generator/hamiltonian_evolution/suzuki_trotter.py +1 -2
- classiq/interface/generator/hardware/hardware_data.py +1 -2
- classiq/interface/generator/hardware_efficient_ansatz.py +2 -3
- classiq/interface/generator/hartree_fock.py +1 -2
- classiq/interface/generator/linear_pauli_rotations.py +1 -2
- classiq/interface/generator/mcmt_method.py +1 -1
- classiq/interface/generator/mcu.py +1 -2
- classiq/interface/generator/mcx.py +1 -2
- classiq/interface/generator/model/constraints.py +2 -3
- classiq/interface/generator/model/model.py +12 -2
- classiq/interface/generator/model/preferences/preferences.py +7 -3
- classiq/interface/generator/model/quantum_register.py +1 -2
- classiq/interface/generator/oracles/arithmetic_oracle.py +1 -2
- classiq/interface/generator/oracles/custom_oracle.py +1 -2
- classiq/interface/generator/oracles/oracle_abc.py +1 -2
- classiq/interface/generator/partitioned_register.py +1 -2
- classiq/interface/generator/piecewise_linear_amplitude_loading.py +1 -2
- classiq/interface/generator/preferences/optimization.py +1 -2
- classiq/interface/generator/qpe.py +1 -2
- classiq/interface/generator/qsvm.py +2 -3
- classiq/interface/generator/quantum_function_call.py +4 -2
- classiq/interface/generator/quantum_program.py +6 -7
- classiq/interface/generator/range_types.py +1 -1
- classiq/interface/generator/register_role.py +8 -2
- classiq/interface/generator/slice_parsing_utils.py +1 -2
- classiq/interface/generator/standard_gates/controlled_standard_gates.py +1 -2
- classiq/interface/generator/state_preparation/metrics.py +2 -3
- classiq/interface/generator/state_preparation/state_preparation.py +1 -2
- classiq/interface/generator/synthesis_metadata/synthesis_execution_data.py +1 -3
- classiq/interface/generator/transpiler_basis_gates.py +1 -1
- classiq/interface/generator/types/builtin_enum_declarations.py +38 -45
- classiq/interface/generator/types/builtin_struct_declarations/pauli_struct_declarations.py +1 -2
- classiq/interface/generator/types/enum_declaration.py +1 -2
- classiq/interface/generator/types/qstruct_declaration.py +17 -0
- classiq/interface/generator/types/struct_declaration.py +2 -3
- classiq/interface/generator/ucc.py +1 -2
- classiq/interface/generator/unitary_gate.py +1 -2
- classiq/interface/generator/validations/flow_graph.py +1 -2
- classiq/interface/generator/validations/validator_functions.py +1 -2
- classiq/interface/hardware.py +1 -1
- classiq/interface/helpers/validation_helpers.py +2 -19
- classiq/interface/ide/visual_model.py +10 -4
- classiq/interface/interface_version.py +1 -0
- classiq/interface/jobs.py +2 -3
- classiq/interface/model/bind_operation.py +26 -7
- classiq/interface/model/classical_parameter_declaration.py +8 -5
- classiq/interface/model/control.py +5 -5
- classiq/interface/model/handle_binding.py +185 -12
- classiq/interface/model/inplace_binary_operation.py +17 -6
- classiq/interface/model/model.py +29 -7
- classiq/interface/model/native_function_definition.py +8 -4
- classiq/interface/model/parameter.py +13 -0
- classiq/interface/model/port_declaration.py +21 -4
- classiq/interface/model/quantum_expressions/amplitude_loading_operation.py +22 -8
- classiq/interface/model/quantum_expressions/arithmetic_operation.py +30 -6
- classiq/interface/model/quantum_expressions/quantum_expression.py +4 -9
- classiq/interface/model/quantum_function_call.py +136 -194
- classiq/interface/model/quantum_function_declaration.py +147 -165
- classiq/interface/model/quantum_lambda_function.py +23 -6
- classiq/interface/model/quantum_statement.py +34 -8
- classiq/interface/model/quantum_type.py +41 -11
- classiq/interface/model/quantum_variable_declaration.py +1 -1
- classiq/interface/model/statement_block.py +2 -0
- classiq/interface/model/validation_handle.py +8 -2
- classiq/interface/server/global_versions.py +4 -4
- classiq/interface/server/routes.py +2 -0
- classiq/interface/source_reference.py +59 -0
- classiq/qmod/__init__.py +2 -3
- classiq/qmod/builtins/classical_execution_primitives.py +1 -1
- classiq/qmod/builtins/functions.py +39 -11
- classiq/qmod/builtins/operations.py +172 -41
- classiq/qmod/classical_function.py +1 -1
- classiq/qmod/declaration_inferrer.py +102 -57
- classiq/qmod/expression_query.py +1 -1
- classiq/qmod/model_state_container.py +2 -0
- classiq/qmod/native/pretty_printer.py +71 -53
- classiq/qmod/pretty_print/pretty_printer.py +98 -52
- classiq/qmod/qfunc.py +11 -5
- classiq/qmod/qmod_constant.py +1 -1
- classiq/qmod/qmod_parameter.py +27 -4
- classiq/qmod/qmod_variable.py +405 -174
- classiq/qmod/quantum_callable.py +3 -3
- classiq/qmod/quantum_expandable.py +128 -68
- classiq/qmod/quantum_function.py +24 -5
- classiq/qmod/semantics/annotation.py +13 -15
- classiq/qmod/semantics/error_manager.py +36 -10
- classiq/qmod/semantics/static_semantics_visitor.py +164 -76
- classiq/qmod/semantics/validation/func_call_validation.py +43 -97
- classiq/qmod/semantics/validation/handle_validation.py +85 -0
- classiq/qmod/semantics/validation/types_validation.py +108 -1
- classiq/qmod/symbolic.py +2 -1
- classiq/qmod/type_attribute_remover.py +32 -0
- classiq/qmod/utilities.py +26 -5
- classiq/{interface/ide/show.py → show.py} +1 -1
- {classiq-0.43.3.dist-info → classiq-0.45.0.dist-info}/METADATA +3 -3
- {classiq-0.43.3.dist-info → classiq-0.45.0.dist-info}/RECORD +219 -207
- classiq/qmod/qmod_struct.py +0 -13
- /classiq/{_internals → interface}/enum_utils.py +0 -0
- {classiq-0.43.3.dist-info → classiq-0.45.0.dist-info}/WHEEL +0 -0
@@ -1,18 +1,15 @@
|
|
1
|
-
from
|
2
|
-
from typing import Any, Dict, Optional
|
1
|
+
from typing import Optional
|
3
2
|
|
4
3
|
import pydantic
|
5
4
|
|
6
5
|
from classiq.interface.backend.backend_preferences import (
|
7
|
-
AWS_DEFAULT_JOB_TIMEOUT_SECONDS,
|
8
|
-
AwsBackendPreferences,
|
9
6
|
BackendPreferencesTypes,
|
10
7
|
backend_preferences_field,
|
11
8
|
)
|
12
|
-
from classiq.interface.backend.pydantic_backend import MAX_EXECUTION_TIMEOUT_SECONDS
|
13
9
|
from classiq.interface.backend.quantum_backend_providers import (
|
14
10
|
ClassiqSimulatorBackendNames,
|
15
11
|
)
|
12
|
+
from classiq.interface.enum_utils import ReprEnum
|
16
13
|
from classiq.interface.executor.optimizer_preferences import OptimizerType
|
17
14
|
from classiq.interface.generator.model.preferences.preferences import (
|
18
15
|
TranspilationOption,
|
@@ -20,19 +17,6 @@ from classiq.interface.generator.model.preferences.preferences import (
|
|
20
17
|
from classiq.interface.generator.model.preferences.randomness import create_random_seed
|
21
18
|
from classiq.interface.generator.noise_properties import NoiseProperties
|
22
19
|
|
23
|
-
from classiq._internals.enum_utils import ReprEnum
|
24
|
-
from classiq.exceptions import ClassiqValueError
|
25
|
-
|
26
|
-
DIFFERENT_TIMEOUT_MSG = (
|
27
|
-
"Timeout is defined differently in the execution preferences and the "
|
28
|
-
"AWS Backend Preferences."
|
29
|
-
)
|
30
|
-
|
31
|
-
TIMEOUT_LARGE_FOR_AWS_MSG = (
|
32
|
-
"Timeout is larger than the current allowed limit of "
|
33
|
-
f"{timedelta(MAX_EXECUTION_TIMEOUT_SECONDS)}"
|
34
|
-
)
|
35
|
-
|
36
20
|
|
37
21
|
class QaeWithQpeEstimationMethod(int, ReprEnum):
|
38
22
|
MAXIMUM_LIKELIHOOD = 0
|
@@ -40,11 +24,6 @@ class QaeWithQpeEstimationMethod(int, ReprEnum):
|
|
40
24
|
|
41
25
|
|
42
26
|
class ExecutionPreferences(pydantic.BaseModel):
|
43
|
-
timeout_sec: Optional[pydantic.PositiveInt] = pydantic.Field(
|
44
|
-
default=None,
|
45
|
-
description="If set, limits the execution runtime. Value is in seconds. "
|
46
|
-
"Not supported on all platforms.",
|
47
|
-
)
|
48
27
|
noise_properties: Optional[NoiseProperties] = pydantic.Field(
|
49
28
|
default=None, description="Properties of the noise in the circuit"
|
50
29
|
)
|
@@ -66,30 +45,6 @@ class ExecutionPreferences(pydantic.BaseModel):
|
|
66
45
|
description="The job name",
|
67
46
|
)
|
68
47
|
|
69
|
-
def __init__(self, **kwargs: Any) -> None:
|
70
|
-
super().__init__(**kwargs)
|
71
|
-
|
72
|
-
@pydantic.validator("backend_preferences", always=True)
|
73
|
-
def validate_timeout_for_aws(
|
74
|
-
cls, backend_preferences: BackendPreferencesTypes, values: Dict[str, Any]
|
75
|
-
) -> BackendPreferencesTypes:
|
76
|
-
timeout = values.get("timeout_sec", None)
|
77
|
-
if (
|
78
|
-
not isinstance(backend_preferences, AwsBackendPreferences)
|
79
|
-
or timeout is None
|
80
|
-
):
|
81
|
-
return backend_preferences
|
82
|
-
if (
|
83
|
-
timeout != backend_preferences.job_timeout
|
84
|
-
and backend_preferences.job_timeout != AWS_DEFAULT_JOB_TIMEOUT_SECONDS
|
85
|
-
):
|
86
|
-
raise ClassiqValueError(DIFFERENT_TIMEOUT_MSG)
|
87
|
-
if timeout > MAX_EXECUTION_TIMEOUT_SECONDS:
|
88
|
-
raise ClassiqValueError(TIMEOUT_LARGE_FOR_AWS_MSG)
|
89
|
-
|
90
|
-
backend_preferences.job_timeout = timeout
|
91
|
-
return backend_preferences
|
92
|
-
|
93
48
|
|
94
49
|
__all__ = [
|
95
50
|
"ExecutionPreferences",
|
@@ -3,6 +3,7 @@ from typing import Any, List, Literal, Union
|
|
3
3
|
from pydantic import BaseModel, Field
|
4
4
|
from typing_extensions import Annotated, TypeAlias
|
5
5
|
|
6
|
+
from classiq.interface.enum_utils import StrEnum
|
6
7
|
from classiq.interface.executor.iqae_result import IQAEResult
|
7
8
|
from classiq.interface.executor.result import (
|
8
9
|
EstimationResult,
|
@@ -13,8 +14,6 @@ from classiq.interface.executor.result import (
|
|
13
14
|
from classiq.interface.executor.vqe_result import VQESolverResult
|
14
15
|
from classiq.interface.helpers.versioned_model import VersionedModel
|
15
16
|
|
16
|
-
from classiq._internals.enum_utils import StrEnum
|
17
|
-
|
18
17
|
|
19
18
|
class SavedResultValueType(StrEnum):
|
20
19
|
Integer = "int"
|
@@ -3,11 +3,10 @@ from typing import Any, Dict, List, Optional
|
|
3
3
|
import pydantic
|
4
4
|
from pydantic import BaseModel
|
5
5
|
|
6
|
+
from classiq.interface.enum_utils import StrEnum
|
7
|
+
from classiq.interface.exceptions import ClassiqValueError
|
6
8
|
from classiq.interface.helpers.custom_pydantic_types import PydanticAlphaParamCVAR
|
7
9
|
|
8
|
-
from classiq._internals.enum_utils import StrEnum
|
9
|
-
from classiq.exceptions import ClassiqValueError
|
10
|
-
|
11
10
|
|
12
11
|
class CostType(StrEnum):
|
13
12
|
MIN = "MIN"
|
@@ -8,14 +8,13 @@ from pydantic import BaseModel
|
|
8
8
|
|
9
9
|
from classiq.interface.backend.ionq.ionq_quantum_program import IonqQuantumCircuit
|
10
10
|
from classiq.interface.backend.pydantic_backend import PydanticArgumentNameType
|
11
|
+
from classiq.interface.exceptions import ClassiqValueError
|
11
12
|
from classiq.interface.executor.quantum_instruction_set import QuantumInstructionSet
|
12
13
|
from classiq.interface.executor.register_initialization import RegisterInitialization
|
13
14
|
from classiq.interface.generator.synthesis_metadata.synthesis_execution_data import (
|
14
15
|
ExecutionData,
|
15
16
|
)
|
16
17
|
|
17
|
-
from classiq.exceptions import ClassiqValueError
|
18
|
-
|
19
18
|
Arguments = Dict[PydanticArgumentNameType, Any]
|
20
19
|
MultipleArguments = Tuple[Arguments, ...]
|
21
20
|
CodeType = str
|
@@ -2,10 +2,9 @@ from typing import Any, Dict, List
|
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
|
5
|
+
from classiq.interface.exceptions import ClassiqStateInitializationError
|
5
6
|
from classiq.interface.generator.arith import number_utils
|
6
7
|
|
7
|
-
from classiq.exceptions import ClassiqStateInitializationError
|
8
|
-
|
9
8
|
_NON_INTEGER_INITIALIZATION_ERROR_MSG: str = (
|
10
9
|
"Only natural numbers are supported as initial conditions"
|
11
10
|
)
|
@@ -2,6 +2,7 @@ import functools
|
|
2
2
|
import operator
|
3
3
|
from collections import defaultdict
|
4
4
|
from typing import (
|
5
|
+
TYPE_CHECKING,
|
5
6
|
Any,
|
6
7
|
DefaultDict,
|
7
8
|
Dict,
|
@@ -17,6 +18,7 @@ import pydantic
|
|
17
18
|
from pydantic import BaseModel
|
18
19
|
from typing_extensions import TypeAlias
|
19
20
|
|
21
|
+
from classiq.interface.exceptions import ClassiqError
|
20
22
|
from classiq.interface.executor.quantum_code import OutputQubitsMap, Qubits
|
21
23
|
from classiq.interface.generator.arith import number_utils
|
22
24
|
from classiq.interface.generator.complex_type import Complex
|
@@ -24,15 +26,13 @@ from classiq.interface.generator.functions.classical_type import QmodPyObject
|
|
24
26
|
from classiq.interface.helpers.custom_pydantic_types import PydanticNonNegIntTuple
|
25
27
|
from classiq.interface.helpers.versioned_model import VersionedModel
|
26
28
|
|
27
|
-
from classiq.exceptions import ClassiqError
|
28
|
-
|
29
29
|
_ILLEGAL_QUBIT_ERROR_MSG: str = "Illegal qubit index requested"
|
30
30
|
_REPEATED_QUBIT_ERROR_MSG: str = "Requested a qubit more than once"
|
31
31
|
_UNAVAILABLE_OUTPUT_ERROR_MSG: str = "Requested output doesn't exist in the circuit"
|
32
32
|
|
33
33
|
State: TypeAlias = str
|
34
34
|
Name: TypeAlias = str
|
35
|
-
RegisterValue: TypeAlias = Union[float, int]
|
35
|
+
RegisterValue: TypeAlias = Union[float, int, list, dict]
|
36
36
|
MeasuredShots: TypeAlias = pydantic.NonNegativeInt
|
37
37
|
ParsedState: TypeAlias = Mapping[Name, RegisterValue]
|
38
38
|
ParsedStates: TypeAlias = Mapping[State, ParsedState]
|
@@ -60,6 +60,7 @@ class SimulatedState(BaseModel):
|
|
60
60
|
return self.state[item]
|
61
61
|
|
62
62
|
|
63
|
+
SimulatedState.update_forward_refs(RegisterValue=RegisterValue)
|
63
64
|
ParsedStateVector: TypeAlias = List[SimulatedState]
|
64
65
|
|
65
66
|
|
@@ -122,6 +123,23 @@ def get_parsed_counts(counts: Counts, parsed_states: ParsedStates) -> ParsedCoun
|
|
122
123
|
return sorted(parsed_counts, key=lambda k: k.shots, reverse=True)
|
123
124
|
|
124
125
|
|
126
|
+
def prepare_parsed_state_vector(
|
127
|
+
state_vector: StateVector, parsed_state_vector_states: ParsedStates
|
128
|
+
) -> Optional[ParsedStateVector]:
|
129
|
+
if not state_vector:
|
130
|
+
return None
|
131
|
+
|
132
|
+
parsed_state_vector = [
|
133
|
+
SimulatedState(
|
134
|
+
state=parsed_state_vector_states[bitstring],
|
135
|
+
bitstring=bitstring,
|
136
|
+
amplitude=complex(amplitude_str),
|
137
|
+
)
|
138
|
+
for bitstring, amplitude_str in state_vector.items()
|
139
|
+
]
|
140
|
+
return sorted(parsed_state_vector, key=lambda k: abs(k.amplitude), reverse=True)
|
141
|
+
|
142
|
+
|
125
143
|
class ExecutionDetails(BaseModel, QmodPyObject):
|
126
144
|
vendor_format_result: Dict[str, Any] = pydantic.Field(
|
127
145
|
..., description="Result in proprietary vendor format"
|
@@ -133,6 +151,9 @@ class ExecutionDetails(BaseModel, QmodPyObject):
|
|
133
151
|
True,
|
134
152
|
description="Is the qubit order of counts field such that the LSB is right?",
|
135
153
|
)
|
154
|
+
probabilities: Dict[State, pydantic.NonNegativeFloat] = pydantic.Field(
|
155
|
+
default_factory=dict, description="Probabilities of each state"
|
156
|
+
)
|
136
157
|
parsed_states: ParsedStates = pydantic.Field(
|
137
158
|
default_factory=dict,
|
138
159
|
description="A mapping between the raw states of counts (bitstrings) to their parsed states (registers' values)",
|
@@ -184,17 +205,9 @@ class ExecutionDetails(BaseModel, QmodPyObject):
|
|
184
205
|
|
185
206
|
@property
|
186
207
|
def parsed_state_vector(self) -> Optional[ParsedStateVector]:
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
SimulatedState(
|
191
|
-
state=self.parsed_state_vector_states[bitstring],
|
192
|
-
bitstring=bitstring,
|
193
|
-
amplitude=complex(amplitude_str),
|
194
|
-
)
|
195
|
-
for bitstring, amplitude_str in self.state_vector.items()
|
196
|
-
]
|
197
|
-
return sorted(parsed_state_vector, key=lambda k: abs(k.amplitude), reverse=True)
|
208
|
+
return prepare_parsed_state_vector(
|
209
|
+
self.state_vector, self.parsed_state_vector_states
|
210
|
+
)
|
198
211
|
|
199
212
|
def flip_execution_counts_bitstring(self) -> None:
|
200
213
|
"""Backends should return result count bitstring in right to left form"""
|
@@ -261,6 +274,8 @@ class ExecutionDetails(BaseModel, QmodPyObject):
|
|
261
274
|
lsb_right=False
|
262
275
|
).items():
|
263
276
|
value = value_from_str_bin(binary_string=results_binary_key)
|
277
|
+
if TYPE_CHECKING:
|
278
|
+
assert isinstance(value, float)
|
264
279
|
register_output[value] = register_output.get(value, 0) + counts
|
265
280
|
|
266
281
|
return register_output
|
@@ -1,19 +1,18 @@
|
|
1
|
-
from typing import
|
1
|
+
from typing import Any, Dict, Optional, Union
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
|
5
|
+
from classiq.interface.exceptions import ClassiqValueError
|
5
6
|
from classiq.interface.generator.expressions.enums.finance_functions import (
|
6
7
|
get_finance_function_dict,
|
7
8
|
)
|
9
|
+
from classiq.interface.generator.types.builtin_enum_declarations import (
|
10
|
+
FinanceFunctionType,
|
11
|
+
)
|
8
12
|
from classiq.interface.helpers.custom_pydantic_types import (
|
9
13
|
PydanticNonZeroProbabilityFloat,
|
10
14
|
)
|
11
15
|
|
12
|
-
from classiq.exceptions import ClassiqValueError
|
13
|
-
|
14
|
-
if TYPE_CHECKING:
|
15
|
-
from classiq.qmod.builtins.enums import FinanceFunctionType
|
16
|
-
|
17
16
|
|
18
17
|
class FunctionCondition(pydantic.BaseModel):
|
19
18
|
threshold: float
|
@@ -71,9 +70,7 @@ class FinanceFunctionInput(pydantic.BaseModel):
|
|
71
70
|
@pydantic.validator("f")
|
72
71
|
def _validate_finance_function(
|
73
72
|
cls, f: Union[int, str, "FinanceFunctionType"]
|
74
|
-
) ->
|
75
|
-
from classiq.qmod.builtins.enums import FinanceFunctionType
|
76
|
-
|
73
|
+
) -> FinanceFunctionType:
|
77
74
|
if isinstance(f, FinanceFunctionType):
|
78
75
|
return f
|
79
76
|
if isinstance(f, int):
|
@@ -86,8 +83,6 @@ class FinanceFunctionInput(pydantic.BaseModel):
|
|
86
83
|
tail_probability: Optional[PydanticNonZeroProbabilityFloat],
|
87
84
|
values: Dict[str, Any],
|
88
85
|
) -> Optional[PydanticNonZeroProbabilityFloat]:
|
89
|
-
from classiq.qmod.builtins.enums import FinanceFunctionType
|
90
|
-
|
91
86
|
if values.get("f") == FinanceFunctionType.SHORTFALL and not tail_probability:
|
92
87
|
raise ClassiqValueError(
|
93
88
|
"Tail probability must be set for expected shortfall"
|
@@ -4,6 +4,8 @@ from typing import Any, Dict, get_args
|
|
4
4
|
import pydantic
|
5
5
|
import sympy
|
6
6
|
|
7
|
+
from classiq.interface.enum_utils import StrEnum
|
8
|
+
from classiq.interface.exceptions import ClassiqValueError
|
7
9
|
from classiq.interface.generator.arith.arithmetic_expression_validator import (
|
8
10
|
validate_expression,
|
9
11
|
)
|
@@ -20,9 +22,6 @@ from classiq.interface.generator.function_params import (
|
|
20
22
|
)
|
21
23
|
from classiq.interface.helpers.custom_pydantic_types import PydanticExpressionStr
|
22
24
|
|
23
|
-
from classiq._internals.enum_utils import StrEnum
|
24
|
-
from classiq.exceptions import ClassiqValueError
|
25
|
-
|
26
25
|
AMPLITUDE_IO_NAME = "AMPLITUDE"
|
27
26
|
TARGET_OUTPUT_NAME = "TARGET"
|
28
27
|
|
@@ -2,13 +2,16 @@ from classiq.interface.generator.functions.classical_function_declaration import
|
|
2
2
|
ClassicalFunctionDeclaration,
|
3
3
|
)
|
4
4
|
from classiq.interface.generator.functions.classical_type import Integer, Real
|
5
|
+
from classiq.interface.model.classical_parameter_declaration import (
|
6
|
+
ClassicalParameterDeclaration,
|
7
|
+
)
|
5
8
|
|
6
9
|
qft_const_adder_phase = ClassicalFunctionDeclaration(
|
7
10
|
name="qft_const_adder_phase",
|
8
|
-
|
9
|
-
"bit_index"
|
10
|
-
"value"
|
11
|
-
"reg_len"
|
12
|
-
|
11
|
+
positional_parameters=[
|
12
|
+
ClassicalParameterDeclaration(name="bit_index", classical_type=Integer()),
|
13
|
+
ClassicalParameterDeclaration(name="value", classical_type=Integer()),
|
14
|
+
ClassicalParameterDeclaration(name="reg_len", classical_type=Integer()),
|
15
|
+
],
|
13
16
|
return_type=Real(),
|
14
17
|
)
|
@@ -10,43 +10,44 @@ from classiq.interface.generator.functions.classical_type import (
|
|
10
10
|
ClassicalList,
|
11
11
|
Integer,
|
12
12
|
Real,
|
13
|
-
Struct,
|
14
|
-
TypeName,
|
15
13
|
VQEResult,
|
16
14
|
)
|
17
15
|
from classiq.interface.generator.functions.port_declaration import (
|
18
16
|
PortDeclarationDirection,
|
19
17
|
)
|
18
|
+
from classiq.interface.generator.functions.type_name import Struct, TypeName
|
20
19
|
from classiq.interface.generator.types.struct_declaration import StructDeclaration
|
20
|
+
from classiq.interface.model.classical_parameter_declaration import (
|
21
|
+
ClassicalParameterDeclaration,
|
22
|
+
)
|
21
23
|
from classiq.interface.model.port_declaration import PortDeclaration
|
22
24
|
from classiq.interface.model.quantum_function_declaration import (
|
23
|
-
|
25
|
+
NamedParamsQuantumFunctionDeclaration,
|
24
26
|
)
|
25
27
|
|
26
|
-
MOLECULE_PROBLEM_PARAM =
|
28
|
+
MOLECULE_PROBLEM_PARAM = ClassicalParameterDeclaration(
|
29
|
+
name="molecule_problem", classical_type=Struct(name="MoleculeProblem")
|
30
|
+
)
|
27
31
|
MOLECULE_PROBLEM_SIZE = "get_field(get_field(molecule_problem_to_hamiltonian(molecule_problem)[0], 'pauli'), 'len')"
|
28
|
-
MOLECULE_PROBLEM_PORT =
|
29
|
-
"qbv"
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
)
|
36
|
-
}
|
32
|
+
MOLECULE_PROBLEM_PORT = PortDeclaration(
|
33
|
+
name="qbv",
|
34
|
+
direction=PortDeclarationDirection.Inout,
|
35
|
+
size=Expression(
|
36
|
+
expr=MOLECULE_PROBLEM_SIZE,
|
37
|
+
),
|
38
|
+
)
|
37
39
|
|
38
|
-
FOCK_HAMILTONIAN_PROBLEM_PARAM =
|
39
|
-
|
40
|
-
|
40
|
+
FOCK_HAMILTONIAN_PROBLEM_PARAM = ClassicalParameterDeclaration(
|
41
|
+
name="fock_hamiltonian_problem",
|
42
|
+
classical_type=Struct(name="FockHamiltonianProblem"),
|
43
|
+
)
|
41
44
|
FOCK_HAMILTONIAN_SIZE = "get_field(get_field(fock_hamiltonian_problem_to_hamiltonian(fock_hamiltonian_problem)[0], 'pauli'), 'len')"
|
42
45
|
|
43
|
-
FOCK_HAMILTONIAN_PROBLEM_PORT =
|
44
|
-
"qbv"
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
)
|
49
|
-
}
|
46
|
+
FOCK_HAMILTONIAN_PROBLEM_PORT = PortDeclaration(
|
47
|
+
name="qbv",
|
48
|
+
direction=PortDeclarationDirection.Inout,
|
49
|
+
size=Expression(expr=FOCK_HAMILTONIAN_SIZE),
|
50
|
+
)
|
50
51
|
|
51
52
|
|
52
53
|
class ChemistryProblemType(Enum):
|
@@ -54,59 +55,63 @@ class ChemistryProblemType(Enum):
|
|
54
55
|
FockHamiltonianProblem = "fock_hamiltonian_problem"
|
55
56
|
|
56
57
|
|
57
|
-
MOLECULE_UCC_ANSATZ =
|
58
|
+
MOLECULE_UCC_ANSATZ = NamedParamsQuantumFunctionDeclaration(
|
58
59
|
name="molecule_ucc",
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
60
|
+
positional_arg_declarations=[
|
61
|
+
MOLECULE_PROBLEM_PARAM,
|
62
|
+
ClassicalParameterDeclaration(
|
63
|
+
name="excitations", classical_type=ClassicalList(element_type=Integer())
|
64
|
+
),
|
65
|
+
MOLECULE_PROBLEM_PORT,
|
66
|
+
],
|
64
67
|
)
|
65
68
|
|
66
69
|
|
67
|
-
MOLECULE_HVA_ANSATZ =
|
70
|
+
MOLECULE_HVA_ANSATZ = NamedParamsQuantumFunctionDeclaration(
|
68
71
|
name="molecule_hva",
|
69
|
-
|
70
|
-
|
71
|
-
"reps"
|
72
|
-
|
73
|
-
|
72
|
+
positional_arg_declarations=[
|
73
|
+
MOLECULE_PROBLEM_PARAM,
|
74
|
+
ClassicalParameterDeclaration(name="reps", classical_type=Integer()),
|
75
|
+
MOLECULE_PROBLEM_PORT,
|
76
|
+
],
|
74
77
|
)
|
75
78
|
|
76
79
|
|
77
|
-
MOLECULE_HARTREE_FOCK =
|
80
|
+
MOLECULE_HARTREE_FOCK = NamedParamsQuantumFunctionDeclaration(
|
78
81
|
name="molecule_hartree_fock",
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
82
|
+
positional_arg_declarations=[
|
83
|
+
MOLECULE_PROBLEM_PARAM,
|
84
|
+
MOLECULE_PROBLEM_PORT,
|
85
|
+
],
|
83
86
|
)
|
84
87
|
|
85
88
|
|
86
|
-
FOCK_HAMILTONIAN_UCC_ANSATZ =
|
89
|
+
FOCK_HAMILTONIAN_UCC_ANSATZ = NamedParamsQuantumFunctionDeclaration(
|
87
90
|
name="fock_hamiltonian_ucc",
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
91
|
+
positional_arg_declarations=[
|
92
|
+
FOCK_HAMILTONIAN_PROBLEM_PARAM,
|
93
|
+
ClassicalParameterDeclaration(
|
94
|
+
name="excitations", classical_type=ClassicalList(element_type=Integer())
|
95
|
+
),
|
96
|
+
FOCK_HAMILTONIAN_PROBLEM_PORT,
|
97
|
+
],
|
93
98
|
)
|
94
99
|
|
95
|
-
FOCK_HAMILTONIAN_HVA_ANSATZ =
|
100
|
+
FOCK_HAMILTONIAN_HVA_ANSATZ = NamedParamsQuantumFunctionDeclaration(
|
96
101
|
name="fock_hamiltonian_hva",
|
97
|
-
|
98
|
-
|
99
|
-
"reps"
|
100
|
-
|
101
|
-
|
102
|
+
positional_arg_declarations=[
|
103
|
+
FOCK_HAMILTONIAN_PROBLEM_PARAM,
|
104
|
+
ClassicalParameterDeclaration(name="reps", classical_type=Integer()),
|
105
|
+
FOCK_HAMILTONIAN_PROBLEM_PORT,
|
106
|
+
],
|
102
107
|
)
|
103
108
|
|
104
|
-
FOCK_HAMILTONIAN_HARTREE_FOCK =
|
109
|
+
FOCK_HAMILTONIAN_HARTREE_FOCK = NamedParamsQuantumFunctionDeclaration(
|
105
110
|
name="fock_hamiltonian_hartree_fock",
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
111
|
+
positional_arg_declarations=[
|
112
|
+
FOCK_HAMILTONIAN_PROBLEM_PARAM,
|
113
|
+
FOCK_HAMILTONIAN_PROBLEM_PORT,
|
114
|
+
],
|
110
115
|
)
|
111
116
|
|
112
117
|
|
@@ -187,20 +192,33 @@ MOLECULE_RESULT = StructDeclaration(
|
|
187
192
|
|
188
193
|
MOLECULE_PROBLEM_TO_HAMILTONIAN = ClassicalFunctionDeclaration(
|
189
194
|
name="molecule_problem_to_hamiltonian",
|
190
|
-
|
195
|
+
positional_parameters=[
|
196
|
+
ClassicalParameterDeclaration(
|
197
|
+
name="problem", classical_type=Struct(name="MoleculeProblem")
|
198
|
+
),
|
199
|
+
],
|
191
200
|
return_type=ClassicalList(element_type=Struct(name="PauliTerm")),
|
192
201
|
)
|
193
202
|
|
194
203
|
FOCK_HAMILTONIAN_PROBLEM_TO_HAMILTONIAN = ClassicalFunctionDeclaration(
|
195
204
|
name="fock_hamiltonian_problem_to_hamiltonian",
|
196
|
-
|
205
|
+
positional_parameters=[
|
206
|
+
ClassicalParameterDeclaration(
|
207
|
+
name="problem", classical_type=Struct(name="FockHamiltonianProblem")
|
208
|
+
),
|
209
|
+
],
|
197
210
|
return_type=ClassicalList(element_type=Struct(name="PauliTerm")),
|
198
211
|
)
|
199
212
|
|
200
213
|
|
201
214
|
MOLECULE_GROUND_STATE_SOLUTION_POST_PROCESS = ClassicalFunctionDeclaration(
|
202
215
|
name="molecule_ground_state_solution_post_process",
|
203
|
-
|
216
|
+
positional_parameters=[
|
217
|
+
ClassicalParameterDeclaration(
|
218
|
+
name="problem", classical_type=Struct(name="MoleculeProblem")
|
219
|
+
),
|
220
|
+
ClassicalParameterDeclaration(name="vqe_result", classical_type=VQEResult()),
|
221
|
+
],
|
204
222
|
return_type=Struct(name="MoleculeResult"),
|
205
223
|
)
|
206
224
|
|
@@ -5,11 +5,14 @@ from classiq.interface.generator.functions.classical_type import (
|
|
5
5
|
ClassicalList,
|
6
6
|
Integer,
|
7
7
|
Real,
|
8
|
-
Struct,
|
9
8
|
StructMetaType,
|
10
9
|
VQEResult,
|
11
10
|
)
|
11
|
+
from classiq.interface.generator.functions.type_name import Struct
|
12
12
|
from classiq.interface.generator.types.struct_declaration import StructDeclaration
|
13
|
+
from classiq.interface.model.classical_parameter_declaration import (
|
14
|
+
ClassicalParameterDeclaration,
|
15
|
+
)
|
13
16
|
|
14
17
|
COMBINATORIAL_OPTIMIZATION_SOLUTION = StructDeclaration(
|
15
18
|
name="CombinatorialOptimizationSolution",
|
@@ -23,20 +26,26 @@ COMBINATORIAL_OPTIMIZATION_SOLUTION = StructDeclaration(
|
|
23
26
|
|
24
27
|
OPTIMIZATION_PROBLEM_TO_HAMILTONIAN = ClassicalFunctionDeclaration(
|
25
28
|
name="optimization_problem_to_hamiltonian",
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
29
|
+
positional_parameters=[
|
30
|
+
ClassicalParameterDeclaration(
|
31
|
+
name="problem_type", classical_type=StructMetaType()
|
32
|
+
),
|
33
|
+
ClassicalParameterDeclaration(name="penalty_energy", classical_type=Real()),
|
34
|
+
],
|
30
35
|
return_type=ClassicalList(element_type=Struct(name="PauliTerm")),
|
31
36
|
)
|
32
37
|
|
33
38
|
GET_OPTIMIZATION_SOLUTION = ClassicalFunctionDeclaration(
|
34
39
|
name="get_optimization_solution",
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
+
positional_parameters=[
|
41
|
+
ClassicalParameterDeclaration(
|
42
|
+
name="problem_type", classical_type=StructMetaType()
|
43
|
+
),
|
44
|
+
ClassicalParameterDeclaration(
|
45
|
+
name="vqe_result_handle", classical_type=VQEResult()
|
46
|
+
),
|
47
|
+
ClassicalParameterDeclaration(name="penalty_energy", classical_type=Real()),
|
48
|
+
],
|
40
49
|
return_type=ClassicalList(
|
41
50
|
element_type=Struct(name="CombinatorialOptimizationSolution")
|
42
51
|
),
|
@@ -6,19 +6,24 @@ from classiq.interface.generator.functions.classical_type import (
|
|
6
6
|
ClassicalList,
|
7
7
|
Integer,
|
8
8
|
)
|
9
|
+
from classiq.interface.model.classical_parameter_declaration import (
|
10
|
+
ClassicalParameterDeclaration,
|
11
|
+
)
|
9
12
|
|
10
13
|
GRID_ENTANGLER_GRAPH = ClassicalFunctionDeclaration(
|
11
14
|
name="grid_entangler_graph",
|
12
|
-
|
13
|
-
"num_qubits"
|
14
|
-
"schmidt_rank"
|
15
|
-
"grid_randomization"
|
16
|
-
|
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
|
+
],
|
17
20
|
return_type=ClassicalList(element_type=ClassicalList(element_type=Integer())),
|
18
21
|
)
|
19
22
|
|
20
23
|
HYPERCUBE_ENTANGLER_GRAPH = ClassicalFunctionDeclaration(
|
21
24
|
name="hypercube_entangler_graph",
|
22
|
-
|
25
|
+
positional_parameters=[
|
26
|
+
ClassicalParameterDeclaration(name="num_qubits", classical_type=Integer()),
|
27
|
+
],
|
23
28
|
return_type=ClassicalList(element_type=ClassicalList(element_type=Integer())),
|
24
29
|
)
|