Skip to content
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

Add optional caching #247

Merged
merged 9 commits into from
Jun 18, 2024
Merged

Add optional caching #247

merged 9 commits into from
Jun 18, 2024

Conversation

GeorgeR227
Copy link
Collaborator

This adds a keyword can_prealloc that when set to false turns off preallocations and only uses out of place versions of functions.

Also cleaned up the if statements
This uses the `can_prealloc` flag to be able to generate a sparse Jacobian.
test/simulation.jl Show resolved Hide resolved
src/simulation.jl Outdated Show resolved Hide resolved
test/simulation.jl Outdated Show resolved Hide resolved
test/simulation.jl Outdated Show resolved Hide resolved
examples/chemistry/brusselator_implicit.jl Outdated Show resolved Hide resolved
tₑ = 20
@info("Solving")
prob = ODEProblem(f, u₀, (0, tₑ), constants_and_parameters)
soln = solve(prob, FBDF(linsolve = KLUFactorization()), progress=true, progress_steps=1, saveat=0.1);
Copy link
Member

Choose a reason for hiding this comment

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

Leave a comment if you expect this to take longer than other solvers and that this is just for demonstration purposes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've shrunk it down a bit and it only takes 22 seconds to solve.

Copy link
Member

Choose a reason for hiding this comment

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

What is the relative time to the other solver

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Quite a bit longer, but I want to showcase how to use implicit methods so I've tagged this as demonstration code.


Generates the entire code body for the simulation function. `user_d` is the user passed Decapodes which will be left unmodified and 'input_vars' is the collection of
state variables and literals in the Decapode.

Optional keyword arguments are `dimension`, which is the dimension of the problem and defaults to 2D, `stateeltype`, which is the element type of the state forms and
defaults to Float64 and `code_target`, which is the intended architecture target for the generated code, defaulting to regular CPU compatible code.
defaults to Float64, `code_target`, which is the intended architecture target for the generated code, defaulting to regular CPU compatible code, and 'can_prealloc' which
is set to `true` by default and determines if intermediate results can be preallocated.
Copy link
Member

Choose a reason for hiding this comment

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

Is setting this flag necessary for using implicit solvers? And if so can that be documented here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, but if you want to find a sparse Jacobian pattern, plus some other more involved implicit solver things I forget exactly what, then you do need this on.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But this is more so a "safe" mode, where there's less optimization stuff going on that could impact solving, such as needing to find a sparse Jacobian.

Copy link
Member

Choose a reason for hiding this comment

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

Can you document that either in this docstring or in a blurb in the Docs page

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I can do that when I make a docs page on Brusselator.

Copy link
Member

Choose a reason for hiding this comment

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

Ok. For the time being can you put something in this doctoring then.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done and I've also cleaned up the whole docstring since this'll be important to the user.

Copy link
Member

Choose a reason for hiding this comment

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

I mean can you mention in the docstring the "why" of this flag (Get JacSparsity to work etc.). The "what" is excellently answered.

Also make dimension check more explicit
Now we just need the who, when, where, and how.
@jpfairbanks
Copy link
Member

This is a great feature! The name can_prealloc is a little weird I would like preallocation or a standardized name from the SciML ecosystem if there is one.

@GeorgeR227
Copy link
Collaborator Author

I couldn't find anything exactly from SciML but they seem to favor using whole words for keywords. I think preallocate would be good because it's a verb and gets across the idea that you tell gensim to either do it (true) or not (false).

@GeorgeR227 GeorgeR227 merged commit 054d252 into main Jun 18, 2024
7 of 8 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