AlgebraicJulia / StockFlow.jl

https://algebraicjulia.github.io/StockFlow.jl/
MIT License
65 stars 6 forks source link

Created Stratification DSL. Required adding getter methods for lss, … #83

Closed neonWhiteout closed 1 year ago

neonWhiteout commented 1 year ago

…lssv, etc to StockFlow.jl, several methods to Syntax.jl (incl infer_links, which is now exported), and a Stratification.jl file. Also created a Stratification tests file and added more tests to Syntax.

neonWhiteout commented 1 year ago

Beyond maybe some comments and formatting, this should be fine.

neonWhiteout commented 1 year ago

Composition DSL has been separated out into #85

neonWhiteout commented 1 year ago

We may want to discuss the use of global flags, which I also use in Composition. I'm unsure what the best practice is. We might just want to delete them altogether.

neonWhiteout commented 1 year ago

If we want to hold off longer I can try generalizing to allow for any amount of arguments. Would need to revamp the stratification syntax, but beyond that shouldn't be too difficult.

Struggling with macros which take a variable number of arguments...

neonWhiteout commented 1 year ago

Have any good ideas for a syntax to generalize beyond a pullback with only 2?

figure it'd be something like [(a1, ..., an), (b1, ..., bm), ... (x1, ..., xk)] => t1, but I dunno if there's something better.

Also, converting all those cumbersome vector and dicts to a struct with all the information for each stock flow.

I've sunk a lot of time into this...

neonWhiteout commented 1 year ago

https://github.com/neonWhiteout/StockFlow.jl/tree/Multi_Stratification Generalized stratification. Now works for an arbitrary number of stockflows.

Significantly different from present stratification, however. Uses structs and a lot of broadcasting. Notation is as I described in the previous comment.

I'm thinking I port over the structs and some of the structure into this branch's stratify, then make a separate stratify macro for the generalized form. Currently using the name 'nstratify', because it can have 'n' inputs, but idk.

neonWhiteout commented 1 year ago

Little funny. When I call a macro with something like A => B, it interprets that as an expression. In a function call, it's bound to a variable. When I try getting the value of that variable inside another expression, it tries finding the variables for A and B, but it isn't defined. In effect, it's unwrapping the original expression.

As such, need to wrap it in another expression. Expr(:quote, my_var)

neonWhiteout commented 1 year ago

Generalized stratification. Now works for an arbitrary number of stockflows.

Please see here for both generalized stratification and a rework of Stratification. We object oriented now.

Need to write tests for generalized stratification, but all the old tests still pass (after slight modification to use the right types)

neonWhiteout commented 1 year ago

May want to close this in favor of #87. Started a new branch because it is quite different from this one, though it's based off of it.