BUG: FIREDRAKE_CACHE_DIR is ignored by loopy's caches when loopy is imported before firedrake

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

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

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

評価

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

調査の方向性

Start with firedrake/configuration.py and setup_cache_dirs(), then trace when loopy and pytools create their persistent caches during imports; the reproduction names loopy.codegen.code_gen_cache and also exercises imports through tsfc. Run the supplied three import-order cases and check whether every cache directory is under FIREDRAKE_CACHE_DIR or a warning is issued when a cache was created earlier.

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

説明

bug

Describe the bug
FIREDRAKE_CACHE_DIR does not apply to loopy's persistent caches if loopy is imported before firedrake, directly or through tsfc. setup_cache_dirs() (firedrake/configuration.py, from #5400) sets XDG_CACHE_HOME during import firedrake. But loopy creates its PersistentDicts at module import (e.g. loopy.codegen.code_gen_cache), and pytools resolves the container directory in __init__. So the caches stay in ~/.cache/pytools for the whole process, with no warning. The PyOP2 and TSFC caches do move to FIREDRAKE_CACHE_DIR.

Steps to Reproduce

for first in "import firedrake; import loopy" "import loopy; import firedrake" "import tsfc; import firedrake"; do
  echo "== $first"
  env -u XDG_CACHE_HOME FIREDRAKE_CACHE_DIR=$(mktemp -d) python -c "
$first
from loopy.codegen import code_gen_cache
print(code_gen_cache.container_dir)"
done

Output:

== import firedrake; import loopy
/tmp/tmp.wglcRkE7wS/pytools
== import loopy; import firedrake
/home/<user>/.cache/pytools
== import tsfc; import firedrake
/home/<user>/.cache/pytools

Expected behavior
All caches live under FIREDRAKE_CACHE_DIR whatever the import order. Failing that, warn when loopy's caches were already created at another location.

Additional Info
Found while benchmarking kernels from two FIAT branches with a fresh FIREDRAKE_CACHE_DIR for each. The script imported loopy first, so loopy's code-gen cache was still shared. Kernels already in that cache from earlier runs looked 10x faster to generate (0.9 s vs ~10 s), and the gap went away once XDG_CACHE_HOME was also set. Related: #2310.

Possible fixes: call setup_cache_dirs() when tsfc and pyop2 are imported too, and warn in setup_cache_dirs() if XDG_CACHE_HOME was unset but "loopy" in sys.modules.

Environment:

  • OS: Linux
  • Python 3.14.4, firedrake main at 2093d46b499, loopy 2025.2, pytools 2026.1.1
  • XDG_CACHE_HOME unset, FIREDRAKE_CACHE_DIR set per run
主要言語
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 を短くまとめたダイジェスト。