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

Replace requires macro with require #848

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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
require(@__MODULE__, :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
require(@__MODULE__, :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
require(@__MODULE__, :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
require(@__MODULE__, :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
require(@__MODULE__, :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
require(@__MODULE__, :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!, ⊂
using ReachabilityBase.Arrays: projection_matrix, SingleEntryVector,
isinvertible, vector_type
using ReachabilityBase.Comparison: _leq, _geq
using ReachabilityBase.Require
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
require(@__MODULE__, :Symbolics)

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