Skip to content

Commit f215b00

Browse files
committed
Switch from JuliaFormatter to Runic.jl for code formatting
- Update CI workflow to use fredrikekre/runic-action@v1 - Remove .JuliaFormatter.toml configuration - Format all source files with Runic.jl 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent a5f1d3a commit f215b00

13 files changed

Lines changed: 99 additions & 67 deletions

File tree

.JuliaFormatter.toml

Lines changed: 0 additions & 2 deletions
This file was deleted.

.github/workflows/FormatCheck.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
name: "Format Check"
1+
name: format-check
22

33
on:
44
push:
55
branches:
6+
- 'master'
67
- 'main'
8+
- 'release-'
79
tags: '*'
810
pull_request:
911

1012
jobs:
11-
format-check:
12-
name: "Format Check"
13-
uses: "SciML/.github/.github/workflows/format-check.yml@v1"
13+
runic:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: fredrikekre/runic-action@v1
18+
with:
19+
version: '1'

docs/make.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ cp("./docs/Project.toml", "./docs/src/assets/Project.toml", force = true)
55

66
include("pages.jl")
77

8-
makedocs(sitename = "ModelOrderReduction.jl",
8+
makedocs(
9+
sitename = "ModelOrderReduction.jl",
910
authors = "Bowen S. Zhu",
1011
modules = [ModelOrderReduction],
1112
clean = true, doctest = false, linkcheck = true,
1213
warnonly = [:missing_docs, :example_block],
13-
format = Documenter.HTML(assets = ["assets/favicon.ico"],
14-
canonical = "https://docs.sciml.ai/ModelOrderReduction/stable/"),
15-
pages = pages)
14+
format = Documenter.HTML(
15+
assets = ["assets/favicon.ico"],
16+
canonical = "https://docs.sciml.ai/ModelOrderReduction/stable/"
17+
),
18+
pages = pages
19+
)
1620

1721
deploydocs(repo = "github.com/SciML/ModelOrderReduction.jl.git")

src/DataReduction/POD.jl

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ using TSVD: tsvd
22
using RandomizedLinAlg: rsvd
33

44
function matricize(VoV::Vector{Vector{T}}) where {T}
5-
reduce(hcat, VoV)
5+
return reduce(hcat, VoV)
66
end
77

88
function _svd(data::Vector{Vector{T}}; kwargs...) where {T}
@@ -38,17 +38,19 @@ mutable struct POD <: AbstractDRProblem
3838
renergy::Any
3939
spectrum::Any
4040
# constructors
41-
function POD(snaps;
41+
function POD(
42+
snaps;
4243
min_renergy = 1.0,
4344
min_nmodes::Int = 1,
44-
max_nmodes::Int = length(snaps[1]))
45+
max_nmodes::Int = length(snaps[1])
46+
)
4547
nmodes = min_nmodes
4648
errorhandle(snaps, nmodes, min_renergy, min_nmodes, max_nmodes)
47-
new(snaps, min_renergy, min_nmodes, max_nmodes, nmodes, missing, 1.0, missing)
49+
return new(snaps, min_renergy, min_nmodes, max_nmodes, nmodes, missing, 1.0, missing)
4850
end
4951
function POD(snaps, nmodes::Int)
5052
errorhandle(snaps, nmodes, 0.0, nmodes, nmodes)
51-
new(snaps, 0.0, nmodes, nmodes, nmodes, missing, 1.0, missing)
53+
return new(snaps, 0.0, nmodes, nmodes, nmodes, missing, 1.0, missing)
5254
end
5355
end
5456

@@ -66,11 +68,13 @@ end
6668
function reduce!(pod::POD, alg::SVD)
6769
u, s, v = _svd(pod.snapshots; alg.kwargs...)
6870
pod.nmodes,
69-
pod.renergy = determine_truncation(s, pod.min_nmodes, pod.max_nmodes,
70-
pod.min_renergy)
71+
pod.renergy = determine_truncation(
72+
s, pod.min_nmodes, pod.max_nmodes,
73+
pod.min_renergy
74+
)
7175
pod.rbasis = u[:, 1:(pod.nmodes)]
7276
pod.spectrum = s
73-
nothing
77+
return nothing
7478
end
7579

7680
function reduce!(pod::POD, alg::TSVD)
@@ -79,7 +83,7 @@ function reduce!(pod::POD, alg::TSVD)
7983
pod.renergy = sum(s) / (sum(s) + (n_max - pod.nmodes) * s[end])
8084
pod.rbasis = u
8185
pod.spectrum = s
82-
nothing
86+
return nothing
8387
end
8488

8589
function reduce!(pod::POD, alg::RSVD)
@@ -88,13 +92,15 @@ function reduce!(pod::POD, alg::RSVD)
8892
pod.renergy = sum(s) / (sum(s) + (n_max - pod.nmodes) * s[end])
8993
pod.rbasis = u
9094
pod.spectrum = s
91-
nothing
95+
return nothing
9296
end
9397

