summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2021-02-03 19:12:03 +0100
committerMassimiliano Culpo <massimiliano.culpo@gmail.com>2021-05-21 15:09:04 +0200
commit94bb37c1070c1f032d805e0b7f7622cf736ada14 (patch)
tree8b75ae30f3d8a06496b9688bcc2b2f60bc97ae7b /lib
parenta59fcd60f5a47b8a7e5ffa561a1211dc7a0eb6f7 (diff)
downloadspack-94bb37c1070c1f032d805e0b7f7622cf736ada14.tar.gz
spack-94bb37c1070c1f032d805e0b7f7622cf736ada14.tar.bz2
spack-94bb37c1070c1f032d805e0b7f7622cf736ada14.tar.xz
spack-94bb37c1070c1f032d805e0b7f7622cf736ada14.zip
concretizer: simplify "fact" method (#21148)
The "fact" method before was dealing with multiple facts registered per call, which was used when we were emitting grounded rules from knowledge of the problem instance. Now that the encoding is changed we can simplify the method to deal only with a single fact per call. (cherry picked from commit ba42c36f00fe40c047121a32117018eb93e0c4b1)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/solver/asp.py28
1 files changed, 5 insertions, 23 deletions
diff --git a/lib/spack/spack/solver/asp.py b/lib/spack/spack/solver/asp.py
index 84753c0b25..e36b5a3d3c 100644
--- a/lib/spack/spack/solver/asp.py
+++ b/lib/spack/spack/solver/asp.py
@@ -210,19 +210,6 @@ class Result(object):
*sorted(str(symbol) for symbol in core))
-def _normalize(body):
- """Accept an AspAnd object or a single Symbol and return a list of
- symbols.
- """
- if isinstance(body, clingo.Symbol):
- args = [body]
- elif hasattr(body, 'symbol'):
- args = [body.symbol()]
- else:
- raise TypeError("Invalid typee: ", type(body))
- return args
-
-
def _normalize_packages_yaml(packages_yaml):
normalized_yaml = copy.copy(packages_yaml)
for pkg_name in packages_yaml:
@@ -280,19 +267,14 @@ class PyclingoDriver(object):
def fact(self, head):
"""ASP fact (a rule without a body)."""
- symbols = _normalize(head)
- self.out.write("%s.\n" % ','.join(str(a) for a in symbols))
+ symbol = head.symbol() if hasattr(head, 'symbol') else head
- atoms = {}
- for s in symbols:
- atoms[s] = self.backend.add_atom(s)
+ self.out.write("%s.\n" % str(symbol))
- self.backend.add_rule(
- [atoms[s] for s in symbols], [], choice=self.cores
- )
+ atom = self.backend.add_atom(symbol)
+ self.backend.add_rule([atom], [], choice=self.cores)
if self.cores:
- for s in symbols:
- self.assumptions.append(atoms[s])
+ self.assumptions.append(atom)
def solve(
self, solver_setup, specs, dump=None, nmodels=0,