Skip to content

Commit 9c7fa73

Browse files
committed
Add and apply .JuliaFormatter.toml with SciML style
1 parent 5fb0074 commit 9c7fa73

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+3245
-3493
lines changed

.JuliaFormatter.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
always_for_in = true
1+
style = "sciml"

benchmark/agents.jl

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,33 +54,32 @@ end
5454

5555
mutable struct ContinuousAgent <: AbstractAgent
5656
id::Int
57-
pos::NTuple{3,Float64}
58-
vel::NTuple{3,Float64}
57+
pos::NTuple{3, Float64}
58+
vel::NTuple{3, Float64}
5959
one::Float64
6060
two::Bool
6161
end
6262

6363
mutable struct ContinuousAgentTwo <: AbstractAgent
6464
id::Int
65-
pos::NTuple{3,Float64}
66-
vel::NTuple{3,Float64}
65+
pos::NTuple{3, Float64}
66+
vel::NTuple{3, Float64}
6767
end
6868

6969
mutable struct ContinuousAgentThree <: AbstractAgent
7070
id::Int
71-
pos::NTuple{3,Float64}
72-
vel::NTuple{3,Float64}
71+
pos::NTuple{3, Float64}
72+
vel::NTuple{3, Float64}
7373
end
7474

7575
mutable struct ContinuousAgentFour <: AbstractAgent
7676
id::Int
77-
pos::NTuple{3,Float64}
78-
vel::NTuple{3,Float64}
77+
pos::NTuple{3, Float64}
78+
vel::NTuple{3, Float64}
7979
end
8080

8181
mutable struct ContinuousAgentFive <: AbstractAgent
8282
id::Int
83-
pos::NTuple{3,Float64}
84-
vel::NTuple{3,Float64}
83+
pos::NTuple{3, Float64}
84+
vel::NTuple{3, Float64}
8585
end
86-

benchmark/benchmarks.jl

Lines changed: 142 additions & 126 deletions
Large diffs are not rendered by default.

benchmark/ensembles.jl

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ function ensemble_benchmark(f, parallel, nreplicates)
2626
adf, mdf, _ = ensemblerun!(models, schelling_agent_step!, dummystep, nsteps;
2727
parallel, adata = [:pos, :mood, :group],
2828
showprogress = true,
29-
when = (model, step) ->
30-
( (step) % whensteps == 0 || step == 0 ),
29+
when = (model, step) -> ((step) % whensteps == 0 ||
30+
step == 0),
3131
mdata = [:min_to_be_happy])
3232
else
3333
# TODO: Why do we need `replicate_idx` here?
3434
# Can't we just use the `Models.schelling`?
3535
function initialize(;
36-
replicate_idx = 1, numagents = 320, griddims = (20, 20), min_to_be_happy = 3
37-
)
36+
replicate_idx = 1, numagents = 320, griddims = (20, 20),
37+
min_to_be_happy = 3)
3838
space = GridSpace(griddims, periodic = false)
3939
properties = Dict(:min_to_be_happy => min_to_be_happy)
4040

@@ -49,17 +49,14 @@ function ensemble_benchmark(f, parallel, nreplicates)
4949
return model
5050
end
5151

52-
parameters = Dict(
53-
:numagents => collect(numagents_low:numagents_high),
54-
:replicate_idx => collect(1:nreplicates),
55-
:griddims => (20, 20),
56-
)
52+
parameters = Dict(:numagents => collect(numagents_low:numagents_high),
53+
:replicate_idx => collect(1:nreplicates),
54+
:griddims => (20, 20))
5755
paramscan(parameters, initialize;
5856
parallel, adata = [:pos, :mood, :group],
5957
mdata = [:min_to_be_happy], showprogress = true,
6058
agent_step! = schelling_agent_step!,
61-
when = (model, step) ->
62-
( (step) % whensteps == 0 || step == 0 ),
59+
when = (model, step) -> ((step) % whensteps == 0 || step == 0),
6360
n = nsteps)
6461
end
6562
end
@@ -72,7 +69,7 @@ for (f, parallel, nreplicates, name) in [
7269
(paramscan, false, 10, "paramscan serial 10 reps"),
7370
(paramscan, true, 10, "paramscan parallel 10 reps"),
7471
(paramscan, false, 20, "paramscan serial 20 reps"),
75-
(paramscan, true, 20, "paramscan parallel 20 reps")
72+
(paramscan, true, 20, "paramscan parallel 20 reps"),
7673
]
77-
ENSEMBLES_SUITE[name] = @benchmarkable ensemble_benchmark($f, $parallel, $nreplicates) samples = 1
74+
ENSEMBLES_SUITE[name] = @benchmarkable ensemble_benchmark($f, $parallel, $nreplicates) samples=1
7875
end

benchmark/schedulers.jl

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function fake_model(; nagents = 500, scheduler)
2020
end
2121

