Skip to content

Have CI tests depend on formatter passing #2451

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

Merged
merged 2 commits into from
Feb 8, 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
48 changes: 0 additions & 48 deletions .github/workflows/FormatCheck.yml

This file was deleted.

33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
pull_request:
branches:
- master
- 'release-'
paths-ignore:
- 'docs/**'
push:
Expand All @@ -18,7 +19,39 @@ concurrency:
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}

jobs:
formatter:
runs-on: ${{ matrix.os }}
strategy:
matrix:
julia-version: [1]
julia-arch: [x86]
os: [ubuntu-latest]
steps:
- uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.julia-version }}

- uses: actions/checkout@v4
- name: Install JuliaFormatter and format
# This will use the latest version by default but you can set the version like so:
#
# julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="0.13.0"))'
run: |
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))'
julia -e 'using JuliaFormatter; format(".", verbose=true)'
- name: Format check
run: |
julia -e '
out = Cmd(`git diff`) |> read |> String
if out == ""
exit(0)
else
@error "Some files have not been formatted !!!"
write(stdout, out)
exit(1)
end'
test:
needs: formatter
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down
13 changes: 5 additions & 8 deletions docs/src/tutorials/bifurcation_diagram_computation.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Let us consider the `BifurcationProblem` from the last section. If we wish to co
```@example Bif1
p_span = (-4.0, 6.0)
opts_br = ContinuationPar(nev = 2,
p_min = p_span[1],
p_min = p_span[1],
p_max = p_span[2])
```

Expand Down Expand Up @@ -111,8 +111,7 @@ bprob = BifurcationProblem(osys,

p_span = (-3.0, 3.0)
opts_br = ContinuationPar(nev = 2,
p_max = p_span[2], p_min = p_span[1],
)
p_max = p_span[2], p_min = p_span[1])

bf = bifurcationdiagram(bprob, PALC(), 2, (args...) -> opts_br; bothside = true)
using Plots
Expand All @@ -130,21 +129,19 @@ We compute the branch of periodic orbits which is nearby the Hopf Bifurcation. W

```@example Bif2
br_po = continuation(bf.γ, 2, opts_br,
PeriodicOrbitOCollProblem(20, 5);
)
PeriodicOrbitOCollProblem(20, 5);)

plot(bf; putspecialptlegend = false,
markersize = 2,
plotfold = false,
xguide = "μ",
yguide = "x")
plot!(br_po, xguide = "μ", yguide = "x", label = "Maximum of periodic orbit")
plot!(br_po, xguide = "μ", yguide = "x", label = "Maximum of periodic orbit")
```

Let's see how to plot the periodic solution we just computed:

```@example Bif2
sol = get_periodic_orbit(br_po, 10)
plot(sol.t, sol[1,:], yguide = "x", xguide = "time", label = "")
plot(sol.t, sol[1, :], yguide = "x", xguide = "time", label = "")
```

