AlgebraicJulia / StockFlow.jl

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

Rewrite DSL #106

Closed neonWhiteout closed 10 months ago

neonWhiteout commented 11 months ago

Created a DSL for rewrite:

aged_sir_rewritten = @rewrite aged_sir begin

    :redefs
    v_meanInfectiousContactsPerSv_cINC := cc_C * v_prevalencev_INC_post
    v_meanInfectiousContactsPerSv_cINA := cc_A * v_prevalencev_INA_post

    :parameters
    + fcc
    + fca
    + fac
    + faa

    :dynamic_variables

    + v_CCContacts = fcc * v_prevalencev_INC
    + v_CAContacts = fca * v_prevalencev_INA

    + v_ACContacts = fac * v_prevalencev_INC
    + v_AAContacts = faa * v_prevalencev_INA

    + v_prevalencev_INC_post = v_CCContacts + v_CAContacts
    + v_prevalencev_INA_post = v_ACContacts + v_AAContacts

end

Requires further tests to fix edge case bugs, but currently works with all our examples. Creates L, I and R, defines the two homs and applies the rule.

codecov[bot] commented 11 months ago

Codecov Report

Attention: 89 lines in your changes are missing coverage. Please review.

Comparison is base (e2b3ca8) 49.96% compared to head (d5717e2) 57.90%.

Files Patch % Lines
src/syntax/Rewrite.jl 82.57% 77 Missing :warning:
src/StockFlow.jl 62.06% 11 Missing :warning:
src/Syntax.jl 96.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #106 +/- ## ========================================== + Coverage 49.96% 57.90% +7.93% ========================================== Files 9 10 +1 Lines 1523 2012 +489 ========================================== + Hits 761 1165 +404 - Misses 762 847 +85 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

neonWhiteout commented 11 months ago

Updated rewrite syntax

neonWhiteout commented 11 months ago

The above example in the new syntax would be

aged_sir_rewritten = @rewrite aged_sir begin

    :redefs
    v_meanInfectiousContactsPerSv_cINC = cc_C * v_prevalencev_INC_post
    v_meanInfectiousContactsPerSv_cINA = cc_A * v_prevalencev_INA_post

    :parameters
    fcc
    fca
    fac
    faa

    :dynamic_variables

    v_CCContacts = fcc * v_prevalencev_INC
    v_CAContacts = fca * v_prevalencev_INA

    v_ACContacts = fac * v_prevalencev_INC
    v_AAContacts = faa * v_prevalencev_INA

    v_prevalencev_INC_post = v_CCContacts + v_CAContacts
    v_prevalencev_INA_post = v_ACContacts + v_AAContacts

end