Skip to content

Fixes for dependent parameters #2668

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 12 commits into from
Jun 6, 2024
Merged

Conversation

SebastianM-C
Copy link
Contributor

@SebastianM-C SebastianM-C commented Apr 24, 2024

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

When build_explicit_observed_function was updated for parameter dependencies, only the ps argument was updated, but internally the function still ckecked for the parameters instead of the full_parameters.

@ChrisRackauckas
Copy link
Member

Format or the tests won't run.

@SebastianM-C
Copy link
Contributor Author

oh, sorry, fixed it

@SebastianM-C
Copy link
Contributor Author

I realized that this is not enough, as the parameter dependencies are dropped in several other places. The above 2 are commits are what I got so far, I'm not sure what other places need this. I'll try to add more tests too.

Copy link
Member

@AayushSabharwal AayushSabharwal left a comment

Choose a reason for hiding this comment

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

This would also benefit from a test where a subsystem has a parameter dependency alongside the parent system it is included in. The subsystem's dependency should be appropriately namespaced

@@ -354,6 +354,7 @@ function flatten(sys::ODESystem, noeqs = false)
get_iv(sys),
unknowns(sys),
parameters(sys),
parameter_dependencies = get_parameter_dependencies(sys),
Copy link
Member

Choose a reason for hiding this comment

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

We could have parameter dependencies in hierarchical systems, which means this needs the guesses treatment where dependencies from subsystems are namespaced and included in the flattened system

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Isn't the system structurally simplified by the time we get here? 95c8567 would take care of that.

Copy link
Member

Choose a reason for hiding this comment

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

No, it isn't

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed this to use parameter_dependencies(sys) instead, so now it gets the renamespaced dependencies of the subsystems.

Comment on lines +70 to +86
@testset "getu with parameter deps" begin
@parameters p1=1.0 p2=1.0
@variables x(t) = 0

@named sys = ODESystem(
[D(x) ~ p1 * t + p2],
t;
parameter_dependencies = [p2 => 2p1]
)
prob = ODEProblem(complete(sys))
get_dep = getu(prob, 2p2)
@test get_dep(prob) == 4
end

Copy link
Member

Choose a reason for hiding this comment

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

Could you also add a testcase for hierarchical systems where the subsystems have parameter dependencies? I have a feeling that will fail

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it failed. I added a test in db89f68 and I tried to do the renamespacing, but something is off and the dependent parameter does not seem to update correctly.

@SebastianM-C SebastianM-C force-pushed the obs_dep branch 2 times, most recently from db89f68 to 94428b4 Compare May 22, 2024 02:38
if has_parameter_dependencies(sys) &&
(pdeps = get_parameter_dependencies(sys)) !== nothing
if has_parameter_dependencies(sys)
pdeps = parameter_dependencies(sys)
Copy link
Member

Choose a reason for hiding this comment

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

This is not technically necessary, although it will work regardless. If the system is simplified, all parameter dependencies will be available at the top level. If it isn't simplified, we can't simulate it anyway so an index cache is immaterial.

@AayushSabharwal
Copy link
Member

Also needs a rebase, since MTK CI passes now

@SebastianM-C SebastianM-C force-pushed the obs_dep branch 2 times, most recently from 095c41b to bc5c51c Compare May 27, 2024 12:40
@SebastianM-C SebastianM-C force-pushed the obs_dep branch 2 times, most recently from 84d951a to c127f24 Compare June 5, 2024 13:27
@AayushSabharwal
Copy link
Member

I can't suggest changes on unchanged files, but in src/systems/parameter_buffer.jl:139 get_parameter_dependencies needs to be parameter_dependencies. If you run a global search for get_parameter_dependencies, all of them except the ones in parameter_dependencies itself need to be replaced this way.

`subsys` might not have parameter dependencies, but subsystems of `subsys` might

Co-authored-by: Aayush Sabharwal <[email protected]>
@SebastianM-C SebastianM-C changed the title Fix observed functions with dependent parameters Fixes for dependent parameters Jun 6, 2024
@SebastianM-C
Copy link
Contributor Author

Thanks! That seems to have solved the issue.

@ChrisRackauckas ChrisRackauckas merged commit 4e91484 into SciML:master Jun 6, 2024
16 of 26 checks passed
@SebastianM-C SebastianM-C deleted the obs_dep branch June 6, 2024 20:03
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