Skip to content

perf: speed up graph parent generation and idempotent checks via size pre-filtering#154

Open
sowndappan5 wants to merge 1 commit into
recursionpharma:trunkfrom
sowndappan5:trunk
Open

perf: speed up graph parent generation and idempotent checks via size pre-filtering#154
sowndappan5 wants to merge 1 commit into
recursionpharma:trunkfrom
sowndappan5:trunk

Conversation

@sowndappan5

Copy link
Copy Markdown

Problem

During GFlowNet trajectory generation and idempotent action checks, the environment frequently computes parent states and checks them for duplicate/isomorphic configurations. Even though NetworkX's is_isomorphic has internal fast-rejection checks, calling it directly incurs Python function call and argument parsing overhead.

Solution

This PR introduces a fast size-based pre-filter in:

  1. parents() in graph_building_env.py
  2. get_idempotent_actions() in trajectory_balance.py

By comparing cached integer counts of nodes and edges (len(g) and g.number_of_edges()), we fast-reject candidate parent graphs of different sizes with zero signature-creation overhead.

Evaluation & Results

  • Small Graphs (7-10 nodes): ~3% speedup
  • Larger Graphs (15-22 nodes): ~7% speedup

Verification

All pytest unit tests pass successfully.

Add quick integer comparisons of node count (len) and edge count
(number_of_edges) before calling `is_isomorphic`. This skips
unnecessary isomorphic matching overhead on different-sized graphs.
@sowndappan5 sowndappan5 requested a review from bengioe as a code owner June 5, 2026 10:14
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