2222
function fake_model_multi(; nagents = 500, scheduler)
23-
model = ABM(Union{FakeAgent,OtherFakeAgent}; scheduler, warn = false)
23+
model = ABM(Union{FakeAgent, OtherFakeAgent}; scheduler, warn = false)
2424
for i in 1:nagents
2525
if i % 2 == 0
2626
add_agent!(FakeAgent(i, 1), model)
@@ -42,7 +42,10 @@ for (model, name) in [
4242
(fake_model(; scheduler = Schedulers.partially(0.7)), "partially"),
4343
(fake_model(; scheduler = Schedulers.Partially(0.7)), "Partially"),
4444
(fake_model_multi(; scheduler = Schedulers.by_type(true, true)), "by_type"),
45-
(fake_model_multi(; scheduler = Schedulers.ByType(true, true, Union{FakeAgent,OtherFakeAgent})), "ByType")
45+
(fake_model_multi(;
46+
scheduler = Schedulers.ByType(true, true,
47+
Union{FakeAgent, OtherFakeAgent})),
48+
"ByType"),
4649
]
4750
SUITE[name] = @benchmarkable Agents.schedule($model)
4851
end
@@ -55,12 +58,18 @@ for (model, name) in [
5558
(fake_model(; nagents = 800000, scheduler = Schedulers.ByID()), "ByID"),
5659
(fake_model(; nagents = 800000, scheduler = Schedulers.randomly), "randomly"),
5760
(fake_model(; nagents = 800000, scheduler = Schedulers.Randomly()), "Randomly"),
58-
(fake_model(; nagents = 800000, scheduler = Schedulers.by_property(:group)), "by_property"),
59-
(fake_model(; nagents = 800000, scheduler = Schedulers.ByProperty(:group)), "ByProperty"),
61+
(fake_model(; nagents = 800000, scheduler = Schedulers.by_property(:group)),
62+
"by_property"),
63+
(fake_model(; nagents = 800000, scheduler = Schedulers.ByProperty(:group)),
64+
"ByProperty"),
6065
(fake_model(; nagents = 800000, scheduler = Schedulers.partially(0.7)), "partially"),
6166
(fake_model(; nagents = 800000, scheduler = Schedulers.Partially(0.7)), "Partially"),
62-
(fake_model_multi(; nagents = 800000, scheduler = Schedulers.by_type(true, true)), "by_type"),
63-
(fake_model_multi(; nagents = 800000, scheduler = Schedulers.ByType(true, true, Union{FakeAgent,OtherFakeAgent})), "ByType")
67+
(fake_model_multi(; nagents = 800000, scheduler = Schedulers.by_type(true, true)),
68+
"by_type"),
69+
(fake_model_multi(; nagents = 800000,
70+
scheduler = Schedulers.ByType(true, true,
71+
Union{FakeAgent, OtherFakeAgent})),
72+
"ByType"),
6473
]
6574
SUITE["large_model"][name] = @benchmarkable Agents.schedule($model)
6675
end
@@ -77,8 +86,12 @@ for (model, name) in [
7786
(fake_model(; nagents = 50, scheduler = Schedulers.ByProperty(:group)), "ByProperty"),
7887
(fake_model(; nagents = 50, scheduler = Schedulers.partially(0.7)), "partially"),
7988
(fake_model(; nagents = 50, scheduler = Schedulers.Partially(0.7)), "Partially"),
80-
(fake_model_multi(; nagents = 50, scheduler = Schedulers.by_type(true, true)), "by_type"),
81-
(fake_model_multi(; nagents = 50, scheduler = Schedulers.ByType(true, true, Union{FakeAgent,OtherFakeAgent})), "ByType")
89+
(fake_model_multi(; nagents = 50, scheduler = Schedulers.by_type(true, true)),
90+
"by_type"),
91+
(fake_model_multi(; nagents = 50,
92+
scheduler = Schedulers.ByType(true, true,
93+
Union{FakeAgent, OtherFakeAgent})),
94+
"ByType"),
8295
]
8396
SUITE["small_model"][name] = @benchmarkable Agents.schedule($model)
8497
end

benchmark/simple_grid/abusive_unkillable.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# die in this simulation.
66
# Based on https://github.com/JuliaDynamics/Agents.jl/issues/640#issuecomment-1166330815
77
mutable struct AbusiveUnkillableAgent
8-
pos::Tuple{Int,Int}
8+
pos::Tuple{Int, Int}
99
group::Int
1010
happy::Bool
1111
end
@@ -19,7 +19,7 @@ function initialize_abusiveunkillable()
1919
model = AbusiveUnkillableModel(AbusiveUnkillableAgent[], fill(0, grid_size...))
2020
N = floor(Int, grid_size[1] * grid_size[2] * grid_occupation * 0.5)
2121

22-
for i in 1:2N
22+
for i in 1:(2N)
2323
grp = i <= N ? 1 : 2
2424
pos = (rand(1:grid_size[1]), rand(1:grid_size[2]))
2525
while model.space[pos...] > 0
@@ -67,7 +67,7 @@ end
6767

