Skip to content

refactor: use IRInfo and IRStructure for full_equations#4525

Open
AayushSabharwal wants to merge 3 commits into
masterfrom
as/faster-full-eqs
Open

refactor: use IRInfo and IRStructure for full_equations#4525
AayushSabharwal wants to merge 3 commits into
masterfrom
as/faster-full-eqs

Conversation

@AayushSabharwal
Copy link
Copy Markdown
Member

This is a considerable improvement for large models.

@AayushSabharwal AayushSabharwal marked this pull request as ready for review May 12, 2026 10:31
function full_equations(sys::AbstractSystem; simplify = false)
subsys = get_systems(sys)
# Fast path using `IRInfo`
if isempty(subsys)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why can we only do this if we don't have subsytems? Is that fixable?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a comment. get_ir_info will build the IRInfo if a cached one does not exist. Doing so requires the ParameterBindingsGraph, which is only valid for flattened systems. I'll add a comment.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how hard would it be to remove that restriction? The bifurcation here seems sub-optimal.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not very hard, but it doesn't matter much. We hit the slow path for hierarchical systems, which we can't simulate anyway. The only case where full_equations on a hierarchical system matters is if the user is directly building a system that they will complete and never mtkcompile. It's safe to assume those systems are few and far between, and not large enough for the speedup here to matter. Flattening the system will also invalidate the cached IRInfo, so we'll redo this anyway.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough. I'm just coming at this from a code simplicity perspective, but I'm fine with this as is.

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.

2 participants