Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor complete #3470

Closed
wants to merge 2 commits into from
Closed

Refactor complete #3470

wants to merge 2 commits into from

Conversation

isaacsas
Copy link
Member

@isaacsas isaacsas commented Mar 18, 2025

Some of the problems that we are experiencing in Catalyst arise from complete doing more than just setting up namespacing. It doesn't really make sense to inject new parameters like initial conditions into a ReactionSystem, as such systems encode a variety of mathematical models, some of which have no notion of an initial condition. That injection should really only occur for a converted system that is in a concrete MTK mathematical system type (i.e. ODEs, SDEs, etc).

This PR attempts to address that by making it possible for us to dispatch complete in a way that we can opt-out of modifications to ps. In the future, hopefully complete-related changes to ps can be restricted to when allow_additional_ps = true, for which we will dispatch complete(::ReactionSystem) to always pass false.

Note that a better approach might be to not have namespacing tied into completion. We could completely ignore complete in Catalyst if it was handled separately. But I assume this would be breaking.

@AayushSabharwal
Copy link
Member

Is _complete intended to be public API? #3466 has an approach to opt-out of adding initial parameters using a trait. The rest of complete's behavior is already controllable via keyword arguments (flatten = false, split = false basically only sets the flag). If the intention is to disable namespacing without doing everything else, it can be done this way. We could also do this by adding a no_namespacing flag which complete also flips, in addition to a toggle_namespacing function to just flip the flag.

@isaacsas
Copy link
Member Author

Yes, it is intended to make it possible for other packages to dispatch complete but still have access to the functionality complete provides.

The intention is to get the namespacing functionality complete provides, but opt out of everything else, which I don't think make sense for ReactionSystems. My impression is that in the future complete may make other system changes beyond just adding initial conditions and namespacing, and I suspect such changes also won't make sense for Catalyst.

An alternative would be if the namespacing functionality were to be separated from complete and/or made available via its own API functions so we could just write our own complete that calls just that component.

@AayushSabharwal
Copy link
Member

The problem with this approach is it doesn't entirely solve your problem. The next time we add something to complete, it'll be enabled by default, which might break Catalyst and require you to add another keyword to your complete method. It's why I'm suggesting an alternative function which simply toggles namespacing.

@isaacsas
Copy link
Member Author

OK, so as to get Catalyst unblocked I think we will just dispatch complete(::ReactionSystem) for now and remove the non-relevant initialization code from the MTK implementation. If/when the flattening, scoped var stuff, and namespacing gets factored out we can switch to whatever API functions are created for them in our implementation.

@isaacsas isaacsas closed this Mar 19, 2025
@isaacsas isaacsas deleted the refactor_complete branch March 19, 2025 16:50
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