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

BUG: Checkpointing and referencing of variables #3780

Open
jrmaddison opened this issue Sep 24, 2024 · 0 comments
Open

BUG: Checkpointing and referencing of variables #3780

jrmaddison opened this issue Sep 24, 2024 · 0 comments
Assignees
Labels

Comments

@jrmaddison
Copy link
Contributor

jrmaddison commented Sep 24, 2024

Describe the bug
Firedrake Block subclasses reference variables via UFL expressions. This can prevent memory usage being reduced by checkpointing.

Firedrake level version of dolfin-adjoint/pyadjoint#169.

Steps to Reproduce

from firedrake import *
from firedrake.adjoint import *
from firedrake.adjoint_utils.blocks.solving import SolveVarFormBlock
from checkpoint_schedules import MultistageCheckpointSchedule

import itertools

N = 100

mesh = UnitIntervalMesh(1)
space = FunctionSpace(mesh, "Lagrange", 1)
test = TestFunction(space)
trial = TrialFunction(space)

tape = get_working_tape()
tape.enable_checkpointing(MultistageCheckpointSchedule(N, 3, 0))

u = Function(space, name="u").interpolate(Constant(2.0))
continue_annotation()
for _ in tape.timestepper(iter(range(N))):
    u_ = Function(space)
    solve(inner(trial, test) * dx == inner(test, u + u) * dx, u_)
    u = u_
    del u_
pause_annotation()
del u

deps = set()
for block in tape._blocks:
    if isinstance(block, SolveVarFormBlock):
        for dep in itertools.chain(ufl.algorithms.extract_coefficients(block.lhs),
                                   ufl.algorithms.extract_coefficients(block.rhs)):
            deps.add(dep.count())

print(f"{len(deps)=}")

leads to output

len(deps)=100
@jrmaddison jrmaddison added the bug label Sep 24, 2024
@jrmaddison jrmaddison changed the title BUG: Checkpointing and memory usage BUG: Checkpointing and referencing of variables Sep 24, 2024
@Ig-dolci Ig-dolci self-assigned this Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants