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

Dualspace update #2294

Merged
merged 180 commits into from
Sep 21, 2023
Merged

Dualspace update #2294

merged 180 commits into from
Sep 21, 2023

Conversation

nbouziani
Copy link
Contributor

@nbouziani nbouziani commented Dec 6, 2021

This PR contains the full dual space implementation. It builds on top of #2034, which introduced dual function spaces, the Cofunction and AssembledMatrix classes, as well as the DAG-based assembly of BaseForm objects.

Main components of this PR:

  • Fix all the tests
  • Extend the dual space implementation to work with pyadjoint
  • Add Coargument
  • Add assembly preprocessing stage (mostly to expand derivatives of the BaseForm being assembled)
  • Add support to solve PDEs with a Cofunction in the rhs (fully annotated operation -> pyadjoint-friendly)
  • Extend assembly of Action and FormSum
  • Equip Cofunctions with assign and augmented assignments
  • Expunge the use of Vector as the default type for adjoint/tlm/hessian values
  • Add riesz_representation to map from Cofunctions to Functions and vice-versa
  • Address implications of recent UFL changes (e.g. Cofunctions and Coarguments now respectively have 1 and 2 arguments)

The associated pyadjoint PR, which simply updates tests, can be found at dolfin-adjoint/pyadjoint#70

@nbouziani nbouziani changed the base branch from dualspace to master September 19, 2023 15:47
firedrake/cofunction.py Outdated Show resolved Hide resolved
Copy link
Member

@dham dham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix cofunction.copy
don't introduce vectors. Introduce dats instead.

firedrake/cofunction.py Outdated Show resolved Hide resolved
firedrake/cofunction.py Outdated Show resolved Hide resolved
@nbouziani
Copy link
Contributor Author

This is ready to go once UFL upstream is merged.

@@ -139,7 +137,7 @@ def evaluate_tlm_component(self, inputs, tlm_inputs, block_variable, idx,
dudmi.assign(ufl.algorithms.expand_derivatives(
ufl.derivative(expr, dep.saved_output,
dep.tlm_value)))
dudm.vector().axpy(1.0, dudmi.vector())
dudm.dat += 1.0 * dudmi.dat
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never seen direct operations on a PyOP2.dat like this before. @connorjward is it the right thing to be doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is exactly what Vector.axpy used to do. We are just lifting the code to not rely on Vector.

@@ -109,14 +107,14 @@ def _adj_assign_constant(self, adj_output, constant_fs):
shape = r.ufl_shape
if shape == () or shape[0] == 1:
# Scalar Constant
r.vector()[:] = adj_output.vector().sum()
r.dat.data[:] = adj_output.dat.data_ro.sum()
Copy link
Contributor

@ReubenHill ReubenHill Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicking, but this I think should be r.dat.data_wo[:]

Copy link
Contributor

@ReubenHill ReubenHill Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
r.dat.data[:] = adj_output.dat.data_ro.sum()
r.dat.data_wo[:] = adj_output.dat.data_ro.sum()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are modifying the value of r so why should we use dat.data_ro ? .dat.data needs to be used whenever you change the value of the .dat, right ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the confusion, I meant to say dat.data_wo and hastily edited the comment after making it but clearly it didn't make it to you in time! I think dat.data_wo is correct here since you don't read the value

Copy link
Contributor Author

@nbouziani nbouziani Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, Dat.data_wo is the same as Dat.data (see https://github.com/OP2/PyOP2/blame/master/pyop2/types/dat.py#L223). Also, we use Dat.data when changing the value of the Dat all over the code so I don't think that is a problem.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I know we've been trying to move towards using the correct access descriptors wherever we ought to. Whether or not the implementation is different @connorjward can comment on. It's just a small change but I think it's a correct one. If you're really not convinced then let @connorjward weigh in

@dham dham merged commit 3676bab into master Sep 21, 2023
10 checks passed
@dham dham deleted the dualspace_update branch September 21, 2023 16:36
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

Successfully merging this pull request may close these issues.

6 participants