-
Notifications
You must be signed in to change notification settings - Fork 89
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
Enforced (Stella Style?) Limits and Warning (Vensim Style) Limits #194
Comments
Hi @gherka, There are two schools of thought as to what a limit should do in a model - one school says that a limit should be a hard boundary, and if a stock was going to exceed that limit, then the modeling software should force no more growth of that stock. I believe this is what Stella does, and is probably why your model works in that environment. The other school says that the limits shouldn't modify the behavior of the model, but should throw a warning to the user to let them know that the stock has exceeded its limit. This is what Vensim does. The logic of the second school is that the structure of the system itself should be explicit about constraining the value of the stock. Here's a toy example - say that a room has a capacity of 100 people. At first the inflow rate is constrained by the number who can get through the door, and so the population in the room grows linearly. Then as the room starts to become full, the rate limiting factor is how fast people can navigate the room and find seats. So, you get gradual adjustment to the capacity. Here's what that would look like over time: Stella lets you just run up against the stop at full speed, which is fine in a lot of cases because it won't matter to the question your model is trying to answer. Vensim says you have to be explicit about the behavior you want as you get close to the constraint, and if you want a hard stop vs a soft landing you have to build that behavior into your model. Here's an example for a soft landing:
In PySD, I've chosen to take the Vensim school, mostly because I started with Vensim and know it best. We might in the future add a I've been working on some bounds testing functions that are post-simulation tests of behavior. They aren't documented yet, but they are here in the code. I'm afraid something seems to be broken at the moment (in the current repo) but eventually you should be able to do: model = pysd.read_xmile('SIR model.xmile')
model.doc()
and then: mat = pysd.testing.create_bounds_test_matrix(model)
mat
(There are clearly some errors in here at the moment!) and then: pysd.testing.bounds_test(model.run(), bounds=mat) unfortunately when I do this at the moment, I'm getting Sorry not to be more help - hope you work out what you need. James |
I'm going to leave this open as a feature request for future dev, so that we can put in an option for hard limits down the line. @alexprey, you probably know more about this than I do. What does the XMILE spec have to say about the different types of limits? |
Thanks a lot for your explanation, James. Very helpful. I wonder if the issue in my example is not just about limits, but also non-negative stocks. When I created the stocks in my model, I set them to be non-negative and that's recorded in the .xmile file. However, PySD coversion is happy to have "negative" number of people in the Susceptible stock under certain outflow conditions. I notice that in your equations you explicitly defined what should happen in case of a negative stock:
I couldn't find an equivalent function in Stella, except for setting the stock as non-negative. Perhaps the code generated when you load the model could check for that? Assuming it's possible to pass the non-negative flag from .xmile parser downstream...
|
Hi every one! 😸 But, xmile is extendable language and I think it's a good point to think about introducing additional attributes and tags for stocks and flows to define custom range of value bounds. Regards, Alexey Mulyukin |
When I set limits to stocks (say, 0-1000), PySD doesn't seem to respect them and I get runaway values in my SIR model. Is there some other setting I'm missing? When I run the model in Stella it works correctly.
model.doc()
shows that limits are set for stocks, but that doesn't seem to have any impact. I've attached the .xmile model from Stella.SIR model.zip
The text was updated successfully, but these errors were encountered: