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

Idea: Exploit hierarchical composition in simulation generation #266

Open
lukem12345 opened this issue Aug 5, 2024 · 2 comments
Open

Idea: Exploit hierarchical composition in simulation generation #266

lukem12345 opened this issue Aug 5, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@lukem12345
Copy link
Member

lukem12345 commented Aug 5, 2024

Currently, we generate simulation code only on single Decapode objects, after oapply is performed.

However, we could take advantage of repeated sub components which only differ in the pointers to their inputs and outputs. For each node in a composition diagram for which the same Decapode is plugged in, we could compile it to a simulation helper function, which could be re-used inside the main ODEProblem function generated.

This will surely result in simulation functions with fewer total lines of code. However, it is not apparent whether this would result in more efficient generated code that the Julia compiler can optimize, or whether this could improve pre-compile times.

So, we should manually create an example of this generated code and compare. A reasonable example would use the unconnected RelationDiagram of 2 or more distinct nodes, plugging in e.g. the Brusselator Decapode for each component. (I.e. The strategy used for non-interacting multi-species Navier-Stokes.)

An occurrence of this “in the wild” is the hierarchical composition in the Non-Hydrostatic Buoyancy example, in which tracer computations for salinity and temperature are repeated:

isotropic_nonhydrostatic_buoyancy = apex(oapply(nonhydrostatic_composition, [
  Open(momentum,          [:V, :v, :b, :StressDivergence]),
  Open(isotropic_tracer,  [:continuity_V, :v, :c, :turbulence_StressDivergence, :turbulence_nu]),
  Open(isotropic_tracer,  [:continuity_V, :v, :c, :turbulence_StressDivergence, :turbulence_nu]),
  Open(equation_of_state, [:b, :T, :S])]));
to_graphviz(isotropic_nonhydrostatic_buoyancy)
@lukem12345 lukem12345 added the enhancement New feature or request label Aug 5, 2024
@lukem12345 lukem12345 self-assigned this Aug 5, 2024
@jpfairbanks
Copy link
Member

MTK also generates code but at the scalar level. I think they generate basic blocks with on the order of 100k lines. I don't think that we are pushing the boundaries of code generation in Julia with even our biggest decapodes.

@lukem12345
Copy link
Member Author

Yeah I'm wondering where the cutoff is in terms of effectively inlining with copies of the same Decapode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants