Skip to content

solver.gradient() takes the adjoint of an unconverged forward solve and returns a wrong-signed number #804

Description

@lmoresi

_adjoint_support documents that an unconverged solve is refused ("a linearisation about a state the solve never reached is not the adjoint of anything"), caught after the fact by _record_solve_outcome. That catch is on the recorded/transcript path. A direct solver.solve() followed by solver.gradient(...) is not refused.

Reproduced on scratch/adjoint-merge (82e697b): softmin viscoplastic box, snes_max_it = 2.

forward reason -5                       # DIVERGED_MAX_IT
gradient RETURNED {eta_min: 0.2197}     # converged answer: -0.1423 (FD agrees to 4e-8)

Wrong sign, no warning. Script: ~/+Simulations/adjoint_note_checks/unconverged_refusal.py.

UWTN 2026-020 (draft) currently states that "the library refuses to take the adjoint of a solve that did not converge", so either the guard moves into adjoint_solve/gradient (check snes.getConvergedReason() > 0 on the solver that did the solving) or the note's sentence goes. The first seems right: the note's argument — a multiplier is undefined off the constraint manifold — is exactly why this should be an error rather than a number.

Activity

  1. lmoresi commented on Oct 7, 2026

    @lmoresi
    MemberAuthor

    Not reproducible on development (7c9cbbfd) — the adjoint API is not there:

    uw.adjoint present:        False
    Stokes adjoint API:        []
    files with 'adjoint' in the path: 0
    

    Only scattered references remain (one line in petsc_generic_snes_solvers.pyx, five in mcp/__init__.py, eight in transcript_query.py), not the implementation. So this defect lives in unmerged work — feature/discrete-adjoint (#744, currently conflicting and red), feature/adjoint-rotated-bc (#751, based on #744), or scratch/adjoint-merge.

    That is why it has sat untouched: there is nothing on the main line to fix. It is not fixed-in-PR — the opposite. It has to be fixed on the branch before that branch lands, or it lands with the defect.

    Checked in the untouched-issue triage. Blocked behind #744, which needs its conflicts resolved and a CI re-run (its red check is test_1063_constrained_traction, whose timeout #814 addressed when it merged on 2026-10-06).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions