At some point we switched from persistent implementation instances for models to creating new ones per-call of a model to (1) ensure options could be updated and (2) provide better support for multiprocessing since some casadi objects that were stored in the implementation are not pickleable. One downside is that code-generated functions ("callables", i.e., expressions from model fields) must be re-generated; even worse for symbolic manipulations before code generation. Previously, implementation instances held all callables that a model would need. Now that we cannot assume the implementation instance has been created when the model is built, some models build callables in random places.
#88 uses caching for an optional callable. This approach could be used generally for generated callables (again, especially with symbolic manipulation), perhaps as methods on the meta class for each model. This approach might usable for implementation instances themselves, but we would need to make sure options could be updated as needed. Ideally we can identify a pattern that can be used to standardize the location for creating model callables and improve performance.
At some point we switched from persistent implementation instances for models to creating new ones per-call of a model to (1) ensure options could be updated and (2) provide better support for multiprocessing since some casadi objects that were stored in the implementation are not pickleable. One downside is that code-generated functions ("callables", i.e., expressions from model fields) must be re-generated; even worse for symbolic manipulations before code generation. Previously, implementation instances held all callables that a model would need. Now that we cannot assume the implementation instance has been created when the model is built, some models build callables in random places.
#88 uses caching for an optional callable. This approach could be used generally for generated callables (again, especially with symbolic manipulation), perhaps as methods on the meta class for each model. This approach might usable for implementation instances themselves, but we would need to make sure options could be updated as needed. Ideally we can identify a pattern that can be used to standardize the location for creating model callables and improve performance.