@@ -90,9 +90,35 @@ def minimize_tao_nls(rf):
9090 return solver .solve ()
9191
9292
93+ def minimize_rol (rf ):
94+ problem = MinimizationProblem (rf )
95+ params = {
96+ "General" : {
97+ "Krylov" : {
98+ "Absolute Tolerance" : 1e-5 ,
99+ },
100+ "Secant" : {
101+ "Type" : "Limited-Memory BFGS" ,
102+ "Maximum Storage" : 10 ,
103+ "Use as Hessian" : True ,
104+ },
105+ },
106+ "Step" : {
107+ "Type" : "Trust Region" ,
108+ },
109+ "Status Test" : {
110+ "Relative Gradient Tolerance" : 0.0 ,
111+ "Gradient Tolerance" : 1e-6 ,
112+ },
113+ }
114+ solver = ROLSolver (problem , params , inner_product = "L2" )
115+ return solver .solve ()
116+
117+
93118@pytest .mark .parametrize ("minimize" , [minimize ,
94119 minimize_tao_lmvm ,
95- minimize_tao_nls ])
120+ minimize_tao_nls ,
121+ minimize_rol ])
96122@pytest .mark .skipcomplex
97123def test_optimisation_constant_control (minimize ):
98124 """This tests a list of controls in a minimisation"""
@@ -152,11 +178,12 @@ def test_simple_inversion(riesz_representation):
152178
153179
154180@pytest .mark .parametrize ("minimize" , [minimize_tao_lmvm ,
155- minimize_tao_nls ])
181+ minimize_tao_nls ,
182+ minimize_rol ])
156183@pytest .mark .parametrize ("riesz_representation" , [None , "l2" , "L2" , "H1" ])
157184@pytest .mark .skipcomplex
158- def test_tao_simple_inversion (minimize , riesz_representation ):
159- """Test inversion of source term in helmholtz eqn using TAO ."""
185+ def test_external_simple_inversion (minimize , riesz_representation ):
186+ """Test inversion of source term in helmholtz eqn using external optimisation packages ."""
160187 mesh = UnitIntervalMesh (10 )
161188 V = FunctionSpace (mesh , "CG" , 1 )
162189 source_ref = Function (V )
@@ -368,3 +395,44 @@ def test_tao_bounds():
368395 u_ref_bound = u_ref .copy (deepcopy = True )
369396 u_ref_bound .dat .data [:] = np .maximum (u_ref_bound .dat .data_ro , lb )
370397 assert_allclose (u_opt .dat .data_ro , u_ref_bound .dat .data_ro , rtol = 1.0e-2 )
398+
399+
400+ @pytest .mark .skipcomplex
401+ def test_rol_bounds ():
402+ mesh = UnitIntervalMesh (11 )
403+ X = SpatialCoordinate (mesh )
404+ space = FunctionSpace (mesh , "Lagrange" , 1 )
405+ u = Function (space , name = "u" )
406+ u_ref = Function (space , name = "u_ref" ).interpolate (0.5 - X [0 ])
407+
408+ J = assemble ((u - u_ref ) ** 2 * dx )
409+ rf = ReducedFunctional (J , Control (u ))
410+
411+ lb = 0.5 - 7.0 / 11.0
412+ ub = 10.0 # ROL doesn't support None as bounds
413+ problem = MinimizationProblem (rf , bounds = (lb , ub ))
414+ params = {
415+ "General" : {
416+ "Krylov" : {
417+ "Absolute Tolerance" : 1e-7 ,
418+ },
419+ "Secant" : {
420+ "Type" : "Limited-Memory BFGS" ,
421+ "Maximum Storage" : 10 ,
422+ "Use as Hessian" : True ,
423+ },
424+ },
425+ "Step" : {
426+ "Type" : "Trust Region" ,
427+ },
428+ "Status Test" : {
429+ "Relative Gradient Tolerance" : 0.0 ,
430+ "Gradient Tolerance" : 0.0 ,
431+ },
432+ }
433+ solver = ROLSolver (problem , params , inner_product = "L2" )
434+ u_opt = solver .solve ()
435+
436+ u_ref_bound = u_ref .copy (deepcopy = True )
437+ u_ref_bound .dat .data [:] = np .maximum (u_ref_bound .dat .data_ro , lb )
438+ assert_allclose (u_opt .dat .data_ro , u_ref_bound .dat .data_ro , rtol = 1.0e-2 )
0 commit comments