mesh-adaptation / goalie

Goal-oriented error estimation and mesh adaptation for finite element problems solved using Firedrake
Other
1 stars 1 forks source link

Fix issues related to updated adjoint #62

Closed jwallwork23 closed 10 months ago

jwallwork23 commented 11 months ago

Closes #61.

Recent updates to Firedrake have introduced various issues. The main ones are that:

The temporary fix for the second issue suggested here is just to map Cofunction data into Functions. We should handle Cofunctions and dual spaces properly in the future, though.

Note that the firedrake-parmmg docker image will need to be updated before the CI will give useful output on this PR.

jwallwork23 commented 11 months ago

@ddundo here is a fix! I had to use a custom Pyadjoint branch (see the latest commits). With that and the changes in this PR, all tests passed locally for me :)

Tomorrow I will find a minimum failing example for this and open an issue to Firedrake.

jwallwork23 commented 11 months ago

Note that the Docker image has been updated. It uses the jwallwork23/parmmg-rebased PETSc branch, but Firedrake master.

ddundo commented 11 months ago

Thanks a lot @jwallwork23 ! All demos pass now as well, apart from burgers_time_integrated.py (AttributeError: 'Cofunction' object has no attribute '_ufl_class_'). I can post the whole traceback if you don't get this.

But now in my glacier experiments I again get the same error as I posted in #61 - the one with the long Traceback that ends with

File "/home/ubuntu/software/firedrake-sep23/src/PyOP2/pyop2/local_kernel.py", line 144, in arguments
    assert len(self.accesses) == len(self.dtypes)

Do you have an idea of what this could be please?

jwallwork23 commented 11 months ago

I'm not certain, but I think it fails because you are trying to interpolate a Cofunction onto a Function (or vice versa). Please could you print the type of the two things being interpolated just before it happens?

ddundo commented 11 months ago

Thanks Joe, but sorry - I'm quite lost in the traceback! Could you please tell me what variables exactly you'd like me to print?

jwallwork23 commented 11 months ago

Does your program include a call to interpolate? If so, please can you print out the types of the source and target just before the interpolation? I expect that one will be a Cofunction and the other will be a Function.

jwallwork23 commented 11 months ago

Oh actually, you might need to print somewhere in the adjoint code. Perhaps print what goes into line 335 of /home/ubuntu/software/firedrake-sep23/src/firedrake/firedrake/adjoint_utils/blocks/function.py.

ddundo commented 11 months ago

Thanks! It fails in the adjoint code, yup.

Here return self.backend.Interpolator(dJdm, self.V).interpolate(adj_inputs[0], output=output, transpose=True), it actually fails at this part self.backend.Interpolator(dJdm, self.V) and not at the call to interpolate. The types are type(dJdm) == <class 'ufl.differentiation.CoefficientDerivative'> and type(self.V) == <class 'firedrake.functionspaceimpl.WithGeometry'>

jwallwork23 commented 11 months ago

What code are you testing this on? Are you able to share it? If not, do you have a minimal failing example that I could do some debugging on?

ddundo commented 11 months ago

Sorry, I just saw this now! I emailed you the code :)