Skip to content

An EventGraph with tests#316

Closed
vineetbansal wants to merge 2 commits into
pathpy:devfrom
vineetbansal:vb/eventgraph
Closed

An EventGraph with tests#316
vineetbansal wants to merge 2 commits into
pathpy:devfrom
vineetbansal:vb/eventgraph

Conversation

@vineetbansal

@vineetbansal vineetbansal commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Introduced an EventGraph class with tests to illustrate basic functionality. EventGraph is a pathpyG Graph so in addition to being constructed from a TemporalGraph, it is capable of being constructed directly from a torch_geometric.data.Data object.

Essentially the usage might be:

  tg = TemporalGraph.from_edge_list([
      ("a", "b", 1),
      ("b", "c", 2),
      ("b", "d", 5),
      ("c", "e", 3),
  ])

  eg = EventGraph.from_temporal_graph(tg, delta=2)

  print(eg)                    # EventGraph (delta=2) ... one line per event, like a->b@1
  print(eg.num_events)         # 4  (one per temporal edge)
  print(eg.num_fo_nodes)       # 5  (a, b, c, d, e)

  print(eg.event_endpoints(0)) # ('a', 'b', 1)
  print(eg[0])                 # same thing
  print(eg.continuations(0))   # [(1, 1)]  -> event 1, with a time gap of 1

  dist, pred = eg.shortest_paths()
  print(dist[eg.fo_mapping.to_idx("a"), eg.fo_mapping.to_idx("e")])  # 3.0

  tg_back = eg.to_temporal_graph()
  
  # This is not part of this PR, but can be added easily.
  model = MultiOrderModel.from_event_graph(event_graph, max_order=2)

A couple of things to discuss:

  • If an EventGraph is constructed from a TemporalGraph and the TemporalGraph is later changed by the caller, should the EventGraph change 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_paths works, but creates a TemporalGraph (if it doesn't exist) to pass on to temporal_shortest_paths. This seems wasteful if EventGraph was constructed from Data and doesn't need all the TemporalGraph machinery. Perhaps temporal_shortest_paths can be tweaked to work with a pre-computed edge-index (as would be the case if EventGraph is constructed directly from torch_geometric.data.Data).

    • Change signature to temporal_shortest_paths(g: TemporalGraph | None, eg: "EventGraph" | None, delta: int). Add methods to EventGraph/TemporalGraph that 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.

@vineetbansal vineetbansal changed the base branch from main to dev July 9, 2026 15:44
@vineetbansal

Copy link
Copy Markdown
Collaborator Author

Closing this in favor of an upcoming PR originating from this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant