Skip to content

BUG: Riesz representation default options is not L2 but l2 #3575

Closed
@APaganini

Description

@APaganini

Describe the bug
Pull request #3552 states "Also default to L2 projection.", but the following test seems to contradict it. Update: the error is in line 228 of firedrake/adjoint_utils/function.py, where

riesz_representation = options.get("riesz_representation", "l2")

should be

riesz_representation = options.get("riesz_representation", "L2")

Steps to Reproduce
The code

from firedrake import *
from firedrake.adjoint import *

mesh = UnitSquareMesh(2,2)
V = FunctionSpace(mesh, "CG", 1)
x, y = SpatialCoordinate(mesh)
u_ = Function(V).interpolate(x**2+y)  #target soln
f = Function(V)  # control
u = Function(V)  # state variable
v = TestFunction(V)
F = (u - f)*v*dx  # state constraint

# annotate solve and define reduced functional
continue_annotation()
solve(F == 0, u)
J = assemble((u - u_)**2*dx)
Jhat = ReducedFunctional(J, Control(f))
pause_annotation()

print("riesz_representation: default")
dJ = Jhat.derivative()
with dJ.dat.vec_ro as dJ: 
    print(dJ.array)
for RR in [None, "l2", "L2", "H1"]:
    print("riesz_representation: ", RR) 
    dJ = Jhat.derivative(options={"riesz_representation": RR})
    with dJ.dat.vec_ro as dJ: 
        print(dJ.array)

outputs

riesz_representation: default
[-0.015625   -0.125      -0.10416667 -0.41666667 -0.15104167 -0.15104167
 -0.33333333 -0.3125     -0.140625  ]
riesz_representation:  None
[-0.015625   -0.125      -0.10416667 -0.41666667 -0.15104167 -0.15104167
 -0.33333333 -0.3125     -0.140625  ]
riesz_representation:  l2
[-0.015625   -0.125      -0.10416667 -0.41666667 -0.15104167 -0.15104167
 -0.33333333 -0.3125     -0.140625  ]
riesz_representation:  L2
[ 1.36160696e-16 -1.00000000e+00 -5.00000000e-01 -1.50000000e+00
 -2.00000000e+00 -2.00000000e+00 -3.00000000e+00 -2.50000000e+00
 -4.00000000e+00]
riesz_representation:  H1
[-1.61414565 -1.67197729 -1.66177321 -1.74489796 -1.75510204 -1.75510204
 -1.83822679 -1.82802271 -1.89605844]

Expected behavior
I would expect the default to be like L2, not l2.

Environment:

  • Output of firedrake-status
Firedrake Configuration:
   package_manager: True
   minimal_petsc: False
   mpicc: None
   mpicxx: None
   mpif90: None
   mpiexec: None
   disable_ssh: True
   honour_petsc_dir: False
   with_parmetis: False
   slepc: False
   packages: []
   honour_pythonpath: False
   opencascade: False
   tinyasm: False
   torch: False
   petsc_int_type: int32
   cache_dir: /Users/admp1/Documents/FIREDRAKE/firedrake/.cache
   complex: False
   remove_build_files: False
   with_blas: download
   netgen: False
Additions:
   None
Environment:
   PYTHONPATH: None
   PETSC_ARCH: None
   PETSC_DIR: None
Status of components:
---------------------------------------------------------------------------
|Package             |Branch                        |Revision  |Modified  |
---------------------------------------------------------------------------
|FInAT               |master                        |f352325   |False     |
|PyOP2               |master                        |7bef38fa  |False     |
|fiat                |master                        |d0bea63   |False     |
|firedrake           |master                        |149f8fda6 |False     |
|h5py                |firedrake                     |6b512e5e  |False     |
|libsupermesh        |master                        |84becef   |False     |
|loopy               |main                          |967461ba  |False     |
|petsc               |firedrake                     |272f13d92c7|False     |
|pyadjoint           |master                        |908b636   |False     |
|pytest-mpi          |main                          |f2566a1   |False     |
|tsfc                |master                        |021589c   |False     |
|ufl                 |master                        |fbd288e6  |False     |
---------------------------------------------------------------------------

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions