@@ -436,7 +436,8 @@ sys = modelingtoolkitize(prob)
436
436
end
437
437
@testset " Nonlinear" begin
438
438
@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])
440
441
prob1 = NonlinearProblem (nlsys, [])
441
442
newsys = complete (modelingtoolkitize (prob1))
442
443
@test is_variable (newsys, newsys. x)
@@ -450,17 +451,23 @@ sys = modelingtoolkitize(prob)
450
451
@test sol1 ≈ sol2
451
452
end
452
453
@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 )
455
462
newsys = complete (modelingtoolkitize (prob1))
456
463
@test is_variable (newsys, newsys. x)
457
464
@test is_variable (newsys, newsys. y)
458
465
@test is_parameter (newsys, newsys. p)
459
466
@test is_parameter (newsys, newsys. q)
460
- prob2 = OptimizationProblem (newsys, [])
467
+ prob2 = OptimizationProblem (newsys, [], grad = true , hess = true )
461
468
462
- sol1 = solve (prob1, LBFGS ())
463
- sol2 = solve (prob2, LBFGS ())
469
+ sol1 = solve (prob1, GradientDescent ())
470
+ sol2 = solve (prob2, GradientDescent ())
464
471
465
472
@test sol1 ≈ sol2
466
473
end
0 commit comments