Closed Saityi closed 1 year ago
Dr Osgood (@ndo885) suggested (in a 1-1 meeting) that generated dynamic variables for flows use the flow name as a base for gensym. This has been added in 4d63d06 ; I plan to do the same for dynamic variable expansion. Interim variables will use the original dynamic variable's name.
d026566 addresses the dynamic variables also being used as a base for generated variable names.
Updated screenshots of SIR models via Graph
:
(Inferred dyvars example)
(Idea # 3 example)
fyi @ndo885 @Xiaoyan-Li
Description
In the target branch of this pull request,
functionStructureInSchema
, a new data type,StockAndFlowF
, has been added to allow for the flow equations of a Stock and Flow model to be captured in the model itself instead of as separate Julia equations. This gives rise to a new difficulty in definition of models: it is very tedious to specify the equations in this new form. One must manually write out the equations as symbolic expressions of tuples, like so:Notable difficulties with this syntax are:
tmp1 = a + b; tmp2 = tmp1 + c; tmp3 = tmp2 + d; tmp4 = tmp3 + e
) rather than just specifying what you mean likef = a + b + c + d + e
:varName
) rather than just naming things (e.g.varName
):S => (:F_NONE, :inf, :N)
, so understanding what has an arrow from where is less directChanges
Add a macro
stock_and_flow
in a new moduleSyntax
which allows Stock and Flow models to be defined using a more configuration language style syntax, e.g.This new syntax has a couple 'syntactic sugar' features:
:flowName => :dynamicVariableName
, and the actual flow equation is specified as a dynamic variable; with this new syntax, dynamic variables can be inferred, and the flow can have an equation specifically on it.As an example, see this version of the model which is the same as the other two above:
Testing
When written in the longer form (see the second example) so that all of the variable names match, you will find the first two models are
==
, partially confirming the transformations performed.When written in the shorter form, the variables are all inferred, so it's less clear it's the same model. There may be bugs in the implementation.
I would like to request testing suggestions from @Xiaoyan-Li especially because this has not been thoroughly tested and may contain many bugs.
~TODOs / Discussion~
☁
) all currently resolve to:F_NONE
. There is no differentiation between them. Is there a way to differentiate between them as input toStockAndFlowF
?~☁
; right now, that keyword is simplyTODO
, which isn't desirable. What should it be?NOTHING
?FNONE
?THE_GREAT_VOID
?~Graph
'd look like~Note on differences
You may notice in the two
Graph
diagrams above a strange arrow in the new version not in the original: this is an artifact of the 'binop' stage, but should be the same model. Specifically:##672 = v_prevalence = I / N
##673 = v_meanInfectiousContactPerS = c * ##672
##674 = S * beta
-- this is part ofv_newInfections
pulled out, the artifact mentioned.##675 = v_newInfections = ##674 * ##672
##676 = v_newRecovery = I / tRec
That is,
v_newInfections = S * v_perSIncidenceRate
==v_newInfections = S * beta * c * (I / N)
.As far as I can tell, despite the differences in the appearance of the models when
Graph
'd, they are the same model encoded slightly differently.Further examples
Dr Nathaniel Osgood gave, as an example of the desired syntax, this model definition:
This syntax now defines an SIR model when used this macro, and when
Graph
'd, looks like:This may not be exactly right but I'm not sure how to verify the changes (see the testing section of this PR).
FYI
@Xiaoyan-Li @ndo885