Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues related to updated adjoint #62

Closed
wants to merge 16 commits into from
Closed

Conversation

jwallwork23
Copy link
Member

@jwallwork23 jwallwork23 commented Sep 28, 2023

Closes #61.

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

  • Imports are handled differently.
  • Cofunction and FunctionSpace.dual() are now used.

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 jwallwork23 added the bug Something isn't working label Sep 28, 2023
@jwallwork23 jwallwork23 added this to the Version 1 milestone Sep 28, 2023
@jwallwork23 jwallwork23 self-assigned this Sep 28, 2023
@jwallwork23 jwallwork23 force-pushed the 61_fix_adjoint branch 2 times, most recently from 8f4ccca to 593d31d Compare September 28, 2023 16:58
@jwallwork23
Copy link
Member Author

@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
Copy link
Member Author

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

@ddundo
Copy link
Member

ddundo commented Sep 28, 2023

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
Copy link
Member Author

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
Copy link
Member

ddundo commented Sep 29, 2023

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
Copy link
Member Author

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
Copy link
Member Author

jwallwork23 commented Sep 29, 2023

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
Copy link
Member

ddundo commented Sep 29, 2023

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
Copy link
Member Author

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
Copy link
Member

ddundo commented Sep 30, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adjoint issues after updating firedrake / leaving pyroteus
2 participants