Graph-based subsystem extraction with pruning#13
Merged
Conversation
OutputMarker labels were incorrectly injecting InputMarkers at the upstream block's input, breaking the cascade and returning wrong transfer functions. Now correctly injects at the block's output to externalize the signal at that point for subsystem extraction. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Subsystem extraction between arbitrary signals was incorrectly including all blocks in the diagram, causing extracted transfer functions to have unwanted state coupling from unrelated upstream/downstream dynamics. This implements bidirectional graph reachability analysis to identify the minimal set of blocks that influence the input-output relationship: - Forward DFS from source finds downstream-reachable blocks - Backward DFS from destination finds upstream-reachable blocks - Intersection gives blocks on paths between source and destination - Pruning removes non-path blocks before building interconnect The algorithm automatically: - Excludes downstream blocks (e.g., extracting controller without plant) - Excludes upstream blocks (e.g., OutputMarker labels) - Preserves internal feedback loops (blocks reachable both ways) - Handles parallel paths (union via set intersection) Complexity: O(V+E) linear in graph size Performance: <10ms for 50-block diagrams, <50ms for 100-block diagrams Coverage: 85% overall (95% on graph_pruning.py) Verified against cascaded.json control system - all 9 test extractions match expected block diagram algebra. Original bug (rate_err → tau_cmd including downstream feedback) is fixed. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Updated task completion status for: - Phase 4 (User Story 2): T025-T034 - Internal feedback preservation - Phase 5 (User Story 3): T035-T044 - Parallel paths handling Both user stories implemented and verified: - US2: Bidirectional reachability correctly preserves internal feedback loops - US3: Set intersection captures all parallel paths while excluding side branches All integration tests passing (12 tests across US1, US2, US3). Backward compatibility maintained (498 total tests passing). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements graph-based pruning for subsystem extraction in Lynx diagrams. Extracts minimal transfer functions between arbitrary signals by automatically identifying and excluding unrelated blocks (downstream coupling, external feedback loops, and unrelated branches).
Problem Solved
Previously,
diagram.get_ss(from_signal, to_signal)included ALL blocks in the diagram when extracting subsystem transfer functions, leading to:Example: Extracting
rate_err → tau_cmdfrom cascaded.json should return 2nd-order PID dynamics, but previously included all 6 states from the entire cascade (incorrect).Solution Approach
Bidirectional graph reachability analysis with DFS-based set intersection:
python-controlsystemComplexity: O(V+E) where V = blocks, E = connections
Performance: <10ms for 50-block diagrams, <50ms for 100-block diagrams
Key Features
User Story 1: Single Block Extraction
Extract individual block transfer functions without downstream coupling.
User Story 2: Internal Feedback Preservation
Extract multi-block subsystems with internal feedback loops.
User Story 3: Parallel Paths
Handle complex topologies with multiple signal paths.
Implementation Details
New Module:
src/lynx/conversion/graph_pruning.py_build_connection_graph()- Build forward/backward adjacency lists_dfs_forward()- Forward reachability with cycle detection_dfs_backward()- Backward reachability with cycle detection_find_reachable_blocks()- Bidirectional analysis with intersectionprune_diagram()- Clone and remove non-path blocksIntegration:
src/lynx/conversion/signal_extraction.pyTesting
Coverage:
Test Organization:
tests/python/unit/test_graph_pruning.py- Algorithm correctnesstests/python/integration/test_pruned_extraction.py- End-to-end extraction scenariosVerification:
Validated against cascaded.json (6-state triple-nested control system) with 9 different extractions:
All extractions match expected transfer function order from manual analysis.
Performance
Breaking Changes
None. Fully backward compatible:
diagram.get_ss(),diagram.get_tf())Next Steps
Optional polish tasks (not blocking):
🤖 Generated with Claude Code