-
Notifications
You must be signed in to change notification settings - Fork 135
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
sim.model as a class? #117
Comments
Adding the model as an injectable is 100% in the spirit of urbansim. An alternative to the way you've set it up is to use the @sim.injectable('hh_transition', cache=True)
def hh_transition():
t = transition.TabularTotalsTransition(controls_df, control_col_name)
return TransitionModel(t) You can if you like set up a callable class. Right now you can't decorate a class because the model decorator doesn't know about classes and that they |
I did some playing around w/ this, if we update the init in _ModelFuncWrapper from:
To:
Then we can can decorate models as classes w/ both initialization and run-year logic. Inputs to both the model initialization and run are all injectables:
Is this something you can support? I personally feel it makes the models a little easier to set up and organize. But perhaps there are some gotachas with this approach that I'm not recognizing? |
I'm okay with supporting something along those lines, though if we're going to support models as classes we'll need to look into doing the same for injectables and tables. |
One thing I'm noticing w/ the sim.model wrappers is it seems that models are being re-initialized for each year in the simulation. This seems undesirable since initialization is then being called many times over. For example:
I've gotten around this by creating an instance of the model outside of the model wrapper and then injecting it, for example:
Is there a better way to do this? Declaring the model themselves as injectables certainly works but it feels a little cumbersome. It might be nice if we could decorate a callable class. Then we could define initialization logic in the init method to create model instances and then run year specific code in the callable method?
thanks,
scott
The text was updated successfully, but these errors were encountered: