Give each autogenerated options prefix a unique index - #53
Conversation
|
Thanks but already fixed in #52 |
This reverts commit 729712d.
`self.count += 1` reads the class attribute and rebinds the result onto
the instance, so `OptionsManager.count` stayed at zero and every manager
built without an explicit `options_prefix` was handed the same prefix,
`{default_prefix}0_`.
Sharing a prefix means sharing a namespace in the global options
database. A manager built while another manager's options are inserted
picks those options up as if they had been passed on the command line.
In Firedrake this makes any solver constructed inside a solve inherit
the outer solver's parameters: the mass solve behind
`Mesh.cell_sizes`, for instance, runs with the outer `-pc_type mg` and
then fails to coarsen a problem that has no hierarchy of its own.
Increment the counter on `OptionsManager` itself, so that one counter
serves the whole hierarchy. `type(self).count += 1` is not enough:
`OptionsManager` is used as a mixin -- Firedrake has
`NonlinearVariationalSolver` -> `LinearVariationalSolver` ->
`LinearSolver`, and `LinearEigensolver` -- and it reads the inherited
value but writes the incremented one onto the subclass, so each class
walks a counter of its own and prefixes repeat across the hierarchy:
firedrake_2_ handed to both a LinearVariationalSolver and a
NonlinearVariationalSolver
`test_options_prefix` builds two subclasses and the base class in turn
and checks the prefixes are distinct, which fails on either spelling of
the bug.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
01e68d4 to
a5e8ad3
Compare
|
Rebased onto
Net effect against Why not The test now catches it. The version on the closed PR only built three managers of the same class, which is unique under Verified against Firedrake by putting this branch ahead of the installed AI-assisted: written with Claude Code. |
AI-assisted: diagnosed and written with Claude Code. I have read and understood every change, and run the tests locally.
Goal
OptionsManagerhands out a unique prefix to any object built without anexplicit
options_prefix. Since #39 it does not:self.count += 1reads theclass attribute and rebinds the result onto the instance, so
OptionsManager.countnever leaves zero and every autogenerated prefix is{default_prefix}0_.Sharing a prefix means sharing a namespace in the global options database. A
manager built while another manager's options are inserted reads those options
back out as if a user had passed them on the command line, and the warning it
emits names them:
After this PR the prefixes are
firedrake_0_,firedrake_1_,firedrake_2_again, and nothing is inherited.
What's in it
petsctools/options.py: increment the counter onOptionsManagerratherthan on
self, so the class attribute actually advances.tests/test_options.py:test_options_prefixnow asserts that successiveautogenerated prefixes differ. It fails on
mainand passes here.OptionsManager.countkeeps its meaning — the index the next autogeneratedprefix will use — so
test_commandline_options, which reads it to predict thatprefix, is unaffected.
Why this matters downstream
Firedrake depends on
petsctools @ git+https://github.com/firedrakeproject/petsctools.git@main,unpinned. #39 merged at 11:32 UTC on 26 August; the next Firedrake CI run on
main, at 12:05 UTC, went red, and it has been red since:macro/test_macro_multigrid.py::test_macro_multigrid_biharmonic[HCT, HCT-red]multigrid/test_snes_adapt.py::test_snes_adapt_sequence_with_adaptive_multigrid[1, 2]regression/test_appctx_cleanup.py::test_appctx_cleanupregression/test_stress_elements.py::test_stress_displacement_convergence[conforming, high-order]regression/test_bddc.py::test_bddc_cellwise_fdm[cube-nprocs=1-True-E-3]All of them fail the same way. A solver runs, and inside its residual
assembly Firedrake builds a second, unrelated solver — the mass solve behind
Mesh.cell_sizes, say. That inner solver takes the samefiredrake_0_prefix,inherits the outer solver's
-pc_type mg, and then dies trying to coarsen aproblem that has no mesh hierarchy of its own:
Notes for review
Checked against Firedrake by putting this checkout ahead of the installed
petsctoolsonPYTHONPATH: each of the tests above fails onmainand passeswith this commit.
tests/test_options.pypasses in full (18 tests) andruffis clean.
The remaining red tests on Firedrake
main—test_io_backward_compatand anintermittent xdist worker segfault in
test_assemble_baseform— predate #39 andare untouched by this.