Skip to content

add new HashedRandom guess option and make it the default#4445

Open
oscardssmith wants to merge 8 commits intoSciML:masterfrom
oscardssmith:os/add-and-default-to-HashedRandom-guesses
Open

add new HashedRandom guess option and make it the default#4445
oscardssmith wants to merge 8 commits intoSciML:masterfrom
oscardssmith:os/add-and-default-to-HashedRandom-guesses

Conversation

@oscardssmith
Copy link
Copy Markdown
Member

HashedRandom uses hash(var)/2^64 as an initial value which has the significant advantage over regular random of being deterministic. As such, I think this is a generally reasonable initialization (although it might make sense to also add a multiplication by getnominal for both Random and HashedRandom now that #4425 is merged.

Copy link
Copy Markdown
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.

The enum is also used in the SCCNonlinearProblem constructor, so it needs to be handled there as well.

@oscardssmith oscardssmith force-pushed the os/add-and-default-to-HashedRandom-guesses branch from c3e7e6f to e8564f5 Compare April 22, 2026 11:27
@hersle
Copy link
Copy Markdown
Contributor

hersle commented Apr 23, 2026

Would this cause silent or hard-to-find bad behavior in the event of missing guesses, where the random algorithm selects bad values?

It's a nice idea though, if you make it default at least it can be disabled with 1 kwarg to ODEProblem, which is great. In my particular application I would prefer errors over random guesses, since bad initial guesses would crash the initialization solver. But I guess that is different in other applications.

@oscardssmith
Copy link
Copy Markdown
Member Author

since bad initial guesses would crash the initialization solver. But I guess that is different in other applications.

My argument is that if bad guesses crash initialization then you're in just as bad a spot as if you had gotten an error before initialization started (but if the guess doesn't matter, then this version is strictly better). We do probably want to mention in the error message if initialization fails that you should consider adding guesses if you know roughly how you want to initialize).

Copy link
Copy Markdown
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.

It would also be nice if the magic constant 0x1p64 was a global constant and/or the hashing logic its own function, so that we can be sure the implementation in SCCNonlinearProblem is the same as the one in problem_utils.jl.

Comment thread lib/ModelingToolkitBase/src/systems/problem_utils.jl Outdated
Comment thread src/problems/sccnonlinearproblem.jl Outdated
oscardssmith and others added 2 commits April 23, 2026 14:02
Co-authored-by: Aayush Sabharwal <aayush.sabharwal@gmail.com>
Co-authored-by: Aayush Sabharwal <aayush.sabharwal@gmail.com>
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