Skip to content

Commit 7953a55

Browse files
authored
Switch to JuliaFormatter v2 (#310)
* Switch to JuliaFormatter v2 * Format examples
1 parent b208c84 commit 7953a55

19 files changed

Lines changed: 81 additions & 84 deletions

.github/workflows/format_check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
shell: julia --color=yes {0}
1919
run: |
2020
using Pkg
21-
Pkg.add(PackageSpec(name="JuliaFormatter", version="1"))
21+
Pkg.add(PackageSpec(name="JuliaFormatter", version="2"))
2222
using JuliaFormatter
2323
format(".", verbose=true)
2424
out = String(read(Cmd(`git diff`)))

docs/src/examples/Thermal_Generation_Dispatch_Example.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function diff_reverse(model::Model, ϵ::Float64 = 1.0)
102102
perturbation = zeros(I + 1)
103103

104104
## Loop for each primal variable
105-
for i in 1:I+1
105+
for i in 1:(I+1)
106106
## Set the perturbation in the Primal Variables and set the context to Backward
107107
perturbation[i] = ϵ
108108
MOI.set.(model, DiffOpt.ReverseVariablePrimal(), vect_ref, perturbation)
@@ -156,7 +156,7 @@ end
156156
# Result Primal Values:
157157
Plots.plot(
158158
d,
159-
data_results[1, :, 1:I+1];
159+
data_results[1, :, 1:(I+1)];
160160
title = "Generation by Demand",
161161
label = ["Thermal Generation 1" "Thermal Generation 2" "Thermal Generation 3" "Generation Deficit"],
162162
xlabel = "Demand [unit]",
@@ -166,7 +166,7 @@ Plots.plot(
166166
# Result Sensitivity Analysis:
167167
Plots.plot(
168168
d,
169-
data_results[1, :, I+2:2*(I+1)];
169+
data_results[1, :, (I+2):(2*(I+1))];
170170
title = "Sensitivity of Generation by Demand",
171171
label = ["T. Gen. 1 Sensitivity" "T. Gen. 2 Sensitivity" "T. Gen. 3 Sensitivity" "Gen. Deficit Sensitivity"],
172172
xlabel = "Demand [unit]",
@@ -177,7 +177,7 @@ Plots.plot(
177177
# Result Primal Values:
178178
Plots.plot(
179179
d,
180-
data_results[2, :, 1:I+1];
180+
data_results[2, :, 1:(I+1)];
181181
title = "Generation by Demand",
182182
label = ["Thermal Generation 1" "Thermal Generation 2" "Thermal Generation 3" "Generation Deficit"],
183183
xlabel = "Demand [unit]",
@@ -187,7 +187,7 @@ Plots.plot(
187187
# Result Sensitivity Analysis:
188188
Plots.plot(
189189
d,
190-
data_results[2, :, I+2:2*(I+1)];
190+
data_results[2, :, (I+2):(2*(I+1))];
191191
title = "Sensitivity of Generation by Demand",
192192
label = ["T. Gen. 1 Sensitivity" "T. Gen. 2 Sensitivity" "T. Gen. 3 Sensitivity" "Gen. Deficit Sensitivity"],
193193
xlabel = "Demand [unit]",

docs/src/examples/Thermal_Generation_Dispatch_Example_new.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function diff_reverse(model::Model, ϵ::Float64 = 1.0)
101101
dvect = Array{Float64,1}(undef, length(vect_ref))
102102

103103
## Loop for each primal variable
104-
for i in 1:I+1
104+
for i in 1:(I+1)
105105
## Reset the sensitivities of the model
106106
DiffOpt.empty_input_sensitivities!(model)
107107

@@ -152,7 +152,7 @@ end
152152
# Result Primal Values:
153153
Plots.plot(
154154
d,
155-
data_results[1, :, 1:I+1];
155+
data_results[1, :, 1:(I+1)];
156156
title = "Generation by Demand",
157157
label = ["Thermal Generation 1" "Thermal Generation 2" "Thermal Generation 3" "Generation Deficit"],
158158
xlabel = "Demand [unit]",
@@ -162,7 +162,7 @@ Plots.plot(
162162
# Result Sensitivity Analysis:
163163
Plots.plot(
164164
d,
165-
data_results[1, :, I+2:2*(I+1)];
165+
data_results[1, :, (I+2):(2*(I+1))];
166166
title = "Sensitivity of Generation by Demand",
167167
label = ["T. Gen. 1 Sensitivity" "T. Gen. 2 Sensitivity" "T. Gen. 3 Sensitivity" "Gen. Deficit Sensitivity"],
168168
xlabel = "Demand [unit]",
@@ -173,7 +173,7 @@ Plots.plot(
173173
# Result Primal Values:
174174
Plots.plot(
175175
d,
176-
data_results[2, :, 1:I+1];
176+
data_results[2, :, 1:(I+1)];
177177
title = "Generation by Demand",
178178
label = ["Thermal Generation 1" "Thermal Generation 2" "Thermal Generation 3" "Generation Deficit"],
179179
xlabel = "Demand [unit]",
@@ -183,7 +183,7 @@ Plots.plot(
183183
# Result Sensitivity Analysis:
184184
Plots.plot(
185185
d,
186-
data_results[2, :, I+2:2*(I+1)];
186+
data_results[2, :, (I+2):(2*(I+1))];
187187
title = "Sensitivity of Generation by Demand",
188188
label = ["T. Gen. 1 Sensitivity" "T. Gen. 2 Sensitivity" "T. Gen. 3 Sensitivity" "Gen. Deficit Sensitivity"],
189189
xlabel = "Demand [unit]",

docs/src/examples/Thermal_Generation_Dispatch_sweep.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ for (k, d_val) in enumerate(d_range)
4545

4646
@variable(model, d in Parameter(d_val)) # parameter
4747
@variables(model, begin # decisions
48-
0 <= g[i = 1:2] <= G[i]
48+
0 <= g[i=1:2] <= G[i]
4949
φ >= 0
5050
end)
5151

docs/src/examples/autotuning-ridge.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ y = X * w_real + noise * randn(N)
4444
l = N ÷ 2 # test train split
4545

4646
X_train = X[1:l, :]
47-
X_test = X[l+1:N, :]
47+
X_test = X[(l+1):N, :]
4848
y_train = y[1:l]
49-
y_test = y[l+1:N];
49+
y_test = y[(l+1):N];
5050

5151
# ## Defining the regression problem
5252

docs/src/examples/autotuning-ridge_new.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ y = X * w_real + noise * randn(N)
4444
l = N ÷ 2 # test train split
4545

4646
X_train = X[1:l, :]
47-
X_test = X[l+1:N, :]
47+
X_test = X[(l+1):N, :]
4848
y_train = y[1:l]
49-
y_test = y[l+1:N];
49+
y_test = y[(l+1):N];
5050

5151
# ## Defining the regression problem
5252

docs/src/examples/chainrules_unit.jl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ function unit_commitment(
105105
model,
106106
Min,
107107
sum(
108-
(Cp[g] * p[g, t]) + (Cnl[g] * u[g, t]) for g in units,
109-
t in 1:n_periods
108+
(Cp[g] * p[g, t]) + (Cnl[g] * u[g, t]) for
109+
g in units, t in 1:n_periods
110110
),
111111
)
112112

@@ -282,14 +282,13 @@ function ChainRulesCore.rrule(
282282
dnoload_costs[2] = sum(JuMP.coefficient.(obj, u[2, :]))
283283

284284
## computing derivative wrt constraint constant
285-
dload1_demand =
286-
JuMP.constant.(
287-
MOI.get.(
288-
model,
289-
DiffOpt.ReverseConstraintFunction(),
290-
energy_balance_cons,
291-
)
292-
)
285+
dload1_demand = JuMP.constant.(
286+
MOI.get.(
287+
model,
288+
DiffOpt.ReverseConstraintFunction(),
289+
energy_balance_cons,
290+
),
291+
)
293292
dload2_demand = copy(dload1_demand)
294293
return (dload1_demand, dload2_demand, dgen_costs, dnoload_costs)
295294
end

docs/src/examples/chainrules_unit_new.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ function unit_commitment(
109109
model,
110110
Min,
111111
sum(
112-
(Cp[g] * p[g, t]) + (Cnl[g] * u[g, t]) for g in units,
113-
t in 1:n_periods
112+
(Cp[g] * p[g, t]) + (Cnl[g] * u[g, t]) for
113+
g in units, t in 1:n_periods
114114
),
115115
)
116116

docs/src/examples/polyhedral_project_new.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ function (polytope::Polytope{N})(
4848
set_silent(model)
4949
@variable(model, x[1:layer_size, 1:batch_size])
5050
@variable(model, y[1:layer_size, 1:batch_size] in Parameter.(y_data))
51-
@variable(model, b[idx = 1:N] in Parameter.(polytope.b[idx]))
51+
@variable(model, b[idx=1:N] in Parameter.(polytope.b[idx]))
5252
@variable(
5353
model,
54-
w[idx = 1:N, i = 1:layer_size] in Parameter(polytope.w[idx][i])
54+
w[idx=1:N, i=1:layer_size] in Parameter(polytope.w[idx][i])
5555
)
5656
@constraint(
5757
model,

docs/src/examples/sensitivity-analysis-ridge.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function fit_ridge(X, Y, alpha = 0.1)
6464
@variable(model, w) # angular coefficient
6565
@variable(model, b) # linear coefficient
6666
## expression defining approximation error
67-
@expression(model, e[i = 1:N], Y[i] - w * X[i] - b)
67+
@expression(model, e[i=1:N], Y[i] - w * X[i] - b)
6868
## objective minimizing squared error and ridge penalty
6969
@objective(model, Min, 1 / N * dot(e, e) + alpha * (w^2))
7070
optimize!(model)

0 commit comments

Comments
 (0)