Skip to content

Commit

Permalink
Merge pull request #1297 from jameshcorbett/default-edge-subsystem
Browse files Browse the repository at this point in the history
JGF: default edge subsystem
  • Loading branch information
mergify[bot] authored Sep 18, 2024
2 parents 2bd4253 + 29bba93 commit d11a3d5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 20 deletions.
13 changes: 3 additions & 10 deletions resource/readers/resource_reader_jgf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ int resource_reader_jgf_t::unpack_edge (json_t *element,
json_t *metadata = NULL;
const char *src = NULL;
const char *tgt = NULL;
const char *subsys = NULL;
const char *subsys = "containment";

if ((json_unpack (element, "{ s:s s:s }", "source", &src, "target", &tgt)) < 0) {
errno = EINVAL;
Expand All @@ -1007,17 +1007,10 @@ int resource_reader_jgf_t::unpack_edge (json_t *element,
m_err_msg += source + std::string (" -> ") + target + ".\n";
goto done;
}
if ((metadata = json_object_get (element, "metadata")) == NULL) {
errno = EINVAL;
m_err_msg += __FUNCTION__;
m_err_msg += ": metadata key not found in an edge for ";
m_err_msg += source + std::string (" -> ") + target + ".\n";
goto done;
}
if ((json_unpack (metadata, "{ s:s }", "subsystem", &subsys)) < 0) {
if ((json_unpack (element, "{ s?{ s?s } }", "metadata", "subsystem", &subsys)) < 0) {
errno = EINVAL;
m_err_msg += __FUNCTION__;
m_err_msg += ": subsystem key not found in edge metadata.\n";
m_err_msg += ": could not unpack edge metadata.\n";
goto done;
}
subsystem = subsys;
Expand Down
2 changes: 1 addition & 1 deletion src/python/fluxion/jsongraph/objects/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def add_edge(self, edge, force_direction=False):#TODO check existence of node id
if isinstance(edge, Edge):
if self._directed:
if edge.is_directed() == None:
edge.is_directed(True)
edge.set_directed(True)
if not edge.is_directed() and not force_direction:
ValueError("Adding undirected edge to directed graph")
if not edge.is_directed() and force_direction:
Expand Down
5 changes: 2 additions & 3 deletions src/python/fluxion/resourcegraph/V1.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ def __init__(self, parentId, vtxId):
super().__init__(
parentId,
vtxId,
directed=True,
metadata={"subsystem": "containment"},
)


Expand All @@ -105,7 +103,8 @@ def __init__(self, rv1):
rv1 -- RV1 Dictorary that conforms to Flux RFC 20:
Resource Set Specification Version 1
"""
super().__init__()
super().__init__(directed=False)
# graph *is* directed, however, suppress unnecessary `"directed": true` fields
self._uniqId = 0
self._rv1NoSched = rv1
self._encode()
Expand Down
6 changes: 0 additions & 6 deletions t/python/t10001-resourcegraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,31 +68,25 @@ def _check_metadata(self, metadata):

def test_basic(self):
graph = FluxionResourceGraphV1(RV1)
self.assertTrue(graph.is_directed())
j = graph.to_JSON()
json.dumps(j) # make sure it doesn't throw an error
self.assertTrue(j["graph"]["directed"])
self.assertEqual(len(j["graph"]["nodes"]), len(graph.get_nodes()))
self.assertEqual(len(j["graph"]["edges"]), len(graph.get_edges()))
for node in graph.get_nodes():
self._check_metadata(node.get_metadata())

def test_basic_2(self):
graph = FluxionResourceGraphV1(RV1_2)
self.assertTrue(graph.is_directed())
j = graph.to_JSON()
json.dumps(j)
self.assertTrue(j["graph"]["directed"])
self.assertEqual(len(j["graph"]["nodes"]), len(graph.get_nodes()))
self.assertEqual(len(j["graph"]["edges"]), len(graph.get_edges()))
for node in graph.get_nodes():
self._check_metadata(node.get_metadata())

def test_basic_3(self):
graph = FluxionResourceGraphV1(RV1_3)
self.assertTrue(graph.is_directed())
j = graph.to_JSON()
self.assertTrue(j["graph"]["directed"])
self.assertEqual(len(j["graph"]["nodes"]), len(graph.get_nodes()))
self.assertEqual(len(j["graph"]["edges"]), len(graph.get_edges()))
for node in graph.get_nodes():
Expand Down

0 comments on commit d11a3d5

Please sign in to comment.