-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
After #152 we are ready to support runtime generated functions.
I am not going to sketch out the full solution, but a few points:
- With Move from requiring modules to storing functions in problem structure #152, you will just need to have a constructor which takes a model definition, genreates the functions, and returns the PerturbationModel type.
- You will need to use https://github.com/SciML/RuntimeGeneratedFunctions.jl (or maybe https://github.com/JuliaStaging/GeneralizedGenerated.jl if that fails) to turn the generated expressions into actual julia functions
- The basic approach is that instead of just turning the expressions into functions in a file (e.g. https://github.com/HighDimensionalEconLab/DifferentiableStateSpaceModels.jl/blob/v0.4.19/src/make_perturbation_model.jl#L287) you can create the function with
@RuntimeGeneratedFunction(ȳ_expr[2])etc., which could then be passed as constructor arguments with the new function. - Before you do that, though, you will need to make sure that whatever method is used to generate these functions supports generic functions because it is required for the derivatives. e.g., we have
function H_x_p!(ˍ₋out, ::Val{:σ}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )andfunction H_x_p!(ˍ₋out, ::Val{:δ}, ˍ₋arg2, ˍ₋arg3, ˍ₋arg4; )for derviatives wrt those different parameters. I suspect this is the most difficult thing to figure out, and if no generic runtime generated functions are possible then you may need to create one with an internal loop by manipulating the internal functions and having it manually call one of those dispatches inside. - If you can do generic functions in one way or another, then the last parts are straightforward:
- Make saving a file out as optional, and only conditionally call https://github.com/HighDimensionalEconLab/DifferentiableStateSpaceModels.jl/blob/v0.4.19/src/make_perturbation_model.jl#L224-L371
- Instead of just returning the module path, construct a
PerturbationModelin https://github.com/HighDimensionalEconLab/DifferentiableStateSpaceModels.jl/blob/v0.4.19/src/make_perturbation_model.jl#L376 to return, maybe along with the saved file path as a second return argument. - To construct that type, just call the core constructor like you did for the modified version of https://github.com/HighDimensionalEconLab/DifferentiableStateSpaceModels.jl/blob/v0.4.19/src/types.jl#L34-L45 from Move from requiring modules to storing functions in problem structure #152 - except pass in generated functions rather than the pointers to functions in the module.
- Then if someone wants to have rutnime generated model they just call that function to get the
PerturbationModelreturn type (with or without it saving it in files, which could be set to default to false)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels