BUG: NonlinearVariationalSolver errors with adj_kwargs

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

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

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

2026年6月17日 から。

  • #5187 @dham による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
75/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
python
領域
api, backend

調査の方向性

adjoint_utils/variational_solver.py の47行目付近にあるラッパーから始め、次に、コンストラクターエラーを再現するため、提供されている最小の Firedrake の例を実行します。NonlinearVariationalSolver が adj_kwargs を受け付けること、および solve 時の workaround に依存せずに例が動作することを確認します。

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

説明

bug

Describe the bug
Passing adj_kwargs to NonlinearVariationalSolver in order to have different solver_parameters for the adjoint problem errors.

Steps to Reproduce
Here is an MFE:

from firedrake import *
from firedrake.adjoint import *

continue_annotation()

mesh = UnitSquareMesh(20,20)
U = FunctionSpace(mesh, "CG", 1)

u = Function(U)
v = TestFunction(U)

f = Function(U)

F = inner(grad(u),grad(v))*dx - inner(f,v)*dx

bcs = [DirichletBC(U, Constant(1), (4,)),
       DirichletBC(U, Constant(0), (1, 2, 3))]

sp_lu = {
        "snes_monitor": None,
        "pc_type": "lu",
        "pc_factor_mat_solver_type": "mumps",}

# This works
solve(F==0, u, bcs=bcs, solver_parameters=sp_lu, adj_kwargs={"solver_parameters": sp_lu})

nvp = NonlinearVariationalProblem(F, u, bcs=bcs)

# This errors
nvs = NonlinearVariationalSolver(nvp, solver_parameters=sp_lu,
                                 adj_kwargs={"solver_parameters": sp_lu})

Expected behavior
I expect the NonlinearVariationalSolver to accept the adj_kwargs argument.

Error message

Traceback (most recent call last):
  File "/home/user/Documents/Code/codex/debug_adjoint_nvs_2.py", line 36, in <module>
    nvs = NonlinearVariationalSolver(nvp, solver_parameters=sp_lu,
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "petsc4py/PETSc/Log.pyx", line 250, in petsc4py.PETSc.Log.EventDecorator.decorator.wrapped_func
  File "petsc4py/PETSc/Log.pyx", line 251, in petsc4py.PETSc.Log.EventDecorator.decorator.wrapped_func
  File "/usr/lib/python3.12/contextlib.py", line 81, in inner
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/user/firedrake-release-30-05-2026/venv-firedrake/lib/python3.12/site-packages/firedrake/adjoint_utils/variational_solver.py", line 47, in wrapper
    init(self, problem, *args, **kwargs)
TypeError: NonlinearVariationalSolver.__init__() got an unexpected keyword argument 'adj_kwargs'

Environment:

  • OS: Linux
  • Python version: 3.12.3

Additional Info
As pointed out by @dham, the workaround is currently to pass adj_kwargs to the first solve as follows:

nvs = NonlinearVariationalSolver(nvp, solver_parameters=sp_lu)
nvs.solve(adj_kwargs={"solver_parameters": sp_lu})
主要言語
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 を短くまとめたダイジェスト。