Skip to content

Commit

Permalink
add graph type support clingraph
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanzwicknagl committed Jul 4, 2023
1 parent e7212f0 commit 6909daf
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
6 changes: 4 additions & 2 deletions backend/src/viasp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,22 +301,24 @@ def relax_constraints(*args, **kwargs) -> viaspControl:
connector = _get_connector(**kwargs)
return connector.relax_constraints(head_name, collect_variables)

def clingraph(viz_encoding, engine, **kwargs) -> None:
def clingraph(viz_encoding, engine="dot", graphviz_type="graph", **kwargs) -> None:
r"""
Generate the a clingraph from the marked models and the visualization encoding.
:param viz_encoding: ``str``
The path to the visualization encoding.
:param engine: ``str``
The visualization engine. See ``clingraph`` for more details.
:param graphviz_type: ``str``
The graph type. See ``clingraph`` for more details.
:param kwargs:
* *viasp_backend_url* (``str``) --
url of the viasp backend
* *_viasp_client* (``ClingoClient``) --
a viasp client object
"""
connector = _get_connector(**kwargs)
connector.clingraph(viz_encoding, engine)
connector.clingraph(viz_encoding, engine, graphviz_type)

def register_transformer(transformer: Transformer, imports: str = "", path: str = "", **kwargs) -> None:
r"""
Expand Down
4 changes: 2 additions & 2 deletions backend/src/viasp/clingoApiClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ def relax_constraints(self, *args, **kwargs):
error(f"Transforming constraints failed [{r.status_code}] ({r.reason})")
return None

def clingraph(self, viz_encoding_path, engine):
def clingraph(self, viz_encoding_path, engine, graphviz_type):
with open(viz_encoding_path, "r") as f:
prg = f.read().splitlines()
prg = '\n'.join(prg)

serialized = json.dumps({"viz-encoding":prg, "engine":engine}, cls=DataclassJSONEncoder)
serialized = json.dumps({"viz-encoding":prg, "engine":engine, "graphviz-type":graphviz_type}, cls=DataclassJSONEncoder)

r = requests.post(f"{self.backend_url}/control/clingraph",
data=serialized,
Expand Down
3 changes: 2 additions & 1 deletion backend/src/viasp/server/blueprints/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def clingraph_generate():
marked_models = wrap_marked_models(marked_models)
viz_encoding = request.json["viz-encoding"]
engine = request.json["engine"]
graphviz_type = request.json["graphviz-type"]


# for every model that was maked
Expand All @@ -208,7 +209,7 @@ def clingraph_generate():
with control.solve(yield_=True) as handle:
for m in handle:
fb = Factbase.from_model(m, default_graph="base")
graphs = compute_graphs(fb)
graphs = compute_graphs(fb, graphviz_type)

filename = uuid4().hex
using_clingraph.append(filename)
Expand Down
4 changes: 2 additions & 2 deletions backend/src/viasp/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ def relax_constraints(self, head_name:str = "unsat", collect_variables:bool = Tr
return ctl


def clingraph(self, viz_encoding, engine="dot"):
self._database.clingraph(viz_encoding, engine)
def clingraph(self, viz_encoding, engine="dot", graphviz_type="graph"):
self._database.clingraph(viz_encoding, engine, graphviz_type)

def register_transformer(self, transformer, imports="", path=""):
self._database._register_transformer(transformer, imports, path)
Expand Down

0 comments on commit 6909daf

Please sign in to comment.