BUG: memory grows with every forward and adjoint evaluation when a mixed space has a Real component

オープン
#5,534 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python

調査の方向性

Start by tracing the example's mixed-space Function creation and the reported MixedDat.dataset / MixedDataSet cache in PyOP2; the issue does not name source files or tests. Reproduce the serial example and inspect cache growth across forward and adjoint evaluations. Done means memory stays roughly flat for the mixed space with a Real component while the plain Poisson comparison remains flat.

索引モデルが issue の本文から書いたものです。

説明

bug LLM used pyop2

In adjoint inversions, memory grows with the number of forward and adjoint evaluations whenever the solve is on a mixed space with a Real component. We first saw this on an HPE Cray EX machine with Firedrake 2026.10.0, in a 256-rank inversion that was killed by the OOM killer after 10 optimisation iterations. The example below shows it in serial on a MacBook (Apple silicon) with Firedrake main at ef9e4b1e2.

The cause seems to be the MixedDataSet cache in PyOP2. MixedDat.dataset builds a MixedDataSet from the datasets of its components, and caches it on the Set of the first component with the tuple of datasets as the key. A Real component is a Global with its own GlobalDataSet, so every new Function on the mixed space gives a new key. The new entry stays in the cache for as long as the mesh lives. pyadjoint makes new Functions at every replay and adjoint step, so the cache grows with every evaluation.

import gc

import psutil
from firedrake import *
from firedrake.adjoint import *

continue_annotation()
mesh = UnitSquareMesh(128, 128)
V = FunctionSpace(mesh, "CG", 1)
Z = V * FunctionSpace(mesh, "R", 0)
x, y = SpatialCoordinate(mesh)
f = Function(V).interpolate(cos(pi * x) * cos(pi * y))

# Poisson problem with an extra uniform source c, chosen so that the mean of u is zero.
z = Function(Z)
u, c = TrialFunctions(Z)
v, d = TestFunctions(Z)
solve(inner(grad(u), grad(v)) * dx + c * v * dx + u * d * dx == f * v * dx, z,
      DirichletBC(Z.sub(0), 0, "on_boundary"))
J = assemble(z.subfunctions[0] ** 2 * dx)
rf = ReducedFunctional(J, Control(f))
pause_annotation()

for i in range(1, 201):
    rf(f)
    rf.derivative()
    if i % 50 == 0:
        gc.collect()
        print(f"after {i} evaluations: {psutil.Process().memory_info().rss / 2**20:.0f} MB")

Output:

after 50 evaluations: 503 MB
after 100 evaluations: 566 MB
after 150 evaluations: 655 MB
after 200 evaluations: 741 MB

The same script without the Real unknown (a plain Dirichlet Poisson problem on V) stays flat at 332 to 339 MB.

I used Claude Code to reproduce this and to write the example.

主要言語
Python
スター
684
フォーク
204
平均マージ
4日 14時間
マージ済み PR(30日)
46

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

firedrakeproject/firedrake のほかの issue

firedrakeproject/firedrake の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。