flamapy 2.9.0.dev0__tar.gz → 2.9.0.dev1__tar.gz
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.
- {flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/PKG-INFO +12 -12
- {flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/flamapy/interfaces/python/flamapy_feature_model.py +132 -37
- {flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/flamapy.egg-info/PKG-INFO +12 -12
- {flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/flamapy.egg-info/SOURCES.txt +1 -0
- flamapy-2.9.0.dev1/flamapy.egg-info/requires.txt +26 -0
- {flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/pyproject.toml +12 -12
- {flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/tests/test_async_streaming.py +63 -0
- flamapy-2.9.0.dev1/tests/test_backend_level_warning.py +58 -0
- {flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/tests/test_planner_routing.py +68 -0
- flamapy-2.9.0.dev0/flamapy.egg-info/requires.txt +0 -26
- {flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/LICENSE +0 -0
- {flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/README.md +0 -0
- {flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/flamapy/commands/__init__.py +0 -0
- {flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/flamapy/interfaces/python/__init__.py +0 -0
- {flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/flamapy/interfaces/python/_stub.py +0 -0
- {flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/flamapy/interfaces/python/flamapy_feature_model.pyi +0 -0
- {flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/flamapy.egg-info/dependency_links.txt +0 -0
- {flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/flamapy.egg-info/entry_points.txt +0 -0
- {flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/flamapy.egg-info/top_level.txt +0 -0
- {flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/setup.cfg +0 -0
- {flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/setup.py +0 -0
- {flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/tests/test_2_9_compatibility.py +0 -0
- {flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/tests/test_basic_units.py +0 -0
- {flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/tests/test_cli_basic_units.py +0 -0
- {flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/tests/test_descriptors_cover_facade.py +0 -0
- {flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/tests/test_documentation_examples.py +0 -0
- {flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/tests/test_fama_suite_bdd.py +0 -0
- {flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/tests/test_fama_suite_sat.py +0 -0
- {flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/tests/test_metrics_fanout.py +0 -0
- {flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/tests/test_optimization_and_sampling.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flamapy
|
|
3
|
-
Version: 2.9.0.
|
|
3
|
+
Version: 2.9.0.dev1
|
|
4
4
|
Summary: Flamapy feature model is a distribution of the flama framework containing all plugins required to analyze feature models. It also offers a richer API and a complete command line interface and documentation.
|
|
5
5
|
Author-email: Flamapy <flamapy@us.es>
|
|
6
6
|
License-Expression: GPL-3.0-or-later
|
|
@@ -8,21 +8,21 @@ Project-URL: Homepage, https://github.com/flamapy/flamapy-feature-model
|
|
|
8
8
|
Requires-Python: >=3.11
|
|
9
9
|
Description-Content-Type: text/markdown
|
|
10
10
|
License-File: LICENSE
|
|
11
|
-
Requires-Dist: flamapy-fw~=2.9.0.
|
|
12
|
-
Requires-Dist: flamapy-fm~=2.9.0.
|
|
13
|
-
Requires-Dist: flamapy-sat~=2.9.0.
|
|
14
|
-
Requires-Dist: flamapy-bdd~=2.9.0.
|
|
15
|
-
Requires-Dist: flamapy-z3~=2.9.0.
|
|
11
|
+
Requires-Dist: flamapy-fw~=2.9.0.dev1
|
|
12
|
+
Requires-Dist: flamapy-fm~=2.9.0.dev1
|
|
13
|
+
Requires-Dist: flamapy-sat~=2.9.0.dev1
|
|
14
|
+
Requires-Dist: flamapy-bdd~=2.9.0.dev1
|
|
15
|
+
Requires-Dist: flamapy-z3~=2.9.0.dev1
|
|
16
16
|
Provides-Extra: sharpsat
|
|
17
|
-
Requires-Dist: flamapy-sharpsat~=2.9.0.
|
|
17
|
+
Requires-Dist: flamapy-sharpsat~=2.9.0.dev1; extra == "sharpsat"
|
|
18
18
|
Provides-Extra: dnnf
|
|
19
|
-
Requires-Dist: flamapy-dnnf~=2.9.0.
|
|
19
|
+
Requires-Dist: flamapy-dnnf~=2.9.0.dev1; extra == "dnnf"
|
|
20
20
|
Provides-Extra: sdd
|
|
21
|
-
Requires-Dist: flamapy-sdd~=2.9.0.
|
|
21
|
+
Requires-Dist: flamapy-sdd~=2.9.0.dev1; extra == "sdd"
|
|
22
22
|
Provides-Extra: all-solvers
|
|
23
|
-
Requires-Dist: flamapy-sharpsat~=2.9.0.
|
|
24
|
-
Requires-Dist: flamapy-dnnf~=2.9.0.
|
|
25
|
-
Requires-Dist: flamapy-sdd~=2.9.0.
|
|
23
|
+
Requires-Dist: flamapy-sharpsat~=2.9.0.dev1; extra == "all-solvers"
|
|
24
|
+
Requires-Dist: flamapy-dnnf~=2.9.0.dev1; extra == "all-solvers"
|
|
25
|
+
Requires-Dist: flamapy-sdd~=2.9.0.dev1; extra == "all-solvers"
|
|
26
26
|
Provides-Extra: dev
|
|
27
27
|
Requires-Dist: pytest; extra == "dev"
|
|
28
28
|
Requires-Dist: pytest-mock; extra == "dev"
|
{flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/flamapy/interfaces/python/flamapy_feature_model.py
RENAMED
|
@@ -82,6 +82,51 @@ def _raise_errors(setting: Optional[bool]) -> bool:
|
|
|
82
82
|
return setting if setting is not None else _env_flag('FLAMAPY_RAISE_ERRORS')
|
|
83
83
|
|
|
84
84
|
|
|
85
|
+
def _caller_stacklevel() -> int:
|
|
86
|
+
"""The ``warnings.warn`` stacklevel, for its caller, of the first frame outside this module:
|
|
87
|
+
the user's call, whichever facade entry point (operation method, iter_configurations) it
|
|
88
|
+
went through."""
|
|
89
|
+
frame = inspect.currentframe()
|
|
90
|
+
frame = frame.f_back if frame is not None else None # the function calling warnings.warn
|
|
91
|
+
level = 1
|
|
92
|
+
while frame is not None and frame.f_globals.get('__name__') == __name__:
|
|
93
|
+
frame = frame.f_back
|
|
94
|
+
level += 1
|
|
95
|
+
return level
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
@dataclasses.dataclass(frozen=True)
|
|
99
|
+
class _Route:
|
|
100
|
+
"""How one call's backend was chosen. It travels with the call (never stored on the
|
|
101
|
+
facade), so concurrent ``run_async`` jobs on one facade cannot see each other's."""
|
|
102
|
+
# The backend name as requested or defaulted; None for an fm-level operation.
|
|
103
|
+
name: Optional[str] = None
|
|
104
|
+
# True when the choice is the query planner's (backend='auto').
|
|
105
|
+
auto: bool = False
|
|
106
|
+
# None (historical default), 'explicit', or 'auto: <planner rationale>'.
|
|
107
|
+
planner: Optional[str] = None
|
|
108
|
+
# Set when the backend ignores part of the model (its manifest does not support the
|
|
109
|
+
# model's language level): the warning to emit; the result is then not exact.
|
|
110
|
+
level_gap: Optional[str] = None
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def _stamp(envelope: OperationResult[Any], route: _Route,
|
|
114
|
+
model: VariabilityModel) -> OperationResult[Any]:
|
|
115
|
+
"""Record on a result envelope how its backend was chosen and whether it is exact."""
|
|
116
|
+
if route.planner is not None:
|
|
117
|
+
envelope = dataclasses.replace(envelope, planner=route.planner)
|
|
118
|
+
if route.level_gap is not None:
|
|
119
|
+
envelope = dataclasses.replace(envelope, exact=False)
|
|
120
|
+
if getattr(model, '_flamapy_cache_hit', False):
|
|
121
|
+
envelope = dataclasses.replace(envelope, cache_hit=True)
|
|
122
|
+
return envelope
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _warn_level_gap(route: _Route) -> None:
|
|
126
|
+
if route.level_gap is not None:
|
|
127
|
+
warnings.warn(route.level_gap, UserWarning, stacklevel=_caller_stacklevel())
|
|
128
|
+
|
|
129
|
+
|
|
85
130
|
class FLAMAFeatureModel:
|
|
86
131
|
"""A feature model together with the analysis operations discovered from the installed plugins.
|
|
87
132
|
|
|
@@ -125,9 +170,6 @@ class FLAMAFeatureModel:
|
|
|
125
170
|
# wall time, model hash). Purely informational in 2.9; methods still return bare
|
|
126
171
|
# values. In 3.0 the envelope becomes the return type.
|
|
127
172
|
self.last_result: Optional[OperationResult] = None
|
|
128
|
-
# How the last operation's backend was chosen: None (historical default),
|
|
129
|
-
# 'explicit', or 'auto: <planner rationale>'.
|
|
130
|
-
self._last_planner: Optional[str] = None
|
|
131
173
|
self._model_language_level: Optional[LanguageLevel] = None
|
|
132
174
|
|
|
133
175
|
def _read(self, model_path: str) -> FeatureModel:
|
|
@@ -147,21 +189,15 @@ class FLAMAFeatureModel:
|
|
|
147
189
|
return Configuration(configuration)
|
|
148
190
|
return self.discover_metamodel.use_transformation_t2m(configuration, "configuration")
|
|
149
191
|
|
|
150
|
-
def
|
|
151
|
-
|
|
152
|
-
allow_approximate: Optional[bool] = None,
|
|
153
|
-
) -> VariabilityModel:
|
|
154
|
-
"""Resolve the operation's target model, lazily transforming (and caching) fm->backend.
|
|
192
|
+
def _route(self, descriptor: OperationDescriptor, backend_arg: Optional[str]) -> _Route:
|
|
193
|
+
"""Decide which backend a call runs on, without building anything.
|
|
155
194
|
|
|
156
195
|
The backend is the per-call one > workspace default > the ``FLAMAPY_BACKEND``
|
|
157
196
|
environment variable > the operation's default (for backend-selectable ops), or
|
|
158
197
|
simply the fixed default. The value ``'auto'`` (opt-in) hands the choice to the
|
|
159
|
-
query planner
|
|
160
|
-
|
|
161
|
-
directly. Otherwise the name is mapped to a transformation extension (only
|
|
162
|
-
``sat -> pysat`` differs) and cached per extension.
|
|
198
|
+
query planner; ``None`` (an fm-level op, or a selectable op with no backend
|
|
199
|
+
requested) runs the operation on the feature model directly.
|
|
163
200
|
"""
|
|
164
|
-
self._last_planner = None
|
|
165
201
|
defaults_apply = (descriptor.selectable_backend
|
|
166
202
|
and descriptor.name not in _SELECTABLE_SINCE_2_9)
|
|
167
203
|
workspace_default = (self.backend or os.environ.get('FLAMAPY_BACKEND')
|
|
@@ -171,14 +207,61 @@ class FLAMAFeatureModel:
|
|
|
171
207
|
else:
|
|
172
208
|
resolved = descriptor.default_backend
|
|
173
209
|
if resolved is None:
|
|
174
|
-
return
|
|
210
|
+
return _Route()
|
|
175
211
|
name = resolved.value if isinstance(resolved, Backend) else str(resolved)
|
|
176
212
|
if name == Backend.AUTO.value and descriptor.selectable_backend:
|
|
177
|
-
return
|
|
178
|
-
|
|
179
|
-
|
|
213
|
+
return _Route(name=name, auto=True)
|
|
214
|
+
return _Route(
|
|
215
|
+
name=name,
|
|
216
|
+
planner='explicit' if backend_arg or workspace_default else None,
|
|
217
|
+
level_gap=self._level_gap(name, descriptor.selectable_backend))
|
|
218
|
+
|
|
219
|
+
def _level_gap(self, name: str, selectable: bool) -> Optional[str]:
|
|
220
|
+
"""The warning for a backend whose manifest does not support the model's language
|
|
221
|
+
level (e.g. sat/bdd ignore arithmetic constraints), or None when it does.
|
|
222
|
+
|
|
223
|
+
In 2.9 this only warns, and the result is marked inexact; flamapy 3.0 raises
|
|
224
|
+
NoCompatibleBackendError instead, like backend='auto' does when no installed plugin
|
|
225
|
+
supports the model.
|
|
226
|
+
"""
|
|
180
227
|
extension = _BACKEND_ALIAS.get(name, name)
|
|
181
|
-
|
|
228
|
+
try:
|
|
229
|
+
manifest = self.discover_metamodel.plugins.get_plugin_by_extension(extension).manifest
|
|
230
|
+
except PluginNotFound:
|
|
231
|
+
return None # an unknown backend fails later, when its model is built
|
|
232
|
+
model_level = self._language_level()
|
|
233
|
+
if manifest.supports(model_level):
|
|
234
|
+
return None
|
|
235
|
+
advice = ''
|
|
236
|
+
if selectable and self._z3_supports(model_level) and name != Backend.Z3.value:
|
|
237
|
+
advice = " Use backend='auto' or backend='z3'."
|
|
238
|
+
return (f"The '{name}' backend supports ({manifest.supported_level}), but this model "
|
|
239
|
+
f"is ({model_level}): constraints beyond the backend's level are ignored, so "
|
|
240
|
+
f"the result is not exact.{advice}")
|
|
241
|
+
|
|
242
|
+
def _z3_supports(self, model_level: LanguageLevel) -> bool:
|
|
243
|
+
try:
|
|
244
|
+
plugin = self.discover_metamodel.plugins.get_plugin_by_extension(Backend.Z3.value)
|
|
245
|
+
except PluginNotFound:
|
|
246
|
+
return False
|
|
247
|
+
return plugin.manifest.supports(model_level)
|
|
248
|
+
|
|
249
|
+
def _model_for(
|
|
250
|
+
self, descriptor: OperationDescriptor, route: _Route,
|
|
251
|
+
allow_approximate: Optional[bool] = None,
|
|
252
|
+
) -> tuple[VariabilityModel, _Route]:
|
|
253
|
+
"""Build the route's target model, lazily transforming (and caching) fm->backend.
|
|
254
|
+
|
|
255
|
+
A backend name is mapped to a transformation extension (only ``sat -> pysat``
|
|
256
|
+
differs) and cached per extension. Returns the route too: for ``'auto'`` it now
|
|
257
|
+
carries the planner's rationale.
|
|
258
|
+
"""
|
|
259
|
+
if route.name is None:
|
|
260
|
+
return self.fm_model, route
|
|
261
|
+
if route.auto:
|
|
262
|
+
return self._model_via_planner(
|
|
263
|
+
descriptor, route, self._approximate_allowed(allow_approximate))
|
|
264
|
+
return self._backend_model(_BACKEND_ALIAS.get(route.name, route.name)), route
|
|
182
265
|
|
|
183
266
|
def _backend_model(self, extension: str) -> VariabilityModel:
|
|
184
267
|
if extension == self.fm_model.get_extension():
|
|
@@ -237,24 +320,32 @@ class FLAMAFeatureModel:
|
|
|
237
320
|
raise FlamaException(f"'{operation}' is not a backend-selectable facade operation.")
|
|
238
321
|
return self._plan_operation(operation, self._approximate_allowed(allow_approximate))
|
|
239
322
|
|
|
240
|
-
def _model_via_planner(self, descriptor: OperationDescriptor,
|
|
241
|
-
allow_approximate: bool = False) -> VariabilityModel:
|
|
323
|
+
def _model_via_planner(self, descriptor: OperationDescriptor, route: _Route,
|
|
324
|
+
allow_approximate: bool = False) -> tuple[VariabilityModel, _Route]:
|
|
242
325
|
chosen = self._plan_operation(descriptor.name, allow_approximate)
|
|
243
|
-
|
|
326
|
+
route = dataclasses.replace(route, planner=f'auto: {chosen.rationale}')
|
|
244
327
|
model = self.fm_model
|
|
245
328
|
for _, destination in chosen.transformation_chain:
|
|
246
329
|
if destination not in self._backend_models:
|
|
247
330
|
self._backend_models[destination] = (
|
|
248
331
|
self.discover_metamodel.use_transformation_m2m(model, destination))
|
|
249
332
|
model = self._backend_models[destination]
|
|
250
|
-
return model
|
|
333
|
+
return model, route
|
|
251
334
|
|
|
252
335
|
def _prepare_operation(
|
|
253
336
|
self, descriptor: OperationDescriptor, backend_arg: Optional[str],
|
|
254
337
|
call_kwargs: Dict[str, Any], allow_approximate: Optional[bool] = None,
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
model
|
|
338
|
+
route: Optional[_Route] = None,
|
|
339
|
+
) -> tuple[Any, VariabilityModel, _Route]:
|
|
340
|
+
"""Resolve the target model and a fully input-wired operation instance.
|
|
341
|
+
|
|
342
|
+
``route`` is passed by a caller that already decided it (and warned) on the user's
|
|
343
|
+
thread; otherwise it is decided, and its warning emitted, here.
|
|
344
|
+
"""
|
|
345
|
+
if route is None:
|
|
346
|
+
route = self._route(descriptor, backend_arg)
|
|
347
|
+
_warn_level_gap(route)
|
|
348
|
+
model, route = self._model_for(descriptor, route, allow_approximate)
|
|
258
349
|
operation = self.discover_metamodel.get_operation(model, descriptor.operation)
|
|
259
350
|
if descriptor.input_adapter is not None:
|
|
260
351
|
descriptor.input_adapter(operation, self, call_kwargs)
|
|
@@ -267,7 +358,7 @@ class FLAMAFeatureModel:
|
|
|
267
358
|
value = self._as_configuration(value)
|
|
268
359
|
if input_spec.setter is not None:
|
|
269
360
|
getattr(operation, input_spec.setter)(value)
|
|
270
|
-
return operation, model
|
|
361
|
+
return operation, model, route
|
|
271
362
|
|
|
272
363
|
def _run_operation(
|
|
273
364
|
self, descriptor: OperationDescriptor, call_kwargs: Dict[str, Any]
|
|
@@ -282,7 +373,7 @@ class FLAMAFeatureModel:
|
|
|
282
373
|
try:
|
|
283
374
|
backend_arg = call_kwargs.pop('backend', None)
|
|
284
375
|
allow_approximate = call_kwargs.pop('allow_approximate', None)
|
|
285
|
-
operation, model = self._prepare_operation(
|
|
376
|
+
operation, model, route = self._prepare_operation(
|
|
286
377
|
descriptor, backend_arg, call_kwargs, allow_approximate)
|
|
287
378
|
# The hash is always the source feature model's (memoized there), whichever
|
|
288
379
|
# backend model the operation actually runs on.
|
|
@@ -293,10 +384,7 @@ class FLAMAFeatureModel:
|
|
|
293
384
|
if descriptor.result_adapter is not None:
|
|
294
385
|
envelope = dataclasses.replace(
|
|
295
386
|
envelope, value=descriptor.result_adapter(envelope.value))
|
|
296
|
-
|
|
297
|
-
envelope = dataclasses.replace(envelope, planner=self._last_planner)
|
|
298
|
-
if getattr(model, '_flamapy_cache_hit', False):
|
|
299
|
-
envelope = dataclasses.replace(envelope, cache_hit=True)
|
|
387
|
+
envelope = _stamp(envelope, route, model)
|
|
300
388
|
self.last_result = envelope
|
|
301
389
|
return envelope.value
|
|
302
390
|
except FlamaException as exception:
|
|
@@ -324,10 +412,12 @@ class FLAMAFeatureModel:
|
|
|
324
412
|
expiry (after requesting cooperative cancellation) — unlike the 2.x synchronous
|
|
325
413
|
methods, errors are **raised**, not swallowed into ``None``.
|
|
326
414
|
|
|
327
|
-
Everything after
|
|
415
|
+
Everything after choosing the backend runs inside the job — including the
|
|
328
416
|
fm->backend transformation (e.g. BDD compilation, often the expensive step on large
|
|
329
417
|
models) — so the timeout covers it and preparation errors (unknown backend,
|
|
330
|
-
invalid inputs) are raised by ``job.result()``.
|
|
418
|
+
invalid inputs) are raised by ``job.result()``. The envelope (``job.envelope()``)
|
|
419
|
+
carries the same provenance as the synchronous ``last_result``; the warning about a
|
|
420
|
+
backend that ignores part of the model is emitted here, by the call itself.
|
|
331
421
|
"""
|
|
332
422
|
method = getattr(type(self), operation, None)
|
|
333
423
|
descriptor = getattr(method, '_facade_descriptor', None)
|
|
@@ -336,10 +426,14 @@ class FLAMAFeatureModel:
|
|
|
336
426
|
call_kwargs = dict(kwargs)
|
|
337
427
|
backend_arg = call_kwargs.pop('backend', None)
|
|
338
428
|
allow_approximate = call_kwargs.pop('allow_approximate', None)
|
|
429
|
+
# Decided (and warned about) on the caller's thread: the route belongs to this job
|
|
430
|
+
# alone, and a warning raised from the worker would point into the thread pool.
|
|
431
|
+
route = self._route(descriptor, backend_arg)
|
|
432
|
+
_warn_level_gap(route)
|
|
339
433
|
|
|
340
434
|
def task(interrupt_event: threading.Event) -> OperationResult[Any]:
|
|
341
|
-
prepared, model = self._prepare_operation(
|
|
342
|
-
descriptor, backend_arg, call_kwargs, allow_approximate)
|
|
435
|
+
prepared, model, job_route = self._prepare_operation(
|
|
436
|
+
descriptor, backend_arg, call_kwargs, allow_approximate, route)
|
|
343
437
|
if interrupt_event.is_set():
|
|
344
438
|
# The deadline expired (or cancel() was called) during preparation: the
|
|
345
439
|
# caller has already given up, so don't start the operation at all.
|
|
@@ -347,10 +441,11 @@ class FLAMAFeatureModel:
|
|
|
347
441
|
f"'{descriptor.name}' was cancelled before execution started.")
|
|
348
442
|
if isinstance(prepared, Interruptible):
|
|
349
443
|
prepared.set_interrupt_event(interrupt_event)
|
|
350
|
-
|
|
444
|
+
envelope = run_and_wrap(
|
|
351
445
|
prepared, model,
|
|
352
446
|
operation_name=descriptor.name, plugin=self._plugin_name_for(model),
|
|
353
447
|
model_hash=self.fm_model.canonical_hash())
|
|
448
|
+
return _stamp(envelope, job_route, model)
|
|
354
449
|
|
|
355
450
|
return default_engine().submit_call(task, result_adapter=descriptor.result_adapter)
|
|
356
451
|
|
|
@@ -363,7 +458,7 @@ class FLAMAFeatureModel:
|
|
|
363
458
|
:meth:`run_async` (raises, never ``None``).
|
|
364
459
|
"""
|
|
365
460
|
descriptor = type(self).configurations._facade_descriptor # type: ignore[attr-defined]
|
|
366
|
-
operation, model = self._prepare_operation(descriptor, backend or 'sat', {})
|
|
461
|
+
operation, model, _ = self._prepare_operation(descriptor, backend or 'sat', {})
|
|
367
462
|
if isinstance(operation, StreamingOperation):
|
|
368
463
|
return operation.iter_execute(model)
|
|
369
464
|
operation.execute(model)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flamapy
|
|
3
|
-
Version: 2.9.0.
|
|
3
|
+
Version: 2.9.0.dev1
|
|
4
4
|
Summary: Flamapy feature model is a distribution of the flama framework containing all plugins required to analyze feature models. It also offers a richer API and a complete command line interface and documentation.
|
|
5
5
|
Author-email: Flamapy <flamapy@us.es>
|
|
6
6
|
License-Expression: GPL-3.0-or-later
|
|
@@ -8,21 +8,21 @@ Project-URL: Homepage, https://github.com/flamapy/flamapy-feature-model
|
|
|
8
8
|
Requires-Python: >=3.11
|
|
9
9
|
Description-Content-Type: text/markdown
|
|
10
10
|
License-File: LICENSE
|
|
11
|
-
Requires-Dist: flamapy-fw~=2.9.0.
|
|
12
|
-
Requires-Dist: flamapy-fm~=2.9.0.
|
|
13
|
-
Requires-Dist: flamapy-sat~=2.9.0.
|
|
14
|
-
Requires-Dist: flamapy-bdd~=2.9.0.
|
|
15
|
-
Requires-Dist: flamapy-z3~=2.9.0.
|
|
11
|
+
Requires-Dist: flamapy-fw~=2.9.0.dev1
|
|
12
|
+
Requires-Dist: flamapy-fm~=2.9.0.dev1
|
|
13
|
+
Requires-Dist: flamapy-sat~=2.9.0.dev1
|
|
14
|
+
Requires-Dist: flamapy-bdd~=2.9.0.dev1
|
|
15
|
+
Requires-Dist: flamapy-z3~=2.9.0.dev1
|
|
16
16
|
Provides-Extra: sharpsat
|
|
17
|
-
Requires-Dist: flamapy-sharpsat~=2.9.0.
|
|
17
|
+
Requires-Dist: flamapy-sharpsat~=2.9.0.dev1; extra == "sharpsat"
|
|
18
18
|
Provides-Extra: dnnf
|
|
19
|
-
Requires-Dist: flamapy-dnnf~=2.9.0.
|
|
19
|
+
Requires-Dist: flamapy-dnnf~=2.9.0.dev1; extra == "dnnf"
|
|
20
20
|
Provides-Extra: sdd
|
|
21
|
-
Requires-Dist: flamapy-sdd~=2.9.0.
|
|
21
|
+
Requires-Dist: flamapy-sdd~=2.9.0.dev1; extra == "sdd"
|
|
22
22
|
Provides-Extra: all-solvers
|
|
23
|
-
Requires-Dist: flamapy-sharpsat~=2.9.0.
|
|
24
|
-
Requires-Dist: flamapy-dnnf~=2.9.0.
|
|
25
|
-
Requires-Dist: flamapy-sdd~=2.9.0.
|
|
23
|
+
Requires-Dist: flamapy-sharpsat~=2.9.0.dev1; extra == "all-solvers"
|
|
24
|
+
Requires-Dist: flamapy-dnnf~=2.9.0.dev1; extra == "all-solvers"
|
|
25
|
+
Requires-Dist: flamapy-sdd~=2.9.0.dev1; extra == "all-solvers"
|
|
26
26
|
Provides-Extra: dev
|
|
27
27
|
Requires-Dist: pytest; extra == "dev"
|
|
28
28
|
Requires-Dist: pytest-mock; extra == "dev"
|
|
@@ -15,6 +15,7 @@ flamapy/interfaces/python/flamapy_feature_model.py
|
|
|
15
15
|
flamapy/interfaces/python/flamapy_feature_model.pyi
|
|
16
16
|
tests/test_2_9_compatibility.py
|
|
17
17
|
tests/test_async_streaming.py
|
|
18
|
+
tests/test_backend_level_warning.py
|
|
18
19
|
tests/test_basic_units.py
|
|
19
20
|
tests/test_cli_basic_units.py
|
|
20
21
|
tests/test_descriptors_cover_facade.py
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
flamapy-fw~=2.9.0.dev1
|
|
2
|
+
flamapy-fm~=2.9.0.dev1
|
|
3
|
+
flamapy-sat~=2.9.0.dev1
|
|
4
|
+
flamapy-bdd~=2.9.0.dev1
|
|
5
|
+
flamapy-z3~=2.9.0.dev1
|
|
6
|
+
|
|
7
|
+
[all-solvers]
|
|
8
|
+
flamapy-sharpsat~=2.9.0.dev1
|
|
9
|
+
flamapy-dnnf~=2.9.0.dev1
|
|
10
|
+
flamapy-sdd~=2.9.0.dev1
|
|
11
|
+
|
|
12
|
+
[dev]
|
|
13
|
+
pytest
|
|
14
|
+
pytest-mock
|
|
15
|
+
prospector
|
|
16
|
+
mypy
|
|
17
|
+
coverage
|
|
18
|
+
|
|
19
|
+
[dnnf]
|
|
20
|
+
flamapy-dnnf~=2.9.0.dev1
|
|
21
|
+
|
|
22
|
+
[sdd]
|
|
23
|
+
flamapy-sdd~=2.9.0.dev1
|
|
24
|
+
|
|
25
|
+
[sharpsat]
|
|
26
|
+
flamapy-sharpsat~=2.9.0.dev1
|
|
@@ -4,30 +4,30 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "flamapy"
|
|
7
|
-
version = "2.9.0.
|
|
7
|
+
version = "2.9.0.dev1"
|
|
8
8
|
description = "Flamapy feature model is a distribution of the flama framework containing all plugins required to analyze feature models. It also offers a richer API and a complete command line interface and documentation."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "GPL-3.0-or-later"
|
|
11
11
|
authors = [{ name = "Flamapy", email = "flamapy@us.es" }]
|
|
12
12
|
requires-python = ">=3.11"
|
|
13
13
|
dependencies = [
|
|
14
|
-
"flamapy-fw~=2.9.0.
|
|
15
|
-
"flamapy-fm~=2.9.0.
|
|
16
|
-
"flamapy-sat~=2.9.0.
|
|
17
|
-
"flamapy-bdd~=2.9.0.
|
|
18
|
-
"flamapy-z3~=2.9.0.
|
|
14
|
+
"flamapy-fw~=2.9.0.dev1",
|
|
15
|
+
"flamapy-fm~=2.9.0.dev1",
|
|
16
|
+
"flamapy-sat~=2.9.0.dev1",
|
|
17
|
+
"flamapy-bdd~=2.9.0.dev1",
|
|
18
|
+
"flamapy-z3~=2.9.0.dev1",
|
|
19
19
|
]
|
|
20
20
|
|
|
21
21
|
[project.optional-dependencies]
|
|
22
22
|
# Optional solver backends: not part of the default install, selectable per call
|
|
23
23
|
# (e.g. backend='sharpsat') or per model (FLAMAFeatureModel(path, backend=...)).
|
|
24
|
-
sharpsat = ["flamapy-sharpsat~=2.9.0.
|
|
25
|
-
dnnf = ["flamapy-dnnf~=2.9.0.
|
|
26
|
-
sdd = ["flamapy-sdd~=2.9.0.
|
|
24
|
+
sharpsat = ["flamapy-sharpsat~=2.9.0.dev1"]
|
|
25
|
+
dnnf = ["flamapy-dnnf~=2.9.0.dev1"]
|
|
26
|
+
sdd = ["flamapy-sdd~=2.9.0.dev1"]
|
|
27
27
|
all-solvers = [
|
|
28
|
-
"flamapy-sharpsat~=2.9.0.
|
|
29
|
-
"flamapy-dnnf~=2.9.0.
|
|
30
|
-
"flamapy-sdd~=2.9.0.
|
|
28
|
+
"flamapy-sharpsat~=2.9.0.dev1",
|
|
29
|
+
"flamapy-dnnf~=2.9.0.dev1",
|
|
30
|
+
"flamapy-sdd~=2.9.0.dev1",
|
|
31
31
|
]
|
|
32
32
|
dev = [
|
|
33
33
|
"pytest",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""The additive async + streaming facade API (v2.9 / Track A phase 6)."""
|
|
2
2
|
import subprocess
|
|
3
3
|
import time
|
|
4
|
+
import warnings
|
|
4
5
|
|
|
5
6
|
import pytest
|
|
6
7
|
|
|
@@ -96,3 +97,65 @@ def test_cli_timeout_flag_passes_fast_operations():
|
|
|
96
97
|
capture_output=True, text=True, check=False)
|
|
97
98
|
assert completed.returncode == 0
|
|
98
99
|
assert completed.stdout.strip() == 'True'
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
# --- flamapy#3: a backend that ignores part of the model, through run_async --------------------
|
|
103
|
+
|
|
104
|
+
_ARITHMETIC_UNSAT = (
|
|
105
|
+
"features\n"
|
|
106
|
+
" A\n"
|
|
107
|
+
" mandatory\n"
|
|
108
|
+
" B {Fun 8}\n"
|
|
109
|
+
"constraints\n"
|
|
110
|
+
" B.Fun < 7\n"
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def _arithmetic_model(tmp_path):
|
|
115
|
+
path = tmp_path / "arithmetic.uvl"
|
|
116
|
+
path.write_text(_ARITHMETIC_UNSAT)
|
|
117
|
+
return FLAMAFeatureModel(str(path))
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
@pytest.mark.parametrize("backend", ['sat', 'bdd'])
|
|
121
|
+
def test_run_async_marks_a_result_beyond_the_backend_level_inexact(tmp_path, backend):
|
|
122
|
+
fm = _arithmetic_model(tmp_path)
|
|
123
|
+
# The warning comes from the run_async call itself, on the caller's thread and line.
|
|
124
|
+
with pytest.warns(UserWarning, match='the result is not exact') as record:
|
|
125
|
+
job = fm.run_async('satisfiable', backend=backend)
|
|
126
|
+
assert record[0].filename == __file__
|
|
127
|
+
envelope = job.envelope(timeout=30)
|
|
128
|
+
assert envelope.exact is False and envelope.planner == 'explicit'
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def test_run_async_envelope_matches_the_sync_provenance(tmp_path):
|
|
132
|
+
fm = _arithmetic_model(tmp_path)
|
|
133
|
+
for backend in ('z3', 'auto'):
|
|
134
|
+
with warnings.catch_warnings():
|
|
135
|
+
warnings.simplefilter('error', UserWarning)
|
|
136
|
+
job = fm.run_async('satisfiable', backend=backend)
|
|
137
|
+
assert job.result(timeout=30) is False
|
|
138
|
+
fm.satisfiable(backend=backend)
|
|
139
|
+
envelope = job.envelope()
|
|
140
|
+
assert envelope.exact is True
|
|
141
|
+
assert envelope.planner == fm.last_result.planner
|
|
142
|
+
assert envelope.backend == fm.last_result.backend
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def test_concurrent_jobs_do_not_share_their_provenance(tmp_path):
|
|
146
|
+
# Many jobs on ONE facade, alternating a backend that ignores the arithmetic constraint
|
|
147
|
+
# (inexact) with one that does not: each envelope must carry its own verdict.
|
|
148
|
+
fm = _arithmetic_model(tmp_path)
|
|
149
|
+
backends = ['sat', 'z3', 'bdd', 'auto'] * 6
|
|
150
|
+
with warnings.catch_warnings():
|
|
151
|
+
warnings.simplefilter('ignore', UserWarning)
|
|
152
|
+
jobs = [(backend, fm.run_async('satisfiable', backend=backend)) for backend in backends]
|
|
153
|
+
for backend, job in jobs:
|
|
154
|
+
envelope = job.envelope(timeout=60)
|
|
155
|
+
inexact = backend in ('sat', 'bdd')
|
|
156
|
+
assert envelope.exact is (not inexact), backend
|
|
157
|
+
assert envelope.value is inexact, backend # the dropped constraint makes it "sat"
|
|
158
|
+
if backend == 'auto':
|
|
159
|
+
assert envelope.planner.startswith('auto: ')
|
|
160
|
+
else:
|
|
161
|
+
assert envelope.planner == 'explicit'
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""Forcing a backend that cannot represent the model's language level (e.g. 'sat'/'bdd' on a
|
|
2
|
+
model with arithmetic constraints) silently drops those constraints. The facade must then warn
|
|
3
|
+
that the result is not exact, instead of reporting a confidently-wrong result. A model the
|
|
4
|
+
backend *can* handle must not warn. Regression test for flamapy/flamapy#3.
|
|
5
|
+
"""
|
|
6
|
+
import warnings
|
|
7
|
+
|
|
8
|
+
import pytest
|
|
9
|
+
|
|
10
|
+
from flamapy.interfaces.python.flamapy_feature_model import FLAMAFeatureModel
|
|
11
|
+
|
|
12
|
+
# B is mandatory with Fun=8, so `B.Fun < 7` is constant-false: the model is UNSAT. The sat/bdd
|
|
13
|
+
# backends only support BOOLEAN+GROUP_CARDINALITY, so they drop the arithmetic constraint.
|
|
14
|
+
ARITHMETIC_MODEL = (
|
|
15
|
+
"features\n"
|
|
16
|
+
" A\n"
|
|
17
|
+
" mandatory\n"
|
|
18
|
+
" B {Fun 8}\n"
|
|
19
|
+
"constraints\n"
|
|
20
|
+
" B.Fun < 7\n"
|
|
21
|
+
)
|
|
22
|
+
BOOLEAN_MODEL = (
|
|
23
|
+
"features\n"
|
|
24
|
+
" A\n"
|
|
25
|
+
" mandatory\n"
|
|
26
|
+
" B\n"
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _model(tmp_path, text: str) -> FLAMAFeatureModel:
|
|
31
|
+
path = tmp_path / "model.uvl"
|
|
32
|
+
path.write_text(text)
|
|
33
|
+
return FLAMAFeatureModel(str(path))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _warning_messages(call) -> list[str]:
|
|
37
|
+
with warnings.catch_warnings(record=True) as recorded:
|
|
38
|
+
warnings.simplefilter("always")
|
|
39
|
+
call()
|
|
40
|
+
return [str(w.message) for w in recorded]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def test_sat_on_arithmetic_model_warns(tmp_path) -> None:
|
|
44
|
+
fm = _model(tmp_path, ARITHMETIC_MODEL)
|
|
45
|
+
with pytest.warns(UserWarning, match="not exact"):
|
|
46
|
+
fm.satisfiable(backend="sat")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_bdd_on_arithmetic_model_warns(tmp_path) -> None:
|
|
50
|
+
fm = _model(tmp_path, ARITHMETIC_MODEL)
|
|
51
|
+
with pytest.warns(UserWarning, match="not exact"):
|
|
52
|
+
fm.configurations_number(backend="bdd")
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_sat_on_boolean_model_does_not_warn(tmp_path) -> None:
|
|
56
|
+
fm = _model(tmp_path, BOOLEAN_MODEL)
|
|
57
|
+
messages = _warning_messages(lambda: fm.satisfiable(backend="sat"))
|
|
58
|
+
assert not any("not exact" in m for m in messages)
|
|
@@ -143,3 +143,71 @@ def test_raise_errors_opts_into_the_3_0_contract():
|
|
|
143
143
|
with pytest.raises(FlamaException):
|
|
144
144
|
strict.satisfiable(backend='sharpsat_is_not_a_backend')
|
|
145
145
|
assert strict.satisfiable() is True
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
# --- explicit backends below the model's language level (issue #3) -----------------------------
|
|
149
|
+
|
|
150
|
+
# B is mandatory with Fun = 8, so the arithmetic constraint makes the model unsatisfiable; the
|
|
151
|
+
# SAT/BDD encodings drop it.
|
|
152
|
+
ARITHMETIC_UNSATISFIABLE_MODEL = (
|
|
153
|
+
'features\n'
|
|
154
|
+
' A\n'
|
|
155
|
+
' mandatory\n'
|
|
156
|
+
' B {Fun 8}\n'
|
|
157
|
+
'constraints\n'
|
|
158
|
+
' B.Fun < 7\n'
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
@pytest.fixture
|
|
163
|
+
def arithmetic_model(tmp_path):
|
|
164
|
+
path = tmp_path / 'arithmetic_unsatisfiable.uvl'
|
|
165
|
+
path.write_text(ARITHMETIC_UNSATISFIABLE_MODEL)
|
|
166
|
+
return str(path)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
@pytest.mark.parametrize('backend', ['sat', 'bdd', None])
|
|
170
|
+
def test_backend_below_the_model_level_warns_and_is_not_exact(arithmetic_model, backend):
|
|
171
|
+
fm = FLAMAFeatureModel(arithmetic_model)
|
|
172
|
+
with pytest.warns(UserWarning, match="constraints beyond the backend's level are ignored"):
|
|
173
|
+
fm.satisfiable(backend=backend)
|
|
174
|
+
assert fm.last_result.exact is False
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
@pytest.mark.parametrize('backend', ['z3', 'auto'])
|
|
178
|
+
def test_backend_supporting_the_model_level_does_not_warn(arithmetic_model, backend, recwarn):
|
|
179
|
+
fm = FLAMAFeatureModel(arithmetic_model)
|
|
180
|
+
assert fm.satisfiable(backend=backend) is False
|
|
181
|
+
assert fm.last_result.exact is True
|
|
182
|
+
assert not [w for w in recwarn if issubclass(w.category, UserWarning)]
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
@pytest.mark.parametrize('backend', ['sat', 'bdd'])
|
|
186
|
+
def test_boolean_model_does_not_warn(backend, recwarn):
|
|
187
|
+
fm = FLAMAFeatureModel(VALID_MODEL)
|
|
188
|
+
assert fm.satisfiable(backend=backend) is True
|
|
189
|
+
assert fm.last_result.exact is True
|
|
190
|
+
assert not [w for w in recwarn if issubclass(w.category, UserWarning)]
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def test_inexact_flag_does_not_leak_into_the_next_call(arithmetic_model):
|
|
194
|
+
fm = FLAMAFeatureModel(arithmetic_model)
|
|
195
|
+
with pytest.warns(UserWarning):
|
|
196
|
+
fm.satisfiable(backend='sat')
|
|
197
|
+
assert fm.last_result.exact is False
|
|
198
|
+
assert fm.satisfiable(backend='z3') is False
|
|
199
|
+
assert fm.last_result.exact is True
|
|
200
|
+
assert fm.leaf_features() == ['B'] # fm-level: never checked against a backend level
|
|
201
|
+
assert fm.last_result.exact is True
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def test_level_warning_only_recommends_a_backend_that_supports_the_model(tmp_path):
|
|
205
|
+
# Feature cardinalities are beyond every backend, z3 included: no backend to recommend.
|
|
206
|
+
path = tmp_path / "feature_cardinality.uvl"
|
|
207
|
+
path.write_text("features\n Root\n optional\n A cardinality [1..3]\n")
|
|
208
|
+
fm = FLAMAFeatureModel(str(path))
|
|
209
|
+
for backend in ('sat', 'z3'):
|
|
210
|
+
with pytest.warns(UserWarning, match='the result is not exact') as record:
|
|
211
|
+
fm.satisfiable(backend=backend)
|
|
212
|
+
assert 'Use backend=' not in str(record[0].message)
|
|
213
|
+
assert fm.last_result.exact is False
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
flamapy-fw~=2.9.0.dev0
|
|
2
|
-
flamapy-fm~=2.9.0.dev0
|
|
3
|
-
flamapy-sat~=2.9.0.dev0
|
|
4
|
-
flamapy-bdd~=2.9.0.dev0
|
|
5
|
-
flamapy-z3~=2.9.0.dev0
|
|
6
|
-
|
|
7
|
-
[all-solvers]
|
|
8
|
-
flamapy-sharpsat~=2.9.0.dev0
|
|
9
|
-
flamapy-dnnf~=2.9.0.dev0
|
|
10
|
-
flamapy-sdd~=2.9.0.dev0
|
|
11
|
-
|
|
12
|
-
[dev]
|
|
13
|
-
pytest
|
|
14
|
-
pytest-mock
|
|
15
|
-
prospector
|
|
16
|
-
mypy
|
|
17
|
-
coverage
|
|
18
|
-
|
|
19
|
-
[dnnf]
|
|
20
|
-
flamapy-dnnf~=2.9.0.dev0
|
|
21
|
-
|
|
22
|
-
[sdd]
|
|
23
|
-
flamapy-sdd~=2.9.0.dev0
|
|
24
|
-
|
|
25
|
-
[sharpsat]
|
|
26
|
-
flamapy-sharpsat~=2.9.0.dev0
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{flamapy-2.9.0.dev0 → flamapy-2.9.0.dev1}/flamapy/interfaces/python/flamapy_feature_model.pyi
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|