Skip to content

Commit 137db25

Browse files
authored
Merge pull request MilesCranmer#504 from MilesCranmer/format-v2
style: update to formatter version 2
2 parents 421b3a0 + 763b9f5 commit 137db25

20 files changed

+103
-103
lines changed

.JuliaFormatter.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
style = "blue"
22
ignore = ["docs"]
3+
# Keep pipe operators as they are more readable
34
pipe_to_function_call = false

.github/workflows/check-format.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
uses: julia-actions/cache@v2
2626
- name: Install JuliaFormatter and format
2727
run: |
28-
julia --startup-file=no -e 'using Pkg; pkg"activate --temp"; pkg"add JuliaFormatter@1.0.61"; using JuliaFormatter; format("."; verbose=true)'
28+
julia --startup-file=no -e 'using Pkg; pkg"activate --temp"; pkg"add JuliaFormatter@2"; using JuliaFormatter; format("."; verbose=true)'
2929
- name: "Format check"
3030
run: |
3131
julia -e '

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repos:
1111
- id: check-yaml
1212
- id: check-added-large-files
1313
- repo: https://github.com/domluna/JuliaFormatter.jl
14-
rev: v1.0.61
14+
rev: v2.1.6
1515
hooks:
1616
- id: julia-formatter
1717
- repo: https://github.com/pre-commit/mirrors-prettier

benchmark/benchmarks.jl

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ function create_utils_benchmark()
8888
suite["best_of_sample"] = @benchmarkable(
8989
best_of_sample(pop, rss, $options),
9090
setup = (
91-
nfeatures = 1;
92-
dataset = Dataset(randn(nfeatures, 32), randn(32));
93-
pop = Population(dataset; npop=100, nlength=20, options=$options, nfeatures);
94-
rss = RunningSearchStatistics(; options=$options)
91+
nfeatures=1;
92+
dataset=Dataset(randn(nfeatures, 32), randn(32));
93+
pop=Population(dataset; npop=100, nlength=20, options=($options), nfeatures);
94+
rss=RunningSearchStatistics(; options=($options))
9595
)
9696
)
9797

