luna-quantum 1.0.8rc2__cp311-cp311-macosx_11_0_arm64.whl → 1.0.8rc4__cp311-cp311-macosx_11_0_arm64.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 luna-quantum might be problematic. Click here for more details.
- luna_quantum/__init__.py +19 -1
- luna_quantum/__init__.pyi +14 -1
- luna_quantum/_core.cpython-311-darwin.so +0 -0
- luna_quantum/_core.pyi +185 -84
- luna_quantum/_utility.py +148 -0
- luna_quantum/_utility.pyi +20 -0
- luna_quantum/exceptions/luna_quantum_call_type_error.py +9 -0
- luna_quantum/factories/usecase_factory.py +32 -0
- luna_quantum/solve/domain/solve_job.py +42 -8
- luna_quantum/solve/interfaces/usecases/__init__.py +4 -0
- luna_quantum/solve/interfaces/usecases/solve_job_get_by_id_usecase_i.py +27 -0
- luna_quantum/solve/parameters/algorithms/quantum_gate/__init__.py +1 -1
- luna_quantum/solve/parameters/algorithms/quantum_gate/flex_qaoa/__init__.py +9 -25
- luna_quantum/solve/parameters/algorithms/quantum_gate/flexqaoa/__init__.py +29 -0
- luna_quantum/solve/parameters/algorithms/quantum_gate/flexqaoa/config.py +58 -0
- luna_quantum/solve/parameters/algorithms/quantum_gate/{flex_qaoa/flex_qaoa.py → flexqaoa/flexqaoa.py} +48 -86
- luna_quantum/solve/parameters/algorithms/quantum_gate/flexqaoa/optimizers.py +53 -0
- luna_quantum/solve/parameters/algorithms/quantum_gate/flexqaoa/pipeline.py +164 -0
- luna_quantum/solve/parameters/backends/__init__.py +2 -0
- luna_quantum/solve/parameters/backends/aqarios_gpu.py +17 -0
- luna_quantum/solve/parameters/errors.py +30 -0
- luna_quantum/solve/usecases/solve_job_get_by_id_usecase.py +44 -0
- luna_quantum/solve/usecases/solve_job_get_result_usecase.py +21 -11
- {luna_quantum-1.0.8rc2.dist-info → luna_quantum-1.0.8rc4.dist-info}/METADATA +1 -1
- {luna_quantum-1.0.8rc2.dist-info → luna_quantum-1.0.8rc4.dist-info}/RECORD +28 -20
- luna_quantum/solve/parameters/algorithms/quantum_gate/flex_qaoa/config.py +0 -80
- luna_quantum/solve/parameters/algorithms/quantum_gate/flex_qaoa/optimizers.py +0 -99
- luna_quantum/solve/parameters/algorithms/quantum_gate/flex_qaoa/pipeline.py +0 -87
- {luna_quantum-1.0.8rc2.dist-info → luna_quantum-1.0.8rc4.dist-info}/WHEEL +0 -0
- {luna_quantum-1.0.8rc2.dist-info → luna_quantum-1.0.8rc4.dist-info}/licenses/LICENSE +0 -0
- {luna_quantum-1.0.8rc2.dist-info → luna_quantum-1.0.8rc4.dist-info}/licenses/NOTICE +0 -0
luna_quantum/__init__.py
CHANGED
|
@@ -21,6 +21,9 @@ from luna_quantum.solve.usecases import (
|
|
|
21
21
|
SolveJobFetchUpdatesUseCase,
|
|
22
22
|
SolveJobGetResultUseCase,
|
|
23
23
|
)
|
|
24
|
+
from luna_quantum.solve.usecases.solve_job_get_by_id_usecase import (
|
|
25
|
+
SolveJobGetByIdUseCase,
|
|
26
|
+
)
|
|
24
27
|
from luna_quantum.util.debug_info import debug_info
|
|
25
28
|
from luna_quantum.util.log_utils import Logging
|
|
26
29
|
|
|
@@ -29,12 +32,14 @@ from ._core import (
|
|
|
29
32
|
Comparator,
|
|
30
33
|
Constant,
|
|
31
34
|
Constraint,
|
|
32
|
-
|
|
35
|
+
ConstraintCollection,
|
|
36
|
+
ConstraintType,
|
|
33
37
|
Environment,
|
|
34
38
|
Expression,
|
|
35
39
|
ExpressionIterator,
|
|
36
40
|
HigherOrder,
|
|
37
41
|
Linear,
|
|
42
|
+
ModelSpecs,
|
|
38
43
|
Quadratic,
|
|
39
44
|
Result,
|
|
40
45
|
ResultIterator,
|
|
@@ -56,8 +61,17 @@ from ._core import (
|
|
|
56
61
|
translator,
|
|
57
62
|
utils,
|
|
58
63
|
)
|
|
64
|
+
from ._utility import deprecated
|
|
59
65
|
from .utils import quicksum
|
|
60
66
|
|
|
67
|
+
|
|
68
|
+
@deprecated(
|
|
69
|
+
"`Constraints` class name is deprecated and will be removed, "
|
|
70
|
+
"use `ConstraintCollection` instead."
|
|
71
|
+
)
|
|
72
|
+
class Constraints(ConstraintCollection): ... # noqa: D101 # comes from aq-models
|
|
73
|
+
|
|
74
|
+
|
|
61
75
|
__version__ = __luna_quantum_version__
|
|
62
76
|
UseCaseFactory.set_model_fetch_class(ModelFetchMetadataUseCase)
|
|
63
77
|
UseCaseFactory.set_model_delete_class(ModelDeleteUseCase)
|
|
@@ -72,12 +86,15 @@ UseCaseFactory.set_solve_job_create_class(SolveJobCreateUseCase)
|
|
|
72
86
|
UseCaseFactory.set_solve_job_delete_class(SolveJobDeleteUseCase)
|
|
73
87
|
UseCaseFactory.set_solve_job_get_result_class(SolveJobGetResultUseCase)
|
|
74
88
|
UseCaseFactory.set_solve_job_fetch_updates_class(SolveJobFetchUpdatesUseCase)
|
|
89
|
+
UseCaseFactory.set_solve_job_get_id_class(SolveJobGetByIdUseCase)
|
|
75
90
|
LunaSolveClientFactory.set_client_class(client_class=LunaSolve)
|
|
76
91
|
__all__ = [
|
|
77
92
|
"Bounds",
|
|
78
93
|
"Comparator",
|
|
79
94
|
"Constant",
|
|
80
95
|
"Constraint",
|
|
96
|
+
"ConstraintCollection",
|
|
97
|
+
"ConstraintType",
|
|
81
98
|
"Constraints",
|
|
82
99
|
"DefaultToken",
|
|
83
100
|
"Environment",
|
|
@@ -90,6 +107,7 @@ __all__ = [
|
|
|
90
107
|
"LunaSolve",
|
|
91
108
|
"LunaSolveClientFactory",
|
|
92
109
|
"Model",
|
|
110
|
+
"ModelSpecs",
|
|
93
111
|
"Quadratic",
|
|
94
112
|
"Result",
|
|
95
113
|
"ResultIterator",
|
luna_quantum/__init__.pyi
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
from warnings import deprecated
|
|
1
2
|
from ._core import (
|
|
2
3
|
Bounds,
|
|
3
4
|
Comparator,
|
|
4
5
|
Constant,
|
|
5
6
|
Constraint,
|
|
6
|
-
|
|
7
|
+
ConstraintCollection,
|
|
8
|
+
ConstraintType,
|
|
7
9
|
Environment,
|
|
8
10
|
Expression,
|
|
9
11
|
ExpressionIterator,
|
|
10
12
|
HigherOrder,
|
|
11
13
|
Linear,
|
|
14
|
+
ModelSpecs,
|
|
12
15
|
Quadratic,
|
|
13
16
|
Result,
|
|
14
17
|
ResultIterator,
|
|
@@ -23,6 +26,7 @@ from ._core import (
|
|
|
23
26
|
Timing,
|
|
24
27
|
Unbounded,
|
|
25
28
|
Variable,
|
|
29
|
+
ValueSource,
|
|
26
30
|
Vtype,
|
|
27
31
|
errors,
|
|
28
32
|
transformations,
|
|
@@ -39,12 +43,19 @@ from luna_quantum.solve.parameters import algorithms, backends, constants
|
|
|
39
43
|
from luna_quantum.util.debug_info import debug_info
|
|
40
44
|
from luna_quantum.util.log_utils import Logging
|
|
41
45
|
|
|
46
|
+
@deprecated(
|
|
47
|
+
"`Constraints` class name is deprecated and will be removed, use `ConstraintCollection` instead."
|
|
48
|
+
)
|
|
49
|
+
class Constraints(ConstraintCollection): ...
|
|
50
|
+
|
|
42
51
|
__version__ = __luna_quantum_version__
|
|
43
52
|
__all__ = [
|
|
44
53
|
"Bounds",
|
|
45
54
|
"Comparator",
|
|
46
55
|
"Constant",
|
|
47
56
|
"Constraint",
|
|
57
|
+
"ConstraintCollection",
|
|
58
|
+
"ConstraintType",
|
|
48
59
|
"Constraints",
|
|
49
60
|
"DefaultToken",
|
|
50
61
|
"Environment",
|
|
@@ -56,6 +67,7 @@ __all__ = [
|
|
|
56
67
|
"LunaQ",
|
|
57
68
|
"LunaSolve",
|
|
58
69
|
"Model",
|
|
70
|
+
"ModelSpecs",
|
|
59
71
|
"Quadratic",
|
|
60
72
|
"Result",
|
|
61
73
|
"ResultIterator",
|
|
@@ -69,6 +81,7 @@ __all__ = [
|
|
|
69
81
|
"Timer",
|
|
70
82
|
"Timing",
|
|
71
83
|
"Unbounded",
|
|
84
|
+
"ValueSource",
|
|
72
85
|
"Variable",
|
|
73
86
|
"Vtype",
|
|
74
87
|
"__version__",
|
|
Binary file
|
luna_quantum/_core.pyi
CHANGED
|
@@ -5,10 +5,13 @@ from types import TracebackType
|
|
|
5
5
|
from typing import Literal, Self, overload
|
|
6
6
|
from numpy.typing import NDArray
|
|
7
7
|
from . import errors, transformations, translator, utils
|
|
8
|
+
from ._utility import deprecated
|
|
8
9
|
from luna_quantum.client.interfaces.services.luna_solve_i import ILunaSolve
|
|
9
10
|
from luna_quantum.solve.domain.model_metadata import ModelMetadata
|
|
10
11
|
from luna_quantum.solve.domain.solve_job import SolveJob
|
|
11
12
|
|
|
13
|
+
__version__ = ...
|
|
14
|
+
|
|
12
15
|
class Vtype(Enum):
|
|
13
16
|
"""
|
|
14
17
|
Enumeration of variable types supported by the optimization system.
|
|
@@ -963,6 +966,11 @@ class Solution:
|
|
|
963
966
|
"""Get the solver / algorithm runtime."""
|
|
964
967
|
...
|
|
965
968
|
|
|
969
|
+
@runtime.setter
|
|
970
|
+
def runtime(self, /, timing: Timing) -> None:
|
|
971
|
+
"""Get the solver / algorithm runtime."""
|
|
972
|
+
...
|
|
973
|
+
|
|
966
974
|
@property
|
|
967
975
|
def sense(self, /) -> Sense:
|
|
968
976
|
"""Get the optimization sense."""
|
|
@@ -1245,39 +1253,6 @@ class Solution:
|
|
|
1245
1253
|
counts: int = ...,
|
|
1246
1254
|
sense: Sense = ...,
|
|
1247
1255
|
) -> Solution: ...
|
|
1248
|
-
@overload
|
|
1249
|
-
@staticmethod
|
|
1250
|
-
def from_dict(
|
|
1251
|
-
data: dict[Variable, int | float],
|
|
1252
|
-
*,
|
|
1253
|
-
env: Environment = ...,
|
|
1254
|
-
model: Model = ...,
|
|
1255
|
-
timing: Timing = ...,
|
|
1256
|
-
counts: int = ...,
|
|
1257
|
-
sense: Sense = ...,
|
|
1258
|
-
) -> Solution: ...
|
|
1259
|
-
@overload
|
|
1260
|
-
@staticmethod
|
|
1261
|
-
def from_dict(
|
|
1262
|
-
data: dict[str, int | float],
|
|
1263
|
-
*,
|
|
1264
|
-
env: Environment = ...,
|
|
1265
|
-
model: Model = ...,
|
|
1266
|
-
timing: Timing = ...,
|
|
1267
|
-
counts: int = ...,
|
|
1268
|
-
sense: Sense = ...,
|
|
1269
|
-
) -> Solution: ...
|
|
1270
|
-
@overload
|
|
1271
|
-
@staticmethod
|
|
1272
|
-
def from_dict(
|
|
1273
|
-
data: dict[Variable | str, int | float],
|
|
1274
|
-
*,
|
|
1275
|
-
env: Environment = ...,
|
|
1276
|
-
model: Model = ...,
|
|
1277
|
-
timing: Timing = ...,
|
|
1278
|
-
counts: int = ...,
|
|
1279
|
-
sense: Sense = ...,
|
|
1280
|
-
) -> Solution: ...
|
|
1281
1256
|
@staticmethod
|
|
1282
1257
|
def from_dict(
|
|
1283
1258
|
data: dict[Variable | str, int | float],
|
|
@@ -1400,39 +1375,6 @@ class Solution:
|
|
|
1400
1375
|
counts: list[int] = ...,
|
|
1401
1376
|
sense: Sense = ...,
|
|
1402
1377
|
) -> Solution: ...
|
|
1403
|
-
@overload
|
|
1404
|
-
@staticmethod
|
|
1405
|
-
def from_dicts(
|
|
1406
|
-
data: list[dict[Variable, int | float]],
|
|
1407
|
-
*,
|
|
1408
|
-
env: Environment = ...,
|
|
1409
|
-
model: Model = ...,
|
|
1410
|
-
timing: Timing = ...,
|
|
1411
|
-
counts: list[int] = ...,
|
|
1412
|
-
sense: Sense = ...,
|
|
1413
|
-
) -> Solution: ...
|
|
1414
|
-
@overload
|
|
1415
|
-
@staticmethod
|
|
1416
|
-
def from_dicts(
|
|
1417
|
-
data: list[dict[str, int | float]],
|
|
1418
|
-
*,
|
|
1419
|
-
env: Environment = ...,
|
|
1420
|
-
model: Model = ...,
|
|
1421
|
-
timing: Timing = ...,
|
|
1422
|
-
counts: list[int] = ...,
|
|
1423
|
-
sense: Sense = ...,
|
|
1424
|
-
) -> Solution: ...
|
|
1425
|
-
@overload
|
|
1426
|
-
@staticmethod
|
|
1427
|
-
def from_dicts(
|
|
1428
|
-
data: list[dict[Variable | str, int | float]],
|
|
1429
|
-
*,
|
|
1430
|
-
env: Environment = ...,
|
|
1431
|
-
model: Model = ...,
|
|
1432
|
-
timing: Timing = ...,
|
|
1433
|
-
counts: list[int] = ...,
|
|
1434
|
-
sense: Sense = ...,
|
|
1435
|
-
) -> Solution: ...
|
|
1436
1378
|
@staticmethod
|
|
1437
1379
|
def from_dicts(
|
|
1438
1380
|
data: list[dict[Variable | str, int | float]],
|
|
@@ -2066,13 +2008,124 @@ class Sense(Enum):
|
|
|
2066
2008
|
Max = ...
|
|
2067
2009
|
"""Indicate the objective function to be maximized."""
|
|
2068
2010
|
|
|
2011
|
+
class ConstraintType(Enum):
|
|
2012
|
+
"""
|
|
2013
|
+
Enumeration of constraint types supported by the optimization system.
|
|
2014
|
+
|
|
2015
|
+
This enum defines the type of constraint used within a model.
|
|
2016
|
+
"""
|
|
2017
|
+
|
|
2018
|
+
Unconstrained = ...
|
|
2019
|
+
"""The model contains no constraints, i.e., is unconstrained."""
|
|
2020
|
+
Equality = ...
|
|
2021
|
+
"""The model contains equality constraints (`Comparator.Eq`)."""
|
|
2022
|
+
Inequality = ...
|
|
2023
|
+
"""The model contains inequality constraints (`Comparator.Le`, `Comparator.Ge`).
|
|
2024
|
+
|
|
2025
|
+
implicitly includes the `ConstraintType.LessEqual` and `ConstraintType.GreaterEqual`
|
|
2026
|
+
options.
|
|
2027
|
+
"""
|
|
2028
|
+
LessEqual = ...
|
|
2029
|
+
"""The model contains less-equal-inequality constraints (`Comparator.Le`)."""
|
|
2030
|
+
GreaterEqual = ...
|
|
2031
|
+
"""The model contains greater-equal-inequality constraints (`Comparator.Ge`)."""
|
|
2032
|
+
|
|
2033
|
+
class ModelSpecs:
|
|
2034
|
+
"""A class containing sepcifications of a model."""
|
|
2035
|
+
|
|
2036
|
+
def __init__(
|
|
2037
|
+
self,
|
|
2038
|
+
/,
|
|
2039
|
+
*,
|
|
2040
|
+
sense: (Sense | None) = ...,
|
|
2041
|
+
vtypes: (list[Vtype] | None) = ...,
|
|
2042
|
+
constraints: (list[ConstraintType] | None) = ...,
|
|
2043
|
+
max_degree: (int | None) = ...,
|
|
2044
|
+
max_constraint_degree: (int | None) = ...,
|
|
2045
|
+
max_num_variables: (int | None) = ...,
|
|
2046
|
+
) -> None:
|
|
2047
|
+
"""Create a ModelSpec instance.
|
|
2048
|
+
|
|
2049
|
+
Parameters
|
|
2050
|
+
----------
|
|
2051
|
+
sense: Sense | None
|
|
2052
|
+
The exepected Sense of a model, default None.
|
|
2053
|
+
vtypes: list[Vtype] | None
|
|
2054
|
+
The exepected vtypes in a model, default None.
|
|
2055
|
+
constraints: list[ConstraintType] | None = ...,
|
|
2056
|
+
The exepected constraint types in a model, default None.
|
|
2057
|
+
max_degree: int | None
|
|
2058
|
+
The exepected maximum degree of the model's objective function,
|
|
2059
|
+
default None.
|
|
2060
|
+
max_constraint_degree: int | None
|
|
2061
|
+
The exepected maximum degree of the model's constraints, default None.
|
|
2062
|
+
max_num_variables: int | None
|
|
2063
|
+
The exepected maximum number of the variables in the model, default None.
|
|
2064
|
+
"""
|
|
2065
|
+
...
|
|
2066
|
+
|
|
2067
|
+
@property
|
|
2068
|
+
def sense(self) -> Sense | None:
|
|
2069
|
+
"""The sense specification, can be `None` if no sense spec is available."""
|
|
2070
|
+
...
|
|
2071
|
+
|
|
2072
|
+
@property
|
|
2073
|
+
def max_degree(self) -> int | None:
|
|
2074
|
+
"""The specification for the max degree of the objective function.
|
|
2075
|
+
|
|
2076
|
+
Can be `None` if no max_degree spec is available.
|
|
2077
|
+
"""
|
|
2078
|
+
...
|
|
2079
|
+
|
|
2080
|
+
@property
|
|
2081
|
+
def max_constraint_degree(self) -> int | None:
|
|
2082
|
+
"""The specification for the max degree of all constraints.
|
|
2083
|
+
|
|
2084
|
+
Can be `None` if no max_constraint_degree spec is available.
|
|
2085
|
+
"""
|
|
2086
|
+
...
|
|
2087
|
+
|
|
2088
|
+
@property
|
|
2089
|
+
def max_num_variables(self) -> int | None:
|
|
2090
|
+
"""The specification for the max number of variables in the model.
|
|
2091
|
+
|
|
2092
|
+
Can be `None` if no max_num_variables spec is available.
|
|
2093
|
+
"""
|
|
2094
|
+
...
|
|
2095
|
+
|
|
2096
|
+
@property
|
|
2097
|
+
def vtypes(self) -> list[Vtype] | None:
|
|
2098
|
+
"""The vtypes specification, can be `None` if no vtypes spec is available."""
|
|
2099
|
+
...
|
|
2100
|
+
|
|
2101
|
+
@property
|
|
2102
|
+
def constraints(self) -> list[ConstraintType] | None:
|
|
2103
|
+
"""
|
|
2104
|
+
The constraints specification.
|
|
2105
|
+
|
|
2106
|
+
Can be `None` if no constraints spec is available.
|
|
2107
|
+
"""
|
|
2108
|
+
...
|
|
2109
|
+
|
|
2110
|
+
def satisfies(self, other: ModelSpecs) -> bool:
|
|
2111
|
+
"""Check if `self` satisfies the model specs given in `other`.
|
|
2112
|
+
|
|
2113
|
+
Parameters
|
|
2114
|
+
----------
|
|
2115
|
+
other : ModelSpecs
|
|
2116
|
+
The model specifications `self` should satisfy.
|
|
2117
|
+
"""
|
|
2118
|
+
...
|
|
2119
|
+
|
|
2120
|
+
def __str__(self, /) -> str: ...
|
|
2121
|
+
|
|
2069
2122
|
class Model:
|
|
2070
2123
|
"""
|
|
2071
2124
|
A symbolic optimization model consisting of an objective and constraints.
|
|
2072
2125
|
|
|
2073
2126
|
The `Model` class represents a structured symbolic optimization problem. It
|
|
2074
|
-
combines a scalar objective `Expression`, a collection of `
|
|
2075
|
-
a shared `Environment` that scopes all variables used in the model.
|
|
2127
|
+
combines a scalar objective `Expression`, a collection of `ConstraintCollection`,
|
|
2128
|
+
and a shared `Environment` that scopes all variables used in the model.
|
|
2076
2129
|
|
|
2077
2130
|
Models can be constructed explicitly by passing an environment, or implicitly
|
|
2078
2131
|
by allowing the model to create its own private environment. If constructed
|
|
@@ -2338,12 +2391,12 @@ class Model:
|
|
|
2338
2391
|
...
|
|
2339
2392
|
|
|
2340
2393
|
@property
|
|
2341
|
-
def constraints(self, /) ->
|
|
2394
|
+
def constraints(self, /) -> ConstraintCollection:
|
|
2342
2395
|
"""Access the set of constraints associated with the model."""
|
|
2343
2396
|
...
|
|
2344
2397
|
|
|
2345
2398
|
@constraints.setter
|
|
2346
|
-
def constraints(self, value:
|
|
2399
|
+
def constraints(self, value: ConstraintCollection, /) -> None:
|
|
2347
2400
|
"""Replace the model's constraints with a new set."""
|
|
2348
2401
|
...
|
|
2349
2402
|
|
|
@@ -2466,7 +2519,7 @@ class Model:
|
|
|
2466
2519
|
"""
|
|
2467
2520
|
...
|
|
2468
2521
|
|
|
2469
|
-
def violated_constraints(self, /, sample: Sample) ->
|
|
2522
|
+
def violated_constraints(self, /, sample: Sample) -> ConstraintCollection:
|
|
2470
2523
|
"""
|
|
2471
2524
|
Get all model constraints that are violated by the given sample.
|
|
2472
2525
|
|
|
@@ -2477,7 +2530,7 @@ class Model:
|
|
|
2477
2530
|
|
|
2478
2531
|
Returns
|
|
2479
2532
|
-------
|
|
2480
|
-
|
|
2533
|
+
ConstraintCollection
|
|
2481
2534
|
The constraints violated by the given sample.
|
|
2482
2535
|
"""
|
|
2483
2536
|
...
|
|
@@ -2513,6 +2566,21 @@ class Model:
|
|
|
2513
2566
|
If the environments of `self`, `target`, and `replacement`
|
|
2514
2567
|
are not compatible.
|
|
2515
2568
|
"""
|
|
2569
|
+
...
|
|
2570
|
+
|
|
2571
|
+
def get_specs(self) -> ModelSpecs:
|
|
2572
|
+
"""Get this model's specs."""
|
|
2573
|
+
...
|
|
2574
|
+
|
|
2575
|
+
def satisfies(self, specs: ModelSpecs) -> bool:
|
|
2576
|
+
"""Check if the model satisfies the given specs.
|
|
2577
|
+
|
|
2578
|
+
Parameters
|
|
2579
|
+
----------
|
|
2580
|
+
specs : ModelSpecs
|
|
2581
|
+
The sepcs this model's specs are compared to.
|
|
2582
|
+
"""
|
|
2583
|
+
...
|
|
2516
2584
|
|
|
2517
2585
|
@overload
|
|
2518
2586
|
def encode(self, /) -> bytes: ...
|
|
@@ -3934,30 +4002,46 @@ class Constraint:
|
|
|
3934
4002
|
def __str__(self, /) -> str: ...
|
|
3935
4003
|
def __repr__(self, /) -> str: ...
|
|
3936
4004
|
|
|
3937
|
-
class
|
|
4005
|
+
class ConstraintCollectionIterator:
|
|
4006
|
+
"""
|
|
4007
|
+
Iterate over the name, constraint tuples of a constraint collection.
|
|
4008
|
+
|
|
4009
|
+
Examples
|
|
4010
|
+
--------
|
|
4011
|
+
>>> from luna_quantum import ConstraintCollection
|
|
4012
|
+
>>> coll: ConstraintCollection = ...
|
|
4013
|
+
for (name, constraint) in coll.items():
|
|
4014
|
+
...
|
|
4015
|
+
"""
|
|
4016
|
+
|
|
4017
|
+
def __next__(self) -> tuple[str, Constraint]: ...
|
|
4018
|
+
def __iter__(self) -> ConstraintCollectionIterator: ...
|
|
4019
|
+
|
|
4020
|
+
class ConstraintCollection:
|
|
3938
4021
|
"""
|
|
3939
4022
|
A collection of symbolic constraints used to define a model.
|
|
3940
4023
|
|
|
3941
|
-
The `
|
|
4024
|
+
The `ConstraintCollection` object serves as a container for individual `Constraint`
|
|
3942
4025
|
instances. It supports adding constraints programmatically and exporting
|
|
3943
4026
|
them for serialization.
|
|
3944
4027
|
|
|
3945
|
-
|
|
4028
|
+
ConstraintCollection are typically added using `add_constraint()`
|
|
4029
|
+
or the `+=` operator.
|
|
3946
4030
|
|
|
3947
4031
|
Examples
|
|
3948
4032
|
--------
|
|
3949
|
-
>>> from luna_quantum import
|
|
4033
|
+
>>> from luna_quantum import ConstraintCollection, Constraint, Environment, Variable
|
|
3950
4034
|
>>> with Environment():
|
|
3951
4035
|
... x = Variable("x")
|
|
3952
4036
|
... c = Constraint(x + 1, 0.0, Comparator.Le)
|
|
3953
4037
|
|
|
3954
|
-
>>> cs =
|
|
4038
|
+
>>> cs = ConstraintCollection()
|
|
3955
4039
|
>>> cs += x >= 1.0
|
|
3956
4040
|
|
|
3957
4041
|
Serialization:
|
|
3958
4042
|
|
|
3959
4043
|
>>> blob = cs.encode()
|
|
3960
|
-
>>> expr =
|
|
4044
|
+
>>> expr = ConstraintCollection.decode(blob)
|
|
3961
4045
|
|
|
3962
4046
|
Notes
|
|
3963
4047
|
-----
|
|
@@ -3985,6 +4069,10 @@ class Constraints:
|
|
|
3985
4069
|
"""
|
|
3986
4070
|
...
|
|
3987
4071
|
|
|
4072
|
+
def items(self, /) -> ConstraintCollectionIterator:
|
|
4073
|
+
"""Iterate over all items (`(name, constraint)`) in the collection."""
|
|
4074
|
+
...
|
|
4075
|
+
|
|
3988
4076
|
@overload
|
|
3989
4077
|
def encode(self, /) -> bytes: ...
|
|
3990
4078
|
@overload
|
|
@@ -4082,7 +4170,7 @@ class Constraints:
|
|
|
4082
4170
|
|
|
4083
4171
|
Returns
|
|
4084
4172
|
-------
|
|
4085
|
-
|
|
4173
|
+
ConstraintCollection
|
|
4086
4174
|
The updated collection.
|
|
4087
4175
|
|
|
4088
4176
|
Raises
|
|
@@ -4094,6 +4182,9 @@ class Constraints:
|
|
|
4094
4182
|
|
|
4095
4183
|
@overload
|
|
4096
4184
|
def get(self, item: str, /) -> Constraint: ...
|
|
4185
|
+
@deprecated(
|
|
4186
|
+
"Constraint access using int will be removed, use name (str) based indexing instead."
|
|
4187
|
+
)
|
|
4097
4188
|
@overload
|
|
4098
4189
|
def get(self, item: int, /) -> Constraint: ...
|
|
4099
4190
|
def get(self, item: (int | str), /) -> Constraint:
|
|
@@ -4102,22 +4193,31 @@ class Constraints:
|
|
|
4102
4193
|
|
|
4103
4194
|
@overload
|
|
4104
4195
|
def remove(self, item: str, /) -> Constraint: ...
|
|
4196
|
+
@deprecated(
|
|
4197
|
+
"Constraint access using int will be removed, use name (str) based indexing instead."
|
|
4198
|
+
)
|
|
4105
4199
|
@overload
|
|
4106
4200
|
def remove(self, item: int, /) -> Constraint: ...
|
|
4107
4201
|
def remove(self, item: (int | str), /) -> Constraint:
|
|
4108
4202
|
"""Remove a constraint for its name or index."""
|
|
4109
4203
|
...
|
|
4110
4204
|
|
|
4111
|
-
def __eq__(self, other:
|
|
4205
|
+
def __eq__(self, other: ConstraintCollection, /) -> bool: ...
|
|
4112
4206
|
def __str__(self, /) -> str: ...
|
|
4113
4207
|
def __repr__(self, /) -> str: ...
|
|
4114
4208
|
@overload
|
|
4115
4209
|
def __getitem__(self, item: str, /) -> Constraint: ...
|
|
4210
|
+
@deprecated(
|
|
4211
|
+
"Constraint access using int will be removed, use name (str) based indexing instead."
|
|
4212
|
+
)
|
|
4116
4213
|
@overload
|
|
4117
4214
|
def __getitem__(self, item: int, /) -> Constraint: ...
|
|
4118
4215
|
def __getitem__(self, item: (int | str), /) -> Constraint: ...
|
|
4119
4216
|
@overload
|
|
4120
4217
|
def __setitem__(self, item: str, content: Constraint, /) -> None: ...
|
|
4218
|
+
@deprecated(
|
|
4219
|
+
"Constraint access using int will be removed, use name (str) based indexing instead."
|
|
4220
|
+
)
|
|
4121
4221
|
@overload
|
|
4122
4222
|
def __setitem__(self, item: int, content: Constraint, /) -> None: ...
|
|
4123
4223
|
def __setitem__(self, item: (int | str), content: Constraint, /) -> None: ...
|
|
@@ -4128,18 +4228,19 @@ class Constraints:
|
|
|
4128
4228
|
Returns
|
|
4129
4229
|
-------
|
|
4130
4230
|
int
|
|
4131
|
-
The number of constraints associated with this `
|
|
4231
|
+
The number of constraints associated with this `ConstraintCollection`
|
|
4232
|
+
object.
|
|
4132
4233
|
"""
|
|
4133
4234
|
...
|
|
4134
4235
|
|
|
4135
4236
|
def __iter__(self, /) -> Iterator[Constraint]: ...
|
|
4136
|
-
def equal_contents(self, other:
|
|
4237
|
+
def equal_contents(self, other: ConstraintCollection, /) -> bool:
|
|
4137
4238
|
"""
|
|
4138
4239
|
Check whether this constraints has equal contents as `other`.
|
|
4139
4240
|
|
|
4140
4241
|
Parameters
|
|
4141
4242
|
----------
|
|
4142
|
-
other :
|
|
4243
|
+
other : ConstraintCollection
|
|
4143
4244
|
|
|
4144
4245
|
Returns
|
|
4145
4246
|
-------
|
|
@@ -4158,7 +4259,7 @@ __all__ = [
|
|
|
4158
4259
|
"Bounds",
|
|
4159
4260
|
"Comparator",
|
|
4160
4261
|
"Constraint",
|
|
4161
|
-
"
|
|
4262
|
+
"ConstraintCollection",
|
|
4162
4263
|
"Environment",
|
|
4163
4264
|
"Expression",
|
|
4164
4265
|
"Model",
|