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

[LFRic] [PSyAD] Integer assignments related to active variables are in wrong order in adjoint #2764

Open
DrTVockerodtMO opened this issue Nov 5, 2024 · 5 comments

Comments

@DrTVockerodtMO
Copy link
Collaborator

DrTVockerodtMO commented Nov 5, 2024

Suppose we have some forward code of the form

k = 0
call some_function( ... , k )

do k = 1, nlayers – 2
  call some_function( ... , k )
end do

k = nlayers - 1
call some_function( ... , k )

When PSyAD generates the adjoint of this code, the k assignments are treated as passive, so they all precipitate up to the top which yields

k = 0
k = nlayers - 1
call adj_some_function( ... , k )

do k = nlayers - 1, 1, -1
  call adj_some_function( ... , k )
end do

call adj_some_function( ... , k )

When it should be

k = nlayers - 1
call adj_some_function( ... , k )

do k = nlayers - 1, 1, -1
  call adj_some_function( ... , k )
end do

k = 0
call adj_some_function( ... , k )
@DrTVockerodtMO DrTVockerodtMO changed the title [LFRic] [PSyAD] Integer assignments related to active variables in wrong order in adjoint [LFRic] [PSyAD] Integer assignments related to active variables are in wrong order in adjoint Nov 5, 2024
@arporter
Copy link
Member

arporter commented Nov 5, 2024

Thanks for reporting this Terry. @LonelyCat124 will the new DA you're working on enable us to look backwards and find the earliest point to which we could move the assignment k = 0 in this example?

@LonelyCat124
Copy link
Collaborator

It would be able to find the previous dependency to k (which in this case would either be the loop or the call inside the loop, maybe both) I think but you'd then have to do something with that information.

@arporter
Copy link
Member

arporter commented Nov 5, 2024

It would be able to find the previous dependency to k (which in this case would either be the loop or the call inside the loop, maybe both) I think but you'd then have to do something with that information.

Great - it was only the information I was after. We'd just have to modify the current code that moves the assignment all the way to the top.

@arporter
Copy link
Member

arporter commented Nov 5, 2024

I have a question for @DrTVockerodtMO: I thought we didn't support constructing the adjoint of code with Call in it? Is that example code exactly what you're giving PSyAD?

@DrTVockerodtMO
Copy link
Collaborator Author

I have a question for @DrTVockerodtMO: I thought we didn't support constructing the adjoint of code with Call in it? Is that example code exactly what you're giving PSyAD?

This is just a conceptual example, not fed to PSyAD.

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

No branches or pull requests

3 participants