OptionsManager does not delete options inherited through default_options_set

Đang mở
#58 0 bình luận 0 reaction 1 người được giao Xem trên GitHub

@pbrubeck đang làm issue này rồi.

Từ ngày 5/10/2026.

  • #59 của @pbrubeck — đang mở

Đánh giá

Issue này chưa được đánh giá.

Mô tả

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.

Ngôn ngữ chính
Python
Star
4
Fork
1
Merge trung bình
2 ngày 18 giờ
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của firedrakeproject/petsctools

Tất cả issue của firedrakeproject/petsctools

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.