Skip to content

Commit 32cbfee

Browse files
committed
style: apply runic to src, docs
1 parent b3161fd commit 32cbfee

4 files changed

Lines changed: 45 additions & 45 deletions

File tree

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ repos:
4444
rev: v1.38.0
4545
hooks:
4646
- id: yamllint
47-
- repo: https://github.com/domluna/JuliaFormatter.jl
48-
rev: v2.3.0
47+
- repo: https://github.com/fredrikekre/runic-pre-commit
48+
rev: v2.0.1
4949
hooks:
50-
- id: julia-formatter
50+
- id: runic

docs/make.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ DocMeta.setdocmeta!(
1515
const page_rename = Dict("developer.md" => "Developer docs") # Without the numbers
1616
const numbered_pages = [
1717
file for file in readdir(joinpath(@__DIR__, "src")) if
18-
file != "index.md" && splitext(file)[2] == ".md"
18+
file != "index.md" && splitext(file)[2] == ".md"
1919
]
2020

2121
makedocs(;

src/gds_interface.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import MetaGraphsNext: labels
33
import Compat: @compat
44

55
@compat public ScheduleStyle,
6-
Asynchronous,
7-
Synchronous,
8-
GraphDynamicalSystem,
9-
GDS,
10-
get_n_entities,
11-
get_schedule,
12-
get_graph,
13-
get_domain,
14-
get_fn
6+
Asynchronous,
7+
Synchronous,
8+
GraphDynamicalSystem,
9+
GDS,
10+
get_n_entities,
11+
get_schedule,
12+
get_graph,
13+
get_domain,
14+
get_fn
1515

1616
abstract type ScheduleStyle end
1717
struct Asynchronous <: ScheduleStyle end
@@ -22,15 +22,15 @@ struct Synchronous <: ScheduleStyle end
2222
# include the ranges of each of the entities. The state of the system is just
2323
# the current value of each of the entities
2424

25-
abstract type GraphDynamicalSystem{N,S} <: DSB.DiscreteTimeDynamicalSystem end
25+
abstract type GraphDynamicalSystem{N, S} <: DSB.DiscreteTimeDynamicalSystem end
2626
const GDS = GraphDynamicalSystem
2727

2828
"""
2929
$(TYPEDSIGNATURES)
3030
3131
Get the number of entities `N` in the GDS.
3232
"""
33-
function get_n_entities(::GDS{N,S}) where {N,S}
33+
function get_n_entities(::GDS{N, S}) where {N, S}
3434
return N
3535
end
3636

@@ -39,7 +39,7 @@ end
3939
4040
Get the schedule for the GDS.
4141
"""
42-
function get_schedule(::GDS{N,S}) where {N,S}
42+
function get_schedule(::GDS{N, S}) where {N, S}
4343
return S
4444
end
4545

src/qualitative_networks.jl

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import Compat: @compat
1515
A graph dynamical system with a finite domain. State values of each entity are
1616
limited to change by at most 1 per time step.
1717
"""
18-
struct QualitativeNetwork{N_Entities,Schedule,Graph<:MG.MetaGraph} <:
19-
GraphDynamicalSystem{N_Entities,Schedule}
18+
struct QualitativeNetwork{N_Entities, Schedule, Graph <: MG.MetaGraph} <:
19+
GraphDynamicalSystem{N_Entities, Schedule}
2020
graph::Graph
2121
end
2222

@@ -34,7 +34,7 @@ DSB.current_time(::QualitativeNetwork) = 0
3434
DSB.reinit!(qn::QN, state::AbstractVector) = DSB.set_state!(qn, Int.(state))
3535

3636

37-
mutable struct QNEntity{F,S,D} <: AbstractEntity
37+
mutable struct QNEntity{F, S, D} <: AbstractEntity
3838
fn::F
3939
state::S
4040
domain::D
@@ -49,16 +49,16 @@ function DSB.set_state!(qne::QNEntity, s)
4949
"New state value for entity must be within its domain (domain: $domain, new state: $s)",
5050
)
5151
end
52-
qne.state = s
52+
return qne.state = s
5353
end
5454
get_domain(qne::QNEntity) = qne.domain
5555

56-
function QualitativeNetwork(graph::G) where {G<:Graphs.AbstractGraph}
57-
QualitativeNetwork{Graphs.nv(graph),Synchronous(),G}(graph)
56+
function QualitativeNetwork(graph::G) where {G <: Graphs.AbstractGraph}
57+
return QualitativeNetwork{Graphs.nv(graph), Synchronous(), G}(graph)
5858
end
5959

6060
function QualitativeNetwork(update_functions::AbstractDict, domains)
61-
QualitativeNetwork{Graphs.SimpleDiGraph}(update_functions, domains)
61+
return QualitativeNetwork{Graphs.SimpleDiGraph}(update_functions, domains)
6262
end
6363

6464
"""
@@ -72,49 +72,49 @@ The entity names (`E` in the signature) can be anything, while the functions (`F
7272
- implement the `TermInterface.jl` interface. Any terminal nodes in the functions must be numerical constants or reference an entity.
7373
"""
7474
function QualitativeNetwork{GraphType}(
75-
update_functions::AbstractDict{E,F},
76-
domains,
77-
)::QualitativeNetwork where {E,F,GraphType<:Graphs.AbstractGraph}
75+
update_functions::AbstractDict{E, F},
76+
domains,
77+
)::QualitativeNetwork where {E, F, GraphType <: Graphs.AbstractGraph}
7878
entity_keys = collect(keys(update_functions))
7979
entity_fns = getindex.((update_functions,), entity_keys)
8080
entity_domains = getindex.((domains,), entity_keys)
8181
get_arguments_or_empty = x -> TI.isexpr(x) ? (x, TI.arguments(x)) : (x, ())
8282
collect_arguments =
8383
x ->
84-
AT.treemap(get_arguments_or_empty, x) |>
85-
AT.Leaves .|>
86-
AT.nodevalue |>
87-
filter(in(entity_keys))
84+
AT.treemap(get_arguments_or_empty, x) |>
85+
AT.Leaves .|>
86+
AT.nodevalue |>
87+
filter(in(entity_keys))
8888

