flamapy-sdd 2.6.0.dev6__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.
File without changes
@@ -0,0 +1,4 @@
1
+ from .sdd_model import SDDModel
2
+
3
+
4
+ __all__ = ['SDDModel']
@@ -0,0 +1,27 @@
1
+ from typing import Any, Optional
2
+
3
+ from flamapy.core.models import VariabilityModel
4
+
5
+
6
+ class SDDModel(VariabilityModel):
7
+ """A Sentential Decision Diagram (SDD) representation of a feature model.
8
+
9
+ An SDD is a knowledge-compilation form (a subset of d-DNNF, strictly more succinct than
10
+ OBDD in cases) that supports exact, polytime queries: model counting, consistency and
11
+ conditioning. It is built by compiling the feature model's CNF with the ``PySDD`` library.
12
+ """
13
+
14
+ @staticmethod
15
+ def get_extension() -> str:
16
+ return 'sdd'
17
+
18
+ def __init__(self) -> None:
19
+ self.manager: Any = None # pysdd SddManager
20
+ self.root: Any = None # pysdd SddNode (the compiled formula)
21
+ self.variables: dict[str, int] = {} # feature name -> SDD variable index (1-based)
22
+ self.features: dict[int, str] = {} # SDD variable index -> feature name
23
+ self.original_model: Optional[VariabilityModel] = None
24
+
25
+ def feature_variables(self) -> list[int]:
26
+ """SDD variable indices that correspond to features."""
27
+ return list(self.features.keys())
@@ -0,0 +1,12 @@
1
+ from .sdd_configurations_number import SDDConfigurationsNumber
2
+ from .sdd_satisfiable import SDDSatisfiable
3
+ from .sdd_core_features import SDDCoreFeatures
4
+ from .sdd_dead_features import SDDDeadFeatures
5
+
6
+
7
+ __all__ = [
8
+ 'SDDConfigurationsNumber',
9
+ 'SDDCoreFeatures',
10
+ 'SDDDeadFeatures',
11
+ 'SDDSatisfiable',
12
+ ]
@@ -0,0 +1,29 @@
1
+ from typing import cast
2
+
3
+ from flamapy.core.models import VariabilityModel
4
+ from flamapy.core.operations import ConfigurationsNumber
5
+ from flamapy.metamodels.sdd_metamodel.models import SDDModel
6
+
7
+
8
+ class SDDConfigurationsNumber(ConfigurationsNumber):
9
+ """Exact number of valid configurations, via SDD model counting.
10
+
11
+ Model counting is a polytime query on the compiled SDD, so this is exact and — for models
12
+ whose SDD stays compact — scales to cases where explicit enumeration does not.
13
+ """
14
+
15
+ def __init__(self) -> None:
16
+ self._result = 0
17
+
18
+ def get_configurations_number(self) -> int:
19
+ return self._result
20
+
21
+ def get_result(self) -> int:
22
+ return self._result
23
+
24
+ def execute(self, model: VariabilityModel) -> 'SDDConfigurationsNumber':
25
+ sdd_model = cast(SDDModel, model)
26
+ # global_model_count counts over every declared variable; SddNode.model_count only
27
+ # counts over the variables the node locally depends on (its own vtree context).
28
+ self._result = int(sdd_model.manager.global_model_count(sdd_model.root))
29
+ return self
@@ -0,0 +1,32 @@
1
+ from typing import Any, cast
2
+
3
+ from flamapy.core.models import VariabilityModel
4
+ from flamapy.core.operations import CoreFeatures
5
+ from flamapy.metamodels.sdd_metamodel.models import SDDModel
6
+
7
+
8
+ class SDDCoreFeatures(CoreFeatures):
9
+ """Core features: present in every valid configuration.
10
+
11
+ A feature is core iff no model selects it as false, i.e. conjoining its negative literal
12
+ with the compiled SDD yields the false node.
13
+ """
14
+
15
+ def __init__(self) -> None:
16
+ self._result: list[Any] = []
17
+
18
+ def get_core_features(self) -> list[Any]:
19
+ return self._result
20
+
21
+ def get_result(self) -> list[Any]:
22
+ return self._result
23
+
24
+ def execute(self, model: VariabilityModel) -> 'SDDCoreFeatures':
25
+ sdd_model = cast(SDDModel, model)
26
+ manager = sdd_model.manager
27
+ core = []
28
+ for variable, name in sdd_model.features.items():
29
+ if (sdd_model.root & manager.literal(-variable)).is_false():
30
+ core.append(name)
31
+ self._result = core
32
+ return self
@@ -0,0 +1,32 @@
1
+ from typing import Any, cast
2
+
3
+ from flamapy.core.models import VariabilityModel
4
+ from flamapy.core.operations import DeadFeatures
5
+ from flamapy.metamodels.sdd_metamodel.models import SDDModel
6
+
7
+
8
+ class SDDDeadFeatures(DeadFeatures):
9
+ """Dead features: present in no valid configuration.
10
+
11
+ A feature is dead iff no model selects it as true, i.e. conjoining its positive literal
12
+ with the compiled SDD yields the false node.
13
+ """
14
+
15
+ def __init__(self) -> None:
16
+ self._result: list[Any] = []
17
+
18
+ def get_dead_features(self) -> list[Any]:
19
+ return self._result
20
+
21
+ def get_result(self) -> list[Any]:
22
+ return self._result
23
+
24
+ def execute(self, model: VariabilityModel) -> 'SDDDeadFeatures':
25
+ sdd_model = cast(SDDModel, model)
26
+ manager = sdd_model.manager
27
+ dead = []
28
+ for variable, name in sdd_model.features.items():
29
+ if (sdd_model.root & manager.literal(variable)).is_false():
30
+ dead.append(name)
31
+ self._result = dead
32
+ return self
@@ -0,0 +1,23 @@
1
+ from typing import cast
2
+
3
+ from flamapy.core.models import VariabilityModel
4
+ from flamapy.core.operations import Satisfiable
5
+ from flamapy.metamodels.sdd_metamodel.models import SDDModel
6
+
7
+
8
+ class SDDSatisfiable(Satisfiable):
9
+ """Whether the feature model is satisfiable (non-void): the SDD is not the false node."""
10
+
11
+ def __init__(self) -> None:
12
+ self._result = False
13
+
14
+ def is_satisfiable(self) -> bool:
15
+ return self._result
16
+
17
+ def get_result(self) -> bool:
18
+ return self._result
19
+
20
+ def execute(self, model: VariabilityModel) -> 'SDDSatisfiable':
21
+ sdd_model = cast(SDDModel, model)
22
+ self._result = not sdd_model.root.is_false()
23
+ return self
@@ -0,0 +1,4 @@
1
+ from .fm_to_sdd import FmToSDD
2
+
3
+
4
+ __all__ = ['FmToSDD']
@@ -0,0 +1,55 @@
1
+ from pysdd.sdd import SddManager, Vtree
2
+
3
+ from flamapy.core.transformations import ModelToModel
4
+ from flamapy.metamodels.fm_metamodel.models import FeatureModel
5
+ from flamapy.metamodels.pysat_metamodel.transformations import FmToPysat
6
+ from flamapy.metamodels.sdd_metamodel.models import SDDModel
7
+
8
+
9
+ class FmToSDD(ModelToModel):
10
+ """Transform a feature model into an SDD by compiling its CNF with PySDD.
11
+
12
+ The CNF is produced by reusing the SAT metamodel's ``FmToPysat`` transformation, then
13
+ conjoined clause by clause into an SDD over a balanced vtree.
14
+ """
15
+
16
+ @staticmethod
17
+ def get_source_extension() -> str:
18
+ return 'fm'
19
+
20
+ @staticmethod
21
+ def get_destination_extension() -> str:
22
+ return 'sdd'
23
+
24
+ def __init__(self, source_model: FeatureModel, cnf_method: str = 'distributive') -> None:
25
+ self.source_model = source_model
26
+ self.cnf_method = cnf_method
27
+ self.destination_model = SDDModel()
28
+
29
+ def transform(self) -> SDDModel:
30
+ # Only pass cnf_method for a non-default encoding, so the plugin also works against
31
+ # releases of flamapy-sat that predate the Tseytin cnf_method option.
32
+ if self.cnf_method == 'distributive':
33
+ sat_model = FmToPysat(self.source_model).transform()
34
+ else:
35
+ sat_model = FmToPysat(self.source_model, cnf_method=self.cnf_method).transform()
36
+
37
+ clauses = [list(clause) for clause in sat_model.get_all_clauses().clauses]
38
+ var_count = max((abs(literal) for clause in clauses for literal in clause), default=1)
39
+
40
+ vtree = Vtree(var_count=var_count, vtree_type='balanced')
41
+ manager = SddManager.from_vtree(vtree)
42
+ root = manager.true()
43
+ for clause in clauses:
44
+ clause_node = manager.false()
45
+ for literal in clause:
46
+ clause_node = clause_node | manager.literal(literal)
47
+ root = root & clause_node
48
+
49
+ model = self.destination_model
50
+ model.manager = manager
51
+ model.root = root
52
+ model.variables = dict(sat_model.variables)
53
+ model.features = dict(sat_model.features)
54
+ model.original_model = self.source_model
55
+ return model
@@ -0,0 +1,67 @@
1
+ Metadata-Version: 2.4
2
+ Name: flamapy-sdd
3
+ Version: 2.6.0.dev6
4
+ Summary: flamapy-sdd is a plugin to flamapy providing Sentential Decision Diagram (SDD) knowledge compilation for exact analysis of feature models
5
+ Author-email: Flamapy <flamapy@us.es>
6
+ License-Expression: GPL-3.0-or-later
7
+ Project-URL: Homepage, https://github.com/flamapy/sdd_metamodel
8
+ Requires-Python: >=3.11
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: flamapy-fw~=2.6.0.dev5
12
+ Requires-Dist: flamapy-fm~=2.6.0.dev5
13
+ Requires-Dist: flamapy-sat~=2.6.0.dev5
14
+ Requires-Dist: PySDD~=1.0
15
+ Provides-Extra: dev
16
+ Requires-Dist: pytest; extra == "dev"
17
+ Requires-Dist: pytest-mock; extra == "dev"
18
+ Requires-Dist: prospector; extra == "dev"
19
+ Requires-Dist: mypy; extra == "dev"
20
+ Requires-Dist: coverage; extra == "dev"
21
+ Dynamic: license-file
22
+
23
+ # flamapy-sdd
24
+
25
+ `flamapy-sdd` is a [flamapy](https://flamapy.github.io) plugin that compiles a feature model
26
+ into a **Sentential Decision Diagram (SDD)** for exact analysis.
27
+
28
+ SDD is a knowledge-compilation language (a subset of d-DNNF, strictly more succinct than OBDD
29
+ in cases), so it supports exact, polytime queries — model counting, consistency, conditioning —
30
+ and can stay compact on models where a BDD blows up. It complements the ecosystem:
31
+
32
+ - `flamapy-bdd` compiles to OBDD (exact, but can explode on large models).
33
+ - `flamapy-sharpsat` gives an *approximate* count (ApproxMC) for very large models.
34
+ - `flamapy-sdd` gives an **exact** count via a more succinct compilation, on top of the SAT CNF.
35
+
36
+ It uses [PySDD](https://github.com/wannesm/PySDD).
37
+
38
+ ## Installation
39
+
40
+ ```
41
+ pip install flamapy-sdd
42
+ ```
43
+
44
+ ## Operations
45
+
46
+ | Operation | Class |
47
+ |---|---|
48
+ | Exact number of configurations | `SDDConfigurationsNumber` |
49
+ | Satisfiable (non-void) | `SDDSatisfiable` |
50
+ | Core features | `SDDCoreFeatures` |
51
+ | Dead features | `SDDDeadFeatures` |
52
+
53
+ ## Usage
54
+
55
+ ```python
56
+ from flamapy.metamodels.fm_metamodel.transformations import UVLReader
57
+ from flamapy.metamodels.sdd_metamodel.transformations import FmToSDD
58
+ from flamapy.metamodels.sdd_metamodel.operations import SDDConfigurationsNumber
59
+
60
+ fm = UVLReader('model.uvl').transform()
61
+ sdd_model = FmToSDD(fm).transform()
62
+ count = SDDConfigurationsNumber().execute(sdd_model).get_result()
63
+ ```
64
+
65
+ ## License
66
+
67
+ GPL-3.0-or-later.
@@ -0,0 +1,15 @@
1
+ flamapy/metamodels/sdd_metamodel/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ flamapy/metamodels/sdd_metamodel/models/__init__.py,sha256=bR7xcBcfqNqhYnOAZc-Pro66wYeLulQVW3lH1gzIOrM,57
3
+ flamapy/metamodels/sdd_metamodel/models/sdd_model.py,sha256=QIQ4t6ba7ygy55qztlNCMn2a30Ok8uP0oBSrOSlL1Ko,1105
4
+ flamapy/metamodels/sdd_metamodel/operations/__init__.py,sha256=NrgZpLepc_a5UaW-cifCn62kCPDx3LfFTugUqT6mQTU,316
5
+ flamapy/metamodels/sdd_metamodel/operations/sdd_configurations_number.py,sha256=WLbCywogkoMZdsoiEqReldzPUJ04suEvu4gLFesNLx0,1104
6
+ flamapy/metamodels/sdd_metamodel/operations/sdd_core_features.py,sha256=K2-xRbBBmYB03-BhTt8cuI37rttg1KGG2bVu3vVnPN8,1031
7
+ flamapy/metamodels/sdd_metamodel/operations/sdd_dead_features.py,sha256=JpbWkFzVRs_2fvk0GKmpHgCAQIRR5Df7BBUkr8Rw42g,1026
8
+ flamapy/metamodels/sdd_metamodel/operations/sdd_satisfiable.py,sha256=e7L1eWlmR8WQyjQrbNO6IbSdDna7tpEX8UuZCqz4uN4,690
9
+ flamapy/metamodels/sdd_metamodel/transformations/__init__.py,sha256=-lqZfRPHTUimN4Z8eSiF6yp4lLucbQkv7QnF5F5pD-E,55
10
+ flamapy/metamodels/sdd_metamodel/transformations/fm_to_sdd.py,sha256=8c0AJZubzevWPI4y762AqLTSJtKSbchfZoCIPaSJfms,2180
11
+ flamapy_sdd-2.6.0.dev6.dist-info/licenses/LICENSE,sha256=46mU2C5kSwOnkqkw9XQAJlhBL2JAf1_uCD8lVcXyMRg,7652
12
+ flamapy_sdd-2.6.0.dev6.dist-info/METADATA,sha256=m7OyFMlgIGs7Afrzg7CJT6LxQuAUdrkKQCzGEKxe4Bs,2276
13
+ flamapy_sdd-2.6.0.dev6.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
14
+ flamapy_sdd-2.6.0.dev6.dist-info/top_level.txt,sha256=2YBI9dg4GVk28AJuyNu6dldi5Riwt5SP0zpNe2lSU5M,8
15
+ flamapy_sdd-2.6.0.dev6.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
@@ -0,0 +1 @@
1
+ flamapy