Skip to content

Commit

Permalink
Add a test for non-finite data in publication_plot (#738)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Apr 30, 2024
1 parent 6609655 commit 8ed2e30
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
18 changes: 5 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,16 @@ jobs:
os: ubuntu-latest
arch: x64
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v1
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
- uses: codecov/codecov-action@v4
with:
file: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
10 changes: 10 additions & 0 deletions src/visualization/publication_plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ function publication_data(
output_array = fill(NaN, length(quantiles), max_stages)
for stage in 1:max_stages
stage_data = stage_function.([data[stage] for data in dataset])
for (i, s) in enumerate(stage_data)
if !isfinite(s)
error(
"Unable to plot `publication_plot` because stage $stage " *
"of replication $i contains data that is not finite. " *
"The data function must return a finite real-valued " *
"scalar. Got: $s",
)
end
end
output_array[:, stage] .= Statistics.quantile(stage_data, quantiles)
end
return output_array
Expand Down
28 changes: 18 additions & 10 deletions test/visualization/visualization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,24 @@ function test_SpaghettiPlot()
end

function test_PublicationPlot()
data = SDDP.publication_data(
[
[Dict{Symbol,Any}(:x => 1), Dict{Symbol,Any}(:x => 5)],
[Dict{Symbol,Any}(:x => 2), Dict{Symbol,Any}(:x => 6)],
[Dict{Symbol,Any}(:x => 3), Dict{Symbol,Any}(:x => 4)],
],
[0.0, 1.0],
(d) -> d[:x],
)
@test data == [1 4; 3 6]
simulations = [
[Dict{Symbol,Any}(:x => 1), Dict{Symbol,Any}(:x => 5)],
[Dict{Symbol,Any}(:x => 2), Dict{Symbol,Any}(:x => 6)],
[Dict{Symbol,Any}(:x => 3), Dict{Symbol,Any}(:x => 4)],
]
data = SDDP.publication_data(simulations, [0.0, 0.25, 0.5, 1.0], d -> d[:x])
@test data == [1 4; 1.5 4.5; 2 5; 3 6]
for val in (-Inf, Inf, NaN)
simulations[2][2] = Dict{Symbol,Any}(:x => val)
@test_throws(
ErrorException(
"Unable to plot `publication_plot` because stage 2 of " *
"replication 2 contains data that is not finite. The data " *
"function must return a finite real-valued scalar. Got: $val",
),
SDDP.publication_data(simulations, [0.5], d -> d[:x]),
)
end
return
end

Expand Down

0 comments on commit 8ed2e30

Please sign in to comment.