7 changes: 6 additions & 1 deletion docs/src/tutorials/optimization.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ cons = [
@named sys = OptimizationSystem(loss, [x, y], [a, b], constraints = cons)
u0 = [x => 0.14
y => 0.14]
prob = OptimizationProblem(complete(sys), u0, grad = true, hess = true, cons_j = true, cons_h = true)
prob = OptimizationProblem(complete(sys),
u0,
grad = true,
hess = true,
cons_j = true,
cons_h = true)
solve(prob, IPNewton())
```

Expand Down
4 changes: 2 additions & 2 deletions src/structural_transformation/symbolics_tearing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,8 @@ function tearing_reassemble(state::TearingState, var_eq_matching;
sys = state.sys
@set! sys.eqs = neweqs
@set! sys.unknowns = Any[v
for (i, v) in enumerate(fullvars)
if diff_to_var[i] === nothing && ispresent(i)]
for (i, v) in enumerate(fullvars)
if diff_to_var[i] === nothing && ispresent(i)]
@set! sys.substitutions = Substitutions(subeqs, deps)

obs_sub = dummy_sub
Expand Down
4 changes: 3 additions & 1 deletion src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,9 @@ function toexpr(sys::AbstractSystem)
name = $name, checks = false)))
end

expr = :(let; $expr; end)
expr = :(let
$expr
end)
Base.remove_linenums!(expr) # keeping the line numbers is never helpful
end

Expand Down
11 changes: 7 additions & 4 deletions src/systems/connectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ function connection2set!(connectionsets, namespace, ss, isouter)
orientation_vars = Symbolics.unwrap.(vec(O.R))
unknown_vars = [unknown_vars; orientation_vars]
end
i != 1 && ((num_unknowns == length(unknown_vars) && all(Base.Fix2(in, sts1), unknown_vars)) ||
i != 1 && ((num_unknowns == length(unknown_vars) &&
all(Base.Fix2(in, sts1), unknown_vars)) ||
connection_error(ss))
io = isouter(s)
for (j, v) in enumerate(unknown_vars)
Expand Down Expand Up @@ -410,7 +411,7 @@ end

function generate_connection_equations_and_stream_connections(csets::AbstractVector{
<:ConnectionSet,
})
})
eqs = Equation[]
stream_connections = ConnectionSet[]

Expand Down Expand Up @@ -605,7 +606,8 @@ function expand_instream(csets::AbstractVector{<:ConnectionSet}, sys::AbstractSy
vtype = get_connection_type(sv)
vtype === Stream || continue
if n_inners == 1 && n_outers == 1
push!(additional_eqs, unknowns(cset[1].sys.sys, sv) ~ unknowns(cset[2].sys.sys, sv))
push!(additional_eqs,
unknowns(cset[1].sys.sys, sv) ~ unknowns(cset[2].sys.sys, sv))
elseif n_inners == 0 && n_outers == 2
# we don't expand `instream` in this case.
v1 = unknowns(cset[1].sys.sys, sv)
Expand Down Expand Up @@ -664,7 +666,8 @@ function expand_instream(csets::AbstractVector{<:ConnectionSet}, sys::AbstractSy
end

function get_current_var(namespace, cele, sv)
unknowns(renamespace(unnamespace(namespace, _getname(cele.sys.namespace)), cele.sys.sys),
unknowns(renamespace(unnamespace(namespace, _getname(cele.sys.namespace)),
cele.sys.sys),
sv)
end

Expand Down
9 changes: 6 additions & 3 deletions src/systems/diffeqs/abstractodesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ function generate_tgrad(sys::AbstractODESystem, dvs = unknowns(sys), ps = parame
end
end

function generate_jacobian(sys::AbstractODESystem, dvs = unknowns(sys), ps = parameters(sys);
function generate_jacobian(sys::AbstractODESystem, dvs = unknowns(sys),
ps = parameters(sys);
simplify = false, sparse = false, kwargs...)
jac = calculate_jacobian(sys; simplify = simplify, sparse = sparse)
pre = get_preprocess_constants(jac)
Expand Down Expand Up @@ -139,7 +140,8 @@ function generate_dae_jacobian(sys::AbstractODESystem, dvs = unknowns(sys),
postprocess_fbody = pre, kwargs...)
end

function generate_function(sys::AbstractODESystem, dvs = unknowns(sys), ps = parameters(sys);
function generate_function(sys::AbstractODESystem, dvs = unknowns(sys),
ps = parameters(sys);
implicit_dae = false,
ddvs = implicit_dae ? map(Differential(get_iv(sys)), dvs) :
nothing,
Expand Down Expand Up @@ -294,7 +296,8 @@ function DiffEqBase.ODEFunction{false}(sys::AbstractODESystem, args...;
ODEFunction{false, SciMLBase.FullSpecialize}(sys, args...; kwargs...)
end

function DiffEqBase.ODEFunction{iip, specialize}(sys::AbstractODESystem, dvs = unknowns(sys),
function DiffEqBase.ODEFunction{iip, specialize}(sys::AbstractODESystem,
dvs = unknowns(sys),
ps = parameters(sys), u0 = nothing;
version = nothing, tgrad = false,
jac = false, p = nothing,
Expand Down
3 changes: 2 additions & 1 deletion src/systems/diffeqs/sdesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ function stochastic_integral_transform(sys::SDESystem, correction_factor)
∇σσ′ = simplify.(jac * get_noiseeqs(sys)[:, 1])
for k in 2:m
eqs = vcat([equations(sys)[i].lhs ~ get_noiseeqs(sys)[Int(i +
(k - 1) * dimunknowns)]
(k - 1) *
dimunknowns)]
for i in eachindex(unknowns(sys))]...)
de = ODESystem(eqs, get_iv(sys), unknowns(sys), parameters(sys), name = name,
checks = false)
Expand Down
9 changes: 6 additions & 3 deletions src/systems/jumps/jumpsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ struct JumpSystem{U <: ArrayPartition} <: AbstractTimeDependentSystem
"""
complete::Bool

function JumpSystem{U}(tag, ap::U, iv, unknowns, ps, var_to_name, observed, name, systems,
function JumpSystem{U}(tag, ap::U, iv, unknowns, ps, var_to_name, observed, name,
systems,
defaults, connector_type, devents,
metadata = nothing, gui_metadata = nothing,
complete = false;
Expand All @@ -119,7 +120,9 @@ struct JumpSystem{U <: ArrayPartition} <: AbstractTimeDependentSystem
connector_type, devents, metadata, gui_metadata, complete)
end
end
JumpSystem(tag, ap, iv, states, ps, var_to_name, args...; kwargs...) = JumpSystem{typeof(ap)}(tag, ap, iv, states, ps, var_to_name, args...; kwargs...)
function JumpSystem(tag, ap, iv, states, ps, var_to_name, args...; kwargs...)
JumpSystem{typeof(ap)}(tag, ap, iv, states, ps, var_to_name, args...; kwargs...)
end

function JumpSystem(eqs, iv, unknowns, ps;
observed = Equation[],
Expand Down Expand Up @@ -498,7 +501,7 @@ function (ratemap::JumpSysMajParamMapper{
U,
V,
W,
})(params) where {U <: AbstractArray,
})(params) where {U <: AbstractArray,
V <: AbstractArray, W}
updateparams!(ratemap, params)
[convert(W, value(substitute(paramexpr, ratemap.subdict)))
Expand Down
3 changes: 2 additions & 1 deletion src/systems/optimization/constraints_system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ function generate_hessian(sys::ConstraintsSystem, vs = unknowns(sys), ps = param
return build_function(hess, vs, ps; kwargs...)
end

function generate_function(sys::ConstraintsSystem, dvs = unknowns(sys), ps = parameters(sys);
function generate_function(sys::ConstraintsSystem, dvs = unknowns(sys),
ps = parameters(sys);
kwargs...)
lhss = generate_canonical_form_lhss(sys)
pre, sol_states = get_substitutions_and_solved_unknowns(sys)
Expand Down
6 changes: 4 additions & 2 deletions src/systems/optimization/optimizationsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ function calculate_gradient(sys::OptimizationSystem)
expand_derivatives.(gradient(objective(sys), unknowns(sys)))
end

function generate_gradient(sys::OptimizationSystem, vs = unknowns(sys), ps = parameters(sys);
function generate_gradient(sys::OptimizationSystem, vs = unknowns(sys),
ps = parameters(sys);
kwargs...)
grad = calculate_gradient(sys)
pre = get_preprocess_constants(grad)
Expand All @@ -149,7 +150,8 @@ function generate_hessian(sys::OptimizationSystem, vs = unknowns(sys), ps = para
kwargs...)
end

function generate_function(sys::OptimizationSystem, vs = unknowns(sys), ps = parameters(sys);
function generate_function(sys::OptimizationSystem, vs = unknowns(sys),
ps = parameters(sys);
kwargs...)
eqs = subs_constants(objective(sys))
return build_function(eqs, vs, ps;
Expand Down
6 changes: 3 additions & 3 deletions src/systems/systems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ function __structural_simplify(sys::AbstractSystem, io = nothing; simplify = fal
sys = state.sys
@set! sys.eqs = new_eqs
@set! sys.unknowns = [v
for (i, v) in enumerate(fullvars)
if !iszero(new_idxs[i]) &&
invview(var_to_diff)[i] === nothing]
for (i, v) in enumerate(fullvars)
if !iszero(new_idxs[i]) &&
invview(var_to_diff)[i] === nothing]
# TODO: IO is not handled.
ode_sys = structural_simplify(sys, io; simplify, kwargs...)
eqs = equations(ode_sys)
Expand Down
1 change: 0 additions & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,6 @@ function collect_vars!(unknowns, parameters, expr, iv)
return nothing
end


function collect_var!(unknowns, parameters, var, iv)
isequal(var, iv) && return nothing
if isparameter(var) || (istree(var) && isparameter(operation(var)))
Expand Down
3 changes: 2 additions & 1 deletion test/funcaffect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ balls = compose(balls, [ball1, ball2])
@test ModelingToolkit.has_discrete_events(balls)
@test length(ModelingToolkit.affects(ModelingToolkit.discrete_events(balls))) == 2

prob = ODEProblem(complete(balls), [ball1.x => 10.0, ball1.v => 0, ball2.x => 10.0, ball2.v => 0],
prob = ODEProblem(complete(balls),
[ball1.x => 10.0, ball1.v => 0, ball2.x => 10.0, ball2.v => 0],
(0, 3.0))
sol = solve(prob, Tsit5())

Expand Down
3 changes: 2 additions & 1 deletion test/jacobiansparsity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ sys = complete(modelingtoolkitize(prob_ode_brusselator_2d))
# test sparse jacobian pattern only.
prob = ODEProblem(sys, u0, (0, 11.5), sparse = true, jac = false)
JP = prob.f.jac_prototype
@test findnz(Symbolics.jacobian_sparsity(map(x -> x.rhs, equations(sys)), unknowns(sys)))[1:2] ==
@test findnz(Symbolics.jacobian_sparsity(map(x -> x.rhs, equations(sys)),
unknowns(sys)))[1:2] ==
findnz(JP)[1:2]

# test sparse jacobian
Expand Down
3 changes: 2 additions & 1 deletion test/nonlinearsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ end

sys_init_simple = structural_simplify(sys_init)

prob = NonlinearProblem(sys_init_simple, get_default_or_guess.(unknowns(sys_init_simple)))
prob = NonlinearProblem(sys_init_simple,
get_default_or_guess.(unknowns(sys_init_simple)))

@test prob.u0 == [0.5, -0.5]

Expand Down
4 changes: 2 additions & 2 deletions test/odesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,15 @@ sol_dpmap = solve(prob_dpmap, Rodas5())

@testset "symbolic remake with nested system" begin
function makesys(name)
@parameters a=1.0
@parameters a = 1.0
@variables x(t) = 0.0
ODESystem([D(x) ~ -a * x], t; name)
end

function makecombinedsys()
sys1 = makesys(:sys1)
sys2 = makesys(:sys2)
@parameters b=1.0
@parameters b = 1.0
complete(ODESystem(Equation[], t, [], [b]; systems = [sys1, sys2], name = :foo))
end

Expand Down
Loading