Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Corrected active_initial (from Vensim) behavior #184
This function didn't prevent circular init (with my World3 again...)
I passed the parameters with "lambda" expressions to avoid premature evaluation of the first parameter (the thing that we exactly do not want by calling active_initial) :
With that update, World3 Vensim model is (normally) fully transpilable and runnable with PySD, without any manual edit (I invite you to try), but it may break compatibility with py models that use former active_initial implementation.
I add a cast to np.float64 before rewriting the numeric constants into the Python model because I noticed that the type of the number changes the output of my model. Particularly the variable perceived_food_ratio of W3 stay at 1 the two first steps and start to increase only at step 3 if I let some init at 1, but start to increase at the second step (as in Vensim) if we put 1.0... I am afraid that this int/float difference has other impacts.
Do I need to create a unit test and a test model for this too?
The ACTIVE INITIAL example provided by Vensim is even not working with PySD...
Here is the doc : https://vensim.com/documentation/index.html?fn_active_initial.htm
referenced this pull request
Jun 21, 2018
Thanks @ainar, this is an interested case and it's a good time for founding that :)
If I understand correctly, the unit test we had for ACTIVE INITIAL had been passing, but there was still a problem with active initial because:
Is that correct? If so, we probably should update the test case in the test models repository so that it fails when it should. @ainar is that something you'd mind doing?
To fix the problem, we need the parameters to
Another way to do this could be to add to the
"active initial": lambda element, subscript_dict, args: ( "functions.active_initial(lambda: %s, lambda: %s)" % args,  )
Then we wouldn't have to add anything to the grammar. What do you think? Is this less clear?
It is possible that there are other situations in which we'll need delayed evaluation. If there are lots, we might consider adding another whole category (like 'builders') that handles functions with delayed evaluation.
@JamesPHoughton yep, you are right. We need to add additional test for circular reference case.
I'm work for that