@@ -110,9 +110,9 @@ function create_utils_benchmark()
110110
end
111111
end,
112112
setup = (
113-
nfeatures = 1;
114-
dataset = Dataset(randn(nfeatures, 32), randn(32));
115-
mutation_weights = MutationWeights(;
113+
nfeatures=1;
114+
dataset=Dataset(randn(nfeatures, 32), randn(32));
115+
mutation_weights=MutationWeights(;
116116
mutate_constant=1.0,
117117
mutate_operator=1.0,
118118
swap_operands=1.0,
@@ -125,21 +125,23 @@ function create_utils_benchmark()
125125
form_connection=0.0,
126126
break_connection=0.0,
127127
);
128-
options = Options(;
129-
unary_operators=[sin, cos], binary_operators=[+, -, *, /], mutation_weights
128+
options=Options(;
129+
unary_operators=[sin, cos],
130+
binary_operators=[+, -, *, /],
131+
mutation_weights,
130132
);
131-
recorder = RecordType();
132-
temperature = 1.0;
133-
curmaxsize = 20;
134-
rss = RunningSearchStatistics(; options);
135-
trees = [
133+
recorder=RecordType();
134+
temperature=1.0;
135+
curmaxsize=20;
136+
rss=RunningSearchStatistics(; options);
137+
trees=[
136138
gen_random_tree_fixed_size(15, options, nfeatures, Float64) for _ in 1:100
137139
];
138-
expressions = [
140+
expressions=[
139141
Expression(tree; operators=options.operators, variable_names=["x1"]) for
140142
tree in trees
141143
];
142-
members = [
144+
members=[
143145
PopMember(dataset, expression, options; deterministic=false) for
144146
expression in expressions
145147
]
@@ -153,14 +155,14 @@ function create_utils_benchmark()
153155
end,
154156
seconds = 20,
155157
setup = (
156-
nfeatures = 1;
157-
T = Float64;
158-
dataset = Dataset(randn(nfeatures, 512), randn(512));
159-
ntrees = $ntrees;
160-
trees = [
158+
nfeatures=1;
159+
T=Float64;
160+
dataset=Dataset(randn(nfeatures, 512), randn(512));
161+
ntrees=($ntrees);
162+
trees=[
161163
gen_random_tree_fixed_size(20, $options, nfeatures, T) for i in 1:ntrees
162164
];
163-
members = [
165+
members=[
164166
PopMember(dataset, tree, $options; deterministic=false) for tree in trees
165167
]
166168
)
@@ -179,9 +181,9 @@ function create_utils_benchmark()
179181
compute_complexity(tree, $options)
180182
end,
181183
setup = (
182-
T = Float64;
183-
nfeatures = 3;
184-
trees = [
184+
T=Float64;
185+
nfeatures=3;
186+
trees=[
185187
gen_random_tree_fixed_size(20, $options, nfeatures, T) for
186188
i in 1:($ntrees)
187189
]
@@ -197,9 +199,9 @@ function create_utils_benchmark()
197199
SymbolicRegression.MutationFunctionsModule.randomly_rotate_tree!(tree)
198200
end,
199201
setup = (
200-
T = Float64;
201-
nfeatures = 3;
202-
trees = [
202+
T=Float64;
203+
nfeatures=3;
204+
trees=[
203205
gen_random_tree_fixed_size(20, $options, nfeatures, T) for
204206
i in 1:($ntrees)
205207
]
@@ -214,9 +216,9 @@ function create_utils_benchmark()
214216
)
215217
end,
216218
setup = (
217-
T = Float64;
218-
nfeatures = 3;
219-
trees = [
219+
T=Float64;
220+
nfeatures=3;
221+
trees=[
220222
gen_random_tree_fixed_size(20, $options, nfeatures, T) for i in 1:($ntrees)
221223
]
222224
)
@@ -240,9 +242,9 @@ function create_utils_benchmark()
240242
check_constraints(tree, $options, $options.maxsize)
241243
end,
242244
setup = (
243-
T = Float64;
244-
nfeatures = 3;
245-
trees = [
245+
T=Float64;
246+
nfeatures=3;
247+
trees=[
246248
gen_random_tree_fixed_size(20, $options, nfeatures, T) for i in 1:($ntrees)
247249
]
248250
)

src/CheckConstraints.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ function check_constraints(
9191
return true
9292
end
9393

94-
check_constraints(
95-
ex::Union{AbstractExpression,AbstractExpressionNode}, options::AbstractOptions
96-
)::Bool = check_constraints(ex, options, options.maxsize)
94+
check_constraints(ex::Union{AbstractExpression,AbstractExpressionNode}, options::AbstractOptions)::Bool = check_constraints(
95+
ex, options, options.maxsize
96+
)
9797

9898
end

src/ComposableExpression.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,9 @@ function apply_operator(op::F, x::Vararg{Any,N}) where {F<:Function,N}
271271
if all(_is_valid, x)
272272
return _apply_operator(op, x...)
273273
else
274-
example_vector =
275-
something(map(xi -> xi isa ValidVector ? xi : nothing, x)...)::ValidVector
274+
example_vector = something(
275+
map(xi -> xi isa ValidVector ? xi : nothing, x)...
276+
)::ValidVector
276277
expected_return_type = Base.promote_op(
277278
_apply_operator, typeof(op), map(typeof, x)...
278279
)

src/Configure.jl

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,10 @@ function activate_env_on_workers(
243243
)
244244
verbosity > 0 && @info "Activating environment on workers."
245245
@everywhere procs begin
246-
Base.MainInclude.eval(
247-
quote
248-
using Pkg
249-
Pkg.activate($$project_path)
250-
end,
251-
)
246+
Base.MainInclude.eval(quote
247+
using Pkg
248+
Pkg.activate($$project_path)
249+
end)
252250
end
253251
end
254252

@@ -291,12 +289,9 @@ function import_module_on_workers(
291289
all_extensions = vcat(relevant_extensions, @something(worker_imports, Symbol[]))
292290

293291
for ext in all_extensions
294-
push!(
295-
expr.args,
296-
quote
297-
using $ext: $ext
298-
end,
299-
)
292+
push!(expr.args, quote
293+
using $ext: $ext
294+
end)
300295
end
301296

302297
verbosity > 0 && if isempty(relevant_extensions)

src/ExpressionBuilder.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import DynamicExpressions: get_operators
1717
import ..CoreModule: create_expression
1818

1919
@unstable function create_expression(
20-
t::T, options::AbstractOptions, dataset::Dataset{T,L}, ::Val{embed}=Val(false)
20+
t::T, options::AbstractOptions, dataset::Dataset{T,L}, (::Val{embed})=Val(false)
2121
) where {T,L,embed}
2222
return create_expression(
2323
t, options, dataset, options.node_type, options.expression_type, Val(embed)
@@ -27,7 +27,7 @@ end
2727
t::AbstractExpressionNode{T},
2828
options::AbstractOptions,
2929
dataset::Dataset{T,L},
30-
::Val{embed}=Val(false),
30+
(::Val{embed})=Val(false),
3131
) where {T,L,embed}
3232
return create_expression(
3333
t, options, dataset, options.node_type, options.expression_type, Val(embed)
@@ -37,7 +37,7 @@ function create_expression(
3737
ex::AbstractExpression{T},
3838
options::AbstractOptions,
3939
::Dataset{T,L},
40-
::Val{embed}=Val(false),
40+
(::Val{embed})=Val(false),
4141
) where {T,L,embed}
4242
return ex::options.expression_type
4343
end
@@ -47,7 +47,7 @@ end
4747
dataset::Dataset{T,L},
4848
::Type{N},
4949
::Type{E},
50-
::Val{embed}=Val(false),
50+
(::Val{embed})=Val(false),
5151
) where {T,L,embed,N<:AbstractExpressionNode,E<:AbstractExpression}
5252
return create_expression(constructorof(N)(; val=t), options, dataset, N, E, Val(embed))
5353
end
@@ -57,7 +57,7 @@ end
5757
dataset::Dataset{T,L},
5858
::Type{<:AbstractExpressionNode},
5959
::Type{E},
60-
::Val{embed}=Val(false),
60+
(::Val{embed})=Val(false),
6161
) where {T,L,embed,E<:AbstractExpression}
6262
return constructorof(E)(t; init_params(options, dataset, nothing, Val(embed))...)
6363
end

src/MLJInterface.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ function _update(
331331
variable_names=variable_names,
332332
y_variable_names=y_variable_names,
333333
y_is_table=MMI.istable(y),
334-
has_class=!isnothing(class),
334+
has_class=(!isnothing(class)),
335335
X_units=X_units_clean,
336336
y_units=y_units_clean,
337337
types=SRFitResultTypes(;
@@ -595,9 +595,9 @@ end
595595
function get_equation_strings_for(
596596
::AbstractSingletargetSRRegressor, trees, options, variable_names
597597
)
598-
return (
599-
t -> string_tree(t, options; variable_names=variable_names, pretty=false)
600-
).(trees)
598+
return (t -> string_tree(t, options; variable_names=variable_names, pretty=false)).(
599+
trees
600+
)
601601
end
602602
function get_equation_strings_for(
603603
::AbstractMultitargetSRRegressor, trees, options, variable_names
@@ -671,7 +671,7 @@ for model in [:SRRegressor, :SRTestRegressor]
671671
target_scitype=AbstractVector{<:MMI.Continuous},
672672
supports_weights=true,
673673
reports_feature_importances=false,
674-
load_path=$("SymbolicRegression.MLJInterfaceModule." * string(model)),
674+
load_path=($("SymbolicRegression.MLJInterfaceModule." * string(model))),
675675
human_name="Symbolic Regression via Evolutionary Search",
676676
)
677677
end
@@ -686,7 +686,7 @@ for model in [:MultitargetSRRegressor, :MultitargetSRTestRegressor]
686686
},
687687
supports_weights=true,
688688
reports_feature_importances=false,
689-
load_path=$("SymbolicRegression.MLJInterfaceModule." * string(model)),
689+
load_path=($("SymbolicRegression.MLJInterfaceModule." * string(model))),
690690
human_name="Multi-Target Symbolic Regression via Evolutionary Search",
691691
)
692692
end

src/Options.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ end
150150
break
151151
end
152152
end
153-
found_degree == 0 && error("Operator $(op) is not in the operator set.")
153+
found_degree == 0 &&
154+
error("Operator $(op) is not in the operator set.")
154155
(found_degree, found_idx)
155156
end,
156157
new_max_nesting_dict = [
@@ -166,7 +167,7 @@ end
166167
end
167168
end
168169
found_degree == 0 &&
169-
error("Operator $(nested_op) is not in the operator set.")
170+
error("Operator $(nested_op) is not in the operator set.")
170171
(found_degree, found_idx)
171172
end
172173
(nested_degree, nested_idx, max_nesting)

0 commit comments

Comments
 (0)