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
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
180 commits
Select commit Hold shift + click to select a range
c8f8ff7
Use dualspace ufl branch in ci
indiamai Apr 21, 2021
0b56ea4
Use dualspace ufl branch in ci
indiamai Apr 21, 2021
576d22f
Merge branch 'dualspace' of https://github.com/firedrakeproject/fired…
indiamai May 5, 2021
6a1ce4e
loose first draft of assemble changes
indiamai May 11, 2021
afa7f6a
further attempts at firedrake cofunction
indiamai May 17, 2021
352a3fe
Assembling Formsum + tests
indiamai May 19, 2021
056946b
Add assembled matrix
indiamai May 21, 2021
50724d3
update assertion in linear solve
indiamai May 21, 2021
bed449e
Basic tests passing, add dual with geometry
indiamai May 24, 2021
febc6bc
Clean up + add matrix-matrix action
indiamai May 26, 2021
5f3b5be
Isolate broken test outside pytest temporarily
indiamai May 26, 2021
88253ce
Fix assemble issue and comment
indiamai Jun 2, 2021
fec4a8a
Lint (finally)
indiamai Jun 2, 2021
c3e1f63
tidying up
indiamai Jun 10, 2021
f0511e9
fixing merge conflicts
colinjcotter Jul 6, 2021
3679674
Use dualspace ufl branch in actions workflow
colinjcotter Jul 6, 2021
0f073f2
fixing lint
colinjcotter Jul 6, 2021
87188ad
Merge master
nbouziani Nov 29, 2021
a04c3c5
Add firedrake.Coargument
nbouziani Nov 30, 2021
b769f44
Remove ABCMeta from MatrixBase
nbouziani Nov 30, 2021
f9229d8
Add UFL branch
nbouziani Nov 30, 2021
1c7c56b
Cleanup
nbouziani Nov 30, 2021
8f71503
Workaround for UFLType
nbouziani Dec 1, 2021
8bdc83f
Fix test_assemble_formbase.py
nbouziani Dec 1, 2021
4bd8412
Fix split for Cofunction
nbouziani Dec 1, 2021
61eb6ef
Fix pyadjoint (chapter 1)
nbouziani Dec 6, 2021
a84b3f6
Update Cofunction assign + add test
nbouziani Dec 7, 2021
82d8557
Fix test_quadrature
nbouziani Dec 7, 2021
9fa651e
Fix syntax for Cofunction
nbouziani Dec 7, 2021
57e7795
Add ConstantValue case in Cofunction.assign
nbouziani Dec 7, 2021
f4f9c61
Fix sub function in solving_utils
nbouziani Dec 9, 2021
53de7c1
Fix few things with pyadjoint
nbouziani Dec 14, 2021
930082e
Fix pyadjoint
nbouziani Dec 14, 2021
86c7943
Fix firedrake tests (chapter 1)
nbouziani Dec 15, 2021
0e70cc9
Update docs.yml
nbouziani Dec 15, 2021
9186f4c
Add node_set to Cofunction
nbouziani Dec 15, 2021
e38f2bd
Merge branch 'dualspace_update' of github.com:firedrakeproject/firedr…
nbouziani Dec 15, 2021
58c42ec
Update docs.yml
nbouziani Dec 15, 2021
44bf5bb
Other attempt to fix docs.yml
nbouziani Dec 15, 2021
3d7f5d6
Fix firedrake tests (chapter 2)
nbouziani Dec 15, 2021
cad1509
Fix firedrake tests (chapter 3)
nbouziani Dec 15, 2021
43cfe2f
Modify AssembledVector
nbouziani Dec 15, 2021
94cc748
Slate: assembled vector data can be a cofunction now.
sv2518 Dec 15, 2021
abb1eaf
Cofunction: introduce cell_node_map function
sv2518 Dec 15, 2021
f833e78
Slate: check fo cofunction not basecoefficient in the coeff map gener…
sv2518 Dec 15, 2021
edbc52f
Expunge UFLType from Firedrake
nbouziani Dec 18, 2021
4a93f46
Fix Interpolate block
nbouziani Dec 23, 2021
cd278c0
Fix notebook 11 by computing the riesz representer of the adjoint
nbouziani Jan 16, 2022
2f2cd66
Merge remote-tracking branch 'origin/master' into dualspace_update
nbouziani Jan 16, 2022
fee731e
Update docs.yml
nbouziani Jan 16, 2022
b7651d9
Docstring whitespace
nbouziani Jan 16, 2022
ada1ce4
Merge remote-tracking branch 'origin/master' into dualspace_update
nbouziani Jan 21, 2022
3f7ed62
Resolve conflicts (merge master)
nbouziani Jul 12, 2022
0f025be
Fix lint
nbouziani Jul 12, 2022
33ea7c4
Fix UFL branch name (dualspace_update got merged)
nbouziani Jul 12, 2022
e4743b8
Clean *.bib files
nbouziani Jul 12, 2022
f3d252b
Merge master
nbouziani Jul 13, 2022
40f29d5
Update assembly doc
nbouziani Jul 15, 2022
7a7b60f
Fix bug in FunctionMergeBlock
nbouziani Jul 15, 2022
08b9ef6
Merge remote-tracking branch 'origin/master' into dualspace
nbouziani Jul 20, 2022
fdb7a25
Merge remote-tracking branch 'origin/master' into dualspace_update
nbouziani Jul 20, 2022
757826a
Merge remote-tracking branch 'origin/master' into dualspace
nbouziani Jul 21, 2022
a51f5a5
Merge dualspace branch
nbouziani Jul 21, 2022
677a717
Add form assembly dispatcher
nbouziani Jul 21, 2022
0760cf5
Fix function space check in _get_map
nbouziani Jul 22, 2022
9002332
Make ImplicitMatrixContext compatible with Cofunction
nbouziani Jul 20, 2022
632e930
Fix few things
nbouziani Jul 22, 2022
b1717d2
Fix failing tests
nbouziani Jul 22, 2022
2a312d1
Update check_pde_args
nbouziani Jul 27, 2022
773efeb
Merge remote-tracking branch 'origin/master' into dualspace_update
nbouziani Jul 27, 2022
7573942
Update assembly of ufl.Matrix's sum
nbouziani Aug 3, 2022
12ad7f9
Fix lint E275
nbouziani Aug 3, 2022
c92ddfa
Overwrite equals for firedrake.Coargument
nbouziani Aug 10, 2022
31be19a
Add support for ZeroBaseForm
nbouziani Aug 14, 2022
2c4d74f
Fix Matrix's arguments
nbouziani Aug 11, 2022
2a8773c
Fix lint
nbouziani Aug 22, 2022
9615a93
Merge remote-tracking branch 'origin/master' into dualspace_update
nbouziani Aug 22, 2022
34adae7
Merge remote-tracking branch 'origin/master' into dualspace_update
nbouziani Oct 21, 2022
22a698f
Merge remote-tracking branch 'origin/master' into dualspace_update
nbouziani Oct 25, 2022
5538081
Merge master
nbouziani Jan 11, 2023
45de28c
Merge master
nbouziani Jan 11, 2023
1807422
Merge master
nbouziani Jan 24, 2023
fdd0016
Remove spurious diff
nbouziani Jan 24, 2023
fda7940
Merge master
nbouziani Jan 24, 2023
09f6b22
Merge dual
nbouziani Jan 24, 2023
f82f748
Merge remote-tracking branch 'origin/master' into dualspace
nbouziani Jan 25, 2023
713f388
Merge remote-tracking branch 'origin/dualspace' into dualspace_update
nbouziani Jan 25, 2023
a47195b
Merge remote-tracking branch 'origin/master' into dualspace_update
nbouziani Jan 26, 2023
26984a0
Establish distinction between public self.comm and internal private s…
nbouziani Jan 26, 2023
3e1ce95
Equip Cofunctions with a Riesz representation method to get the Riesz…
nbouziani Jan 26, 2023
e61b79c
Add conj handler to CoefficientCollector
nbouziani Jan 26, 2023
0bec966
Annotation of 1-forms operates on Cofunction
nbouziani Jan 26, 2023
d3c0ec8
Fix lack of annotations for Riesz representation of Cofunctions
nbouziani Jan 26, 2023
7d3edd1
Remove conj handler in CoefficientCollector
nbouziani Jan 29, 2023
e5f5331
Remove UFL branch
nbouziani Mar 18, 2023
621478c
Merge master
nbouziani Mar 18, 2023
e34af65
Merge master
nbouziani Mar 18, 2023
e90d257
Fix decorator typo
nbouziani Mar 19, 2023
81eccd4
Fix decorator typo
nbouziani Mar 19, 2023
b5ae54e
Merge remote-tracking branch 'origin/dualspace' into dualspace_update
nbouziani Mar 19, 2023
f7604d1
Clean up
nbouziani Mar 19, 2023
8d58ede
Fix doc
nbouziani Mar 19, 2023
61f235a
Fix indent
nbouziani Mar 19, 2023
95d72d0
Merge master
nbouziani May 29, 2023
ef9b314
Merge master
nbouziani May 29, 2023
5d0a9c7
Merge dual
nbouziani May 29, 2023
17434ca
Merge master
nbouziani Jun 18, 2023
ba224b9
Fix domain extractions for parloop's arguments
nbouziani Jun 21, 2023
bffc2f8
Extract domains: check if Constant is the only edge case
nbouziani Jun 22, 2023
b634289
Finish _extract_domains
nbouziani Jun 24, 2023
4afc69f
Address comments
nbouziani Jun 24, 2023
6d510a3
Merge remote-tracking branch 'origin/master' into dualspace_update
nbouziani Jun 24, 2023
43731d7
Merge remote-tracking branch 'origin/master' into dualspace
nbouziani Jun 25, 2023
22a77ee
Wrap extract_unique_domain for Cofunctions
nbouziani Jun 25, 2023
9a4ea31
Merge remote-tracking branch 'origin/dualspace' into dualspace_update
nbouziani Jun 25, 2023
3a8b42b
Fix tests
nbouziani Jun 25, 2023
c901874
Extend action assembly to 1-form against 1-form
nbouziani Jun 25, 2023
e480e7f
Add imul for cofunction + fix pytorch type check
nbouziani Jun 26, 2023
20f115e
Fix some tests
nbouziani Jun 26, 2023
ffa228e
Fix typo
nbouziani Jun 26, 2023
dca4695
Support solve(a == L, u) with L a Cofunction
nbouziani Jun 29, 2023
9e0cdf5
Fix tensor update for base form assembly
nbouziani Jun 29, 2023
d573ffd
Fix some tests
nbouziani Jun 29, 2023
9a62d94
Add fix_dual ufl branch
nbouziani Jun 29, 2023
e561bcd
Fix riesz representation's annotation: solve with a rhs Cofunction
nbouziani Jul 4, 2023
0c543ca
Merge remote-tracking branch 'origin/master' into dualspace_update
nbouziani Jul 6, 2023
88149f6
Extend derivative check to Cofunction
nbouziani Jul 6, 2023
f4dcc54
Add zero-order FormSum assembly
nbouziani Jul 6, 2023
631ed9e
Transmit weight kwarg through base form assembly visitor
nbouziani Jul 6, 2023
680b223
Minor fixes
nbouziani Jul 7, 2023
5b6dc24
FiredrakeTorchOperator: Take the dual output space as the adjoint inp…
nbouziani Jul 13, 2023
b5b8fe9
Extend riesz representation mapping to Function for l2 case
nbouziani Jul 13, 2023
8f8de5b
Notebook 11: Update the way of getting riesz representer
nbouziani Jul 13, 2023
8d18cfd
Merge remote-tracking branch 'origin/master' into dualspace_update
nbouziani Jul 13, 2023
d5ca8e6
Merge remote-tracking branch 'origin/master' into dualspace
nbouziani Jul 14, 2023
921d4a4
Adapt FunctionMixin._ad_mul to cofunctions
nbouziani Jul 14, 2023
a8018b8
Update pointwise division in linear wave equation demo
nbouziani Jul 14, 2023
1ccde41
FiredrakeTorchOperator: Simplify constant adjoint input to sidestep c…
nbouziani Jul 14, 2023
27728ed
Fix Coargument form argument analysis
nbouziani Jul 14, 2023
9bd6c75
Coarguments have one argument in the primal space and one in the dual…
nbouziani Jul 18, 2023
a7d4932
Merge remote-tracking branch 'origin/dualspace' into dualspace_update
nbouziani Jul 18, 2023
2bb9d5b
Merge remote-tracking branch 'origin/JDBetteridge/installation_hotfix…
nbouziani Jul 18, 2023
7c0a721
Merge remote-tracking branch 'origin/master' into dualspace
nbouziani Aug 20, 2023
4cf92f3
Merge dualspace
nbouziani Aug 23, 2023
9728463
Move Pyadjoint dual space changes to Firedrake
nbouziani Aug 23, 2023
6023cee
Fix FunctionMixin import
nbouziani Aug 25, 2023
2cf9863
Update function used to extract unique domain during assembly
nbouziani Aug 26, 2023
7b877d8
Fix TLM of Assemble in spatial coordinate case
nbouziani Sep 5, 2023
a235aa7
Add comment
nbouziani Sep 5, 2023
13d3722
Extend assembly arguments type to ufl.Argument
nbouziani Sep 7, 2023
db31d7e
Merge remote-tracking branch 'origin/master' into dualspace
nbouziani Sep 7, 2023
a42f7fd
Merge remote-tracking branch 'origin/dualspace' into dualspace_update
nbouziani Sep 7, 2023
f57354e
Assemble block: fix ZeroBaseForm output for adjoint of spatialcoordin…
nbouziani Sep 7, 2023
9a0ab79
Lift some fixes from external operator branch
nbouziani Sep 10, 2023
75c2056
Fix a few things
nbouziani Sep 12, 2023
c188c16
mer
nbouziani Sep 12, 2023
436aef0
Strenghten criterion on preprocessing assemble_base_form input
nbouziani Sep 13, 2023
62ebd19
Fix docs test (hopefully)
nbouziani Sep 13, 2023
93e65a2
Fix docs (attempt 2)
nbouziani Sep 13, 2023
07f4628
Update Cofunction's docs
nbouziani Sep 14, 2023
623917b
Expunge Vector from firedrake.adjoint: adjoint/tlm/hessian values are…
nbouziani Sep 18, 2023
8f5da43
Fix WithGeometryBase docs
nbouziani Sep 18, 2023
49f4a13
Add riesz_representation to Function objects to get the corresponding…
nbouziani Sep 18, 2023
e54db96
Merge remote-tracking branch 'origin/master' into dualspace
nbouziani Sep 18, 2023
e3727fa
Merge remote-tracking branch 'origin/dualspace' into dualspace_update
nbouziani Sep 18, 2023
f537eaf
Delete tests/regression/isolated_auxilary.py
nbouziani Sep 19, 2023
7f37ca0
Merge remote-tracking branch 'origin/dualspace' into dualspace_update
nbouziani Sep 19, 2023
c5aff03
Clean up output of 11-extract-adjoint-solutions.ipynb
nbouziani Sep 19, 2023
bcd0185
Clean up
nbouziani Sep 19, 2023
4c0258c
Merge remote-tracking branch 'origin/master' into dualspace_update
nbouziani Sep 19, 2023
5e85161
Don't preprocess slate.TensorBase form
nbouziani Sep 19, 2023
fda4a7e
Clean up
nbouziani Sep 20, 2023
9cb03d7
Additional cleaning
nbouziani Sep 20, 2023
d3d3694
Update .github/workflows/build.yml
nbouziani Sep 20, 2023
f2bf456
Update firedrake/cofunction.py
nbouziani Sep 20, 2023
291cd99
Update multifunction import (recently changed in UFL upstream)
nbouziani Sep 20, 2023
6935f33
Address PR's comments
nbouziani Sep 20, 2023
0b8a0c2
Fix bcs tests
nbouziani Sep 21, 2023
4bda0d0
Add UFL branch that fixes the pyadjoint tests
nbouziani Sep 21, 2023
c550838
Update .github/workflows/build.yml
nbouziani Sep 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions firedrake/adjoint_utils/blocks/dirichlet_bc.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,15 @@ def evaluate_adj_component(self, inputs, adj_inputs, block_variable, idx,
for adj_input in adj_inputs:
if self.compat.isconstant(c):
adj_value = self.backend.Function(self.parent_space.dual())
adj_input.apply(adj_value.vector())
adj_input.apply(adj_value)
if self.function_space != self.parent_space:
vec = self.compat.extract_bc_subvector(
adj_value, self.collapsed_space, bc
)
adj_value = self.compat.function_from_vector(
self.collapsed_space, vec
)
adj_value = self.backend.Function(self.collapsed_space, vec.dat)

if adj_value.ufl_shape == () or adj_value.ufl_shape[0] <= 1:
r = adj_value.vector().sum()
r = adj_value.dat.data_ro.sum()
else:
output = []
subindices = _extract_subindices(self.function_space)
Expand All @@ -64,7 +62,7 @@ def evaluate_adj_component(self, inputs, adj_inputs, block_variable, idx,
output.append(
current_subfunc.sub(
prev_idx, deepcopy=True
).vector().sum()
).dat.data_ro.sum()
)

r = self.backend.cpp.la.Vector(self.backend.MPI.comm_world,
Expand All @@ -78,13 +76,13 @@ def evaluate_adj_component(self, inputs, adj_inputs, block_variable, idx,
# For now we will just assume the FunctionSpace is the same for
# the BC and the Function.
adj_value = self.backend.Function(self.parent_space.dual())
adj_input.apply(adj_value.vector())
adj_input.apply(adj_value)
r = self.compat.extract_bc_subvector(
adj_value, c.function_space(), bc
)
elif isinstance(c, self.compat.Expression):
adj_value = self.backend.Function(self.parent_space.dual())
adj_input.apply(adj_value.vector())
adj_input.apply(adj_value)
output = self.compat.extract_bc_subvector(
adj_value, self.collapsed_space, bc
)
Expand Down
16 changes: 7 additions & 9 deletions firedrake/adjoint_utils/blocks/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def evaluate_adj_component(self, inputs, adj_inputs, block_variable, idx,
if isinstance(block_variable.output, AdjFloat):
try:
# Adjoint of a broadcast is just a sum
return adj_inputs[0].vector().sum()
return adj_inputs[0].dat.data_ro.sum()
except AttributeError:
# Catch the case where adj_inputs[0] is just a float
return adj_inputs[0]
Expand All @@ -67,8 +67,7 @@ def evaluate_adj_component(self, inputs, adj_inputs, block_variable, idx,
adj_output = self.backend.Function(
block_variable.output.function_space())
adj_output.assign(prepared)
adj_output = self.backend.Cofunction(adj_output.function_space().dual(),
val=adj_output.vector())
adj_output = adj_output.riesz_representation(riesz_map="l2")
return adj_output
else:
# Linear combination
Expand All @@ -82,8 +81,7 @@ def evaluate_adj_component(self, inputs, adj_inputs, block_variable, idx,
)
# Firedrake does not support assignment of conjugate functions
adj_output.interpolate(ufl.conj(diff_expr))
adj_output = self.backend.Cofunction(adj_output.function_space().dual(),
val=adj_output.vector())
adj_output = adj_output.riesz_representation(riesz_map="l2")
else:
mesh = adj_output.function_space().mesh()
diff_expr = ufl.algorithms.expand_derivatives(
Expand All @@ -94,7 +92,7 @@ def evaluate_adj_component(self, inputs, adj_inputs, block_variable, idx,
)
)
adj_output.assign(diff_expr)
return adj_output.vector().inner(adj_input_func.vector())
return adj_output.dat.inner(adj_input_func.dat)

if self.compat.isconstant(block_variable.output):
R = block_variable.output._ad_function_space(
Expand All @@ -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

else:
# We assume the shape of the constant == shape of the output
# function if not scalar. This assumption is due to FEniCS not
# supporting products with non-scalar constants in assign.
values = []
for i in range(shape[0]):
values.append(adj_output.sub(i, deepcopy=True).vector().sum())
values.append(adj_output.sub(i, deepcopy=True).dat.data_ro.sum())
r.assign(self.backend.Constant(values))
return r

Expand All @@ -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.


return dudm

Expand Down
15 changes: 7 additions & 8 deletions firedrake/adjoint_utils/blocks/solving.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def prepare_evaluate_adj(self, inputs, adj_inputs, relevant_dependencies):
)
)
dFdu_form = self.backend.adjoint(dFdu)
dJdu = dJdu.vector().copy()
dJdu = dJdu.copy()

compute_bdy = self._should_compute_boundary_adjoint(
relevant_dependencies
Expand Down Expand Up @@ -184,14 +184,14 @@ def _assemble_and_solve_adj_eq(self, dFdu_adj_form, dJdu, compute_bdy):

adj_sol = self.compat.create_function(self.function_space)
self.compat.linalg_solve(
dFdu, adj_sol.vector(), dJdu, *self.adj_args, **self.adj_kwargs
dFdu, adj_sol, dJdu, *self.adj_args, **self.adj_kwargs
)

adj_sol_bdy = None
if compute_bdy:
adj_sol_bdy = self.compat.function_from_vector(
adj_sol_bdy = self.backend.Function(
self.function_space.dual(),
dJdu_copy - self.compat.assemble_adjoint_value(self.backend.action(dFdu_adj_form, adj_sol)).vector()
dJdu_copy.dat - self.compat.assemble_adjoint_value(self.backend.action(dFdu_adj_form, adj_sol)).dat
)

return adj_sol, adj_sol_bdy
Expand Down Expand Up @@ -359,8 +359,7 @@ def _assemble_and_solve_soa_eq(self, dFdu_form, adj_sol, hessian_input,
b = self._assemble_soa_eq_rhs(dFdu_form, adj_sol, hessian_input,
d2Fdu2)
dFdu_form = self.backend.adjoint(dFdu_form)
adj_sol2, adj_sol2_bdy = self._assemble_and_solve_adj_eq(dFdu_form, b.vector(),
compute_bdy)
adj_sol2, adj_sol2_bdy = self._assemble_and_solve_adj_eq(dFdu_form, b, compute_bdy)
if self.adj2_cb is not None:
self.adj2_cb(adj_sol2)
if self.adj2_bdy_cb is not None and compute_bdy:
Expand Down Expand Up @@ -523,7 +522,7 @@ def _assembled_solve(self, lhs, rhs, func, bcs, **kwargs):
for bc in bcs:
bc.apply(rhs_func)
rhs.assign(rhs_func.riesz_representation(riesz_map="l2"))
self.backend.solve(lhs, func.vector(), rhs, **kwargs)
self.backend.solve(lhs, func, rhs, **kwargs)
return func

def recompute_component(self, inputs, block_variable, idx, prepared):
Expand Down Expand Up @@ -662,7 +661,7 @@ def prepare_evaluate_adj(self, inputs, adj_inputs, relevant_dependencies):
F_form = self._create_F_form()

dFdu_form = self.adj_F
dJdu = dJdu.vector().copy()
dJdu = dJdu.copy()

# Replace the form coefficients with checkpointed values.
replace_map = self._replace_map(dFdu_form)
Expand Down
4 changes: 2 additions & 2 deletions firedrake/adjoint_utils/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def _ad_convert_riesz(self, value, options=None):
raise TypeError("Expected a Cofunction, Function or a float")

if riesz_representation == "l2":
value = value.vector() if isinstance(value, (Cofunction, Function)) else value
value = value.dat if isinstance(value, (Cofunction, Function)) else value
return Function(V, val=value)

elif riesz_representation in ("L2", "H1"):
Expand Down Expand Up @@ -308,7 +308,7 @@ def _ad_dot(self, other, options=None):
options = {} if options is None else options
riesz_representation = options.get("riesz_representation", "l2")
if riesz_representation == "l2":
return self.vector().inner(other.vector())
return self.dat.inner(other.dat)
elif riesz_representation == "L2":
return assemble(firedrake.inner(self, other)*firedrake.dx)
elif riesz_representation == "H1":
Expand Down
8 changes: 4 additions & 4 deletions firedrake/cofunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, function_space, val=None, name=None, dtype=ScalarType):
V = V.function_space()
# Deep copy prevents modifications to Vector copies.
# Also, this discard the value of `val` if it was specified (consistent with Function)
val = function_space.copy(deepcopy=True).vector()
val = function_space.copy(deepcopy=True).dat
elif not isinstance(V, functionspaceimpl.FiredrakeDualSpace):
raise NotImplementedError("Can't make a Cofunction defined on a "
+ str(type(function_space)))
Expand Down Expand Up @@ -79,12 +79,12 @@ def __del__(self):
if hasattr(self, "_comm"):
mpi.decref(self._comm)

def copy(self, deepcopy=False):
def copy(self, deepcopy=True):
r"""Return a copy of this :class:`firedrake.function.CoordinatelessFunction`.

:kwarg deepcopy: If ``True``, the new
:kwarg deepcopy: If ``True``, the default, the new
:class:`firedrake.function.CoordinatelessFunction` will allocate new space
and copy values. If ``False``, the default, then the new
and copy values. If ``False``, then the new
:class:`firedrake.function.CoordinatelessFunction` will share the dof values.
"""
if deepcopy:
Expand Down
2 changes: 1 addition & 1 deletion firedrake/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ def riesz_representation(self, riesz_map='L2'):

V = self.function_space()
if riesz_map == "l2":
return Cofunction(V.dual(), val=self.vector())
return Cofunction(V.dual(), val=self.dat)

elif riesz_map in ("L2", "H1"):
a = self._define_riesz_map_form(riesz_map, V)
Expand Down
4 changes: 3 additions & 1 deletion firedrake/matrix_free/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,11 @@ def _assemble_diagonal(self):

def getDiagonal(self, mat, vec):
self._assemble_diagonal()
diagonal_func = self._diagonal.riesz_representation(riesz_map="l2")
for bc in self.bcs:
# Operator is identity on boundary nodes
bc.set(self._diagonal, 1)
bc.set(diagonal_func, 1)
self._diagonal.assign(diagonal_func.riesz_representation(riesz_map="l2"))
with self._diagonal.dat.vec_ro as v:
v.copy(vec)

Expand Down
11 changes: 8 additions & 3 deletions firedrake/ufl_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,17 @@ def function_space(self):
def make_dat(self):
return self.function_space().make_dat()

def _analyze_form_arguments(self):
def _analyze_form_arguments(self, outer_form=None):
# Returns the argument found in the Coargument object
self._coefficients = ()
# Coarguments map from V* to V*, i.e. V* -> V*, or equivalently V* x V -> R.
# So they have one argument in the primal space and one in the dual space.
self._arguments = (Argument(self.function_space().dual(), 0), self)
self._coefficients = ()
# However, when they are composed with linear forms with dual arguments, such as BaseFormOperators,
# the primal argument is discarded when analysing the argument as Coarguments.
if not outer_form:
self._arguments = (Argument(self.function_space().dual(), 0), self)
else:
self._arguments = (self,)

def reconstruct(self, function_space=None,
number=None, part=None):
Expand Down
2 changes: 1 addition & 1 deletion tests/multigrid/test_p_multigrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def test_p_multigrid_mixed(mat_type):

# Make the Function spanning the nullspace
c_basis = assemble(TestFunction(Z.sub(1))*dx)
f_basis = Function(c_basis.function_space().dual(), val=c_basis.vector())
f_basis = Function(c_basis.function_space().dual(), val=c_basis.dat)

basis = VectorSpaceBasis([f_basis])
basis.orthonormalize()
Expand Down
8 changes: 4 additions & 4 deletions tests/regression/test_adjoint_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def test_interpolate_hessian_linear_expr():
dJdm = J.block_variable.tlm_value
assert isinstance(f.block_variable.adj_value, Cofunction)
assert isinstance(f.block_variable.hessian_value, Cofunction)
Hm = f.block_variable.hessian_value.vector().inner(h.vector())
Hm = f.block_variable.hessian_value.dat.inner(h.dat)
# If the new interpolate block has the right hessian, taylor test
# convergence rate should be as for the unmodified test.
assert taylor_test(Jhat, g, h, dJdm=dJdm, Hm=Hm) > 2.9
Expand Down Expand Up @@ -374,7 +374,7 @@ def test_interpolate_hessian_nonlinear_expr():
dJdm = J.block_variable.tlm_value
assert isinstance(f.block_variable.adj_value, Cofunction)
assert isinstance(f.block_variable.hessian_value, Cofunction)
Hm = f.block_variable.hessian_value.vector().inner(h.vector())
Hm = f.block_variable.hessian_value.dat.inner(h.dat)
# If the new interpolate block has the right hessian, taylor test
# convergence rate should be as for the unmodified test.
assert taylor_test(Jhat, g, h, dJdm=dJdm, Hm=Hm) > 2.9
Expand Down Expand Up @@ -436,7 +436,7 @@ def test_interpolate_hessian_nonlinear_expr_multi():
dJdm = J.block_variable.tlm_value
assert isinstance(f.block_variable.adj_value, Cofunction)
assert isinstance(f.block_variable.hessian_value, Cofunction)
Hm = f.block_variable.hessian_value.vector().inner(h.vector())
Hm = f.block_variable.hessian_value.dat.inner(h.dat)
# If the new interpolate block has the right hessian, taylor test
# convergence rate should be as for the unmodified test.
assert taylor_test(Jhat, g, h, dJdm=dJdm, Hm=Hm) > 2.9
Expand Down Expand Up @@ -640,7 +640,7 @@ def test_supermesh_project_hessian(vector):
dJdm = J.block_variable.tlm_value
assert isinstance(source.block_variable.adj_value, Cofunction)
assert isinstance(source.block_variable.hessian_value, Cofunction)
Hm = source.block_variable.hessian_value.vector().inner(h.vector())
Hm = source.block_variable.hessian_value.dat.inner(h.dat)
assert taylor_test(rf, source, h, dJdm=dJdm, Hm=Hm) > 2.9


Expand Down
4 changes: 2 additions & 2 deletions tests/regression/test_assemble_baseform.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def test_cofunction_riesz_representation(a):
M.petscmat.mult(v_vec, res_vec)
else:
# l2 mass matrix is identity
Mr = Function(V, val=r.vector())
Mr = Function(V, val=r.dat)

# Check residual
for a, b in zip(Mr.subfunctions, c.subfunctions):
Expand Down Expand Up @@ -265,7 +265,7 @@ def test_function_riesz_representation(f):
M.petscmat.mult(v_vec, res_vec)
else:
# l2 mass matrix is identity
Mf = Cofunction(V.dual(), val=f.vector())
Mf = Cofunction(V.dual(), val=f.dat)

# Check residual
for a, b in zip(Mf.subfunctions, r.subfunctions):
Expand Down
Loading