Skip to content

Commit

Permalink
fix: partial commit with improvements. Still some tests do not pass
Browse files Browse the repository at this point in the history
  • Loading branch information
jagalindo committed Jul 23, 2024
1 parent 5452a2b commit 314f939
Show file tree
Hide file tree
Showing 18 changed files with 261 additions and 701 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flamapy-fm
pip install prospector[with_everything]==1.10.2
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
pip install prospector[with_everything]==1.10.3
pip install .
- name: Analysing the code with prospector
run: |
source venv/bin/activate
prospector
mypy:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -52,4 +55,4 @@ jobs:
pip install pytest==5.4.3
- name: Running test
run: |
python -m pytest
python -m pytest tests/unit_tests/diagnosis_test.py::test_fastdiag_with_configuration
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from flamapy.metamodels.configuration_metamodel.models import Configuration

from flamapy.metamodels.pysat_metamodel.models import PySATModel

from flamapy.metamodels.fm_metamodel.models.feature_model import Feature

class DiagnosisModel(PySATModel):
"""
Expand Down Expand Up @@ -164,9 +164,14 @@ def _prepare_assumptions_for_kb(self, assumption: List[int], id_assumption: int)

return id_assumption

def _convert_keys_to_features(self, configuration: 'Configuration') -> 'Configuration':
new_elements = {Feature(key) if isinstance(key, str) else key: value for key, value in configuration.elements.items()}
return Configuration(new_elements)

def _prepare_assumptions_for_configuration(self, assumption: List[int],
configuration: Configuration,
id_assumption: int) -> int:
configuration = self._convert_keys_to_features(configuration)
config = [feat.name for feat in configuration.elements]
for feat in config:
if feat not in self.variables.keys():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# pylint: disable=cyclic-import

from .pysat_abstract_identifier import PySATAbstractIdentifier
from .pysat_conflict import PySATConflict
from .pysat_diagnosis import PySATDiagnosis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


class ConsistencyChecker:

def __init__(self, solver_name: str, set_kb: List[List[int]]) -> None:
self.result = False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
A Java version of this implementation is available at:
https://github.com/HiConfiT/hiconfit-core/blob/main/ca-cdr-package/src/main/java/at/tugraz/ist/ase/cacdr/algorithms/hs/HSDAG.java
"""
from typing import List, Optional, Dict
from typing import List, Optional, Dict, Union

from .labeler.labeler import IHSLabelable, LabelerType, AbstractHSParameters
from .node import Node, NodeStatus
Expand Down Expand Up @@ -234,7 +234,7 @@ def get_reusable_labels(self, node: Node) -> List[List[int]]:
labels.append(label)
return labels

def get_reusable_node(self, path_labels: List[int], arc_label: int) -> Node | None:
def get_reusable_node(self, path_labels: List[int], arc_label: int) -> Union[Node, None]:
if len(path_labels) == 0:
new_path_labels = [arc_label]
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ def get_destination_extension() -> str:
def __init__(self, source_model: FeatureModel) -> None:
super().__init__(source_model)
self.destination_model = DiagnosisModel()


def add_root(self, feature: Feature) -> None:
#self.r_cnf.append([self.destination_model.variables.get(feature.name)])

var = self.destination_model.variables.get(feature.name)
if var is None:
raise KeyError(f'Feature {feature.name} not found in the model')
Expand All @@ -48,7 +45,7 @@ def get_term_variable(term: Any) -> int:
negated = True

var = self.destination_model.get_variable(term)

if negated:
return -var
return var
Expand All @@ -60,5 +57,4 @@ def get_term_variable(term: Any) -> int:
ctc_clauses.append(clause_variables)
self.destination_model.add_clause(clause_variables)

self.destination_model.add_clause_to_map(str(ctc), ctc_clauses)

self.destination_model.add_clause_to_map(str(ctc), ctc_clauses)
2 changes: 2 additions & 0 deletions flamapy/metamodels/pysat_metamodel/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# pylint: disable=cyclic-import