6868
model_abusiveunkillable = initialize_abusiveunkillable()
6969
println("Benchmarking abusive unkillable version")
70-
@btime simulate_abusiveunkillable!($model_abusiveunkillable) setup = (model_abusiveunkillable = initialize_abusiveunkillable())
70+
@btime simulate_abusiveunkillable!($model_abusiveunkillable) setup=(model_abusiveunkillable = initialize_abusiveunkillable())
7171
println("Benchmarking abusive unkillable version: count nearby same")
7272
model_abusiveunkillable = initialize_abusiveunkillable()
73-
@btime count_nearby_same_abusiveunkillable(agent, model_abusiveunkillable) setup = (agent = rand(model_abusiveunkillable.agents))
73+
@btime count_nearby_same_abusiveunkillable(agent, model_abusiveunkillable) setup=(agent = rand(model_abusiveunkillable.agents))

benchmark/simple_grid/continuous_space_impact.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ function count_nearby_same_exact(agent, model)
3131
end
3232

3333
println("Continuous space count nearby ids, spacing=$spacing, r=$r, inexact")
34-
@btime count_nearby_same(agent, $model) setup = (agent = random_agent($model))
34+
@btime count_nearby_same(agent, $model) setup=(agent = random_agent($model))
3535
println("Continuous space count nearby ids, spacing=$spacing, r=$r, exact")
36-
@btime count_nearby_same_exact(agent, $model) setup = (agent = random_agent($model))
36+
@btime count_nearby_same_exact(agent, $model) setup=(agent = random_agent($model))
3737

3838
#= Results
3939
# Current state
@@ -47,7 +47,6 @@ Continuous space count nearby ids, spacing=0.05, r=0.1, exact
4747
Continuous space count nearby ids, spacing=0.1, r=0.1, exact
4848
4.843 μs (58 allocations: 5.22 KiB)
4949
50-
5150
# master
5251
Continuous space count nearby ids, spacing=0.05, r=0.1, inexact
5352
3.612 μs (71 allocations: 4.91 KiB)
@@ -58,4 +57,4 @@ Continuous space count nearby ids, spacing=0.1, r=0.1, inexact
5857
5.900 μs (118 allocations: 8.05 KiB)
5958
Continuous space count nearby ids, spacing=0.1, r=0.1, exact
6059
10.300 μs (218 allocations: 32.88 KiB)
61-
=#
60+
=#

benchmark/simple_grid/dict_based.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ end
55

66
function initialize_dict()
77
model = Dict{NTuple{2, Int}, DictAgent}()
8-
N = grid_size[1]*grid_size[2]*grid_occupation
8+
N = grid_size[1] * grid_size[2] * grid_occupation
99
for n in 1:N
1010
group = n < N / 2 ? 1 : 2
1111
pos = (rand(1:grid_size[1]), rand(1:grid_size[2]))
@@ -49,4 +49,4 @@ end
4949

5050
model_dict = initialize_dict()
5151
println("benchmarking dict-based step")
52-
@btime simulation_step!($model_dict) setup = (model_dict = initialize_dict())
52+
@btime simulation_step!($model_dict) setup=(model_dict = initialize_dict())

benchmark/simple_grid/gridspace_based.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function initialize_gridspace()
1010
properties = Dict(:min_to_be_happy => min_to_be_happy)
1111
rng = Random.Xoshiro(rand(UInt))
1212
model = ABM(GridSpaceAgent, space; properties, rng)
13-
N = grid_size[1]*grid_size[2]*grid_occupation
13+
N = grid_size[1] * grid_size[2] * grid_occupation
1414
for n in 1:N
1515
group = n < N / 2 ? 1 : 2
1616
agent = GridSpaceAgent(n, (1, 1), group, false)
@@ -41,18 +41,18 @@ end
4141
model = initialize_gridspace()
4242
agent = model[1]
4343
println("Benchmarking GridSpace version")
44-
@btime step!($model, agent_step_gridspace!) setup = (model = initialize_gridspace())
44+
@btime step!($model, agent_step_gridspace!) setup=(model = initialize_gridspace())
4545

4646
println("Benchmarking GridSpace version: count nearby same")
4747
model = initialize_gridspace()
48-
@btime count_nearby_same(agent, model) setup = (agent = random_agent(model))
48+
@btime count_nearby_same(agent, model) setup=(agent = random_agent(model))
4949

5050
function profile_nearby_same(model, agent = random_agent(model))
5151
x = 0
5252
N = 1000000
5353
for i in 1:N
5454
x += count_nearby_same(agent, model)
5555
end
56-
return x/N
56+
return x / N
5757
end
58-
# Then use @profview in VSCode
58+
# Then use @profview in VSCode

benchmark/simple_grid/run_comparison.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ const min_to_be_happy = 3 # how many nearby agents you need of same group
55
const grid_occupation = 0.8 # percentage of space occupied by agents
66
const grid_size = (30, 30)
77
const moore = [
8-
(1,0), (1,1), (1,-1),
9-
(0,1), (0,-1),
10-
(-1,0), (-1,1), (-1,-1),
8+
(1, 0), (1, 1), (1, -1),
9+
(0, 1), (0, -1),
10+
(-1, 0), (-1, 1), (-1, -1),
1111
]
1212

1313
include("dict_based.jl")
1414
include("gridspace_based.jl")
1515
include("simple_grid_space.jl")
16-
include("abusive_unkillable.jl")
16+
include("abusive_unkillable.jl")

0 commit comments

Comments
 (0)