9498
function Base.show(io::IO, pod::POD)
9599
print(io, "POD \n")
96100
print(io, "Reduction Order = ", pod.nmodes, "\n")
97-
print(io, "Snapshot size = (", size(pod.snapshots, 1), ",", size(pod.snapshots[1], 2),
98-
")\n")
99-
print(io, "Relative Energy = ", pod.renergy, "\n")
101+
print(
102+
io, "Snapshot size = (", size(pod.snapshots, 1), ",", size(pod.snapshots[1], 2),
103+
")\n"
104+
)
105+
return print(io, "Relative Energy = ", pod.renergy, "\n")
100106
end

src/ErrorHandle.jl

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
function errorhandle(data::AbstractMatrix, nmodes::Int, max_energy, min_nmodes, max_nmodes)
2-
@assert size(data, 1)>1 "State vector is expected to be vector valued."
2+
@assert size(data, 1) > 1 "State vector is expected to be vector valued."
33
s = minimum(size(data))
4-
@assert 0<nmodes<=s "Number of modes should be in {1,2,...,$s}."
5-
@assert min_nmodes<=max_nmodes "Minimum number of modes must lie below maximum number of modes"
6-
@assert 0.0<=max_energy<=1.0 "Maximum relative energy must be in [0,1]"
4+
@assert 0 < nmodes <= s "Number of modes should be in {1,2,...,$s}."
5+
@assert min_nmodes <= max_nmodes "Minimum number of modes must lie below maximum number of modes"
6+
return @assert 0.0 <= max_energy <= 1.0 "Maximum relative energy must be in [0,1]"
77
end
88

9-
function errorhandle(data::AbstractVector{T}, nmodes::Int, max_energy, min_nmodes,
10-
max_nmodes) where {T <: AbstractVector}
11-
@assert size(data[1], 1)>1 "State vector is expected to be vector valued."
9+
function errorhandle(
10+
data::AbstractVector{T}, nmodes::Int, max_energy, min_nmodes,
11+
max_nmodes
12+
) where {T <: AbstractVector}
13+
@assert size(data[1], 1) > 1 "State vector is expected to be vector valued."
1214
s = min(size(data, 1), size(data[1], 1))
13-
@assert 0<nmodes<=s "Number of modes should be in {1,2,...,$s}."
14-
@assert min_nmodes<=max_nmodes "Minimum number of modes must lie below maximum number of modes"
15-
@assert 0.0<=max_energy<=1.0 "Maximum relative energy must be in [0,1]"
15+
@assert 0 < nmodes <= s "Number of modes should be in {1,2,...,$s}."
16+
@assert min_nmodes <= max_nmodes "Minimum number of modes must lie below maximum number of modes"
17+
return @assert 0.0 <= max_energy <= 1.0 "Maximum relative energy must be in [0,1]"
1618
end

src/ModelOrderReduction.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ module ModelOrderReduction
33
using DocStringExtensions: DocStringExtensions, FUNCTIONNAME, SIGNATURES, TYPEDSIGNATURES
44

55
using ModelingToolkit: ModelingToolkit, @variables, Differential, Equation, Num, ODESystem,
6-
SymbolicUtils, Symbolics, arguments, build_function, complete,
7-
expand, substitute, tearing_substitution
6+
SymbolicUtils, Symbolics, arguments, build_function, complete,
7+
expand, substitute, tearing_substitution
88
using LinearAlgebra: LinearAlgebra, /, \, mul!, qr, svd
99

1010
using Setfield: Setfield, @set!

src/Types.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ abstract type AbstractSVD end
77
struct SVD <: AbstractSVD
88
kwargs::Any
99
function SVD(; kwargs...)
10-
new(kwargs)
10+
return new(kwargs)
1111
end
1212
end
1313

1414
struct TSVD <: AbstractSVD
1515
kwargs::Any
1616
function TSVD(; kwargs...)
17-
new(kwargs)
17+
return new(kwargs)
1818
end
1919
end
2020

2121
struct RSVD <: AbstractSVD
2222
p::Int
2323
function RSVD(p::Int = 0)
24-
new(p)
24+
return new(p)
2525
end
2626
end

