Skip to content

Commit

Permalink
code styling
Browse files Browse the repository at this point in the history
  • Loading branch information
ThummeTo committed Aug 19, 2024
1 parent c5fe840 commit 8d90073
Show file tree
Hide file tree
Showing 16 changed files with 1,061 additions and 2,800 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
| Package evaluation| [![Run PkgEval](https://github.com/ThummeTo/FMI.jl/actions/workflows/Eval.yml/badge.svg)](https://github.com/ThummeTo/FMI.jl/actions/workflows/Eval.yml) |
| Code coverage | [![Coverage](https://codecov.io/gh/ThummeTo/FMI.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/ThummeTo/FMI.jl) |
| Collaboration | [![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor's%20Guide-blueviolet)](https://github.com/SciML/ColPrac) |
| Formatting | [![SciML Code Style](https://img.shields.io/static/v1?label=code%20style&message=SciML&color=9558b2&labelColor=389826)](https://github.com/SciML/SciMLStyle) |

## Breaking Changes in FMI.jl (starting from v0.14.0 until release of v1.0.0)
If you want to migrate your project from [*FMI.jl*](https://github.com/ThummeTo/FMI.jl) < v1.0.0 to >= v1.0.0, you will face some breaking changes - but they are worth it as you will see! We decided to do multiple smaller breaking changes starting with v0.14.0, instead of one big one. Some of them are already implemented (checked), some are still on the todo (unchecked) but will be implemented before releasing v1.0.0.
Expand Down
257 changes: 181 additions & 76 deletions cross_checks/cross_check.jl

Large diffs are not rendered by default.

73 changes: 56 additions & 17 deletions cross_checks/cross_check_lib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@ Hint: This will not check the cross check repository for integrety
# Returns
- `repoPath::String`: The path where the repository can be found locally (including the repository name)
"""
function getFmuCrossCheckRepo(crossCheckRepo::String, unpackPath::Union{String, Nothing} = nothing)::String
function getFmuCrossCheckRepo(
crossCheckRepo::String,
unpackPath::Union{String,Nothing} = nothing,
)::String
@info "Create temporary working directory"
if unpackPath === nothing
# cleanup=true leads to issues with automatic testing on linux server.
unpackPath = mktempdir(; prefix="fmicrosschecks_", cleanup=false)
unpackPath = mktempdir(; prefix = "fmicrosschecks_", cleanup = false)
@info "temporary working directory created at $(unpackPath)"
end

@info "Retrieving cross-checks"
fmiCrossCheckRepoPath = joinpath(unpackPath, FMI_CROSS_CHECK_REPO_NAME)
if !isdir(fmiCrossCheckRepoPath)
println("Checking out cross-checks from $(crossCheckRepo)...")
run(Cmd(`$(git()) clone $(crossCheckRepo)`, dir=unpackPath))
run(Cmd(`$(git()) clone $(crossCheckRepo)`, dir = unpackPath))
else
println("Using existing cross-checks at $(fmiCrossCheckRepoPath)")
end
Expand All @@ -39,7 +42,11 @@ 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(repoPath::String, fmiVersion::String, os::String)::Vector{FmuCrossCheck}
function getFmusToTest(
repoPath::String,
fmiVersion::String,
os::String,
)::Vector{FmuCrossCheck}
results = []
fmiTypes = [ME, CS]
for type in fmiTypes
Expand All @@ -65,7 +72,22 @@ function getFmusToTest(repoPath::String, fmiVersion::String, os::String)::Vector
@info "$checkPath is not compliant with latest rules"
notCompliant = true
end
push!(results, FmuCrossCheck(fmiVersion, type, os, system, version, check, notCompliant, missing, missing, missing, missing))
push!(
results,
FmuCrossCheck(
fmiVersion,
type,
os,
system,
version,
check,
notCompliant,
missing,
missing,
missing,
missing,
),
)
end
end
end
Expand All @@ -83,7 +105,11 @@ It is normalized to the difference between the smallest and largest values of th
# Returns
- `nrmse::Float64`: the mean of the nrmse of all recorded variables
"""
function calucateNRMSE(recordedVariables::Vector{String}, simData::FMUSolution, referenceData)::Float64
function calucateNRMSE(
recordedVariables::Vector{String},
simData::FMUSolution,
referenceData,
)::Float64
squaredErrorSums = zeros(length(recordedVariables))
valueCount = zeros(length(recordedVariables))
minimalValues = []
Expand All @@ -96,16 +122,26 @@ function calucateNRMSE(recordedVariables::Vector{String}, simData::FMUSolution,
if (length(minimalValues) < nameIndex + 1)
push!(minimalValues, referenceData[nameIndex+1][valIndex])
else
minimalValues[nameIndex] = min(minimalValues[nameIndex], referenceData[nameIndex+1][valIndex])
minimalValues[nameIndex] = min(
minimalValues[nameIndex],
referenceData[nameIndex+1][valIndex],
)
end
if (length(maximalValues) < nameIndex + 1)
push!(maximalValues, referenceData[nameIndex+1][valIndex])
else
maximalValues[nameIndex] = max(maximalValues[nameIndex], referenceData[nameIndex+1][valIndex])
maximalValues[nameIndex] = max(
maximalValues[nameIndex],
referenceData[nameIndex+1][valIndex],
)
end
squaredErrorSums[nameIndex] += ((simData.values.saveval[simIndex][nameIndex] - referenceData[nameIndex+1][valIndex]))^2
squaredErrorSums[nameIndex] +=
((
simData.values.saveval[simIndex][nameIndex] -
referenceData[nameIndex+1][valIndex]
))^2
end
break;
break
end
end
end
Expand All @@ -115,13 +151,18 @@ function calucateNRMSE(recordedVariables::Vector{String}, simData::FMUSolution,
if (valueRange == 0)
valueRange = 1
end
value = (sqrt(squaredErrorSums[recordValue]/valueCount[recordValue])/(valueRange))
value =
(sqrt(squaredErrorSums[recordValue] / valueCount[recordValue]) / (valueRange))
push!(errors, value)
end
return mean(errors)
end

function create_ssh_private_key(dir::AbstractString, ssh_pkey::AbstractString, os::AbstractString)::String
function create_ssh_private_key(
dir::AbstractString,
ssh_pkey::AbstractString,
os::AbstractString,
)::String
is_linux = occursin("linux", os)
if is_linux
run(`chmod 700 $dir`)
Expand Down Expand Up @@ -158,10 +199,8 @@ function decode_ssh_private_key(content::AbstractString)::String
return content
end

@info(
"This doesn't look like a raw SSH private key.
I will assume that it is a Base64-encoded SSH private key."
)
@info("This doesn't look like a raw SSH private key.
I will assume that it is a Base64-encoded SSH private key.")
decoded_content = String(Base64.base64decode(content))
return decoded_content
end
end
131 changes: 70 additions & 61 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,72 +3,77 @@
# Licensed under the MIT license. See LICENSE file in the project root for details.
#

import Pkg; Pkg.develop(path=joinpath(@__DIR__,"../../FMI.jl"))
import Pkg;
Pkg.develop(path = joinpath(@__DIR__, "../../FMI.jl"));
using Documenter, Plots, JLD2, DataFrames, CSV, MAT, FMI, FMIImport, FMICore
using Documenter: GitHubActions

makedocs(sitename="FMI.jl",
format = Documenter.HTML(
collapselevel = 1,
sidebar_sitename = false,
edit_link = nothing,
size_threshold = 512000,
size_threshold_ignore = ["deprecated.md"]
),
modules = [FMI, FMIImport, FMICore],
checkdocs=:exports,
linkcheck=true,
linkcheck_ignore=["https://thummeto.github.io/FMI.jl/dev/examples/inputs/", "https://github.com/ThummeTo/FMICore.jl/blob/main/src/FMI2_c.jl#L718"],
pages= Any[
"Introduction" => "index.md"
"Features" => "features.md"
"FAQ" => "faq.md"
"Examples" => [
"Overview" => "examples/overview.md"
"Simulate" => "examples/simulate.md"
"Parameterize" => "examples/parameterize.md"
"Multiple instances" => "examples/multiple_instances.md"
"Modelica conference 2021" => "examples/modelica_conference_2021.md"
"Manipulation" => "examples/manipulation.md"
"Multithreading" => "examples/multithreading.md"
"Multiprocessing" => "examples/multiprocessing.md"
]
"User Level API - FMI.jl" => "library.md"
"Developer Level API" => Any[
"fmi version independent content" => Any[
"fmi_lowlevel_library_types.md",
"fmi_lowlevel_library_constants.md",
"fmi_lowlevel_library_functions.md"
],
"FMI2 specific content" => Any[
"fmi2_lowlevel_library_types.md",
"fmi2_lowlevel_library_constants.md",
"FMI2 Functions in FMI Import/Core .jl" => Any[
"fmi2_lowlevel_modeldescription_functions.md",
"fmi2_lowlevel_library_functions.md",
"fmi2_lowlevel_ME_functions.md",
"fmi2_lowlevel_CS_functions.md",
]
makedocs(
sitename = "FMI.jl",
format = Documenter.HTML(
collapselevel = 1,
sidebar_sitename = false,
edit_link = nothing,
size_threshold = 512000,
size_threshold_ignore = ["deprecated.md"],
),
modules = [FMI, FMIImport, FMICore],
checkdocs = :exports,
linkcheck = true,
linkcheck_ignore = [
"https://thummeto.github.io/FMI.jl/dev/examples/inputs/",
"https://github.com/ThummeTo/FMICore.jl/blob/main/src/FMI2_c.jl#L718",
],
pages = Any[
"Introduction" => "index.md"
"Features" => "features.md"
"FAQ" => "faq.md"
"Examples" => [
"Overview" => "examples/overview.md"
"Simulate" => "examples/simulate.md"
"Parameterize" => "examples/parameterize.md"
"Multiple instances" => "examples/multiple_instances.md"
"Modelica conference 2021" => "examples/modelica_conference_2021.md"
"Manipulation" => "examples/manipulation.md"
"Multithreading" => "examples/multithreading.md"
"Multiprocessing" => "examples/multiprocessing.md"
]
"User Level API - FMI.jl" => "library.md"
"Developer Level API" => Any[
"fmi version independent content"=>Any[
"fmi_lowlevel_library_types.md",
"fmi_lowlevel_library_constants.md",
"fmi_lowlevel_library_functions.md",
],
"FMI2 specific content"=>Any[
"fmi2_lowlevel_library_types.md",
"fmi2_lowlevel_library_constants.md",
"FMI2 Functions in FMI Import/Core .jl"=>Any[
"fmi2_lowlevel_modeldescription_functions.md",
"fmi2_lowlevel_library_functions.md",
"fmi2_lowlevel_ME_functions.md",
"fmi2_lowlevel_CS_functions.md",
],
"FMI3 specific content" => Any[
"fmi3_lowlevel_library_types.md",
"fmi3_lowlevel_library_constants.md",
"FMI3 Functions in FMI Import/Core .jl" => Any[
"fmi3_lowlevel_modeldescription_functions.md",
"fmi3_lowlevel_library_functions.md",
"fmi3_lowlevel_ME_functions.md",
"fmi3_lowlevel_CS_functions.md",
"fmi3_lowlevel_SE_functions.md",
]
],
"FMI3 specific content"=>Any[
"fmi3_lowlevel_library_types.md",
"fmi3_lowlevel_library_constants.md",
"FMI3 Functions in FMI Import/Core .jl"=>Any[
"fmi3_lowlevel_modeldescription_functions.md",
"fmi3_lowlevel_library_functions.md",
"fmi3_lowlevel_ME_functions.md",
"fmi3_lowlevel_CS_functions.md",
"fmi3_lowlevel_SE_functions.md",
],
]
"API Index" => "index_library.md"
"FMI Tool Information" => "fmi-tool-info.md"
"Related Publication" => "related.md"
"Contents" => "contents.md"
hide("Deprecated" => "deprecated.md")
],
]
)
"API Index" => "index_library.md"
"FMI Tool Information" => "fmi-tool-info.md"
"Related Publication" => "related.md"
"Contents" => "contents.md"
hide("Deprecated" => "deprecated.md")
],
)

function deployConfig()
github_repository = get(ENV, "GITHUB_REPOSITORY", "")
Expand All @@ -80,4 +85,8 @@ function deployConfig()
return GitHubActions(github_repository, github_event_name, github_ref)
end

deploydocs(repo = "github.com/ThummeTo/FMI.jl.git", devbranch = "main", deploy_config = deployConfig())
deploydocs(
repo = "github.com/ThummeTo/FMI.jl.git",
devbranch = "main",
deploy_config = deployConfig(),
)
Loading

0 comments on commit 8d90073

Please sign in to comment.