Skip to content

Commit

Permalink
added plots for cross checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ThummeTo committed Aug 21, 2024
1 parent b4e2cce commit 01cabc6
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 27 deletions.
1 change: 1 addition & 0 deletions cross_checks/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
FMI = "14a09403-18e3-468f-ad8a-74f8dda2d9ac"
Expand Down
1 change: 1 addition & 0 deletions cross_checks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ optional arguments:
hasn't been executed (e.g. officially not
compliant FMUs if they are not skipped)
--commitfailed Also commit the result file for failed FMUs
--plotfailed Plot result for failed FMUs (e.g. debugging)
-h, --help show this help message and exit
```
Expand Down
82 changes: 56 additions & 26 deletions cross_checks/cross_check.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ using DelimitedFiles
using Tables
using Statistics
using DifferentialEquations
using Plots, Colors

import Base64

Expand Down Expand Up @@ -66,6 +67,9 @@ function parse_commandline()
"--commitfailed"
help = "Also commit the result file for failed FMUs"
action = :store_true
"--plotfailed"
help = "Plot result for failed FMUs"
action = :store_true

end
println("Arguments used for cross check:")
Expand All @@ -75,18 +79,19 @@ function parse_commandline()
return parse_args(s)
end

function runCrossCheckFmu(
function runCrossCheckFMU(
checkPath::String,
resultPath::String,
check::FmuCrossCheck,
skipnotcompliant::Bool,
commitrejected::Bool,
commitfailed::Bool,
plotfailed::Bool
)::FmuCrossCheck
pathToFMU = joinpath(checkPath, "$(check.fmuCheck).fmu")

fmuToCheck = nothing
try
#try
if !(check.notCompliant && skipnotcompliant)
fmuToCheck = loadFMU(pathToFMU)
info(fmuToCheck)
Expand Down Expand Up @@ -200,11 +205,34 @@ function runCrossCheckFmu(
if commitfailed
mkpath(resultPath)
cd(resultPath)

rm("passed", force = true)
rm("rejected", force = true)
rm("README.md", force = true)
touch("failed")
end
if plotfailed
mkpath(resultPath)
cd(resultPath)

names = keys(GfmuRefValues)
num = length(names)-1
colors = distinguishable_colors(num, [RGB(1,1,1), RGB(0,0,0)])

fig = plot()
for j in 1:num
ts = GfmuRefValues[1]
vals = GfmuRefValues[1+j]
plot!(fig, ts, vals; style=:solid, color=colors[j], label="$(names[j])")

ts = GsimData.values.t
vals = collect(u[j] for u in GsimData.values.saveval)
plot!(fig, ts, vals; style=:dash, color=colors[j], label=:none)
end
display(fig)
@assert false
end

end
else
check.skipped = true
Expand All @@ -218,28 +246,28 @@ function runCrossCheckFmu(
end
end
check.error = nothing
catch e
@warn e
check.result = nothing
check.skipped = false
io = IOBuffer()
showerror(io, e)
check.error = String(take!(io))
check.success = false
mkpath(resultPath)
cd(resultPath)
rm("rejected", force = true)
rm("passed", force = true)
rm("README.md", force = true)
if commitfailed
touch("failed")
end
finally
try
unloadFMU(fmuToCheck)
catch
end
end
# catch e
# @warn e
# check.result = nothing
# check.skipped = false
# io = IOBuffer()
# showerror(io, e)
# check.error = String(take!(io))
# check.success = false
# mkpath(resultPath)
# cd(resultPath)
# rm("rejected", force = true)
# rm("passed", force = true)
# rm("README.md", force = true)
# if commitfailed
# touch("failed")
# end
# finally
# try
# unloadFMU(fmuToCheck)
# catch
# end
# end
return check

end
Expand All @@ -261,6 +289,7 @@ function main()
skipnotcompliant = haskey(ENV, "crosscheck_skipnotcompliant") ? true : parsed_args["skipnotcompliant"]
commitrejected = parsed_args["commitrejected"]
commitfailed = parsed_args["commitfailed"]
plotfailed = haskey(ENV, "crosscheck_plotfailed") ? true : parsed_args["plotfailed"]

# checking of inputs
if fmiVersion != "2.0"
Expand Down Expand Up @@ -307,7 +336,7 @@ function main()
end

# Excecute FMUs
crossChecks = getFmusToTest(fmiCrossCheckRepoPath, fmiVersion, os)
crossChecks = getFMUsToTest(fmiCrossCheckRepoPath, fmiVersion, os)
if !includeFatals
crossChecks = filter(c -> (!(c.system in EXCLUDED_SYSTEMS)), crossChecks)
end
Expand Down Expand Up @@ -338,13 +367,14 @@ function main()
cd(checkPath)
println("Checking $check for $checkPath and expecting $resultPath")

check = runCrossCheckFmu(
check = runCrossCheckFMU(
checkPath,
resultPath,
check,
skipnotcompliant,
commitrejected,
commitfailed,
plotfailed,
)
crossChecks[index] = check
end
Expand Down
2 changes: 1 addition & 1 deletion cross_checks/cross_check_lib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Returns a array of all available FMI Cross Checks
- `fmiVersion::String`: FMI Version used for running the FMUs. Note: Currently only 2.0 officially supported
- `os::String`: The operating system that is used for running the FMUs
"""
function getFmusToTest(
function getFMUsToTest(
repoPath::String,
fmiVersion::String,
os::String,
Expand Down

0 comments on commit 01cabc6

Please sign in to comment.