Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise Literate script and deactivate notebook generation #774

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 47 additions & 32 deletions docs/generate.jl
Original file line number Diff line number Diff line change
@@ -1,41 +1,56 @@
import Literate
using Literate: script, markdown, notebook

# source directory for model files written using Literate.jl format
source_dir = joinpath(@__DIR__, "..", "examples")

# target directory for the tests files (bare .jl files)
# target directory for script files (*.jl) (used in the tests)
target_dir_jl = joinpath(@__DIR__, "..", "test", "models", "generated")

# target directory for the markdown files (used by Documenter)
# target directory for markdown and notebook files (used by Documenter)
target_dir_md = joinpath(@__DIR__, "src", "generated_examples")
mkpath(target_dir_md)

# model files in sub-directories of source_dir
MODELS = ["Brusselator/Brusselator.jl",
"Building/Building.jl",
"DuffingOscillator/DuffingOscillator.jl",
"EMBrake/EMBrake.jl",
"Heat3D/Heat3D.jl",
"ISS/ISS.jl",
"LaubLoomis/LaubLoomis.jl",
"Lorenz/Lorenz.jl",
"LotkaVolterra/LotkaVolterra.jl",
"OpAmp/OpAmp.jl",
"SquareWaveOscillator/SquareWaveOscillator.jl",
"Platoon/Platoon.jl",
"ProductionDestruction/ProductionDestruction.jl",
"Quadrotor/Quadrotor.jl",
"SEIR/SEIR.jl",
"Spacecraft/Spacecraft.jl",
"TransmissionLine/TransmissionLine.jl",
"VanDerPol/VanDerPol.jl"]
MODELS = [
"Brusselator",
"Building",
"DuffingOscillator",
"EMBrake",
"Heat3D",
"ISS",
"LaubLoomis",
"Lorenz",
"LotkaVolterra",
"OpAmp",
"SquareWaveOscillator",
"Platoon",
"ProductionDestruction",
"Quadrotor",
"SEIR",
"Spacecraft",
"TransmissionLine",
"VanDerPol"
]

for model in MODELS
model_path = abspath(joinpath(source_dir, model))
for file in readdir(model_path)
if endswith(file, ".jl")
input = abspath(joinpath(model_path, file))
script = Literate.script(input, target_dir_jl; credit=false)
code = strip(read(script, String))
mdpost(str) = replace(str, "@__CODE__" => code)
if get(ENV, "DOCUMENTATIONGENERATOR", "") == "true"
Literate.markdown(input, target_dir_md; postprocess=mdpost, credit=false)
else
# for the local build, one needs to set `nbviewer_root_url`
Literate.markdown(input, target_dir_md; postprocess=mdpost, credit=false, nbviewer_root_url="..")
end

for file in MODELS
source_path = abspath(joinpath(source_dir, file))
text = script(source_path, target_dir_jl; credit=false)
code = strip(read(text, String))
mdpost(str) = replace(str, "@__CODE__" => code)
markdown(source_path, target_dir_md; postprocess=mdpost, credit=false)
notebook(source_path, target_dir_md; execute=true, credit=false)
# notebooks are deactivated to speed up the generation
# Literate.notebook(input, target_dir_md; execute=true, credit=false)
# if used, add the following to the top of the script files (where `MODELNAME` is the model name):
#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/MODELNAME.ipynb)
elseif any(endswith.(file, [".jld2", ".png"]))
# ignore *.jld2 and *.png files without warning
else
@warn "ignoring $file in $model_path"
end
end
end
1 change: 0 additions & 1 deletion examples/Brusselator/Brusselator.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# # Brusselator
#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/Brusselator.ipynb)
#
#md # !!! note "Overview"
#md # System type: polynomial continuous system\
Expand Down
1 change: 0 additions & 1 deletion examples/Building/Building.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# # Building
#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/Building.ipynb)
#
#md # !!! note "Overview"
#md # System type: Affine system\
Expand Down
1 change: 0 additions & 1 deletion examples/DuffingOscillator/DuffingOscillator.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# # Duffing Oscillator
#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/DuffingOscillator.ipynb)
#
#md # !!! note "Overview"
#md # System type: nonlinear\
Expand Down
1 change: 0 additions & 1 deletion examples/EMBrake/EMBrake.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# # Electromechanic break
#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/EMBrake.ipynb)
#
#md # !!! note "Overview"
#md # System type: Affine system\
Expand Down
1 change: 0 additions & 1 deletion examples/Heat3D/Heat3D.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# # Heat PDE
#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/Heat3D.ipynb)
#
#md # !!! note "Overview"
#md # System type: Affine system\
Expand Down
1 change: 0 additions & 1 deletion examples/ISS/ISS.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# # Structural Model
#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/ISS.ipynb)
#
#md # !!! note "Overview"
#md # System type: linear time-invariant continuous system\
Expand Down
1 change: 0 additions & 1 deletion examples/LaubLoomis/LaubLoomis.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# # Laub-Loomis
#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/LaubLoomis.ipynb)
#
#md # !!! note "Overview"
#md # System type: polynomial with quadratic nonlinearities\
Expand Down
1 change: 0 additions & 1 deletion examples/Lorenz/Lorenz.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# # Lorenz equations
#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/Lorenz.ipynb)
#
#md # !!! note "Overview"
#md # System type: Continuous blackbox system\
Expand Down
1 change: 0 additions & 1 deletion examples/LotkaVolterra/LotkaVolterra.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# # Lotka-Volterra
#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/LotkaVolterra.ipynb)
#
#md # !!! note "Overview"
#md # System type: Nonlinear system\
Expand Down
1 change: 0 additions & 1 deletion examples/LotkaVolterraTangential/LotkaVolterraTangential
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# # Lotka-Voltera with Nonlinear Guard
#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/LotkaVolterraGuard.ipynb)
#
#md # !!! note "Overview"
#md # System type: hybrid system with nonlinear guard\
Expand Down
1 change: 0 additions & 1 deletion examples/OpAmp/OpAmp.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# # Amplifier circuit
#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/OpAmp.ipynb)
#
#md # !!! note "Overview"
#md # System type: linear continuous system with piecewise-linear input\
Expand Down
1 change: 0 additions & 1 deletion examples/Platoon/Platoon.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# # Vehicle Platoon Model
#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/Platoon.ipynb)
#
#md # !!! note "Overview"
#md # System type: affine with hybrid dynamics\
Expand Down
1 change: 0 additions & 1 deletion examples/ProductionDestruction/ProductionDestruction.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# # Production-Destruction
#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/ProductionDestruction.ipynb)
#
#md # !!! note "Overview"
#md # System type: rational function\
Expand Down
1 change: 0 additions & 1 deletion examples/Quadrotor/Quadrotor.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# # Quadrotor
#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/Quadrotor.ipynb)
#
#md # !!! note "Overview"
#md # System type: polynomial continuous system\
Expand Down
1 change: 0 additions & 1 deletion examples/SEIR/SEIR.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# # SEIR
#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/SEIR.ipynb)
#
#md # !!! note "Overview"
#md # System type: Nonlinear system\
Expand Down
1 change: 0 additions & 1 deletion examples/Spacecraft/Spacecraft.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# # Spacecraft
#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/Spacecraft.ipynb)
#
#md # !!! note "Overview"
#md # System type: hybrid system with nonlinear dynamics\
Expand Down
1 change: 0 additions & 1 deletion examples/SquareWaveOscillator/SquareWaveOscillator.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# # Square Wave Oscillator
#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/SquareWaveOscillator.ipynb)
#
#md # !!! note "Overview"
#md # System type: linear hybrid\
Expand Down
2 changes: 0 additions & 2 deletions examples/TransmissionLine/TransmissionLine.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# # Transmission line circuit
#
#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/TransmissionLine.ipynb)
#
#md # !!! note "Overview"
#md # System type: linear continuous system\
#md # State dimension: parametric, typically between 4 to 40\
Expand Down
1 change: 0 additions & 1 deletion examples/VanDerPol/VanDerPol.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# # Van der Pol oscillator
#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated_examples/VanDerPol.ipynb)
#
#md # !!! note "Overview"
#md # System type: polynomial continuous system\
Expand Down
Loading