Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Automatic inference of discrete parameters in events#3991

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
TorkelE wants to merge6 commits intoSciML:master
base:master
Choose a base branch
Loading
fromTorkelE:event_discpars_autoinfer

Conversation

@TorkelE
Copy link
Member

@TorkelETorkelE commentedOct 26, 2025
edited
Loading

When creating a symbolic event throughSymbolicContinuousCallback orSymbolicDiscreteCallback it is possible to infer which parameters are updated by the event (everything withinPre(...) statements in the affect are protected, but everything outside can be updated). This PR adds a small routine to do this for the user if thediscrete_parameters argument is not provided. This should prevent the possibility of silent errors if they forgets this argument. Furthermore, it enables programmatic use of events without explicitly importingSymbolicContinuousCallback/SymbolicDiscreteCallback (as one can how just use the normal map for in the input, instead of using these functions).

I have tried, and it is possible to remove alldiscrete_parameters statements from all events in the test files, and everything passes. Right now I have not done so, as I wanted to provide minimal changes (isntead I added a bunch of additional new tests as well).

sol=solve(prob)
@test SciMLBase.successful_retcode(sol)
@test sol[x,end]1.0 atol=1e-6
@test sol[x,end]0.75 atol=1e-6
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

There is an error in this test. Thediscrete_parameters argument was forgotten, so the event is not actually triggered. Unless the intention of the test is to check that everything works as (un)expected when the input is omitted (but the naming and test do not suggest that), this should be changed. With this PR, the event is now triggered, and the correct value0.75 is achieved.

@TorkelE
Copy link
MemberAuthor

There are test errors, however, they are the same as in:#3989

@AayushSabharwal
Copy link
Member

I'm not so sure of this. If I understand correctly, this takes all parameters in affect equations that don't occur inside aPre and considers them discretes? Isn't this breaking, since prior to this change the callback

@parametersp(t)@variablesx(t)cb= [some_condition]=> [x~Pre(x)+ p]

is well-defined, but after the changep would be considered discrete thus making the affect underdetermined?

@TorkelE
Copy link
MemberAuthor

Wouldn'tcb = [some_condition] => [x ~ Pre(x) + p] be overdetermined, as we have two unknowns (x andp), and one known (Pre(x))?

@TorkelE
Copy link
MemberAuthor

For non time-dependent parameters I could make it optional to usePre though, i.e. if you have

@parameters p# not `(t)`

but I was hesitant as I figured it might make more sense to just enforcePre on everything that should not be solved for.

@AayushSabharwal
Copy link
Member

For non-time-dependent parameters,Pre isn't necessary. I'm not sure if having them indiscrete_parameters makes a difference, but I don't think it does.

Wouldn't cb = [some_condition] => [x ~ Pre(x) + p] be overdetermined, as we have two unknowns (x and p), and one known (Pre(x))?

We have 2 unknowns and one equation.Pre(x) is a parameter here. It's underdetermined.

TorkelE reacted with thumbs up emoji

@TorkelE
Copy link
MemberAuthor

Sounds good, I can discount non-time dependent parameters if that the case.

We have 2 unknowns and one equation. Pre(x) is a parameter here. It's underdetermined.

Sorry, yes, meant underdetermined. But my point is thatcb = [some_condition] => [x ~ Pre(x) + p] is already underdetermined without this change (it yields and error if you try to simualte it). It being underdetermined is not something this change affects.

@TorkelE
Copy link
MemberAuthor

Or maybe you meant

@parameters p# Not `(t)`@variablesx(t)cb= [some_condition]=> [x~Pre(x)+ p]

that would make sense, I will update the PR to discount non-time-dependent parameters, which should harmonize this case with current behaviours.

@AayushSabharwal
Copy link
Member

AayushSabharwal commentedOct 27, 2025
edited
Loading

Weird. I investigated, and turns out thatmtkcompile doesn't handle the system right. Ifp isn't provided todiscrete_parameters, the system it creates is

julia> pasysModel affectsys:Equations (1):1 standard: seeequations(affectsys)Unknowns (1): seeunknowns(affectsys)x(t)Parameters (2): seeparameters(affectsys)Pre(x(t))p(t)julia>equations(pasys)1-element Vector{Equation}:x(t)~p(t)+Pre(x(t))

However, after simplification the equation becomesx(t) ~ Pre(x(t)) + pₜ₋₁(t) which is a bug.

@ChrisRackauckas
Copy link
Member

It's not generally correct for the user to not be selecting it? What do you do about the case ofp1 + p2 ~ 1? How do you choose which parameter to change? That is underdetermined.

@ChrisRackauckas
Copy link
Member

It being underdetermined is not something this change affects.

It causes malformed systems to be automatically created rather than requiring the user to give a correct system. That seems like a recipe for trouble.

@TorkelE
Copy link
MemberAuthor

Right, but doesn't that align with this PR? I agree thatconditon => [p1 + p2 ~ 1] should yield an error, and this should correctly deduce that bothp1 andp2 (if both are declared as time varying) are free in the update equation. This wield yield an error due to an underdetermined system. If you want eitherp1 orp2 to stay fixed, you can designate this using the current notation, e.g.Pre(p1) + p2 ~ 1 to note that thep1 value should be the pre-eventp1 value (not the post-event one, as the initial equations suggest).
(again, correct me if i am wrong)

@ChrisRackauckas
Copy link
Member

@AayushSabharwal thoughts?

@TorkelE
Copy link
MemberAuthor

Me and Aayush had a meeting discussing this, and I think we managed to iron things out. There are definitely some additional syntactic sugar that could be done, but it will require some more thoughts than here. I will update the PR to only fix the test issue, and then we can think if there are any long-term improvements that can be made later on.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@TorkelE@AayushSabharwal@ChrisRackauckas

[8]ページ先頭

©2009-2025 Movatter.jp