Skip to content

Commit 575c09d

Browse files
authored
Fix change in Expr == for Julia nightly (#2780)
1 parent cc6437e commit 575c09d

File tree

4 files changed

+25
-22
lines changed

4 files changed

+25
-22
lines changed

src/Test/test_nonlinear.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ MOI.objective_expr(::FeasibilitySenseEvaluator) = :()
323323

324324
function MOI.constraint_expr(::FeasibilitySenseEvaluator, i::Int)
325325
@assert i == 1
326-
return :(x[$(MOI.VariableIndex(1))]^2 == 1)
326+
return :(x[$(MOI.VariableIndex(1))]^2.0 == 1.0)
327327
end
328328

329329
MOI.eval_objective(d::FeasibilitySenseEvaluator, x) = 0.0
@@ -1072,7 +1072,7 @@ written. External solvers can exclude this test without consequence.
10721072
function test_nonlinear_Feasibility_internal(::MOI.ModelLike, ::Config)
10731073
d = FeasibilitySenseEvaluator(true)
10741074
@test MOI.objective_expr(d) == :()
1075-
@test MOI.constraint_expr(d, 1) == :(x[$(MOI.VariableIndex(1))]^2 == 1.0)
1075+
@test MOI.constraint_expr(d, 1) == :(x[$(MOI.VariableIndex(1))]^2.0 == 1.0)
10761076
@test_throws AssertionError MOI.constraint_expr(d, 2)
10771077
MOI.initialize(d, [:Grad, :Jac, :ExprGraph, :Hess])
10781078
@test :Hess in MOI.features_available(d)

test/FileFormats/MOF/MOF.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ function HS071(x::Vector{MOI.VariableIndex})
9696
ExprEvaluator(
9797
:(x[$x1] * x[$x4] * (x[$x1] + x[$x2] + x[$x3]) + x[$x3]),
9898
[
99-
:(x[$x1] * x[$x2] * x[$x3] * x[$x4] >= 25),
100-
:(x[$x1]^2 + x[$x2]^2 + x[$x3]^2 + x[$x4]^2 == 40),
99+
:(x[$x1] * x[$x2] * x[$x3] * x[$x4] >= 25.0),
100+
:(x[$x1]^2.0 + x[$x2]^2.0 + x[$x3]^2.0 + x[$x4]^2.0 == 40.0),
101101
],
102102
),
103103
true,
@@ -117,7 +117,9 @@ function test_HS071()
117117
target = read(joinpath(@__DIR__, "nlp.mof.json"), String)
118118
target = replace(target, r"\s" => "")
119119
target = replace(target, "MathOptFormatModel" => "MathOptFormat Model")
120-
@test read(TEST_MOF_FILE, String) == target
120+
# Normalize .0 floats and integer representations in JSON
121+
normalize(x) = replace(x, ".0" => "")
122+
@test normalize(read(TEST_MOF_FILE, String)) == normalize(target)
121123
_validate(TEST_MOF_FILE)
122124
return
123125
end
@@ -308,7 +310,7 @@ function test_nonlinear_readingwriting()
308310
block = MOI.get(model2, MOI.NLPBlock())
309311
MOI.initialize(block.evaluator, [:ExprGraph])
310312
@test MOI.constraint_expr(block.evaluator, 1) ==
311-
:(2 * x[$x] + sin(x[$x])^2 - x[$y] == 1.0)
313+
:(2.0 * x[$x] + sin(x[$x])^2.0 - x[$y] == 1.0)
312314
_validate(TEST_MOF_FILE)
313315
return
314316
end

test/FileFormats/NL/read.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ function test_parse_expr()
6464
# (* x1 (* 2 (* x4 x2)))
6565
seekstart(io)
6666
x = MOI.VariableIndex.(1:4)
67-
@test NL._parse_expr(io, model) == :(*($(x[1]), *(2, *($(x[4]), $(x[2])))))
67+
@test NL._parse_expr(io, model) ==
68+
:(*($(x[1]), *(2.0, *($(x[4]), $(x[2])))))
6869
@test eof(io)
6970
return
7071
end
@@ -76,7 +77,7 @@ function test_parse_expr_nary()
7677
seekstart(io)
7778
x = MOI.VariableIndex.(1:4)
7879
@test NL._parse_expr(io, model) ==
79-
:(+($(x[1])^2, $(x[3])^2, $(x[4])^2, $(x[2])^2))
80+
:(+($(x[1])^2.0, $(x[3])^2.0, $(x[4])^2.0, $(x[2])^2.0))
8081
@test eof(io)
8182
return
8283
end

test/Nonlinear/Nonlinear.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function test_parse_sin_squared()
6262
Nonlinear.set_objective(model, :(sin($x)^2))
6363
evaluator = Nonlinear.Evaluator(model)
6464
MOI.initialize(evaluator, [:ExprGraph])
65-
@test MOI.objective_expr(evaluator) == :(sin(x[$x])^2)
65+
@test MOI.objective_expr(evaluator) == :(sin(x[$x])^2.0)
6666
return
6767
end
6868

@@ -72,7 +72,7 @@ function test_parse_ifelse()
7272
Nonlinear.set_objective(model, :(ifelse($x, 1, 2)))
7373
evaluator = Nonlinear.Evaluator(model)
7474
MOI.initialize(evaluator, [:ExprGraph])
75-
@test MOI.objective_expr(evaluator) == :(ifelse(x[$x], 1, 2))
75+
@test MOI.objective_expr(evaluator) == :(ifelse(x[$x], 1.0, 2.0))
7676
return
7777
end
7878

@@ -83,7 +83,7 @@ function test_parse_ifelse_inequality_less()
8383
evaluator = Nonlinear.Evaluator(model)
8484
MOI.initialize(evaluator, [:ExprGraph])
8585
@test MOI.objective_expr(evaluator) ==
86-
:(ifelse(x[$x] < 1, x[$x] - 1, x[$x] + 1))
86+
:(ifelse(x[$x] < 1.0, x[$x] - 1.0, x[$x] + 1.0))
8787
return
8888
end
8989

@@ -94,7 +94,7 @@ function test_parse_ifelse_inequality_greater()
9494
evaluator = Nonlinear.Evaluator(model)
9595
MOI.initialize(evaluator, [:ExprGraph])
9696
@test MOI.objective_expr(evaluator) ==
97-
:(ifelse(x[$x] > 1, x[$x] - 1, x[$x] + 1))
97+
:(ifelse(x[$x] > 1.0, x[$x] - 1.0, x[$x] + 1.0))
9898
return
9999
end
100100

@@ -105,7 +105,7 @@ function test_parse_ifelse_comparison()
105105
evaluator = Nonlinear.Evaluator(model)
106106
MOI.initialize(evaluator, [:ExprGraph])
107107
@test MOI.objective_expr(evaluator) ==
108-
:(ifelse(0 <= x[$x] <= 1, x[$x] - 1, x[$x] + 1))
108+
:(ifelse(0.0 <= x[$x] <= 1.0, x[$x] - 1.0, x[$x] + 1.0))
109109
return
110110
end
111111

@@ -251,7 +251,7 @@ function test_set_objective()
251251
@test model.objective == Nonlinear.parse_expression(model, input)
252252
evaluator = Nonlinear.Evaluator(model)
253253
MOI.initialize(evaluator, [:ExprGraph])
254-
@test MOI.objective_expr(evaluator) == :(x[$x]^2 + 1)
254+
@test MOI.objective_expr(evaluator) == :(x[$x]^2.0 + 1.0)
255255
return
256256
end
257257

@@ -263,7 +263,7 @@ function test_set_objective_subexpression()
263263
Nonlinear.set_objective(model, :($expr^2))
264264
evaluator = Nonlinear.Evaluator(model)
265265
MOI.initialize(evaluator, [:ExprGraph])
266-
@test MOI.objective_expr(evaluator) == :((x[$x]^2 + 1)^2)
266+
@test MOI.objective_expr(evaluator) == :((x[$x]^2.0 + 1.0)^2.0)
267267
return
268268
end
269269

@@ -276,7 +276,7 @@ function test_set_objective_nested_subexpression()
276276
Nonlinear.set_objective(model, :($expr_2^2))
277277
evaluator = Nonlinear.Evaluator(model)
278278
MOI.initialize(evaluator, [:ExprGraph])
279-
@test MOI.objective_expr(evaluator) == :(((x[$x]^2 + 1)^2)^2)
279+
@test MOI.objective_expr(evaluator) == :(((x[$x]^2.0 + 1.0)^2.0)^2.0)
280280
return
281281
end
282282

@@ -287,7 +287,7 @@ function test_set_objective_parameter()
287287
Nonlinear.set_objective(model, :($x^2 + $p))
288288
evaluator = Nonlinear.Evaluator(model)
289289
MOI.initialize(evaluator, [:ExprGraph])
290-
@test MOI.objective_expr(evaluator) == :(x[$x]^2 + 1.2)
290+
@test MOI.objective_expr(evaluator) == :(x[$x]^2.0 + 1.2)
291291
return
292292
end
293293

@@ -300,7 +300,7 @@ function test_add_constraint_less_than()
300300
@test model[c].set == set
301301
evaluator = Nonlinear.Evaluator(model)
302302
MOI.initialize(evaluator, [:ExprGraph])
303-
@test MOI.constraint_expr(evaluator, 1) == :(x[$x]^2 + 1 <= 1.0)
303+
@test MOI.constraint_expr(evaluator, 1) == :(x[$x]^2.0 + 1.0 <= 1.0)
304304
return
305305
end
306306

@@ -311,7 +311,7 @@ function test_add_constraint_delete()
311311
_ = Nonlinear.add_constraint(model, :(sqrt($x)), MOI.LessThan(1.0))
312312
evaluator = Nonlinear.Evaluator(model)
313313
MOI.initialize(evaluator, [:ExprGraph])
314-
@test MOI.constraint_expr(evaluator, 1) == :(x[$x]^2 + 1 <= 1.0)
314+
@test MOI.constraint_expr(evaluator, 1) == :(x[$x]^2.0 + 1.0 <= 1.0)
315315
@test MOI.constraint_expr(evaluator, 2) == :(sqrt(x[$x]) <= 1.0)
316316
Nonlinear.delete(model, c1)
317317
evaluator = Nonlinear.Evaluator(model)
@@ -330,7 +330,7 @@ function test_add_constraint_greater_than()
330330
@test model[c].set == set
331331
evaluator = Nonlinear.Evaluator(model)
332332
MOI.initialize(evaluator, [:ExprGraph])
333-
@test MOI.constraint_expr(evaluator, 1) == :(x[$x]^2 + 1 >= 1.0)
333+
@test MOI.constraint_expr(evaluator, 1) == :(x[$x]^2.0 + 1.0 >= 1.0)
334334
return
335335
end
336336

@@ -342,7 +342,7 @@ function test_add_constraint_equal_to()
342342
@test model[c].set == set
343343
evaluator = Nonlinear.Evaluator(model)
344344
MOI.initialize(evaluator, [:ExprGraph])
345-
@test MOI.constraint_expr(evaluator, 1) == :(x[$x]^2 + 1 == 1.0)
345+
@test MOI.constraint_expr(evaluator, 1) == :(x[$x]^2.0 + 1.0 == 1.0)
346346
return
347347
end
348348

@@ -354,7 +354,7 @@ function test_add_constraint_interval()
354354
@test model[c].set == set
355355
evaluator = Nonlinear.Evaluator(model)
356356
MOI.initialize(evaluator, [:ExprGraph])
357-
@test MOI.constraint_expr(evaluator, 1) == :(-1.0 <= x[$x]^2 + 1 <= 1.0)
357+
@test MOI.constraint_expr(evaluator, 1) == :(-1.0 <= x[$x]^2.0 + 1.0 <= 1.0)
358358
return
359359
end
360360

0 commit comments

Comments
 (0)