Skip to content

fix: infer oop form for SDEProblem/SDEFunction with StaticArrays #2834

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 2 commits into from
Jul 3, 2024

Conversation

AayushSabharwal
Copy link
Member

Close #2814

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

Add any other context about the problem here.

@AayushSabharwal
Copy link
Member Author

The problem here is that this line doesn't work with static arrays. K is an SVector{1} whereas L is an SMatrix{1, 1} (since noise is a matrix). I guess that line should have an @..?

julia> [1;;] + [1]
1×1 Matrix{Int64}:
 2
julia> @SArray[1;;] + @SArray[1]
ERROR: DimensionMismatch: Sizes (Size(1, 1), Size(1,)) of input arrays do not match

@ChrisRackauckas
Copy link
Member

That's a method only for diagonal noise, so that method won't work on array

@AayushSabharwal
Copy link
Member Author

1x1 noise is diagonal, right? Which I guess is why I guess it hits that

@ChrisRackauckas
Copy link
Member

Yeah, what we should do is detect that if isdiagonal then turn it it into a vector so it represents diagonal noise.

@ChrisRackauckas ChrisRackauckas merged commit d64f973 into SciML:master Jul 3, 2024
19 of 22 checks passed
@TorkelE
Copy link
Member

TorkelE commented Jul 6, 2024

This update causes Catalyst CI to fail. Given that Catalyst has a very extensive test set, and often has catched things that the MTK tests have missed, would it make sense to not merge things which cause Catalyst downstream errors?

@TorkelE
Copy link
Member

TorkelE commented Jul 6, 2024

(I have modified Catalyst so that it works with this new version. However, generally, I do think we should try and not ignore the CI that we got)

@ChrisRackauckas
Copy link
Member

I don't think the Catalyst tests are right here?

@TorkelE
Copy link
Member

TorkelE commented Jul 6, 2024

The Catalyst tests are fine. Basically, this PR goes from requiring an internal matrix to be Matrix{Num} from Matrix{Any} (I know Sam has argued for the latter representation being used, personally I have no strong opinion). Anyway, this breaks a couple of things (which I Catalyst I switched around so that it should be fine).

@ChrisRackauckas
Copy link
Member

Oh I thought the Catalyst issue was the sizing thing we were talking about? Requiring Matrix{Num} isn't intentional, though it is somewhat bettter.

@TorkelE
Copy link
Member

TorkelE commented Jul 6, 2024

No, the sizing got fixed (thanks for that!). Practically, I'm not sure of changing to Matrix{Num} is a big change, but next time it would be useful to at least have a note that there has been an update which breaks the Catalyst tests 👍

@isaacsas
Copy link
Member

isaacsas commented Jul 6, 2024

Shouldn’t one be able to generate SDESystems without using Nums? If not, wouldn’t this require all compositional modeling tools to know to rewrap internal unwrapped expressions when generating SDESystems from other systems?

Comment on lines +234 to +236
if eqs isa AbstractMatrix && isdiag(eqs)
eqs = diag(eqs)
end
Copy link
Member

Choose a reason for hiding this comment

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

@ChrisRackauckas @AayushSabharwal I don't think this is correct code for symbolics. The problem is that isdiag calls iszero which for a non-Num will create a symbolic boolean expression, i.e.

julia> @variables A
e1-element Vector{Num}:
 A

julia> eq = 5*A^2 + 2*A + 65
65 + 2A + 5(A^2)

julia> iszero(eq)
false

julia> iszero(ModelingToolkit.unwrap(eq))
(65 + 2A + 5(A^2)) == 0

So this now explicitly breaks creating an SDESystem with unwrapped expressions.

Copy link
Member

Choose a reason for hiding this comment

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

Also, as @TorkelE mentioned Catalyst master tests should now generally pass, so if Catalyst tests fail when running downstream tests on an MTK PR that is meaningful again (unlike before we updated Catalyst to MTK 9).

Copy link
Member

Choose a reason for hiding this comment

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

The Catalyst v14 release hasn't been made yet, so it's still not testing the updated code?

Copy link
Member

Choose a reason for hiding this comment

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

The problem is that isdiag calls iszero which for a non-Num will create a symbolic boolean expression, i.e.

Thanks, we need to have a different isdiag that uses isequal. @AayushSabharwal can you prioritize this?

Copy link
Member

Choose a reason for hiding this comment

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

@isaacsas is there an issue open on this? If so, let's assign @AayushSabharwal to it.

Copy link
Member

Choose a reason for hiding this comment

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

I opened #2868

Copy link
Member

Choose a reason for hiding this comment

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

The Catalyst v14 release hasn't been made yet, so it's still not testing the updated code?

Also, doesn't this:

https://github.com/SciML/ModelingToolkit.jl/actions/runs/9772401615/job/26976712250#step:6:579

indicate it was tested against Catalyst master?

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.

Unable to simualte SDEs with static array u0/ps
4 participants