Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies = [
"petsctools",
"pkgconfig",
"progress",
"pyadjoint-ad>=2025.10.0",
"pyadjoint-ad @ git+https://github.com/dolfin-adjoint/pyadjoint.git@master",
"pycparser",
"pytools[siphash]",
"requests",
Expand Down Expand Up @@ -111,6 +111,7 @@ ci = [
"pdf2image",
"pygraphviz",
"pylit",
"pyroltrilinos",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to enable pip install firedrake[pyrol] by adding another dependency group. If so we also add a little bit of info here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this resolved?

"pytest",
"pytest-split", # needed for firedrake-run-split-tests
"pytest-timeout",
Expand Down
76 changes: 72 additions & 4 deletions tests/firedrake/adjoint/test_optimisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,35 @@ def minimize_tao_nls(rf):
return solver.solve()


def minimize_rol(rf):
problem = MinimizationProblem(rf)
params = {
"General": {
"Krylov": {
"Absolute Tolerance": 1e-5,
},
"Secant": {
"Type": "Limited-Memory BFGS",
"Maximum Storage": 10,
"Use as Hessian": True,
},
},
"Step": {
"Type": "Trust Region",
},
"Status Test": {
"Relative Gradient Tolerance": 0.0,
"Gradient Tolerance": 1e-6,
},
}
solver = ROLSolver(problem, params, inner_product="L2")
return solver.solve()


@pytest.mark.parametrize("minimize", [minimize,
minimize_tao_lmvm,
minimize_tao_nls])
minimize_tao_nls,
minimize_rol])
@pytest.mark.skipcomplex
def test_optimisation_constant_control(minimize):
"""This tests a list of controls in a minimisation"""
Expand Down Expand Up @@ -152,11 +178,12 @@ def test_simple_inversion(riesz_representation):


@pytest.mark.parametrize("minimize", [minimize_tao_lmvm,
minimize_tao_nls])
minimize_tao_nls,
minimize_rol])
@pytest.mark.parametrize("riesz_representation", [None, "l2", "L2", "H1"])
@pytest.mark.skipcomplex
def test_tao_simple_inversion(minimize, riesz_representation):
"""Test inversion of source term in helmholtz eqn using TAO."""
def test_external_simple_inversion(minimize, riesz_representation):
"""Test inversion of source term in helmholtz eqn using external optimisation packages."""
mesh = UnitIntervalMesh(10)
V = FunctionSpace(mesh, "CG", 1)
source_ref = Function(V)
Expand Down Expand Up @@ -368,3 +395,44 @@ def test_tao_bounds():
u_ref_bound = u_ref.copy(deepcopy=True)
u_ref_bound.dat.data[:] = np.maximum(u_ref_bound.dat.data_ro, lb)
assert_allclose(u_opt.dat.data_ro, u_ref_bound.dat.data_ro, rtol=1.0e-2)


@pytest.mark.skipcomplex
def test_rol_bounds():
mesh = UnitIntervalMesh(11)
X = SpatialCoordinate(mesh)
space = FunctionSpace(mesh, "Lagrange", 1)
u = Function(space, name="u")
u_ref = Function(space, name="u_ref").interpolate(0.5 - X[0])

J = assemble((u - u_ref) ** 2 * dx)
rf = ReducedFunctional(J, Control(u))

lb = 0.5 - 7.0 / 11.0
ub = 10.0 # ROL doesn't support None as bounds
problem = MinimizationProblem(rf, bounds=(lb, ub))
params = {
"General": {
"Krylov": {
"Absolute Tolerance": 1e-7,
},
"Secant": {
"Type": "Limited-Memory BFGS",
"Maximum Storage": 10,
"Use as Hessian": True,
},
},
"Step": {
"Type": "Trust Region",
},
"Status Test": {
"Relative Gradient Tolerance": 0.0,
"Gradient Tolerance": 0.0,
},
}
solver = ROLSolver(problem, params, inner_product="L2")
u_opt = solver.solve()

u_ref_bound = u_ref.copy(deepcopy=True)
u_ref_bound.dat.data[:] = np.maximum(u_ref_bound.dat.data_ro, lb)
assert_allclose(u_opt.dat.data_ro, u_ref_bound.dat.data_ro, rtol=1.0e-2)
Loading