Skip to content

More assembly cache bork #319

Closed
OP2/PyOP2
#451

Description

@wence-
from firedrake import *
import numpy as np

m = UnitSquareMesh(2, 2)
V = FunctionSpace(m, 'CG', 1)
g = Function(V)
g.interpolate(Expression("sin(x[0])"))
v = TestFunction(V)
lump = assemble(v*dx)
g.assign(assemble(g*v*dx) / lump)

tmp = Function(V)
v = TestFunction(V)
tmp.interpolate(Expression("sin(x[0])"))
tmp.assign(assemble(tmp*v*dx) / assemble(v*dx))

assert np.allclose(tmp.dat.data, g.dat.data)

tmp is full of NaNs. No idea what's going on. Disappears if either lazy evaluation is off, or assembly caching is off.

Activity

  1. wence- commented on Aug 6, 2014

    @wence-
    ContributorAuthor

    Prod. Appears to be a bad interaction of assembly cache and lazy evaluation. If I turn either of those /off/ then things work.

  2. wence- commented on Oct 24, 2014

    @wence-
    ContributorAuthor

    I think this is similar to #386

  3. wence- commented on Oct 24, 2014

    @wence-
    ContributorAuthor

    Simpler test case:

    from firedrake import *
    import numpy as np
    
    m = UnitSquareMesh(1, 1)
    V = FunctionSpace(m, 'CG', 1)
    g = Function(V)
    tmp = Function(V)
    v = TestFunction(V)
    g.assign(assemble(v*dx))
    tmp.assign(assemble(v*dx))
    print tmp.dat.data
    print g.dat.data

    The copy par_loop that's queued up never gets run.

  4. wence- commented on Oct 24, 2014

    @wence-
    ContributorAuthor

    I think this is fixed by the following pyop2 patch. But I don't understand the comment I'm modifying, and this quite possibly breaks other things.

    diff --git a/pyop2/base.py b/pyop2/base.py
    index 7501658..81291f3 100644
    --- a/pyop2/base.py
    +++ b/pyop2/base.py
    @@ -1870,8 +1873,9 @@ class Dat(SetAssociated, _EmptyDataMixin, CopyOnWrite):
             # Set up the copy to happen when required.
             other._cow_parloop = self._copy_parloop(other)
             # Remove the write dependency of the copy (in order to prevent
    -        # premature execution of the loop).
    -        other._cow_parloop.writes = set()
    +        # premature execution of the loop), and replace it with the
    +        # one dat we're writing to.
    +        other._cow_parloop.writes = set(other)
             if configuration['lazy_evaluation']:
                 # In the lazy case, we enqueue now to ensure we are at the
                 # right point in the trace.
    
  5. added a commit that references this issue on Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions