Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
vdebauche committed Oct 20, 2023
2 parents a953af0 + f8347ad commit 9d37e10
Show file tree
Hide file tree
Showing 60 changed files with 424 additions and 413 deletions.
1 change: 0 additions & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[deps]
CDDLib = "3391f64e-dcde-5f30-b752-e11513730f60"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Dionysos = "d92c97cf-b87d-42c1-a9c0-25df00b4d958"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
GLPK = "60bf3e95-4087-53dc-ae20-288a0d20c6a6"
Expand Down
Binary file modified docs/assets/abstraction.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 24 additions & 8 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
using Dionysos
using Documenter, Literate

const EXAMPLES_DIR = joinpath(@__DIR__, "src", "examples")
const EXAMPLES_SOLVERS_DIR = joinpath(@__DIR__, "src", "examples", "solvers")
const EXAMPLES_UTILS_DIR = joinpath(@__DIR__, "src", "examples", "utils")

const REFERENCE_DIR = joinpath(@__DIR__, "src", "reference")
const OUTPUT_DIR = joinpath(@__DIR__, "src", "generated")

const EXAMPLES = readdir(EXAMPLES_DIR)
const EXAMPLES_SOLVERS = readdir(EXAMPLES_SOLVERS_DIR)
const EXAMPLES_UTILS = readdir(EXAMPLES_UTILS_DIR)
const REFERENCE = readdir(REFERENCE_DIR)

for example in EXAMPLES
example_filepath = joinpath(EXAMPLES_DIR, example)
Literate.markdown(example_filepath, OUTPUT_DIR)
Literate.notebook(example_filepath, OUTPUT_DIR)
Literate.script(example_filepath, OUTPUT_DIR)
function literate_actions(file, output_dir)
Literate.markdown(file, output_dir)
Literate.notebook(file, output_dir)
return Literate.script(file, output_dir)
end

for example in EXAMPLES_SOLVERS
literate_actions(joinpath(EXAMPLES_SOLVERS_DIR, example), OUTPUT_DIR)
end
for example in EXAMPLES_UTILS
literate_actions(joinpath(EXAMPLES_UTILS_DIR, example), OUTPUT_DIR)
end
literate_actions(joinpath(@__DIR__, "src", "examples", "Getting Started.jl"), OUTPUT_DIR)

const _PAGES = [
"Index" => "index.md",
"Manual" => ["manual/abstraction-based-control.md", "manual/manual.md"],
"Examples" => map(EXAMPLES) do jl_file
"Getting Started" => "generated/Getting Started.md",
"Solvers" => map(EXAMPLES_SOLVERS) do jl_file
# Need `string` as Documenter fails if `name` is a `SubString{String}`.
name = string(split(jl_file, ".")[1])
return name => "generated/$name.md"
end,
"Utils" => map(EXAMPLES_UTILS) do jl_file
# Need `string` as Documenter fails if `name` is a `SubString{String}`.
name = string(split(jl_file, ".")[1])
return name => "generated/$name.md"
Expand Down
13 changes: 7 additions & 6 deletions docs/src/developers/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,13 @@ julia> using Revise

If you don't plan to test the examples, comment out the Literate part in `docs/make.jl`:
```julila
11 #for example in EXAMPLES
12 # example_filepath = joinpath(EXAMPLES_DIR, example)
13 # Literate.markdown(example_filepath, OUTPUT_DIR)
14 # Literate.notebook(example_filepath, OUTPUT_DIR)
15 # Literate.script(example_filepath, OUTPUT_DIR)
16 #end
20 # for example in EXAMPLES_SOLVERS
21 # literate_actions(joinpath(EXAMPLES_SOLVERS_DIR, example), OUTPUT_DIR)
22 # end
23 # for example in EXAMPLES_UTILS
24 # literate_actions(joinpath(EXAMPLES_UTILS_DIR, example), OUTPUT_DIR)
25 # end
26 # literate_actions(joinpath(@__DIR__, "src", "Getting Started.jl"), OUTPUT_DIR)
```
This will speed up building the documentation quite a lot.

Expand Down
1 change: 0 additions & 1 deletion docs/src/examples/Getting Started.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const DI = Dionysos
const UT = DI.Utils
const DO = DI.Domain
const ST = DI.System
const CO = DI.Control
const SY = DI.Symbolic

# Additionally, we will short the submodules accondingly
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Test #src
# # Example: DC-DC converter
# # Example: DC-DC converter solved by [Naive abstraction](https://github.com/dionysos-dev/Dionysos.jl/blob/master/docs/src/manual/manual.md#solvers).
#
#md # [![Binder](https://mybinder.org/badge_logo.svg)](@__BINDER_ROOT_URL__/generated/DC-DC converter.ipynb)
#md # [![nbviewer](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated/DC-DC converter.ipynb)
Expand All @@ -19,24 +19,13 @@ using Test #src
# A_1 = \begin{bmatrix} -\frac{r_l}{x_l} &0 \\ 0 & -\frac{1}{x_c}\frac{1}{r_0+r_c} \end{bmatrix}, A_2= \begin{bmatrix} -\frac{1}{x_l}\left(r_l+\frac{r_0r_c}{r_0+r_c}\right) & -\frac{1}{x_l}\frac{r_0}{r_0+r_c} \\ \frac{1}{x_c}\frac{r_0}{r_0+r_c} & -\frac{1}{x_c}\frac{1}{r_0+r_c} \end{bmatrix}, b = \begin{bmatrix} \frac{v_s}{x_l}\\0\end{bmatrix}.
# ```
# The goal is to design a controller to keep the state of the system in a safety region around the reference desired value, using as input only the switching
# signal.
#
#
# In order to study the concrete system and its symbolic abstraction in a unified framework, we will solve the problem
# for the sampled system with a sampling time $\tau$.
#
# The abstraction is based on a feedback refinment relation [4,V.2 Definition].
# Basically, this is equivalent to an alternating simulation relationship with the additional constraint that the input of the
# concrete and symbolic system preserving the relation must be identical.
# This allows to easily determine the controller of the concrete system from the abstraction controller by simply adding a quantization step.
#
# For the construction of the relations in the abstraction, it is necessary to over-approximate attainable sets of
# a particular cell. In this example, we consider the used of a growth bound function [4, VIII.2, VIII.5] which is one of the possible methods to over-approximate
# attainable sets of a particular cell based on the state reach by its center. Therefore, it is used
# to compute the relations in the abstraction based on the feedback refinement relation.
# signal. In order to study the concrete system and its symbolic abstraction in a unified framework, we will solve the problem
# for the sampled system with a sampling time $\tau$. For the construction of the relations in the abstraction, it is necessary to over-approximate attainable sets of
# a particular cell. In this example, we consider the use of a growth bound function [4, VIII.2, VIII.5] which is one of the possible methods to over-approximate
# attainable sets of a particular cell based on the state reach by its center.
#

# First, let us import [StaticArrays](https://github.com/JuliaArrays/StaticArrays.jl) and [Plots].
# First, let us import [StaticArrays](https://github.com/JuliaArrays/StaticArrays.jl) and [Plots](https://github.com/JuliaPlots/Plots.jl).

using StaticArrays, Plots

Expand All @@ -47,7 +36,6 @@ const UT = DI.Utils
const DO = DI.Domain
const ST = DI.System
const SY = DI.Symbolic
const CO = DI.Control
const OP = DI.Optim
const AB = OP.Abstraction

Expand All @@ -67,7 +55,7 @@ hu = SVector(1)
input_grid = DO.GridFree(u0, hu)

using JuMP
optimizer = MOI.instantiate(AB.SCOTSAbstraction.Optimizer)
optimizer = MOI.instantiate(AB.NaiveAbstraction.Optimizer)
MOI.set(optimizer, MOI.RawOptimizerAttribute("concrete_problem"), concrete_problem)
MOI.set(optimizer, MOI.RawOptimizerAttribute("state_grid"), state_grid)
MOI.set(optimizer, MOI.RawOptimizerAttribute("input_grid"), input_grid)
Expand All @@ -82,12 +70,12 @@ concrete_controller = MOI.get(optimizer, MOI.RawOptimizerAttribute("concrete_con
# as well as the true initial state `x0` which is contained in the initial state-space defined previously.
nstep = 300
x0 = SVector(1.2, 5.6)
x_traj, u_traj =
CO.get_closed_loop_trajectory(concrete_system.f, concrete_controller, x0, nstep)
control_trajectory =
ST.get_closed_loop_trajectory(concrete_system.f, concrete_controller, x0, nstep)

fig = plot(; aspect_ratio = :equal);
plot!(concrete_system.X);
plot!(UT.DrawTrajectory(x_traj))
plot!(control_trajectory)

# ### References
# 1. A. Girard, G. Pola and P. Tabuada, "Approximately Bisimilar Symbolic Models for Incrementally Stable Switched Systems," in IEEE Transactions on Automatic Control, vol. 55, no. 1, pp. 116-126, Jan. 2010.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Test #src
# # Example: Gol, Lazar and Belta (2013)
# # Example: Gol, Lazar and Belta (2013) solved by [Bemporad Morari](https://github.com/dionysos-dev/Dionysos.jl/blob/master/docs/src/manual/manual.md#solvers).
#
#md # [![Binder](https://mybinder.org/badge_logo.svg)](@__BINDER_ROOT_URL__/generated/Gol%2C Lazar %26 Belta (2013).ipynb)
#md # [![nbviewer](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated/Gol%2C Lazar %26 Belta (2013).ipynb)
Expand Down Expand Up @@ -30,7 +30,7 @@ import Ipopt
using Dionysos
const DI = Dionysos
const UT = DI.Utils
const CO = DI.Control
const ST = DI.System
const OP = DI.Optim

# And the file defining the hybrid system for this problem
Expand Down Expand Up @@ -86,7 +86,7 @@ objective_value = MOI.get(optimizer, MOI.ObjectiveValue())
@test objective_value 11.38 atol = 1e-2 #src

# and recover the corresponding continuous trajectory
xu = MOI.get(optimizer, CO.ContinuousTrajectoryAttribute());
xu = MOI.get(optimizer, ST.ContinuousTrajectoryAttribute());

# ## A little bit of data visualization now:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# # Hierarchical-abstraction
# # Example: Reachability problem solved by [Hierarchical abstraction](https://github.com/dionysos-dev/Dionysos.jl/blob/master/docs/src/manual/manual.md#solvers).
#
#md # [![Binder](https://mybinder.org/badge_logo.svg)](@__BINDER_ROOT_URL__/generated/Hierarchical-abstraction.ipynb)
#md # [![nbviewer](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated/Hierarchical-abstraction.ipynb)
Expand All @@ -13,12 +13,11 @@ const UT = DI.Utils
const DO = DI.Domain
const ST = DI.System
const SY = DI.Symbolic
const CO = DI.Control
const PR = DI.Problem
const OP = DI.Optim
const AB = OP.Abstraction

include("../../../problems/simple_problem.jl")
include(joinpath(dirname(dirname(pathof(Dionysos))), "problems", "simple_problem.jl"))

## specific functions
function post_image(abstract_system, concrete_system, xpos, u)
Expand Down Expand Up @@ -126,11 +125,11 @@ AB.LazyAbstraction.set_optimizer_parameters!(
)

# Global optimizer parameters
hx_global = [10.0, 10.0] #[15.0, 15.0]
hx_global = [10.0, 10.0]
u0 = SVector(0.0, 0.0)
hu = SVector(0.5, 0.5)
Ugrid = DO.GridFree(u0, hu)
max_iter = 6 # 9
max_iter = 6
max_time = 1000

optimizer = MOI.instantiate(AB.HierarchicalAbstraction.Optimizer)
Expand Down Expand Up @@ -160,9 +159,12 @@ println("Solved : ", optimizer.solved)

# ## Simulation
x0 = UT.get_center(concrete_problem.initial_set)
x_traj, u_traj, cost_traj = AB.HierarchicalAbstraction.simulate_trajectory(optimizer, x0)
cost = sum(cost_traj);
println("Goal set reached: $(x_traj[end]concrete_problem.target_set)")
cost_control_trajectory =
AB.HierarchicalAbstraction.get_closed_loop_trajectory(optimizer, x0)
cost = sum(cost_control_trajectory.costs.seq);
println(
"Goal set reached: $(ST.get_state(cost_control_trajectory, ST.length(cost_control_trajectory))concrete_problem.target_set)",
)
println("Cost:\t $(cost)")

# ## Display the results
Expand All @@ -180,7 +182,7 @@ plot!(concrete_problem.initial_set; color = :green, opacity = 0.8);
plot!(concrete_problem.target_set; dims = [1, 2], color = :red, opacity = 0.8);

#We display the concrete trajectory
plot!(UT.DrawTrajectory(x_traj); ms = 0.5)
plot!(cost_control_trajectory; ms = 0.5)

# # Display the lazy abstraction
fig = plot(; aspect_ratio = :equal);
Expand All @@ -191,4 +193,4 @@ plot!(
heuristic = false,
fine = true,
)
plot!(UT.DrawTrajectory(x_traj); ms = 0.5)
plot!(cost_control_trajectory; ms = 0.5)
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# # Example: Reachability problem solved by [Lazy ellipsoid abstraction](https://github.com/dionysos-dev/Dionysos.jl/blob/master/docs/src/manual/manual.md#solvers).
#

using StaticArrays, LinearAlgebra, Random, IntervalArithmetic
using MathematicalSystems, HybridSystems
using JuMP, Mosek, MosekTools
Expand All @@ -11,12 +14,11 @@ const UT = DI.Utils
const DO = DI.Domain
const ST = DI.System
const SY = DI.Symbolic
const CO = DI.Control
const PR = DI.Problem
const OP = DI.Optim
const AB = OP.Abstraction

include("../../../problems/non_linear.jl")
include(joinpath(dirname(dirname(pathof(Dionysos))), "problems", "non_linear.jl"))

# # First example

Expand Down Expand Up @@ -73,7 +75,7 @@ reached(x) = x ∈ concrete_problem.target_set
nstep = typeof(concrete_problem.time) == PR.Infinity ? 100 : concrete_problem.time; # max num of steps
# We simulate the closed loop trajectory
x0 = concrete_problem.initial_set.c
x_traj, u_traj, cost_traj = CO.get_closed_loop_trajectory(
cost_control_trajectory = ST.get_closed_loop_trajectory(
concrete_system.f_eval,
concrete_controller,
cost_eval,
Expand All @@ -83,7 +85,7 @@ x_traj, u_traj, cost_traj = CO.get_closed_loop_trajectory(
noise = true,
)
cost_bound = concrete_lyap_fun(x0)
cost_true = sum(cost_traj);
cost_true = sum(cost_control_trajectory.costs.seq);
println("Goal set reached")
println("Guaranteed cost:\t $(cost_bound)")
println("True cost:\t\t $(cost_true)")
Expand All @@ -96,23 +98,24 @@ fig = plot(;
ytickfontsize = 10,
guidefontsize = 16,
titlefontsize = 14,
label = false,
);
xlabel!("\$x_1\$");
ylabel!("\$x_2\$");
title!("Specifictions and domains");

#Display the concrete domain
plot!(concrete_system.X; color = :yellow, opacity = 0.5);
plot!(concrete_system.X; color = :yellow, opacity = 0.5, label = false);
for obs in concrete_system.obstacles
plot!(obs; color = :black)
plot!(obs; color = :black, label = false)
end

#Display the abstract domain
plot!(abstract_system; arrowsB = false, cost = false);
plot!(abstract_system; arrowsB = false, cost = false, label = false);

#Display the concrete specifications
plot!(concrete_problem.initial_set; color = :green);
plot!(concrete_problem.target_set; color = :red)
plot!(concrete_problem.initial_set; color = :green, label = false);
plot!(concrete_problem.target_set; color = :red, label = false)

# # Display the abstraction
fig = plot(;
Expand Down Expand Up @@ -141,6 +144,6 @@ for obs in concrete_system.obstacles
plot!(obs; color = :black)
end
plot!(abstract_system; arrowsB = false, cost = true);
plot!(UT.DrawTrajectory(x_traj); color = :black)
plot!(cost_control_trajectory; color = :black)

@test cost_true <= cost_bound #src
Loading

0 comments on commit 9d37e10

Please sign in to comment.