Avoid quadrature representation in norm or silence the warning
MWE:
from dolfin import *
mesh = UnitSquareMesh(3, 3)
V = FunctionSpace(mesh, "P", 1)
u = Function(V)
norm(u)
stdout:
/vivid/home/jan/dev/fenics-master/src/ffc/ffc/jitcompiler.py:235: QuadratureRepresentationDeprecationWarning:
*** ===================================================== ***
*** FFC: quadrature representation is deprecated! It will ***
*** likely be removed in 2018.1.0 release. Use uflacs ***
*** representation instead. ***
*** ===================================================== ***
issue_deprecation_warning()
Comments (11)
-
reporter -
Is
norm(u)
justsqrt(assemble(u**2))
? If so, then I don't see any reason not to useuflacs
instead ofquadrature
. -
Quadrature was probably explicitly selected because FFC would otherwise have picked tensor, which is disastrous especially in the
norm(u - v)
case, since tensor has to rearrange(u - v)**2
tou**2 - 2*u*v + v**2
, but that expansion is not valid with floating-point arithmetic, and might give a negative number even though (u - v)^2 >= 0. Then taking the square root a negative number fails... -
I might be wrong, but I am not aware of uflacs applying the tensor contraction trick for 0-forms. But as far as I can tell, tensor representation won't give you a drastic performance improvement even in the u^2 case, and is outright dangerous for (u - v)^2.
-
reporter Thanks for the comments, @miklos1.
Yes, user might call
norm(u-uh)
and disaster can happen. I will check if uflacs can be told to avoid tensor contraction.On the other hand one can call
errornorm(u, uh)
which will- interpolate
u
anduh
to some same higher order space, - compute function
e = u_intepolant - uh_interpolant
and callnorm(e)
(with singleArgument
e
).
Is there further cancellation possible by expanding
e**2*dx
with smalle
into tensor contractions? - interpolate
-
For polynomial degree p and topological dimension d, both quadrature and tensor will take O(p^2d) operations for both norm(u) and norm(u - v), but the constant factors are likely different for the two approaches, and it is hard to tell in general which one is faster.
-
reporter I am rather worried about stability rather then speed, i.e. whether cancellation can happen for
u**2*dx
withu
without a sign when expanded into tensor contraction.Consider integral
u**2*dx
. Quadraturesum_k ( sum_i u_i phi_ik )**2 q_k
is non-negative by construction. But tensor contractionsum_ij C_ij u_i u_j
can possibly suffer with cancellation whenu
does not have a sign. Is it correct?So I speculate that tensor can be unstable even when integrating a single argument, just saying that
errornorm()
trick does not save the day. -
Is it correct?
I think, yes.
-
If the terms (n of them) all have the same sign, then any ordering of the summation gives a relative error of at most nu (where u is the unit roundoff). For heavy cancellation (sum_i |x_i| >> |sum_i x_i|), then summing with decreasing ordering is OK. But the error bounds are much worse. See Higham, Accuracy and Stability of Numerical Algorithms (pp79-90).
-
reporter I might be wrong, but I am not aware of uflacs applying the tensor contraction trick for 0-forms.
I didn't find it either.
-
reporter - changed status to resolved
- Log in to comment
The deprecation warning revealed that
quadrature
is forced because of its better stability compared totensor
. Can we be sure thatuflacs
will provide sufficient adequately stable replacement? Doesn't it use tensor-contraction trick too?Opinions @martinal, @miklos1, @garth-wells?
If we don't reach a conclusion before the release, we can just silence the warning and keep using
quadrature
for some time.