Skip to content

handle connections in change_independent_variable #3625

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

Merged
merged 4 commits into from
May 12, 2025

Conversation

aml5600
Copy link
Contributor

@aml5600 aml5600 commented May 12, 2025

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

Expand change_independent_variable to handle systems with connections. This was chosen over forcing expand_connections prior to calling, as expand_connections forces flatness and that is undesirable in some cases.

@hersle
Copy link
Contributor

hersle commented May 12, 2025

I'm not super familiar with the connect mechanics. But from what I understand, the main change is to recursively apply the change of independent variable transform to systems inside connections, which seems very sensible to me!

Maybe @ChrisRackauckas wants to have a quick look?

@ChrisRackauckas
Copy link
Member

I'm not super familiar with the connect mechanics. But from what I understand, the main change is to recursively apply the change of independent variable transform to systems inside connections, which seems very sensible to me!

All connections are linear combinations so it should be fine to handle them the simple way.

@@ -158,7 +158,7 @@ function change_independent_variable(
function transform(ex::T) where {T}
# 1) Replace the argument of every function; e.g. f(t) -> f(u(t))
for var in vars(ex; op = Nothing) # loop over all variables in expression (op = Nothing prevents interpreting "D(f(t))" as one big variable)
is_function_of_iv1 = iscall(var) && isequal(only(arguments(var)), iv1) # of the form f(t)?
is_function_of_iv1 = iscall(var) && isequal(first(arguments(var)), iv1) # of the form f(t)?
Copy link
Member

Choose a reason for hiding this comment

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

why is this needed? It should be only or error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reverted back to only, @hersle PR handles this correctly.

@ChrisRackauckas
Copy link
Member

This looks reasonable, though I'd be scared of changing that only because I presume this shouldn't ever hit a two call variable?

@aml5600
Copy link
Contributor Author

aml5600 commented May 12, 2025

This looks reasonable, though I'd be scared of changing that only because I presume this shouldn't ever hit a two call variable?

@ChrisRackauckas This was an artifact of me trying to allow symbolic arrays to be similarly handled. It was failing previously as the only was hitting cases of e.g. only([var(t), index]). I was going to remove it as I switched to connections first, but it didn't seem to break anything so I left it...

@ChrisRackauckas
Copy link
Member

Oh I see. Hmm, okay that's fine.

@aml5600
Copy link
Contributor Author

aml5600 commented May 12, 2025

Also, I tried implementing this first by simply transforming the systems in each connection and then rebuilding the connection (without the use of the systems_map approach). This gave odd errors when trying to display the resulting system (so show/display calls) and also was unable to structurally simplify.

Is this something you would expect?

@ChrisRackauckas
Copy link
Member

Retriggering tests post scimlbase hotfix

@ChrisRackauckas
Copy link
Member

Also, I tried implementing this first by simply transforming the systems in each connection and then rebuilding the connection (without the use of the systems_map approach). This gave odd errors when trying to display the resulting system (so show/display calls) and also was unable to structurally simplify.

That is not something I'd expect. I'm not sure why the display would care? You may not have reconstructed the connect equation correctly, i.e. it's not really an equation so check the conversion what the lhs should be.

@aml5600
Copy link
Contributor Author

aml5600 commented May 12, 2025

Also, I tried implementing this first by simply transforming the systems in each connection and then rebuilding the connection (without the use of the systems_map approach). This gave odd errors when trying to display the resulting system (so show/display calls) and also was unable to structurally simplify.

That is not something I'd expect. I'm not sure why the display would care? You may not have reconstructed the connect equation correctly, i.e. it's not really an equation so check the conversion what the lhs should be.

Gotcha. If we are okay with the current approach (which saves us from re-transforming a bunch of systems) I will just use this.

@ChrisRackauckas ChrisRackauckas merged commit 36abc8b into SciML:master May 12, 2025
32 of 45 checks passed
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.

3 participants