Skip to content

Commit

Permalink
Merge pull request #623 from mimiframework/tests
Browse files Browse the repository at this point in the history
Fix failing tests
  • Loading branch information
lrennels authored Dec 18, 2019
2 parents 8e30eb0 + 278bdd3 commit 843c4de
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 92 deletions.
27 changes: 2 additions & 25 deletions docs/src/tutorials/tutorial_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,32 +97,12 @@ getdataframe(m, :Component1=>:Var1, :Component2=>:Var2) # request variables from
```

Try doing this for the `income` variable of the `socioeconomic` component using:
```jldoctest tutorial1; output = false
```jldoctest tutorial1; output = false, filter = r".*"s
getdataframe(m, :socioeconomic=>:income) # request one variable from one component
getdataframe(m, :socioeconomic=>:income)[1:16,:] # results for all regions in first year (1950)
# output
16×3 DataFrame
│ Row │ time │ regions │ income │
│ │ Int64 │ String │ Float64⍰ │
├─────┼───────┼─────────┼──────────┤
│ 1 │ 1950 │ USA │ 1643.9 │
│ 2 │ 1950 │ CAN │ 84.8225 │
│ 3 │ 1950 │ WEU │ 1913.32 │
│ 4 │ 1950 │ JPK │ 616.022 │
│ 5 │ 1950 │ ANZ │ 119.058 │
│ 6 │ 1950 │ EEU │ 87.9192 │
│ 7 │ 1950 │ FSU │ 167.309 │
│ 8 │ 1950 │ MDE │ 76.065 │
│ 9 │ 1950 │ CAM │ 40.5139 │
│ 10 │ 1950 │ LAM │ 193.139 │
│ 11 │ 1950 │ SAS │ 57.9714 │
│ 12 │ 1950 │ SEA │ 25.6943 │
│ 13 │ 1950 │ CHI │ 18.8014 │
│ 14 │ 1950 │ MAF │ 13.4482 │
│ 15 │ 1950 │ SSA │ 94.686 │
│ 16 │ 1950 │ SIS │ 6.82114 │
```

### Step 4. Access Results: Plots and Graphs
Expand All @@ -147,12 +127,9 @@ save("MyFilePath.svg", p)
```
More specifically for our tutorial use of FUND, try:

```jldoctest tutorial1; output = false, filter = r".*"s
```julia
p = Mimi.plot(m, :socioeconomic, :income)
save("MyFilePath.svg", p)
# output
```

#### Component Graph
Expand Down
3 changes: 1 addition & 2 deletions docs/src/tutorials/tutorial_2.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,14 @@ run(m)
A more complex example may a situation where you want to update several parameters, including some with a `:time` dimension, in conjunction with altering the time index of the model itself. DICE uses a default time horizon of 2005 to 2595 with 10 year increment timesteps. If you wish to change this, say, to 2000 to 2500 by 10 year increment timesteps and use parameters that match this time, you could use the following code:

First you upate the `time` dimension of the model as follows:
```jldoctest tutorial2; output = false
```jldoctest tutorial2; output = false, filter = r".*"s
const ts = 10
const years = collect(2000:ts:2500)
nyears = length(years)
set_dimension!(m, :time, years)
# output
[2000, 2010, 2020, 2030, 2040, 2050, 2060, 2070, 2080, 2090 … 2400, 2410, 2420, 2430, 2440, 2450, 2460, 2470, 2480, 2490, 2500]
```

Next, create a dictionary `params` with one entry `(k, v)` per external parameter by name `k` to value `v`. Each key `k` must be a symbol or convert to a symbol matching the name of an external parameter that already exists in the model definition. Part of this dictionary may look like:
Expand Down
55 changes: 4 additions & 51 deletions docs/src/tutorials/tutorial_3.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Note that as an alternative to using many of the `set_param!` calls above, one m

Now we can run the model and examine the results:

```jldoctest tutorial3; output = false
```jldoctest tutorial3; output = false, filter = r".*"s
# Run model
m = construct_model()
run(m)
Expand All @@ -136,39 +136,12 @@ getdataframe(m, :emissions, :E) # or m[:emissions, :E_Global] to return just the
# output
20×2 DataFrame
│ Row │ time │ E │
│ │ Int64 │ Float64⍰ │
├─────┼───────┼──────────┤
│ 1 │ 2015 │ 4211.09 │
│ 2 │ 2020 │ 15079.5 │
│ 3 │ 2025 │ 23922.3 │
│ 4 │ 2030 │ 30255.8 │
│ 5 │ 2035 │ 35175.7 │
│ 6 │ 2040 │ 39293.0 │
│ 7 │ 2045 │ 42947.7 │
│ 13 │ 2075 │ 62909.4 │
│ 14 │ 2080 │ 66496.9 │
│ 15 │ 2085 │ 70244.9 │
│ 16 │ 2090 │ 74173.1 │
│ 17 │ 2095 │ 78299.0 │
│ 18 │ 2100 │ 82638.8 │
│ 19 │ 2105 │ 87208.1 │
│ 20 │ 2110 │ 92022.3 │
```
Finally we can visualize the results via plotting:
```jldoctest tutorial3; output = false, filter = r".*"s
using VegaLite
Finally we can visualize the results via plotting and explorer:
```julia
# Plot model results
Mimi.plot(m, :emissions, :E);

# output
```
and via explorer:
```julia
# Observe all model result graphs in UI
explore(m)
```
Expand Down Expand Up @@ -357,7 +330,7 @@ using Mimi
include("MyModel.jl")
using .MyModel
```
```jldoctest tutorial3; output = false
```jldoctest tutorial3; output = false, filter = r".*"s
m = construct_MyModel()
run(m)
Expand All @@ -366,26 +339,6 @@ getdataframe(m, :emissions, :E_Global) # or m[:emissions, :E_Global] to return j
# output
20×2 DataFrame
│ Row │ time │ E_Global │
│ │ Int64 │ Float64⍰ │
├─────┼───────┼──────────┤
│ 1 │ 2015 │ 2392.08 │
│ 2 │ 2020 │ 7740.88 │
│ 3 │ 2025 │ 11842.4 │
│ 4 │ 2030 │ 14629.7 │
│ 5 │ 2035 │ 16686.5 │
│ 6 │ 2040 │ 18338.4 │
│ 7 │ 2045 │ 19763.7 │
│ 13 │ 2075 │ 27340.2 │
│ 14 │ 2080 │ 28694.1 │
│ 15 │ 2085 │ 30105.8 │
│ 16 │ 2090 │ 31581.4 │
│ 17 │ 2095 │ 33126.3 │
│ 18 │ 2100 │ 34745.6 │
│ 19 │ 2105 │ 36444.1 │
│ 20 │ 2110 │ 38226.2 │
```
```julia
# Observe model result graphs
Expand Down
12 changes: 2 additions & 10 deletions docs/src/tutorials/tutorial_4.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,22 +265,14 @@ explore(si; title = "MyWindow", model_index = 1) # we do not indicate scen_name

To view the results for one of the saved variables from the `save` command in `@defsim`, use the (unexported to avoid namespace collisions) `Mimi.plot` function. This function has the same keyword arguments and requirements as `explore` (except for `title`), and three required arguments: the `SimulationInstance`, the component name (as a `Symbol`), and the variable name (as a `Symbol`).

```jldoctest tutorial4; output = false, filter = r".*"s
```julia
Mimi.plot(si, :grosseconomy, :K)
# output
```
To save your figure, use the `save` function to save typical file formats such as [PNG](https://en.wikipedia.org/wiki/Portable_Network_Graphics), [SVG](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics), [PDF](https://en.wikipedia.org/wiki/PDF) and [EPS](https://en.wikipedia.org/wiki/Encapsulated_PostScript) files. Note that while `explore(sim_inst)` returns interactive plots for several graphs, `Mimi.plot(si, :foo, :bar)` will return only static plots.

```jldoctest tutorial4; output = false, filter = r".*"s
```julia
p = Mimi.plot(si, :grosseconomy, :K)
save("MyFigure.png", p)
# output
WARN Layer's shared color channel is overriden
WARN Layer's shared color channel is overriden
```

## Advanced Features - Social Cost of Carbon (SCC) Example
Expand Down
8 changes: 6 additions & 2 deletions test/test_components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ add_comp!(my_model, testcomp1)
# Testing to catch if before or after does not exist
@test_throws ErrorException add_comp!(my_model, testcomp2, before=:testcomp3)

# N.B. Throws ArgumentError in v1.0, but ErrorException in 0.7!
@test_throws ArgumentError add_comp!(my_model, testcomp2, after=:testcomp3)
# ArgumentError in v1.0-v1.2, ErrorException in v1.3
if(VERSION < v"1.3.0")
@test_throws ArgumentError add_comp!(my_model, testcomp2, after=:testcomp3)
else
@test_throws ErrorException add_comp!(my_model, testcomp2, after=:testcomp3)
end

# Add more components to model
add_comp!(my_model, testcomp2)
Expand Down
8 changes: 6 additions & 2 deletions test/test_model_structure_variabletimestep.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ last_A = 2150
m = Model()
set_dimension!(m, :time, years)

@test_throws ArgumentError add_comp!(m, A, after=:B)
# @test_throws ErrorException add_comp!(m, A, after=:B)
# ArgumentError in v1.0-v1.2, ErrorException in v1.3
if(VERSION < v"1.3.0")
@test_throws ArgumentError add_comp!(m, A, after=:B)
else
@test_throws ErrorException add_comp!(m, A, after=:B)
end

add_comp!(m, A)

Expand Down

0 comments on commit 843c4de

Please sign in to comment.