Skip to content

Conversation

lrennels
Copy link
Collaborator

@lrennels lrennels commented Apr 23, 2021

This PR (1) adds a multiplier build in component to help with FUND-FAIR unit conversion and (2) per suggestion from #560 adds an @allow_missing wrapper to the adder and multiplier components, which also simplifies MimiFUND-MimiFAIR-Flat.

This means that if the multiplier component:

@defcomp multiplier begin

    multiply  = Parameter(index=[time])
    input       = Parameter(index=[time])
    output      = Variable(index=[time])

    function run_timestep(p, v, d, t)
        v.output[t] = @allow_missing(p.input[t]) * p.multiply[t]
    end
end

accesses a missing in p.input[t] it will not throw an error but just pass the value through. Sometimes needing this can be avoid with setting a first and last for the multiplier component, but sometimes there's still an irritating off-by-one issue. For example in MimiFUND-MimiFAIR-Fla we have

set_param!(m, :multiplier, :multiplier, 1/1000) # convert Mtons CO₂ coming out of FUND to Gtons CO₂ going into FAIR
connect_param!(m, :multiplier, :input, :emissions, :mco2)
connect_param!(m, :co2_cycle, :E_CO₂, :multiplier, :output, FAIR_CO₂_backup, backup_offset = 1)

where the :mco2 from FUND's :emission is missing for the first year FUND runs (1950), and thus we would need multiplier to run from FUND_first + 1 to FUND_last ... or do something fancy with backups which also works. In my opinion we want these to be sort of no-brainer pass-through components that don't do anything fancy so I'd rather just do @allow_missing but we can discuss if you'd like.

@codecov
Copy link

codecov bot commented Apr 23, 2021

Codecov Report

Merging #816 (36f7eed) into master (cf87a03) will decrease coverage by 0.13%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #816      +/-   ##
==========================================
- Coverage   84.25%   84.12%   -0.14%     
==========================================
  Files          39       40       +1     
  Lines        3551     3552       +1     
==========================================
- Hits         2992     2988       -4     
- Misses        559      564       +5     
Flag Coverage Δ
unittests 84.12% <0.00%> (-0.14%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/Mimi.jl 100.00% <ø> (ø)
src/components/adder.jl 0.00% <0.00%> (ø)
src/components/multiplier.jl 0.00% <0.00%> (ø)
src/core/defcomp.jl 82.48% <ø> (+0.46%) ⬆️
src/explorer/buildspecs.jl 92.00% <0.00%> (-2.67%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c17e50c...36f7eed. Read the comment docs.

arnavgautam
arnavgautam previously approved these changes Apr 26, 2021
Copy link
Collaborator

@arnavgautam arnavgautam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just minor comments on the tutorial language


* `adder.jl` -- Defines `Mimi.adder`, which simply adds two parameters, `input` and `add` and stores the result in `output`.

* `multiplier.jl` -- Defines `Mimi.multiplier`, which simply multiplies two parameters, `input` and `add` and stores the result in `output`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second parameter here is 'multiply' right?

## 3. Pre-compilation and built-in components

To get `__precompile__()` to work required moving the creation of "helper" components to an `__init__()` method in Mimi.jl, which is run automatically after Mimi loads. It defines the two "built-in" components, from `adder.jl` and `connector.jl` in the `components` subdirectory.
To get `__precompile__()` to work required moving the creation of "helper" components to an `__init__()` method in Mimi.jl, which is run automatically after Mimi loads. It defines the two "built-in" components, from `adder.jl`, `multiplier.jl`, and `connector.jl` in the `components` subdirectory.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there three "built-in" components now?

@lrennels lrennels merged commit 91603d4 into master Apr 27, 2021
@lrennels lrennels deleted the comps branch April 27, 2021 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants