Skip to content

Commit

Permalink
Merge pull request #871 from JuliaReach/schillic/required
Browse files Browse the repository at this point in the history
Use outsourced `@required` macro from `ReachabilityBase`
  • Loading branch information
schillic authored Sep 19, 2024
2 parents 1b32620 + b5c521e commit c6b7dfd
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ LinearAlgebra = "<0.0.1, 1.6"
MathematicalSystems = "0.11 - 0.13"
Parameters = "0.10 - 0.12"
Random = "<0.0.1, 1.6"
ReachabilityBase = "0.1 - 0.3"
ReachabilityBase = "0.3.1"
RecipesBase = "0.6 - 0.8, 1"
Reexport = "0.2, 1"
Requires = "0.5, 1"
Expand Down
6 changes: 0 additions & 6 deletions docs/src/lib/internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ Pages = ["internals.md"]
Depth = 3
```

## Function annotations

```@docs
@requires
```

## Algorithm defaults

```@docs
Expand Down
2 changes: 1 addition & 1 deletion src/Algorithms/CARLIN/post.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ canonical_form(s::CanonicalQuadraticForm) = s.F1, s.F2

# TODO generalize to AbstractContinuousSystem using vector_field
function canonical_form(s::BlackBoxContinuousSystem)
@requires Symbolics
@required Symbolics
return f = s.f
# differentiate
end
Expand Down
6 changes: 3 additions & 3 deletions src/Algorithms/FLOWSTAR/post.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function FLOWSTAR(; δ::Union{Float64,Nothing}=nothing,
precision=53,
verbose=false,
scheme=NonPolyODEScheme())
@requires Flowstar
@required Flowstar

step_size = !isnothing(δ) ? δ :
(!isnothing(step_size) ? step_size :
Expand All @@ -28,7 +28,7 @@ end

function post(alg::FLOWSTAR{ST,OT,PT,IT}, ivp::IVP{<:AbstractContinuousSystem}, timespan;
Δt0::TimeInterval=zeroI, kwargs...) where {ST,OT,PT,IT}
@requires Flowstar
@required Flowstar

@unpack step_size, order, remainder_estimation, precondition, cutoff, precision, verbose, scheme = alg

Expand All @@ -45,7 +45,7 @@ function post(alg::FLOWSTAR{ST,OT,PT,IT}, ivp::IVP{<:AbstractContinuousSystem},
s, n = system(ivp), statedim(ivp)

# vector field in string form
@requires Symbolics
@required Symbolics
fstr = convert(Vector{Tuple{String,String}}, s)

# initial set
Expand Down
2 changes: 1 addition & 1 deletion src/Continuous/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function solve(ivp::IVP{<:AbstractContinuousSystem_}, args...; kwargs...)
got_ensemble = get(kwargs, :ensemble, false)
dict = Dict{Symbol,Any}(:ensemble => nothing)
if got_ensemble
@requires OrdinaryDiffEq
@required OrdinaryDiffEq
ensemble_sol = _solve_ensemble(ivp, args...; kwargs...)
dict[:ensemble] = ensemble_sol
end
Expand Down
2 changes: 1 addition & 1 deletion src/Hybrid/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function solve(ivp::IVP{<:AbstractHybridSystem}, args...;

got_ensemble = get(kwargs, :ensemble, false)
if got_ensemble
@requires OrdinaryDiffEq
@required OrdinaryDiffEq
ensemble_sol = _solve_ensemble(ivp, args...; kwargs...)
dict = Dict{Symbol,Any}(:ensemble => ensemble_sol)
sol = ReachSolution(HFout, cpost, dict)
Expand Down
36 changes: 1 addition & 35 deletions src/Initialization/init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ using LazySets: Interval, radius, sample, ∅, dim, scale, scale!, ⊂, matrix
using ReachabilityBase.Arrays: projection_matrix, SingleEntryVector,
isinvertible, vector_type
using ReachabilityBase.Comparison: _leq, _geq
using ReachabilityBase.Require: @required
using LazySets.Approximations: AbstractDirections
using LazySets: @commutative, AbstractReductionMethod, linear_map!

Expand Down Expand Up @@ -130,38 +131,3 @@ function __init__()
#@require ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78" include("init_ModelingToolkit.jl")
@require Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7" include("init_Symbolics.jl")
end

# ===========================
# Utility macros
# ===========================

"""
@requires(module_name)
Convenience macro to annotate that a package is required to use a certain function.
### Input
- `module_name` -- name of the required package
### Output
The macro expands to an assertion that checks whether the module `module_name` is
known in the calling scope.
### Notes
Usage:
```julia
function foo(...)
@require MyPackage
... # functionality that requires MyPackage to be loaded
end
```
"""
macro requires(module_name)
m = Meta.quot(Symbol(module_name))
return esc(:(@assert isdefined(@__MODULE__, $m) "package `$($m)` is required " *
"for this function; do `using $($m)` and try again"))
end
2 changes: 1 addition & 1 deletion src/Initialization/init_Symbolics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include("../Continuous/symbolics.jl")

function Base.convert(::Type{Vector{Tuple{String,String}}}, s::BlackBoxContinuousSystem; params=[],
t=nothing)
@requires Symbolics
@required Symbolics

n = statedim(s)
f! = MathematicalSystems.mapping(s)
Expand Down

0 comments on commit c6b7dfd

Please sign in to comment.