classiq 0.94.2__py3-none-any.whl → 0.96.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.
Potentially problematic release.
This version of classiq might be problematic. Click here for more details.
- classiq/_internals/api_wrapper.py +0 -83
- classiq/_internals/authentication/auth0.py +32 -3
- classiq/_internals/authentication/authorization_code.py +9 -0
- classiq/_internals/authentication/authorization_flow.py +41 -0
- classiq/_internals/authentication/device.py +31 -50
- classiq/_internals/authentication/hybrid_flow.py +19 -0
- classiq/_internals/authentication/token_manager.py +5 -4
- classiq/applications/__init__.py +2 -2
- classiq/applications/iqae/iqae.py +6 -3
- classiq/applications/qnn/gradients/simple_quantum_gradient.py +1 -1
- classiq/applications/qnn/qlayer.py +1 -1
- classiq/applications/qnn/torch_utils.py +2 -2
- classiq/applications/qsp/qsp.py +6 -5
- classiq/evaluators/qmod_node_evaluators/classical_function_evaluation.py +10 -0
- classiq/execution/__init__.py +0 -3
- classiq/execution/user_budgets.py +0 -1
- classiq/interface/_version.py +1 -1
- classiq/interface/backend/backend_preferences.py +11 -35
- classiq/interface/backend/quantum_backend_providers.py +0 -2
- classiq/interface/exceptions.py +0 -4
- classiq/interface/generator/application_apis/__init__.py +0 -1
- classiq/interface/generator/arith/register_user_input.py +1 -1
- classiq/interface/generator/function_param_list.py +0 -2
- classiq/interface/generator/generated_circuit_data.py +1 -6
- classiq/interface/generator/hardware_efficient_ansatz.py +1 -1
- classiq/interface/generator/quantum_function_call.py +1 -1
- classiq/interface/generator/quantum_program.py +0 -4
- classiq/interface/generator/transpiler_basis_gates.py +3 -0
- classiq/interface/generator/types/builtin_enum_declarations.py +0 -9
- classiq/interface/hardware.py +0 -1
- classiq/interface/interface_version.py +1 -1
- classiq/interface/model/block.py +4 -0
- classiq/interface/model/classical_if.py +4 -0
- classiq/interface/model/control.py +7 -0
- classiq/interface/model/invert.py +4 -0
- classiq/interface/model/model_visitor.py +40 -1
- classiq/interface/model/power.py +4 -0
- classiq/interface/model/quantum_statement.py +8 -1
- classiq/interface/model/repeat.py +4 -0
- classiq/interface/model/skip_control.py +4 -0
- classiq/interface/model/within_apply_operation.py +4 -0
- classiq/interface/server/routes.py +0 -12
- classiq/model_expansions/generative_functions.py +6 -8
- classiq/model_expansions/interpreters/base_interpreter.py +1 -1
- classiq/model_expansions/interpreters/frontend_generative_interpreter.py +2 -1
- classiq/model_expansions/visitors/symbolic_param_inference.py +3 -3
- classiq/model_expansions/visitors/uncomputation_signature_inference.py +14 -3
- classiq/open_library/functions/__init__.py +3 -2
- classiq/open_library/functions/amplitude_loading.py +85 -0
- classiq/open_library/functions/lcu.py +47 -18
- classiq/open_library/functions/modular_exponentiation.py +5 -8
- classiq/open_library/functions/qsvt.py +4 -4
- classiq/open_library/functions/state_preparation.py +7 -7
- classiq/qmod/builtins/classical_execution_primitives.py +0 -12
- classiq/qmod/builtins/enums.py +15 -17
- classiq/qmod/builtins/functions/__init__.py +5 -5
- classiq/qmod/builtins/functions/allocation.py +21 -0
- classiq/qmod/builtins/functions/mcx.py +7 -0
- classiq/qmod/builtins/operations.py +125 -23
- classiq/qmod/builtins/structs.py +22 -33
- classiq/qmod/semantics/annotation/call_annotation.py +3 -3
- classiq/qmod/semantics/error_manager.py +7 -8
- classiq/qmod/utilities.py +0 -10
- {classiq-0.94.2.dist-info → classiq-0.96.0.dist-info}/METADATA +1 -1
- {classiq-0.94.2.dist-info → classiq-0.96.0.dist-info}/RECORD +67 -71
- {classiq-0.94.2.dist-info → classiq-0.96.0.dist-info}/WHEEL +1 -1
- classiq/applications/qsvm/__init__.py +0 -8
- classiq/applications/qsvm/qsvm.py +0 -11
- classiq/execution/iqcc.py +0 -128
- classiq/interface/applications/qsvm.py +0 -114
- classiq/interface/execution/iqcc.py +0 -42
- classiq/interface/generator/application_apis/qsvm_declarations.py +0 -6
- classiq/interface/generator/qsvm.py +0 -96
- classiq/open_library/functions/lookup_table.py +0 -58
- classiq/qmod/builtins/functions/qsvm.py +0 -24
- {classiq-0.94.2.dist-info → classiq-0.96.0.dist-info}/licenses/LICENSE.txt +0 -0
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
from collections.abc import Iterable as IterableType, Sequence
|
|
2
|
-
from typing import (
|
|
3
|
-
Any,
|
|
4
|
-
Union,
|
|
5
|
-
)
|
|
6
|
-
|
|
7
|
-
import numpy as np
|
|
8
|
-
import pydantic
|
|
9
|
-
from numpy.typing import ArrayLike
|
|
10
|
-
from pydantic import ConfigDict, field_validator
|
|
11
|
-
|
|
12
|
-
from classiq.interface.helpers.versioned_model import VersionedModel
|
|
13
|
-
|
|
14
|
-
DataList = list[list[float]]
|
|
15
|
-
LabelsInt = list[int]
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def listify(obj: IterableType | ArrayLike) -> list:
|
|
19
|
-
if isinstance(obj, np.ndarray):
|
|
20
|
-
return obj.tolist()
|
|
21
|
-
elif isinstance(obj, Sequence) and obj and isinstance(obj[0], np.ndarray):
|
|
22
|
-
return np.array(obj).tolist()
|
|
23
|
-
elif isinstance(obj, list):
|
|
24
|
-
return obj
|
|
25
|
-
else:
|
|
26
|
-
return list(obj) # type: ignore[arg-type]
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def validate_array_to_list(name: str) -> Any:
|
|
30
|
-
@field_validator(name, mode="before")
|
|
31
|
-
def _listify(cls: type[pydantic.BaseModel], value: Any) -> Any:
|
|
32
|
-
return listify(value)
|
|
33
|
-
|
|
34
|
-
return _listify
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
Shape = tuple[int, ...]
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
class QSVMInternalState(VersionedModel):
|
|
41
|
-
underscore_sparse: bool
|
|
42
|
-
class_weight: list
|
|
43
|
-
classes: list
|
|
44
|
-
underscore_gamma: float
|
|
45
|
-
underscore_base_fit: list
|
|
46
|
-
support: list
|
|
47
|
-
support_vectors: list
|
|
48
|
-
underscore_n_support: list
|
|
49
|
-
dual_coef_2: list
|
|
50
|
-
intercept: list
|
|
51
|
-
underscore_p_a: list
|
|
52
|
-
underscore_p_b: list
|
|
53
|
-
fit_status: int
|
|
54
|
-
shape_fit: Shape
|
|
55
|
-
underscore_intercept: list
|
|
56
|
-
dual_coef: list
|
|
57
|
-
|
|
58
|
-
class_weight__shape: Shape
|
|
59
|
-
classes__shape: Shape
|
|
60
|
-
underscore_base_fit__shape: Shape
|
|
61
|
-
support__shape: Shape
|
|
62
|
-
support_vectors__shape: Shape
|
|
63
|
-
underscore_n_support__shape: Shape
|
|
64
|
-
dual_coef_2__shape: Shape
|
|
65
|
-
intercept__shape: Shape
|
|
66
|
-
underscore_p_a__shape: Shape
|
|
67
|
-
underscore_p_b__shape: Shape
|
|
68
|
-
underscore_intercept__shape: Shape
|
|
69
|
-
dual_coef__shape: Shape
|
|
70
|
-
|
|
71
|
-
set_class_weight = validate_array_to_list("class_weight")
|
|
72
|
-
set_classes = validate_array_to_list("classes")
|
|
73
|
-
set_underscore_base_fit = validate_array_to_list("underscore_base_fit")
|
|
74
|
-
set_support = validate_array_to_list("support")
|
|
75
|
-
set_support_vectors = validate_array_to_list("support_vectors")
|
|
76
|
-
set_underscore_n_support = validate_array_to_list("underscore_n_support")
|
|
77
|
-
set_dual_coef_2 = validate_array_to_list("dual_coef_2")
|
|
78
|
-
set_intercept = validate_array_to_list("intercept")
|
|
79
|
-
set_underscore_p_a = validate_array_to_list("underscore_p_a")
|
|
80
|
-
set_underscore_p_b = validate_array_to_list("underscore_p_b")
|
|
81
|
-
set_underscore_intercept = validate_array_to_list("underscore_intercept")
|
|
82
|
-
set_dual_coef = validate_array_to_list("dual_coef")
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
class QSVMData(VersionedModel):
|
|
86
|
-
data: DataList
|
|
87
|
-
labels: LabelsInt | None = None
|
|
88
|
-
internal_state: QSVMInternalState | None = None
|
|
89
|
-
model_config = ConfigDict(extra="forbid")
|
|
90
|
-
|
|
91
|
-
@pydantic.field_validator("data", mode="before")
|
|
92
|
-
@classmethod
|
|
93
|
-
def set_data(cls, data: IterableType | ArrayLike) -> list:
|
|
94
|
-
return listify(data)
|
|
95
|
-
|
|
96
|
-
@pydantic.field_validator("labels", mode="before")
|
|
97
|
-
@classmethod
|
|
98
|
-
def set_labels(cls, labels: IterableType | ArrayLike | None) -> list | None:
|
|
99
|
-
if labels is None:
|
|
100
|
-
return None
|
|
101
|
-
else:
|
|
102
|
-
return listify(labels)
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
class QSVMTestResult(VersionedModel):
|
|
106
|
-
data: float # between 0 to 1
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
class QSVMPredictResult(VersionedModel):
|
|
110
|
-
data: list # serialized np.array
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
Data = Union[DataList, np.ndarray]
|
|
114
|
-
Labels = Union[list[Any], np.ndarray]
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
from pydantic import BaseModel, Field
|
|
2
|
-
|
|
3
|
-
from classiq.interface.helpers.versioned_model import VersionedModel
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class IQCCInitAuthData(VersionedModel):
|
|
7
|
-
auth_scope_id: str
|
|
8
|
-
auth_method_id: str
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class IQCCInitAuthResponse(VersionedModel):
|
|
12
|
-
auth_url: str
|
|
13
|
-
token_id: str
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class IQCCProbeAuthData(IQCCInitAuthData):
|
|
17
|
-
token_id: str
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class IQCCProbeAuthResponse(VersionedModel):
|
|
21
|
-
auth_token: str
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
class IQCCAuthItemDetails(BaseModel):
|
|
25
|
-
id: str
|
|
26
|
-
name: str
|
|
27
|
-
description: str
|
|
28
|
-
scope_id: str | None = Field(default=None)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
class IQCCAuthItemsDetails(VersionedModel):
|
|
32
|
-
items: list[IQCCAuthItemDetails]
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
class IQCCListAuthMethods(VersionedModel):
|
|
36
|
-
auth_scope_id: str
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
class IQCCListAuthTargets(VersionedModel):
|
|
40
|
-
auth_scope_id: str
|
|
41
|
-
auth_method_id: str
|
|
42
|
-
auth_token: str
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
from typing import Literal, 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: int | None = 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,58 +0,0 @@
|
|
|
1
|
-
from itertools import product
|
|
2
|
-
|
|
3
|
-
from classiq.interface.exceptions import ClassiqValueError
|
|
4
|
-
|
|
5
|
-
from classiq.qmod.builtins.operations import assign, bind, within_apply
|
|
6
|
-
from classiq.qmod.qmod_variable import QNum
|
|
7
|
-
from classiq.qmod.symbolic import subscript
|
|
8
|
-
from classiq.qmod.utilities import RealFunction, get_temp_var_name, qnum_values
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def _get_qnum_values(num: QNum) -> list[float]:
|
|
12
|
-
size = num.size
|
|
13
|
-
is_signed = num.is_signed
|
|
14
|
-
fraction_digits = num.fraction_digits
|
|
15
|
-
if (
|
|
16
|
-
not isinstance(size, int)
|
|
17
|
-
or not isinstance(is_signed, bool)
|
|
18
|
-
or not isinstance(fraction_digits, int)
|
|
19
|
-
):
|
|
20
|
-
raise ClassiqValueError(
|
|
21
|
-
"Must call 'span_lookup_table' inside a generative qfunc"
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
return qnum_values(size, is_signed, fraction_digits)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def span_lookup_table(func: RealFunction, *targets: QNum) -> QNum:
|
|
28
|
-
"""
|
|
29
|
-
Applies a classical function to quantum numbers.
|
|
30
|
-
|
|
31
|
-
Works by reducing the function into a lookup table over all the possible values
|
|
32
|
-
of the quantum numbers.
|
|
33
|
-
|
|
34
|
-
Args:
|
|
35
|
-
func: A Python function
|
|
36
|
-
*targets: One or more initialized quantum numbers
|
|
37
|
-
|
|
38
|
-
Returns:
|
|
39
|
-
The quantum result of applying func to targets
|
|
40
|
-
|
|
41
|
-
Notes:
|
|
42
|
-
Must be called inside a generative function (`@qfunc`)
|
|
43
|
-
"""
|
|
44
|
-
if len(targets) == 0:
|
|
45
|
-
raise ClassiqValueError("No targets specified")
|
|
46
|
-
|
|
47
|
-
target_vals = [_get_qnum_values(target) for target in targets]
|
|
48
|
-
lookup_table = [func(*vals[::-1]) for vals in product(*target_vals[::-1])]
|
|
49
|
-
|
|
50
|
-
index_size = sum(target.size for target in targets)
|
|
51
|
-
index: QNum = QNum(get_temp_var_name(), size=index_size)
|
|
52
|
-
result: QNum = QNum(get_temp_var_name("result"))
|
|
53
|
-
|
|
54
|
-
within_apply(
|
|
55
|
-
lambda: bind(list(targets), index),
|
|
56
|
-
lambda: assign(subscript(lookup_table, index), result),
|
|
57
|
-
)
|
|
58
|
-
return result
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
from typing import Literal
|
|
2
|
-
|
|
3
|
-
from classiq.qmod.builtins.structs import (
|
|
4
|
-
QSVMFeatureMapPauli,
|
|
5
|
-
)
|
|
6
|
-
from classiq.qmod.qfunc import qfunc
|
|
7
|
-
from classiq.qmod.qmod_parameter import CInt
|
|
8
|
-
from classiq.qmod.qmod_variable import QArray, QBit
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
@qfunc(external=True)
|
|
12
|
-
def pauli_feature_map(
|
|
13
|
-
feature_map: QSVMFeatureMapPauli,
|
|
14
|
-
qbv: QArray[QBit, Literal["feature_map.feature_dimension"]],
|
|
15
|
-
) -> None:
|
|
16
|
-
pass
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
@qfunc(external=True)
|
|
20
|
-
def bloch_sphere_feature_map(
|
|
21
|
-
feature_dimension: CInt,
|
|
22
|
-
qbv: QArray[QBit, Literal["ceiling(feature_dimension / 2)"]],
|
|
23
|
-
) -> None:
|
|
24
|
-
pass
|
|
File without changes
|