Skip to content

Fix assemble(slate.Tensor, diagonal=True) #4378

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

Draft
wants to merge 1 commit into
base: pbrubeck/fix/slate-cofunction
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions firedrake/assemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -1745,7 +1745,7 @@ def _as_global_kernel_arg_output(_, self):
if rank == 0:
return op2.GlobalKernelArg((1,))
elif rank == 1 or rank == 2 and self._diagonal:
V, = Vs
V = Vs[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

We have V, here to assert a singleton. Why is that now violated? What are the contents of V[1:]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With slate we get the two copies of the same space in Vs. For some reason diagonal=True will cause len(indices) == 1 only for ufl.Form, but not for slate.Tensor. On both cases len(form.arguments()) == 2.

return tuple(a.ufl_function_space()[i] for i, a in zip(indices, form.arguments()))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And this is where we get the indices from

self._indices, self._kinfo = local_knl

Which means that we should trim the lenght of indices somewhere in slate/slac/compiler.py, but it gets hard to track down because diagonal is not mentioned at all in that script.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you use V = pytools.single_valued(Vs) then?

if V.ufl_element().family() == "Real":
return op2.GlobalKernelArg((1,))
else:
Expand Down Expand Up @@ -2052,7 +2052,7 @@ def _as_parloop_arg_output(_, self):
if rank == 0:
return op2.GlobalParloopArg(self._tensor)
elif rank == 1 or rank == 2 and self._diagonal:
V, = Vs
V = Vs[0]
if V.ufl_element().family() == "Real":
return op2.GlobalParloopArg(self._tensor)
else:
Expand Down
3 changes: 1 addition & 2 deletions firedrake/slate/slate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1387,8 +1387,7 @@ def arg_function_spaces(self):
"""Returns a tuple of function spaces that the tensor
is defined on.
"""
tensor, = self.operands
return tuple(arg.function_space() for arg in tensor.arguments())
return tuple(arg.function_space() for arg in self.arguments())

def arguments(self):
"""Returns a tuple of arguments associated with the tensor."""
Expand Down
12 changes: 3 additions & 9 deletions tests/firedrake/slate/test_linear_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,8 @@ def test_inverse_action(mat_type, rhs_type):
assert np.allclose(x.dat.data, f.dat.data, rtol=1.e-13)


@pytest.mark.parametrize("mat_type, rhs_type", [
("slate", "slate"), ("slate", "form"), ("slate", "cofunction"),
("aij", "cofunction"), ("aij", "form"),
("matfree", "cofunction"), ("matfree", "form")])
@pytest.mark.parametrize("rhs_type", ["slate", "form", "cofunction"])
@pytest.mark.parametrize("mat_type", ["slate", "aij", "matfree"])
def test_solve_interface(mat_type, rhs_type):
mesh = UnitSquareMesh(1, 1)
V = FunctionSpace(mesh, "HDivT", 0)
Expand All @@ -180,12 +178,8 @@ def test_solve_interface(mat_type, rhs_type):
else:
raise ValueError("Invalid rhs type")

sp = None
if mat_type == "matfree":
sp = {"pc_type": "none"}

x = Function(V)
problem = LinearVariationalProblem(A, b, x, bcs=bcs)
solver = LinearVariationalSolver(problem, solver_parameters=sp)
solver = LinearVariationalSolver(problem)
solver.solve()
assert np.allclose(x.dat.data, f.dat.data, rtol=1.e-13)
Loading