Skip to content

Conversation

dpad
Copy link
Contributor

@dpad dpad commented Dec 3, 2020

This adds the ability to manually specify which module's cache to use when an RGF is built as part of an ODEFunction. Basically, together with eval_expression you can now specify eval_module=@__MODULE__ (the default, which simply uses ModelingToolkit's RGF cache).

I've added an example test case, which consists of building an ODEFunction as part of a precompiled user module.
In this case, "f_bad" throws a KeyError because it does not use eval_module, so it's tagged in the ModelingToolkit RGF cache which is not kept after precompilation of the user module is done.
On the other hand, "f_good" works because it supplies the user module to eval_module, allowing ModelingToolkit to build the RGF within the user module's cache.

NOTE: there's a few other uses of @RuntimeGeneratedFunctions that probably could do with a similar fix to this, or some better solution. I am not sure how best to tackle this other than the current way, so I would appreciate any comments, but I'll leave that out of scope for this PR as it at least fixes #678 for me.

@ChrisRackauckas
Copy link
Member

I think this should work. I'll just want @c42f's opinion on the safety.

@c42f
Copy link

c42f commented Dec 4, 2020

Perhaps there's two separate things desired here?

  1. Ability to specify which module's precompile cache the RGF lives in
  2. Ability to specify which module is used to look up global symbols used in that RGF (including generic functions)

In principle these might be separate modules, I suppose, so SciML/RuntimeGeneratedFunctions.jl#20 might only be half the story?

@ChrisRackauckas
Copy link
Member

Oh I just read this. Yes, good point.

@dpad
Copy link
Contributor Author

dpad commented Dec 18, 2020

Updated this to work with SciML/RuntimeGeneratedFunctions.jl#20.
NOTE: I changed the compat requirements for RuntimeGeneratedFunctions.jl to 0.4.3 which I assumed will be the next tagged release including the change of SciML/RuntimeGeneratedFunctions.jl#20.

@ChrisRackauckas
Copy link
Member

Can this get updated for SciML/RuntimeGeneratedFunctions.jl#22 and handle all of the system types?

@dpad dpad mentioned this pull request Feb 2, 2021
@shashi shashi merged commit d4d6ca9 into SciML:master Feb 12, 2021
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.

[Regression] RuntimeGeneratedFunctions tagged under ModelingToolkit instead of precompiled user module
4 participants