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

Adjoint models #107

Open
RPrudden opened this issue Jul 19, 2019 · 7 comments
Open

Adjoint models #107

RPrudden opened this issue Jul 19, 2019 · 7 comments

Comments

@RPrudden
Copy link

Has anyone given any thought to calculating the adjoints of CliMT models? As far as I can tell there is no easy way to do this, but I'd be delighted to be wrong.

@mcgibbon
Copy link
Member

I don't know much about adjoints, but if calculating an adjoint can be done by computing the outputs of sympl components with slight perturbations to the inputs about some reference state, then I would say there should be an easy way to do it, but there isn't an existing way to do it. I don't know that anyone has done this before, maybe @JoyMonteiro has some insight. I think the result would make a neat Python package!

@JoyMonteiro
Copy link
Member

@RPrudden you are correct that this is a non-trivial task. A lot of code in climt is in Fortran, and
there aren't really any good free tools (that I know of) that can do automatic differentiation (AD) of Fortran code.

Even if we did get our hands on code like this, ADs have a hard time dealing with model physics because of strong nonlinearities present in the atmosphere in the presence of clouds and water vapour. See this paper for example.

While it would certainly be interesting to see adjoint models for climt components, it is not on my priority list currently.

If you are interested, I think the dynamical core would be a good target to develop an adjoint for.
The core dynamics is contained in a few files that make it quite amenable for such an effort.

@RPrudden
Copy link
Author

Many thanks, both! I think computing the adjoint of the dynamical core would be enough to cover the kind of work I have in mind, so I may be able to avoid the difficulties involved in differentiating the physics components.

In terms of the dynamical core, it looks like this directory would be the place to start. I guess you were thinking to use autograd to compute the gradients, is that right?

@JoyMonteiro
Copy link
Member

That directory only contains the wrapper. The actual algorithmic part is written in Fortran and resides
here

The easiest way I would think is to translate the relevant parts to python code and then run autograd on it. There are only two core functions:

which does the actual time stepping and

which calculates the tendencies used by the timestepper. Each will need some helper functions,
but these are your entry points to the code.

There is a subtle issue to keep in mind -- There are parts of the code which do differentiation themselves, calling the shtns library. These will have to be translated by hand to calls to differentiation by shtns (there is a python wrapper to shtns, so not a big issue there).

I think it is doable, but requires some grunt work!

@RPrudden
Copy link
Author

Ok, I understand better now. As you say, it looks fairly intensive to translate.. but I am quite interested, so I might try to carve out some time.

@JoyMonteiro
Copy link
Member

Great!! We can keep this issue open in case you need any other input. While I can't contribute to the coding effort itself, I can certainly take a look at any code or help you to navigate the fortran code.
It would be really cool if this works out :)

@JoyMonteiro
Copy link
Member

A bit of googling around yielded a AD package for Fortran:
http://www-sop.inria.fr/tropics/tapenade.html
which seems to be actively developed.

They seem to have used it for an ocean model (NEMO).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants