Repository navigation
Dropped solvers and meshes leave nothing in PETSc's options database (#950) - #980
Conversation
…abase Each solver writes its PETSc options under its own prefix (Solver_N_, with private_Solver_N_ copies for its sub-objects), and each mesh wrote three meshproj_N_ keys for its coordinate element; nothing removed either, so a loop that rebuilds a mesh and a solver grew the global database without bound (17 keys a cycle for a Poisson solve on development). - A solver drops its options when it is collected (weakref.finalize on the base class, not run at interpreter exit, when PETSc may be finalised). The prefix is unique to the solver, so no live solver reads them. A solver lives as long as its mesh, which holds it for its rebuild hook. - The mesh drops its three coordinate-element keys right after PETSc.FE().createDefault has read them. This touches petsc_generic_snes_solvers.pyx only in the base constructor and a module-level helper; no option a live solver reads is changed. test_0079 (tier B): rebuilding a mesh and a Poisson solver three times leaves the database the same size (development: 27 -> 78), and a live solver keeps its options. Broad serial set (test_00*, test_01*, test_100-102*): 1380 passed, 17 skipped. Underworld development team with AI support from Claude Code
Adversarial review of #980Verdict: ready with the changes below. Head 4031947, base eddab70, np 2 and 4 through the supervisor. Nothing hangs in parallel, and the key count is flat. One crash after Findings
Attacks that failed
Issues
Merge conditions
Could not testCheckpoint reload and refinement paths with Underworld development team with AI support from Claude Code |
…and never after PetscFinalize From hyperion's review of #980: - The mesh and its solvers form a reference cycle that the collector can reach after PetscFinalize; a finalizer touching the options database then ended the process (a segfault on Linux, rc 1 on macOS). It now returns once PETSc is finalised. - After uw_object._reset() a new solver can take a dropped one's prefix, and the dropped one's finalizer deleted the new solver's options. Each prefix now records its owner by a token, and a finalizer acts only while its solver still owns the prefix. - test_0079 keeps one solver alive while another is collected and checks every one of its options (a finalizer deleting every Solver_* key passed the old test), checks a reused prefix after uw_object._reset(), and runs the late finalizer in a child process (rc 1 before the guard, 0 after). Mutants deleting every solver's options, or ignoring ownership, fail it. Underworld development team with AI support from Claude Code
|
Response to hyperion's review, at 3a3b731:
test_0079: 4 passed serially. Thanks for the parallel runs, which are recorded above. Underworld development team with AI support from Claude Code |
…anup-950 Underworld development team with AI support from Claude Code
Dropped solvers and meshes leave nothing behind in PETSc's global options database (#950).
The bug
Each solver writes its PETSc options under a prefix unique to it:
Solver_N_, plusprivate_Solver_N_copies for its sub-objects. Each mesh wrote threemeshproj_N_keys for its coordinate element. Nothing removed either. A loop that rebuilds a mesh and a solver therefore grew the database without bound: 17 keys a cycle for a Poisson solve on development eddab70, and about 41 a rebuild in the rotated-FMG rebuild fixture where #950 was found. That is kilobytes, not #948's megabytes, but it is unbounded, and every later options lookup searches a longer list.The change
cython/petsc_generic_snes_solvers.pyx, the base constructor and a module-level helper): a solver drops its options when it is collected, throughweakref.finalize. The finalizer does not run at interpreter exit, when PETSc may already be finalised. The prefix is unique to the solver, so no live solver reads those keys. This is the only change in the solver file, and it changes no option that a live solver reads.discretisation_mesh.py): the three coordinate-element keys are dropped as soon asPETSc.FE().createDefaulthas read them, as the rotated route already does with its own keys.A solver lives as long as its mesh, because the mesh holds it for its rebuild hook. A solver the user drops therefore keeps its options until its mesh is dropped too. That ownership is unchanged here.
Tests
tests/test_0079_options_database_does_not_grow.py(tier B):The broad serial set (test_00*, test_01*, test_100-102*) gives 1380 passed and 17 skipped.
Issues
Underworld development team with AI support from Claude Code