Skip to content

fix(solvers): pyamgx solvers crash on instantiation due to precon attribute typo#1206

Open
gaoflow wants to merge 1 commit into
usnistgov:masterfrom
gaoflow:fix-1199-pyamgx-precon
Open

fix(solvers): pyamgx solvers crash on instantiation due to precon attribute typo#1206
gaoflow wants to merge 1 commit into
usnistgov:masterfrom
gaoflow:fix-1199-pyamgx-precon

Conversation

@gaoflow

@gaoflow gaoflow commented May 29, 2026

Copy link
Copy Markdown

Fixes #1199.

Problem

Instantiating any pyamgx-backed solver raises immediately, before any GPU work:

>>> from fipy.solvers.pyamgx import LinearGMRESSolver
>>> LinearGMRESSolver()
AttributeError: 'LinearGMRESSolver' object has no attribute 'precon'

PyAMGXSolver.__init__ checks self.precon, but the base Solver stores the
preconditioner on self.preconditioner (set from the precon argument via
value_or_default(precon, default_preconditioner)). There is no self.precon
attribute, so construction fails.

This matches the maintainer’s diagnosis in #1199 ("it looks like there’s a typo … that should be if self.preconditioner is not None: self.preconditioner._applyToSolver(...)"), and the reporter confirmed that renaming it removes the error.

Fix

  1. Use self.preconditioner instead of the non-existent self.precon.
  2. Forward precon=precon to the base Solver.__init__, matching scipySolver
    and petscKrylovSolver. Without this, both an explicitly passed precon
    and the pyamgx solvers’ class DEFAULT_PRECONDITIONER were silently
    dropped — the base initializes self.preconditioner from its precon arg,
    which previously defaulted to "default"None for every pyamgx solver.
super(PyAMGXSolver, self).__init__(tolerance=tolerance, criterion=criterion,
                                   iterations=iterations, precon=precon)
...
if self.preconditioner is not None:
    self.preconditioner._applyToSolver(self.config_dict["solver"])

Verification

  • py_compile clean; no remaining self.precon reference.
  • Verified by code inspection and consistency with the sibling scipySolver /
    petscKrylovSolver __init__ signatures, plus the maintainer diagnosis and
    reporter confirmation in object has no attribute 'precon' in pyamgx solvers #1199.
  • Not runtime-tested locally: pyamgx requires the AMGX library and an NVIDIA
    GPU, which are unavailable in this environment, so I could not add a
    CI-runnable regression test without that dependency. Happy to add one if there
    is a pyamgx-capable CI lane I can target.

PyAMGXSolver referenced self.precon, but the base Solver stores the
preconditioner on self.preconditioner. Instantiating any pyamgx solver
(e.g. LinearGMRESSolver()) therefore raised
'AttributeError: ... has no attribute precon' before any GPU work began.

Also forward precon to the base __init__ (matching scipySolver and
petscKrylovSolver), so an explicitly passed preconditioner and the
class DEFAULT_PRECONDITIONER are honored instead of silently dropped.

Fixes usnistgov#1199.
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

guyer added a commit that referenced this pull request Jun 16, 2026
* Add policy on AI contributions

Inspired by #1179, #1200, #1201, #1202, #1203, #1205, #1206, #1209, #1210

* Ignore extractive issues and PRs in changelog

https://llvm.org/docs/AIToolPolicy.html#extractive-contributions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

object has no attribute 'precon' in pyamgx solvers

1 participant