PSyclone icon indicating copy to clipboard operation
PSyclone copied to clipboard

modify Adjoint metadata

Open rupertford opened this issue 2 years ago • 1 comments

Metadata names and access patterns may need to be updated when transforming from tangent-linear metadata to adjoint metadata. When dealing with stencil codes further modications may be required. At the moment this is not easily done as the PSyIR captures the metadata as an UnknownFortranType. Work is ongoing to provide a PSyIR interface to the metadata. Once this is done the metadata can be updated.

rupertford avatar Jun 24 '22 15:06 rupertford

This also includes the interface name for mixed precision kernels as the interface name is essentially metadata information.

rupertford avatar Aug 03 '22 13:08 rupertford

Now that the LFRic kernel metadata PR is on master we can start working on this issue. There are a number of potential other hurdles to jump so this may need to be done in a few steps. I am thinking of 1) how to determine the metadata associated with an active variable and 2) modifying mixed precision interfaces.

rupertford avatar Dec 05 '22 09:12 rupertford

Created branch 1772_adjoint_metadata

rupertford avatar Dec 05 '22 09:12 rupertford

The first step will be to check that the raising and lowering of LFRic kernels works with PSyAD kernels as this has not been tested on LFRic kernels yet.

rupertford avatar Dec 05 '22 09:12 rupertford

The raising doesn't work yet because of #928 (I hit this in #1892 and ended up leaving TODOs).

arporter avatar Dec 05 '22 09:12 arporter

The raising doesn't work yet because of #928 (I hit this in #1892 and ended up leaving TODOs).

I'm going to use the metadata raising which has not yet been merged with the kernel code raising so won't be using that. However, shouldn't it be OK anyway, as the raising itself should not do any validation (I would hope)?

rupertford avatar Dec 05 '22 10:12 rupertford

I think I must be misunderstanding something: in order to raise we use the LFRic kernel psyir which isn't yet complete and thus raises NotImplementedErrors. Anyway, if you're not using it then it will be fine :-)

arporter avatar Dec 05 '22 11:12 arporter

I'm using the recently-added-to-master RaisePSyIR2LFRicKernTrans which only raises the metadata.

rupertford avatar Dec 05 '22 11:12 rupertford

Creating a new branch which will modify the adjoint metadata appropriately. This branch will create a new ArgOrdering class which uses the new metadata to call methods representing arguments in the order in which they are expected to be found in the psy-layer, kernel-layer etc. This will then be used to create a mapping from a metadata argument index to a kernel argument index.

rupertford avatar Jan 27 '23 22:01 rupertford

Creating a new branch which will modify the adjoint metadata appropriately. This branch will create a new ArgOrdering class which uses the new metadata to call methods representing arguments in the order in which they are expected to be found in the psy-layer, kernel-layer etc. This will then be used to create a mapping from a metadata argument index to a kernel argument index.

Just a quick comment that I have a PR under review that modifies ArgOrdering (#1975) , and I think there is another minor change/bugfix in a later PR as well.

hiker avatar Jan 29 '23 01:01 hiker

Related to this, there are cases (e.g. tl_rhs_sample_eos_kernel_mod.F90) where the modified meta-data requires that the interface to the kernel be updated too. e.g. a function space associated with a field that was previously read-only but is now written and is also associated with quadrature. In this case we gain extra ndf and mapping arguments.

arporter avatar Jan 30 '23 11:01 arporter

Thanks for the heads up @hiker. As this is a new base class, I can develop it independently and happily introduce my ownr bugs :-). When we start working on integrating the new metadata parsing with LFRic code generation we will need to replace the existing base class with this one.

rupertford avatar Jan 31 '23 17:01 rupertford

That's a good point @arporter. The same is true for code with stencils. That would be a subsequent PR I think, but I'm not sure whether the Met Office's suggesting funding regime would give us effort to fix things like this - as they just want us to do 'maintenance', unless things have changed in my absence?

rupertford avatar Jan 31 '23 17:01 rupertford

No, I don't think it will give us effort to do this.

arporter avatar Jan 31 '23 20:01 arporter

Just updated to use the new ArgIndexToMetadataIndex class to check this works OK, which it does (for the test case). Full implementation, tidying etc will be done once the new adjoint funding is in place.

rupertford avatar Apr 07 '23 00:04 rupertford