from .pysat_model import PySATModel
from .txtcnf_model import (
TextCNFModel,
Expand Down
4 changes: 2 additions & 2 deletions flamapy/metamodels/pysat_metamodel/models/txtcnf_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ def extract_variables(cnf_formula: str) -> list[str]:
if ')' in clauses[len(clauses) - 1]:
clauses[len(clauses) - 1] = clauses[len(clauses) - 1][:-1]

for clause in clauses:
tokens = flamapy.metamodels.pysat_metamodel.operations.diagnosis.utils.split(' ')
for _clause in clauses:
tokens = flamapy.metamodels.pysat_metamodel.operations.diagnosis.utils.split(' ') # type: ignore[name-defined] # pylint: disable=undefined-variable # noqa: F821, E501
tokens = list(filter(lambda t: t != cnf_notation.value[CNFLogicConnective.OR], tokens))
for feature in tokens:
if feature == cnf_notation.value[CNFLogicConnective.NOT]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from flamapy.metamodels.pysat_metamodel.models.pysat_model import PySATModel
from flamapy.core.models import VariabilityModel


class PySATConfigurations(Configurations):

def __init__(self) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from flamapy.metamodels.pysat_metamodel import operations as sat_operations


def metric_method(func: Callable) -> Callable:
def metric_method(func: Callable[..., Any]) -> Callable[..., Any]:
"""Decorator to mark a method as a metric method.
It has the value of the measure, it can also have a size and a ratio.
Example:
Expand Down Expand Up @@ -61,7 +61,8 @@ def satisfiable(self) -> dict[str, Any]:
raise FlamaException('Model not initialized.')
name = "Satisfiable"
_satisfiable = sat_operations.PySATSatisfiable().execute(self.model).get_result()
result = self.construct_result(name=name, doc=self.satisfiable.__doc__, result=_satisfiable)
result = self.construct_result(name=name,
doc=self.satisfiable.__doc__, result=_satisfiable)
return result

@metric_method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def set_configuration(self, configuration: Configuration, is_full: bool) -> None

def execute(self, model: VariabilityModel) -> 'PySATSatisfiableConfiguration':
sat_model = cast(PySATModel, model)

for clause in sat_model.get_all_clauses(): # AC es conjunto de conjuntos
self.solver.add_clause(clause) # añadimos la constraint

if not self.is_full:
assumptions = []
for feature, selected in self.configuration.elements.items():
Expand All @@ -40,23 +40,24 @@ def execute(self, model: VariabilityModel) -> 'PySATSatisfiableConfiguration':
else:
assumptions.append(-sat_model.variables[feature])
else:
missing_features = [feature for feature in self.configuration.elements.keys() if feature not in sat_model.variables.keys()]

missing_features = [feature for feature in self.configuration.elements.keys()
if feature not in sat_model.variables.keys()]

if missing_features:
print("The features that are missing are:", [feature for feature in missing_features])
print("The feature model contains the following features:", list(sat_model.variables.keys()))
print("The features that are missing are:", list(missing_features))
print("The feature model contains the following features:",
list(sat_model.variables.keys()))
self.result = False
return self


assumptions = []
for feature in sat_model.features.values():

if feature in self.configuration.elements.keys():
assumptions.append(sat_model.variables[feature])
else:
assumptions.append(-sat_model.variables[feature])

self.result = self.solver.solve(assumptions=assumptions)
self.solver.delete()
return self
return self
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _extract_clauses(self, cnf_formula: str, cnf_notation: TextCNFNotation) -> N
clauses[len(clauses) - 1] = clauses[len(clauses) - 1][:-1]

for _c in clauses:
tokens = flamapy.metamodels.pysat_metamodel.operations.diagnosis.utils.split(' ')
tokens = flamapy.metamodels.pysat_metamodel.operations.diagnosis.utils.split(' ') # type: ignore[name-defined] # noqa: F821, E501
tokens = list(filter(lambda t: t != cnf_notation.value[CNFLogicConnective.OR], tokens))
logic_not = False
cnf_clause = []
Expand Down
41 changes: 0 additions & 41 deletions python-publish.yml

This file was deleted.

4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
flamapy-fw~=2.0.0.dev2
flamapy-fm~=2.0.0.dev2
flamapy-fw~=2.0.0.dev4
flamapy-fm~=2.0.0.dev5
python-sat~=0.1.7.dev1
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def read_requirements(file):

setuptools.setup(
name="flamapy-sat",
version="2.0.0.dev2",
version="2.0.0.dev3",
author="Flamapy",
author_email="[email protected]",
description="flamapy-sat is a plugin to flamapy module",
Expand Down
Loading

0 comments on commit 314f939

Please sign in to comment.