src/deim.jl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,12 @@ the ``\\rho_i``-th column of the identity matrix ``I_n\\in\\mathbb R^{n\\times n
6464
- `reduced_rhss`: the right-hand side of ROM.
6565
- `linear_projection_eqs`: the linear projection mapping ``\\mathbf y=V\\hat{\\mathbf y}``.
6666
"""
67-
function deim(full_vars::AbstractVector, linear_coeffs::AbstractMatrix,
67+
function deim(
68+
full_vars::AbstractVector, linear_coeffs::AbstractMatrix,
6869
constant_part::AbstractVector, nonlinear_part::AbstractVector,
6970
reduced_vars::AbstractVector, linear_projection_matrix::AbstractMatrix,
70-
nonlinear_projection_matrix::AbstractMatrix; kwargs...)
71+
nonlinear_projection_matrix::AbstractMatrix; kwargs...
72+
)
7173
# rename variables for convenience
7274
y = full_vars
7375
A = linear_coeffs
@@ -91,7 +93,7 @@ function deim(full_vars::AbstractVector, linear_coeffs::AbstractMatrix,
9193
= V' * A * V
9294
= V' * g
9395
reduced_rhss =*++
94-
reduced_rhss, linear_projection_eqs
96+
return reduced_rhss, linear_projection_eqs
9597
end
9698
"""
9799
$(FUNCTIONNAME)(
@@ -118,9 +120,11 @@ The POD basis used for DEIM interpolation is obtained from the snapshot matrix o
118120
nonlinear terms, which is computed by executing the runtime-generated function for
119121
nonlinear expressions.
120122
"""
121-
function deim(sys::ODESystem, snapshot::AbstractMatrix, pod_dim::Integer;
123+
function deim(
124+
sys::ODESystem, snapshot::AbstractMatrix, pod_dim::Integer;
122125
deim_dim::Integer = pod_dim, name::Symbol = Symbol(nameof(sys), :_deim),
123-
kwargs...)::ODESystem
126+
kwargs...
127+
)::ODESystem
124128
sys = deepcopy(sys)
125129
@set! sys.name = name
126130

@@ -166,15 +170,17 @@ function deim(sys::ODESystem, snapshot::AbstractMatrix, pod_dim::Integer;
166170
old_observed = ModelingToolkit.get_observed(sys)
167171
fullstates = [map(eq -> eq.lhs, old_observed); dvs; ModelingToolkit.get_unknowns(sys)]
168172
new_observed = [old_observed; linear_projection_eqs]
169-
new_sorted_observed = ModelingToolkit.topsort_equations(new_observed, fullstates;
170-
kwargs...)
173+
new_sorted_observed = ModelingToolkit.topsort_equations(
174+
new_observed, fullstates;
175+
kwargs...
176+
)
171177
@set! sys.observed = new_sorted_observed
172178

173179
inv_dict = Dict(Symbolics.scalarize(ŷ .=> V' * dvs)) # reduced vars to original vars
174180
@set! sys.defaults = merge(ModelingToolkit.defaults(sys), inv_dict)
175181

176182
# CRITICAL: Call complete() on the system before returning to ensure all subsystems,
177-
# variables, and parameters are properly registered and namespaced. Without this,
183+
# variables, and parameters are properly registered and namespaced. Without this,
178184
# attempting to create an ODEProblem from the DEIM system will fail with errors about
179185
# missing initial conditions for variables that should exist in the system.
180186
# This is required due to changes in ModelingToolkit.jl's internal structure handling.

src/utils.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function get_deqs(sys::ODESystem)::Tuple{Vector{Equation}, Vector{Equation}}
2222
push!(others, eq)
2323
end
2424
end
25-
deqs, others
25+
return deqs, others
2626
end
2727

2828
"""
@@ -78,7 +78,7 @@ function separate_terms(exprs::AbstractVector, vars, iv)
7878
push!(linear_I, row_index)
7979
push!(linear_J, idxmap[term])
8080
push!(linear_V, value)
81-
nothing
81+
return nothing
8282
end
8383

8484
other_terms = similar(exprs, Num) # create a vector of the same size
@@ -95,7 +95,7 @@ function separate_terms(exprs::AbstractVector, vars, iv)
9595
else
9696
other_terms[i] += expr
9797
end
98-
nothing
98+
return nothing
9999
end
100100

101101
for (i, expr) in enumerate(exprs)
@@ -125,4 +125,4 @@ function separate_terms(exprs::AbstractVector, vars, iv)
125125
end
126126
linear = sparse(linear_I, linear_J, linear_V, length(exprs), length(vars))
127127
return linear, other_terms, nonlinear_terms
128-
end
128+
end

test/DataReduction.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ function lorenz_prob()
55
function lorenz!(du, u, p, t)
66
du[1] = p[1] * (u[2] - u[1])
77
du[2] = u[1] * (p[2] - u[3]) - u[2]
8-
du[3] = u[1] * u[2] - p[3] * u[3]
8+
return du[3] = u[1] * u[2] - p[3] * u[3]
99
end
1010

1111
u0 = [1, 0, 0]
1212
p = [10, 28, 8 / 3]
1313
tspan = (0, 100)
1414
prob = ODEProblem(lorenz!, u0, tspan, p)
1515
sol = solve(prob, Tsit5())
16-
sol
16+
return sol
1717
end
1818

1919
@testset "POD-Utils" begin

0 commit comments

Comments
 (0)