@@ -417,46 +417,52 @@ sys = modelingtoolkitize(prob)
417
417
@test is_parameter (sys, :q )
418
418
end
419
419
420
- @variables x (t)= 1.0 y (t)= 2.0
421
- @parameters p= 3.0 q= 4.0
422
- @mtkbuild sys = ODESystem ([D (x) ~ p * y, D (y) ~ q * x], t)
423
- prob1 = ODEProblem (sys, [], (0.0 , 5.0 ))
424
- newsys = modelingtoolkitize (prob1)
425
- @test is_variable (newsys, newsys. x)
426
- @test is_variable (newsys, newsys. y)
427
- @test is_parameter (newsys, newsys. p)
428
- @test is_parameter (newsys, newsys. q)
429
- prob2 = ODEProblem (newsys, [], (0.0 , 5.0 ))
430
-
431
- sol1 = solve (prob1, Tsit5 ())
432
- sol2 = solve (prob2, Tsit5 ())
433
- @test sol1 ≈ sol2
434
-
435
- @variables x= 1.0 y= 2.0
436
- @mtkbuild nlsys = NonlinearSystem ([0 ~ p * y^ 2 + x, 0 ~ y + x * q])
437
- prob1 = NonlinearProblem (nlsys, [])
438
- newsys = modelingtoolkitize (prob1)
439
- @test is_variable (newsys, newsys. x)
440
- @test is_variable (newsys, newsys. y)
441
- @test is_parameter (newsys, newsys. p)
442
- @test is_parameter (newsys, newsys. q)
443
- prob2 = NonlinearProblem (newsys, [])
444
-
445
- sol1 = solve (prob1)
446
- sol2 = solve (prob2)
447
- @test sol1 ≈ sol2
448
-
449
- @mtkbuild optsys = OptimizationSystem ((x - p)^ 3 + y^ 2 - q)
450
- prob1 = OptimizationProblem (optsys, [])
451
- newsys = modelingtoolkitize (prob1)
452
- @test is_variable (newsys, newsys. x)
453
- @test is_variable (newsys, newsys. y)
454
- @test is_parameter (newsys, newsys. p)
455
- @test is_parameter (newsys, newsys. q)
456
- prob2 = OptimizationProblem (newsys, [])
457
-
458
- sol1 = solve (prob1, LBFGS ())
459
- sol2 = solve (prob2, LBFGS ())
460
-
461
- @test sol1 ≈ sol2
420
+ @testset " From MTK model" begin
421
+ @testset " ODE" begin
422
+ @variables x (t)= 1.0 y (t)= 2.0
423
+ @parameters p= 3.0 q= 4.0
424
+ @mtkbuild sys = ODESystem ([D (x) ~ p * y, D (y) ~ q * x], t)
425
+ prob1 = ODEProblem (sys, [], (0.0 , 5.0 ))
426
+ newsys = complete (modelingtoolkitize (prob1))
427
+ @test is_variable (newsys, newsys. x)
428
+ @test is_variable (newsys, newsys. y)
429
+ @test is_parameter (newsys, newsys. p)
430
+ @test is_parameter (newsys, newsys. q)
431
+ prob2 = ODEProblem (newsys, [], (0.0 , 5.0 ))
432
+
433
+ sol1 = solve (prob1, Tsit5 ())
434
+ sol2 = solve (prob2, Tsit5 ())
435
+ @test sol1 ≈ sol2
436
+ end
437
+ @testset " Nonlinear" begin
438
+ @variables x= 1.0 y= 2.0
439
+ @mtkbuild nlsys = NonlinearSystem ([0 ~ p * y^ 2 + x, 0 ~ y + x * q])
440
+ prob1 = NonlinearProblem (nlsys, [])
441
+ newsys = complete (modelingtoolkitize (prob1))
442
+ @test is_variable (newsys, newsys. x)
443
+ @test is_variable (newsys, newsys. y)
444
+ @test is_parameter (newsys, newsys. p)
445
+ @test is_parameter (newsys, newsys. q)
446
+ prob2 = NonlinearProblem (newsys, [])
447
+
448
+ sol1 = solve (prob1)
449
+ sol2 = solve (prob2)
450
+ @test sol1 ≈ sol2
451
+ end
452
+ @testset " Optimization" begin
453
+ @mtkbuild optsys = OptimizationSystem ((x - p)^ 3 + y^ 2 - q)
454
+ prob1 = OptimizationProblem (optsys, [])
455
+ newsys = complete (modelingtoolkitize (prob1))
456
+ @test is_variable (newsys, newsys. x)
457
+ @test is_variable (newsys, newsys. y)
458
+ @test is_parameter (newsys, newsys. p)
459
+ @test is_parameter (newsys, newsys. q)
460
+ prob2 = OptimizationProblem (newsys, [])
461
+
462
+ sol1 = solve (prob1, LBFGS ())
463
+ sol2 = solve (prob2, LBFGS ())
464
+
465
+ @test sol1 ≈ sol2
466
+ end
467
+ end
462
468
end
0 commit comments