Skip to content

Commit 57c3f4d

Browse files
fixup! test: add extensive modelingtoolkitize tests
1 parent 1a83c92 commit 57c3f4d

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

test/modelingtoolkitize.jl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,8 @@ sys = modelingtoolkitize(prob)
436436
end
437437
@testset "Nonlinear" begin
438438
@variables x=1.0 y=2.0
439-
@mtkbuild nlsys = NonlinearSystem([0 ~ p * y^2 + x, 0 ~ y + x * q])
439+
@parameters p=3.0 q=4.0
440+
@mtkbuild nlsys = NonlinearSystem([0 ~ p * y^2 + x, 0 ~ x + exp(x) * q])
440441
prob1 = NonlinearProblem(nlsys, [])
441442
newsys = complete(modelingtoolkitize(prob1))
442443
@test is_variable(newsys, newsys.x)
@@ -450,17 +451,23 @@ sys = modelingtoolkitize(prob)
450451
@test sol1 sol2
451452
end
452453
@testset "Optimization" begin
453-
@mtkbuild optsys = OptimizationSystem((x - p)^3 + y^2 - q)
454-
prob1 = OptimizationProblem(optsys, [])
454+
@variables begin
455+
x = 1.0, [bounds = (-2.0, 10.0)]
456+
y = 2.0, [bounds = (-1.0, 10.0)]
457+
end
458+
@parameters p=3.0 q=4.0
459+
loss = (p - x)^2 + q * (y - x^2)^2
460+
@mtkbuild optsys = OptimizationSystem(loss, [x, y], [p, q])
461+
prob1 = OptimizationProblem(optsys, [], grad=true, hess=true)
455462
newsys = complete(modelingtoolkitize(prob1))
456463
@test is_variable(newsys, newsys.x)
457464
@test is_variable(newsys, newsys.y)
458465
@test is_parameter(newsys, newsys.p)
459466
@test is_parameter(newsys, newsys.q)
460-
prob2 = OptimizationProblem(newsys, [])
467+
prob2 = OptimizationProblem(newsys, [], grad=true, hess=true)
461468

462-
sol1 = solve(prob1, LBFGS())
463-
sol2 = solve(prob2, LBFGS())
469+
sol1 = solve(prob1, GradientDescent())
470+
sol2 = solve(prob2, GradientDescent())
464471

465472
@test sol1 sol2
466473
end

0 commit comments

Comments
 (0)