An EventGraph class with tests - #319
Conversation
|
Some TODOs that came out of discussion:
|
|
Thanks for keeping track of everything we discussed in the meeting. Some additional suggestions:
I think these are all things that we need to agree on now since changing them later would mean breaking changes. So, maybe you can also add what you think @hackl and @IngoScholtes FYI: Just merged the pytest CI fix to main, so after rebasing you shouldn't run into problems anymore. |
|
@M-Lampert - I've moved the and returns the exact same thing as before (the If not, let me know - happy to move around. For the purposes of fixing the documentation related to this, let me know if simply renaming Of course this is to get the docs consistent with the PR and get the CI to pass wrt this PR - it might move again in the (near) future. |
|
Just replacing every |
|
I've addressed the bullet points above. Main additions since we met:
|
… namespace); continuations method removed from EventGraph
45f5765 to
a0fd316
Compare
|
Related to the visualisation issue that I just mentioned at the beginning of our meeting, the issue is caused by the following method: pathpyG/src/pathpyG/visualisations/network_plot.py Lines 120 to 146 in 02c0dc6 In the method, we check the order of the graph in line 130. Since it correctly detects that the event graph is of order 2, it wants to add an additional separator between the node labels. This is because, as we just discussed, in our current implementation, we use the |
|
@M-Lampert - hmm, I think the fix might be upstream of this - by the time I get here, |
|
You are right. Line 130 in pathpyG/src/pathpyG/core/graph.py Lines 329 to 342 in 02c0dc6 This is the same underlying problem: All of these classes are implemented to handle higher-order graphs using the pathpyG/src/pathpyG/core/event_graph.py Lines 103 to 108 in a0fd316 Then In between stages, I think there is no good solution for this, so maybe we can leave it as it is for now, open an issue for this and then solve it for every higher-order graph ( |
|
I opened #323 regarding this and we can come back to it once the |
|
|
||
| return eg | ||
|
|
||
| def __str__(self) -> str: |
There was a problem hiding this comment.
Sorry, that I keep coming up with new things but I just compared the __str__ here to the one in TemporalGraph. There, we also return information about the node, edge, and graph attributes:
pathpyG/src/pathpyG/core/temporal_graph.py
Lines 346 to 380 in 02c0dc6
Something similar should also be added here. Maybe you can even deduplicate the code in graph and temporal graph since I just saw that they share almost half of the function.
In general, does the event graph construction from a temporal graph currently automatically convert existing attributes in the temporal graph to attributes in the event graph? I.e. edge attributes in the temporal graph should become node attributes in the event graph, node attributes in the temporal graph should be dropped and graph attributes should stay the same as before.
There was a problem hiding this comment.
No - currently it doesn't. Good point though, since pathpyG identifies attribute kind by prefix (node/edge). I'll implement this in a separate commit.
| """Return the number of events in the graph.""" | ||
| return self.n | ||
|
|
||
| def __getitem__(self, key): |
There was a problem hiding this comment.
Sorry, this is something that we haven't explained properly. __getitem__ is also related to the attributes just like __str__ above. You could for example have an attribute called node_color. When calling event_graph["node_color"] you should get an iterable of the saved colors for each node. I think this is something that should work directly with the implementation from Graph so you might not even need to implement the function here. The only thing that you need to consider is that during the creation of the event graph, node attributes from a temporal graph will be transformed to edge attributes in the event graph.
| assert [event_graph.event_time(i) for i in range(event_graph.num_events)] == [1, 2, 3, 5] | ||
|
|
||
|
|
||
| def test_getitem(event_graph): |
There was a problem hiding this comment.
It would be good if you could test if the attribute handling works properly here.
Introduced an
EventGraphclass with tests to illustrate basic functionality.EventGraphis a pathpyGGraphso in addition to being constructed from aTemporalGraph, it is capable of being constructed directly from atorch_geometric.data.Dataobject.Essentially the usage might be:
A couple of things to discuss:
If an
EventGraphis constructed from aTemporalGraphand theTemporalGraphis later changed by the caller, should theEventGraphchange as well? Right now we don't -eg._temporal_graph = TemporalGraph(g.data.clone(), mapping=g.mapping). This seems to me like the right thing to do.eg.shortest_pathsworks, but creates aTemporalGraph(if it doesn't exist) to pass on totemporal_shortest_paths. This seems wasteful ifEventGraphwas constructed fromDataand doesn't need all theTemporalGraphmachinery. Perhapstemporal_shortest_pathscan be tweaked to work with a pre-computed edge-index (as would be the case ifEventGraphis constructed directly fromtorch_geometric.data.Data).temporal_shortest_paths(g: TemporalGraph | None, eg: "EventGraph" | None, delta: int). Add methods toEventGraph/TemporalGraphthat call this function under the hood.Some changes in other files were for my understanding of the code by adding comments, and are unrelated to the PR.