8989
referenced_entities = union.(collect_arguments.(entity_fns))
9090
referenced_indices =
9191
map(ref_for_e -> findfirst.(.==(ref_for_e), (entity_keys,)), referenced_entities)
9292
edges =
9393
Iterators.flatten(
94-
map(((j, idxs),) -> tuple.(idxs, (j,)), enumerate(referenced_indices)),
95-
) |> collect
94+
map(((j, idxs),) -> tuple.(idxs, (j,)), enumerate(referenced_indices)),
95+
) |> collect
9696
graph = GraphType()
9797
Graphs.add_vertices!(graph, length(entity_keys))
9898
Graphs.add_edge!.((graph,), Graphs.Edge.(edges))
99-
vertices_description = Pair{E,QNEntity}[
99+
vertices_description = Pair{E, QNEntity}[
100100
(e => QNEntity(fn, 0, d)) for
101-
(e, fn, d) in zip(entity_keys, entity_fns, entity_domains)
101+
(e, fn, d) in zip(entity_keys, entity_fns, entity_domains)
102102
]
103-
edges_description = Pair{Tuple{E,E},Nothing}[
103+
edges_description = Pair{Tuple{E, E}, Nothing}[
104104
(entity_keys[s], entity_keys[d]) => nothing for (s, d) in edges
105105
]
106106
return QualitativeNetwork(
107107
MG.MetaGraph(graph, vertices_description, edges_description, nothing),
108108
)
109109
end
110110

111-
function SciMLBase.step!(qn::QualitativeNetwork{N,S}) where {N,S}
112-
SciMLBase.step!(S, qn)
111+
function SciMLBase.step!(qn::QualitativeNetwork{N, S}) where {N, S}
112+
return SciMLBase.step!(S, qn)
113113
end
114114
SciMLBase.step!(qn::QN, n::Int, _...) = foreach(_ -> SciMLBase.step!(qn), 1:n)
115115

116116
function limit_change(next, prev, lower, upper)
117-
if next > prev
117+
return if next > prev
118118
min(upper, prev + 1)
119119
elseif next < prev
120120
max(lower, prev - 1)
@@ -124,18 +124,18 @@ function limit_change(next, prev, lower, upper)
124124
end
125125

126126
function DSB.set_state!(
127-
qn::QN{N,S,M},
128-
new_state::Int,
129-
entity::L,
130-
) where {N,S,I,G,L,M<:MG.MetaGraph{I,G,L}}
127+
qn::QN{N, S, M},
128+
new_state::Int,
129+
entity::L,
130+
) where {N, S, I, G, L, M <: MG.MetaGraph{I, G, L}}
131131
g = get_graph(qn)
132-
DSB.set_state!(g[entity], new_state)
132+
return DSB.set_state!(g[entity], new_state)
133133
end
134134

135135
function DSB.set_state!(qn::QN, new_state::AbstractVector)
136136
g = get_graph(qn)
137137

138-
DSB.set_state!.((qn,), new_state, MG.labels(g))
138+
return DSB.set_state!.((qn,), new_state, MG.labels(g))
139139
end
140140

141141
function SciMLBase.step!(::Synchronous, qn::QualitativeNetwork)
@@ -155,7 +155,7 @@ function SciMLBase.step!(::Synchronous, qn::QualitativeNetwork)
155155
end
156156

157157
function interpret(fn, state)
158-
MLStyle.@match fn begin
158+
return MLStyle.@match fn begin
159159
::Int => fn
160160
::Symbol => state[fn]
161161
:($a + $b) => interpret(a, state) + interpret(b, state)

0 commit comments

Comments
 (0)