Skip to content

Commit 38b0f2b

Browse files
authored
[docs] remove src lines. All tutorials should show all lines (#4126)
1 parent 0b42e5f commit 38b0f2b

17 files changed

+54
-63
lines changed

docs/make.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,6 @@ function _literate_directory(dir)
106106
end
107107
end
108108
for filename in _file_list(dir, dir, ".jl")
109-
# `include` the file to test it before `#src` lines are removed. It is
110-
# in a testset to isolate local variables between files.
111-
Test.@testset "$(filename)" begin
112-
_include_sandbox(filename)
113-
end
114109
Literate.markdown(
115110
filename,
116111
dir;

docs/src/tutorials/algorithms/benders_decomposition.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,12 @@ set_silent(model)
166166
@constraint(model, [i = 2:(n-1)], sum(y[i, :]) == sum(y[:, i]))
167167
@objective(model, Min, 0.1 * sum(x) - sum(y[1, :]))
168168
optimize!(model)
169-
assert_is_solved_and_feasible(model) #src
169+
assert_is_solved_and_feasible(model)
170170
solution_summary(model)
171171

172172
# The optimal objective value is -5.1:
173173

174-
Test.@test isapprox(objective_value(model), -5.1; atol = 1e-4) #src
174+
Test.@test isapprox(objective_value(model), -5.1; atol = 1e-4)
175175
objective_value(model)
176176

177177
# and the optimal flows are:
@@ -434,8 +434,7 @@ inplace_solution = optimal_flows(optimal_ret.y)
434434

435435
# which is the same as the monolithic solution:
436436

437-
Test.@test inplace_solution == monolithic_solution #src
438-
inplace_solution == monolithic_solution
437+
Test.@test inplace_solution == monolithic_solution
439438

440439
# ## Feasibility cuts
441440

@@ -541,5 +540,4 @@ feasible_inplace_solution = optimal_flows(optimal_ret.y)
541540
# which is the same as the monolithic solution (because `sum(y) >= 1` in the
542541
# monolithic solution):
543542

544-
Test.@test feasible_inplace_solution == monolithic_solution #src
545-
feasible_inplace_solution == monolithic_solution
543+
Test.@test feasible_inplace_solution == monolithic_solution

docs/src/tutorials/algorithms/cutting_stock_column_generation.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import DataFrames
1515
import HiGHS
1616
import Plots
1717
import SparseArrays
18-
import Test #src
18+
import Test
1919

2020
# ## Background
2121

@@ -236,8 +236,8 @@ set_silent(model)
236236
@constraint(model, demand[i in 1:I], patterns[i]' * x >= data.pieces[i].d)
237237
optimize!(model)
238238
assert_is_solved_and_feasible(model)
239+
Test.@test isapprox(objective_value(model), 386; atol = 1e-6)
239240
solution_summary(model)
240-
Test.@test isapprox(objective_value(model), 386; atol = 1e-6) #src
241241

242242
# This solution requires 386 rolls. This solution is sub-optimal because the
243243
# model does not contain the full set of possible patterns.
@@ -359,8 +359,7 @@ filter!(row -> row.rolls > 0, solution)
359359
# solutions. We can create a integer feasible solution by rounding up the
360360
# orders. This requires 306 rolls:
361361

362-
Test.@test sum(ceil.(Int, solution.rolls)) == 306 #src
363-
sum(ceil.(Int, solution.rolls))
362+
Test.@test sum(ceil.(Int, solution.rolls)) == 306
364363

365364
# Alternatively, we can re-introduce the integrality constraints and resolve the
366365
# problem:
@@ -375,7 +374,7 @@ filter!(row -> row.rolls > 0, solution)
375374

376375
# This now requires 299 rolls:
377376

378-
Test.@test isapprox(sum(solution.rolls), 299; atol = 1e-6) #src
377+
Test.@test isapprox(sum(solution.rolls), 299; atol = 1e-6)
379378
sum(solution.rolls)
380379

381380
# Note that this may not be the global minimum because we are not adding new

docs/src/tutorials/applications/optimal_power_flow.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ set_silent(model)
121121
# real power range (all 10, as it turns out in this case):
122122

123123
basic_lower_bound = value(lower_bound, objective_function(model));
124-
Test.@test isapprox(basic_lower_bound, 1188.75; atol = 1e-2) #src
124+
Test.@test isapprox(basic_lower_bound, 1188.75; atol = 1e-2)
125125
println("Objective value (basic lower bound) : $basic_lower_bound")
126126

127127
# to see that we can do no better than an objective cost of 1188.75.
@@ -282,7 +282,7 @@ P_G = real(S_G)
282282

283283
optimize!(model)
284284
assert_is_solved_and_feasible(model)
285-
Test.@test isapprox(objective_value(model), 3087.84; atol = 1e-2) #src
285+
Test.@test isapprox(objective_value(model), 3087.84; atol = 1e-2)
286286
solution_summary(model)
287287

288288
#-
@@ -422,7 +422,7 @@ optimize!(model)
422422

423423
assert_is_solved_and_feasible(model; allow_almost = true)
424424
sdp_relaxation_lower_bound = round(objective_value(model); digits = 2)
425-
Test.@test isapprox(sdp_relaxation_lower_bound, 2753.04; rtol = 1e-3) #src
425+
Test.@test isapprox(sdp_relaxation_lower_bound, 2753.04; rtol = 1e-3)
426426
println(
427427
"Objective value (W & V relax. lower bound): $sdp_relaxation_lower_bound",
428428
)

docs/src/tutorials/conic/arbitrary_precision.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
using JuMP
1616
import CDDLib
1717
import Clarabel
18-
import Test #src
18+
import Test
1919

2020
# ## Higher-precision arithmetic
2121

@@ -102,7 +102,7 @@ value.(x) .- [3 // 7, 3 // 14]
102102

103103
# The primal feasibility violation is on the order of `1e-16`
104104

105-
Test.@test 1e-16 <= maximum(values(primal_feasibility_report(model))) <= 1e-15 #src
105+
Test.@test 1e-16 <= maximum(values(primal_feasibility_report(model))) <= 1e-15
106106
primal_feasibility_report(model)
107107

108108
# But by reducing the tolerances, we can obtain a more accurate solution:
@@ -116,7 +116,7 @@ value.(x) .- [3 // 7, 3 // 14]
116116

117117
# The primal feasibility violation is also much smaller:
118118

119-
Test.@test maximum(values(primal_feasibility_report(model))) < 1e-30 #src
119+
Test.@test maximum(values(primal_feasibility_report(model))) < 1e-30
120120
primal_feasibility_report(model)
121121

122122
# ## Rational arithmetic
@@ -176,5 +176,5 @@ value(c2)
176176
# Because the solution is in exact arithmetic, there are no primal
177177
# infeasibilities:
178178

179-
Test.@test isempty(primal_feasibility_report(model)) #src
179+
Test.@test isempty(primal_feasibility_report(model))
180180
primal_feasibility_report(model)

docs/src/tutorials/conic/ellipse_approx.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ f = [1 - S[i, :]' * Z * S[i, :] + 2 * S[i, :]' * z - s for i in 1:m]
206206
@objective(model, Max, 1 * t + 0)
207207
optimize!(model)
208208
assert_is_solved_and_feasible(model)
209-
Test.@test isapprox(D, value.(Z); atol = 1e-3) #src
209+
Test.@test isapprox(D, value.(Z); atol = 1e-3)
210210
solve_time_1 = solve_time(model)
211211

212212
# This formulation gives the much smaller graph:
@@ -242,7 +242,7 @@ f = [1 - S[i, :]' * Z * S[i, :] + 2 * S[i, :]' * z - s for i in 1:m]
242242
@objective(model, Max, 1 * t + 0)
243243
optimize!(model)
244244
assert_is_solved_and_feasible(model)
245-
Test.@test isapprox(D, value.(Z); atol = 1e-3) #src
245+
Test.@test isapprox(D, value.(Z); atol = 1e-3)
246246
solve_time_2 = solve_time(model)
247247

248248
# This formulation gives the much smaller graph:

docs/src/tutorials/conic/min_ellipse.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ q = P \ value.(P_q)
136136
# Finally, overlaying the solution in the plot we see the minimal area enclosing
137137
# ellipsoid:
138138

139-
Test.@test isapprox(P, [0.4237 -0.0396; -0.0396 0.3163]; atol = 1e-2) #src
140-
Test.@test isapprox(q, [-0.3960, -0.0214]; atol = 1e-2) #src
139+
Test.@test isapprox(P, [0.4237 -0.0396; -0.0396 0.3163]; atol = 1e-2)
140+
Test.@test isapprox(q, [-0.3960, -0.0214]; atol = 1e-2)
141141

142142
Plots.plot!(
143143
plot,

docs/src/tutorials/conic/simple_examples.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ function example_k_means_clustering()
166166
assert_is_solved_and_feasible(model)
167167
Z_val = value.(Z)
168168
current_cluster, visited = 0, Set{Int}()
169-
solution = [1, 1, 2, 1, 2, 2] #src
169+
solution = [1, 1, 2, 1, 2, 2]
170170
for i in 1:m
171171
if !(i in visited)
172172
current_cluster += 1
@@ -175,7 +175,7 @@ function example_k_means_clustering()
175175
if isapprox(Z_val[i, i], Z_val[i, j]; atol = 1e-3)
176176
println(a[j])
177177
push!(visited, j)
178-
Test.@test solution[j] == current_cluster #src
178+
Test.@test solution[j] == current_cluster
179179
end
180180
end
181181
end
@@ -218,12 +218,12 @@ function example_correlation_problem()
218218
optimize!(model)
219219
assert_is_solved_and_feasible(model)
220220
println("An upper bound for ρ_AC is $(value(ρ["A", "C"]))")
221-
Test.@test value(ρ["A", "C"]) 0.87195 atol = 1e-4 #src
221+
Test.@test value(ρ["A", "C"]) 0.87195 atol = 1e-4
222222
@objective(model, Min, ρ["A", "C"])
223223
optimize!(model)
224224
assert_is_solved_and_feasible(model)
225225
println("A lower bound for ρ_AC is $(value(ρ["A", "C"]))")
226-
Test.@test value(ρ["A", "C"]) -0.978 atol = 1e-3 #src
226+
Test.@test value(ρ["A", "C"]) -0.978 atol = 1e-3
227227
return
228228
end
229229

docs/src/tutorials/getting_started/sum_if.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ nodes, edges, demand = build_random_graph(1_000, 2_000)
148148
run_times = Float64[]
149149
factors = 1:10
150150
for factor in factors
151-
GC.gc() #src
151+
GC.gc()
152152
graph = build_random_graph(1_000 * factor, 5_000 * factor)
153153
push!(run_times, @elapsed build_naive_model(graph...))
154154
end
@@ -217,7 +217,7 @@ run_times_naive = Float64[]
217217
run_times_cached = Float64[]
218218
factors = 1:10
219219
for factor in factors
220-
GC.gc() #src
220+
GC.gc()
221221
graph = build_random_graph(1_000 * factor, 5_000 * factor)
222222
push!(run_times_naive, @elapsed build_naive_model(graph...))
223223
push!(run_times_cached, @elapsed build_cached_model(graph...))

docs/src/tutorials/getting_started/tolerances.jl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ set_silent(model)
107107
@variable(model, x >= 0)
108108
@constraint(model, x == -1e-8)
109109
optimize!(model)
110-
assert_is_solved_and_feasible(model) #src
110+
assert_is_solved_and_feasible(model)
111111
is_solved_and_feasible(model)
112112

113113
#-
@@ -122,7 +122,7 @@ value(x)
122122

123123
set_attribute(model, "primal_feasibility_tolerance", 1e-10)
124124
optimize!(model)
125-
@assert !is_solved_and_feasible(model) #src
125+
@assert !is_solved_and_feasible(model)
126126
is_solved_and_feasible(model)
127127

128128
# ### Realistic example
@@ -142,7 +142,7 @@ optimize!(model)
142142

143143
# SCS reports that it solved the problem to optimality:
144144

145-
assert_is_solved_and_feasible(model) #src
145+
assert_is_solved_and_feasible(model)
146146
is_solved_and_feasible(model)
147147

148148
# and that the solution for `x[1]` is nearly zero:
@@ -199,7 +199,6 @@ optimize!(model)
199199

200200
#-
201201

202-
assert_is_solved_and_feasible(model) #src
203202
assert_is_solved_and_feasible(model)
204203
value(x[1])
205204

@@ -234,12 +233,12 @@ set_attribute(model, "presolve", "off")
234233
set_attribute(model, "mip_heuristic_run_feasibility_jump", false)
235234
@variable(model, x == 1 + 1e-6, Int)
236235
optimize!(model)
237-
assert_is_solved_and_feasible(model) #src
236+
assert_is_solved_and_feasible(model)
238237
is_solved_and_feasible(model)
239238

240239
# HiGHS found an optimal solution, and the value of `x` is:
241240

242-
@assert isapprox(value(x), 1.000001) #src
241+
@assert isapprox(value(x), 1.000001)
243242
value(x)
244243

245244
# In other words, HiGHS thinks that the solution `x = 1.000001` satisfies the
@@ -255,7 +254,7 @@ primal_feasibility_report(model)
255254

256255
set_attribute(model, "mip_feasibility_tolerance", 1e-10)
257256
optimize!(model)
258-
@assert !is_solved_and_feasible(model) #src
257+
@assert !is_solved_and_feasible(model)
259258
is_solved_and_feasible(model)
260259

261260
# ### Realistic example
@@ -348,7 +347,7 @@ set_silent(model)
348347
@variable(model, y >= 0)
349348
@constraint(model, x + 1e8 * y == -1)
350349
optimize!(model)
351-
@assert !is_solved_and_feasible(model) #src
350+
@assert !is_solved_and_feasible(model)
352351
is_solved_and_feasible(model)
353352

354353
# The feasible solution `(x, y) = (0.0, -1e-8)` has a maximum primal violation
@@ -371,7 +370,7 @@ set_silent(model)
371370
@constraint(model, y <= 0.5)
372371
@constraint(model, x <= M * y)
373372
optimize!(model)
374-
@assert !is_solved_and_feasible(model) #src
373+
@assert !is_solved_and_feasible(model)
375374
is_solved_and_feasible(model)
376375

377376
# HiGHS reports the problem is infeasible, but there is a feasible (to
@@ -394,7 +393,7 @@ set_start_value(y, 1e-6)
394393
# Now HiGHS will report that the problem is feasible:
395394

396395
optimize!(model)
397-
assert_is_solved_and_feasible(model) #src
396+
assert_is_solved_and_feasible(model)
398397
is_solved_and_feasible(model)
399398

400399
# ## Problem is optimal, solution is infeasible

0 commit comments

Comments
 (0)