OptionsManager does not delete options inherited through default_options_set

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

@pbrubeck がすでに取り組んでいます。

2026年10月5日 から。

  • #59 @pbrubeck による — オープン

評価

この issue はまだ評価されていません。

説明

OptionsManager does not delete the options that it inherits through default_options_set. When inserted_options() exits, these options stay in the global PETSc options database under the prefix of the manager. The next manager that has the same prefix then reads them back as options that the user set.

Minimal example
from petsc4py import PETSc
from petsctools import DefaultOptionSet, OptionsManager

options = PETSc.Options()
options["base_ksp_type"] = "cg"

child = OptionsManager({}, options_prefix="base_0",
                       default_options_set=DefaultOptionSet("base", [0]))
print(child.parameters)  # {'ksp_type': 'cg'}
with child.inserted_options():
    pass

del options["base_ksp_type"]
print(options.getAll())  # expected {}, actual {'base_0_ksp_type': 'cg'}

This reproduces on main (d4caedc).

Cause

OptionsManager.__init__ builds to_delete before it merges the default options into parameters:

https://github.com/firedrakeproject/petsctools/blob/d4caedc/petsctools/options.py#L505-L509

inserted_options() inserts every key of parameters, but deletes only the keys in to_delete. The inherited keys are therefore inserted and never deleted.

Possible fix
to_delete = set(default_options | parameters)
parameters = default_options | parameters

The loop that follows already discards every key that the database held before, so options from the command line are kept.


This issue was written by Claude (Claude Code) on behalf of @pbrubeck.

主要言語
Python
スター
4
フォーク
1
平均マージ
2日 18時間
マージ済み PR(30日)
1

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

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

firedrakeproject/petsctools のほかの issue

firedrakeproject/petsctools の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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