Skip to content

Commit 1c02918

Browse files
committed
bonesis-attractors: add scope option
1 parent 0d59fa8 commit 1c02918

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

bonesis/cli.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,23 @@ def main_attractors():
9090
_setup_argument_domain(ap)
9191
ap.add_argument("--fixpoints-only", action="store_true",
9292
help="Enumerate only fixed points")
93+
ap.add_argument("--scope", default=None,
94+
help="List of nodes to display - JSON format")
9395
ap.add_argument("--limit", type=int,
9496
help="Maximum number of solutions")
9597
args = ap.parse_args()
9698

9799
bonesis.settings["quiet"] = True
98100

101+
scope = json.loads(args.scope) if args.scope else None
102+
99103
dom = _load_domain(args)
100104

101105
bo = bonesis.BoNesis(dom)
102106
x = bo.cfg() if args.fixpoints_only else bo.hypercube()
103107
bo.fixed(x)
104108

105-
it = x.assignments()
109+
it = x.assignments(scope=scope)
106110
if args.limit:
107111
it = islice(it, args.limit)
108112

bonesis/views.py

+16-14
Original file line numberDiff line numberDiff line change
@@ -340,29 +340,31 @@ def __iter__(self):
340340

341341
class ConfigurationView(BonesisView):
342342
project = True
343-
def __init__(self, cfg, *args, **kwargs):
343+
_pred_name = "cfg"
344+
def __init__(self, cfg, *args, scope=None, **kwargs):
344345
super().__init__(*args, **kwargs)
345346
self.cfg = cfg
347+
self.scope = scope
346348
def configure_show(self):
347349
name = symbol_of_py(self.cfg.name)
348-
self.control.add("base", [],
349-
"#show."
350-
f"#show cfg(X,N,V) : cfg(X,N,V), X={name}.")
350+
self.control.add("base", [], "#show.")
351+
if self.scope is not None:
352+
for n in self.scope:
353+
n = symbol_of_py(n)
354+
self.control.add("base", [], f"show_scope({self._pred_name}({name},{n})).")
355+
self.control.add("base", [], f"#show {self._pred_name}(X,N,V) : "
356+
f"{self._pred_name}(X,N,V), X={name},"
357+
f"show_scope({self._pred_name}(X,N)).")
358+
else:
359+
self.control.add("base", [], f"#show {self._pred_name}(X,N,V) :"
360+
f"{self._pred_name}(X,N,V), X={name}.")
351361
def format_model(self, model):
352362
atoms = model.symbols(shown=True)
353363
x = self.cfg.name
354364
return configurations_of_facts(atoms, keys=[x])[x]
355365

356-
class HypercubeView(BonesisView):
357-
project = True
358-
def __init__(self, h, *args, **kwargs):
359-
super().__init__(*args, **kwargs)
360-
self.h = h
361-
def configure_show(self):
362-
name = symbol_of_py(self.h.name)
363-
self.control.add("base", [],
364-
"#show."
365-
f"#show hypercube(X,N,V) : hypercube(X,N,V), X={name}.")
366+
class HypercubeView(ConfigurationView):
367+
_pred_name = "hypercube"
366368
def format_model(self, model):
367369
pairs = []
368370
for a in model.symbols(shown=True):

tests/hypercubes.py

+2
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@
2828

2929
for i, sol in enumerate(h.assignments()):
3030
print(i, sol)
31+
for i, sol in enumerate(h.assignments(scope=["a"])):
32+
print(i, sol)

tests/in_attractor.py

+2
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@
1212

1313
for v in x.assignments():
1414
print(v)
15+
for v in x.assignments(scope=["a","b"]):
16+
print(v)

0 commit comments

Comments
 (0)