-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from JuliaReach/schillic/revise
Revise code
- Loading branch information
Showing
4 changed files
with
103 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,5 +20,5 @@ docs/site/ | |
|
||
Manifest.toml | ||
|
||
/docs/src/models/ | ||
docs/src/overview.md | ||
docs/src/models/ | ||
docs/src/overview* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,129 +1,89 @@ | ||
RM_dir = joinpath(dirname(pathof(ReachabilityModels)), "..") | ||
MODEL_DIR = joinpath(dirname(pathof(ReachabilityModels)), "..", "src/models") | ||
|
||
function load_model(instance::AbstractString; kwargs...) | ||
nakeinstance = replace(instance, Pair(".jl", "")) | ||
if haskey(kwargs, :X0) | ||
X0 = kwargs[:X0] | ||
else | ||
X0 = load_meta(nakeinstance)["X0"] | ||
function load_model(model::String; kwargs...) | ||
X0 = get(kwargs, :X0, nothing) | ||
if isnothing(X0) | ||
X0 = load_meta(model)["X0"] | ||
end | ||
dir = joinpath(RM_dir, "src/models", "$(nakeinstance)/$(nakeinstance).jl") | ||
if isfile(dir) | ||
include(dir) | ||
m = getfield(ReachabilityModels, Symbol(nakeinstance)) | ||
Base.invokelatest(m.model, X0) | ||
file = joinpath(MODEL_DIR, model, model * ".jl") | ||
if isfile(file) | ||
include(file) | ||
model_module = getfield(ReachabilityModels, Symbol(model)) | ||
Base.invokelatest(model_module.model, X0) | ||
else | ||
throw(ArgumentError("Model $nakeinstance not found")) | ||
throw(ArgumentError("Model $model not found")) | ||
end | ||
end | ||
|
||
function load_meta(instance::AbstractString) | ||
nakeinstance = replace(instance, Pair(".jl", "")) | ||
|
||
file = joinpath(RM_dir, "src/models", "$(nakeinstance)/$(nakeinstance)_meta.jl") | ||
function load_meta(model::String) | ||
file = joinpath(MODEL_DIR, model, model * "_meta.jl") | ||
if isfile(file) | ||
return include(file) | ||
else | ||
throw(ArgumentError("Meta for $instance not found")) | ||
throw(ArgumentError("Meta for $model not found")) | ||
end | ||
return S | ||
end | ||
|
||
function list_models(arg, f) | ||
function list_models(category, predicate) | ||
models = Vector() | ||
dir = joinpath(RM_dir, "src/models") | ||
for model in readdir(dir) | ||
meta = include(joinpath(dir, model, model * "_meta.jl")) | ||
if f(meta["info"][arg]) | ||
push!(models, meta["info"]["name"]) | ||
for model in readdir(MODEL_DIR) | ||
meta = include(joinpath(MODEL_DIR, model, model * "_meta.jl")) | ||
dict = meta["info"] | ||
if predicate(dict[category]) | ||
push!(models, dict["name"]) | ||
end | ||
end | ||
return models | ||
end | ||
|
||
# generate models overview in documentation | ||
function generate_summary() | ||
|
||
### OVERVIEW | ||
open(joinpath(dirname(@__FILE__), "../docs/src/overview.md"), "w") do file | ||
nmodels = length(list_models("dim", x -> x > 0)) | ||
nlinear = length(list_models("linear", x -> x == true)) | ||
nnonlinear = length(list_models("linear", x -> x == false)) | ||
nhybrid = length(list_models("hybrid", x -> x == true)) | ||
return print(file, """ | ||
# Models | ||
Here is a table showing the number of models for each type | ||
of system. | ||
| Linear | Nonlinear | Hybrid | Total | | ||
|:---------|------------:|---------:|---------:| | ||
|$(nlinear)|$(nnonlinear)|$(nhybrid)|$(nmodels)| | ||
""") | ||
end | ||
|
||
### LINEAR | ||
open(joinpath(dirname(@__FILE__), "../docs/src/models/linear_overview.md"), "w") do file | ||
function printrow(model) | ||
meta = load_meta(model)["info"] | ||
return println(file, "| **$(meta["name"])** | $(meta["dim"]) | $(-) | $(-) | $(-) |") | ||
end | ||
|
||
function write_overview_file(models, TYPE, type) | ||
open(joinpath(dirname(@__FILE__), "../docs/src/overview_$type.md"), "w") do file | ||
print(file, | ||
""" | ||
# Linear models | ||
Here are the models with linear dynamics. | ||
| Name | State dim | Input dim | Safety Property | Application Domain | Nominal Runtime (sec) | | ||
|:------|----------:|----------:|-----------------:|-------------------:|----------------:| | ||
""") | ||
|
||
linear_models = list_models("linear", x -> x == true) | ||
for model in linear_models | ||
printrow(model) | ||
end | ||
end | ||
# $TYPE models | ||
### NONLINEAR | ||
open(joinpath(dirname(@__FILE__), "../docs/src/models/nonlinear_overview.md"), "w") do file | ||
function printrow(model) | ||
meta = load_meta(model)["info"] | ||
return println(file, "| **$(meta["name"])** | $(meta["dim"]) | $(-) | $(-) | $(-) |") | ||
end | ||
|
||
print(file, | ||
""" | ||
# Nonlinear models | ||
Here are the models with nonlinear dynamics. | ||
The following models have $type dynamics. | ||
| Name | State dim | Input dim | Safesty Property | Application Domain | Nominal Runtime | | ||
|:------|----------:|----------:|-----------------:|-------------------:|----------------:| | ||
| Name | State dimension | | ||
|:------|----------------:| | ||
""") | ||
|
||
nonlinear_models = list_models("linear", x -> x == false) | ||
for model in nonlinear_models | ||
printrow(model) | ||
# | Name | State dim | Input dim | Safety Property | Application Domain | | ||
# |:------|----------:|----------:|----------------:|-------------------:| | ||
for model in models | ||
meta = load_meta(model)["info"] | ||
name = replace(meta["name"], "_" => "\\_") | ||
println(file, "| **$name** | $(meta["dim"]) |")# $(-) | $(-) | $(-) |") | ||
end | ||
end | ||
end | ||
|
||
### HYBRID | ||
open(joinpath(dirname(@__FILE__), "../docs/src/models/hybrid_overview.md"), "w") do file | ||
function printrow(model) | ||
meta = load_meta(model)["info"] | ||
return println(file, "| **$(meta["name"])** | $(meta["dim"]) | $(-) | $(-) | $(-) |") | ||
end | ||
# generate models summary in documentation | ||
function generate_summary() | ||
linear_models = list_models("linear", x -> x) | ||
nonlinear_models = list_models("linear", x -> !x) | ||
hybrid_models = list_models("hybrid", x -> x) | ||
|
||
open(joinpath(dirname(@__FILE__), "../docs/src/overview_total.md"), "w") do file | ||
nlinear = length(linear_models) | ||
nnonlinear = length(nonlinear_models) | ||
nhybrid = length(hybrid_models) | ||
ntotal = nlinear + nnonlinear + nhybrid | ||
print(file, """ | ||
# Model overview | ||
The following table shows the number of models for each type of system. | ||
| Linear | Nonlinear | Hybrid | Total | | ||
|:------:|:---------:|:------:|:-----:| | ||
|$nlinear|$nnonlinear|$nhybrid|$ntotal| | ||
""") | ||
return nothing | ||
end | ||
|
||
print(file, | ||
""" | ||
# Hybrid models | ||
Here are the models with hybrid systems. | ||
write_overview_file(linear_models, "Linear", "linear") | ||
|
||
| Name | State dim | Input dim | Safesty Property | Application Domain | Nominal Runtime | | ||
|:------|----------:|----------:|-----------------:|-------------------:|----------------:| | ||
""") | ||
write_overview_file(nonlinear_models, "Nonlinear", "nonlinear") | ||
|
||
hybrid_models = list_models("hybrid", x -> x == true) | ||
for model in hybrid_models | ||
printrow(model) | ||
end | ||
end | ||
return write_overview_file(hybrid_models, "Hybrid", "hybrid") | ||
end |