Berton restricted W_a0 conditioning check

User

Please start work on TASK-017.

Assistant

Started TASK-017.

  • Set status to In Progress
  • Assigned to @pi
  • Updated the implementation plan to reflect the current evidence:
  • TASK-015 full-4D log-mass W_a0 still failed seed-only
  • TASK-018 restricted/scaled 3D diagnostics are complete
  • TASK-017 should proceed through the restricted/scaled W_a0 sanity-check route rather than rerunning TASK-015 unchanged

Please confirm you want me to proceed with implementation using this updated plan.

User

Please go ahead.

Assistant

Implemented the TASK-017 W_a0 sanity-check attempt, but it produced a negative result.

Changed/added:

  • episodes/07-restricted-equilibrium-auto/auto/berton_restricted_task017/
  • restricted/scaled AUTO variant using TASK-018 coordinates
  • W_a0 plus/minus configs and run_auto.sh
  • episodes/07-restricted-equilibrium-auto/scripts/berton_restricted_task017_wa0_sanity.py
  • episodes/07-restricted-equilibrium-auto/outputs/task017/
  • episodes/07-restricted-equilibrium-auto/docs/task017_wa0_conditioning_sanity_check.md
  • tests/test_episode07_restricted_task017.py
Show remaining 15 lines
  • Updated episode 07 README

Result:

  • TASK-012 Python W_a0 probe remains smooth/stable over 0.1–1.2 m/s.
  • Restricted/scaled AUTO still accepts only the seed at W_a0=0.6.
  • AUTO diagnostics still show DGEBAL/NaN first-step failures.
  • Conclusion: current H_a3 failures should not be treated as control-specific Hopf evidence; they remain broader AUTO formulation/conditioning concerns.

Validation:

  • uv run pytest → 66 passed

Backlog:

  • Checked AC #1, #2, #4, #5.
  • Left AC #3 unchecked because the branch still does not move beyond the seed as written.
  • TASK-017 remains In Progress, with notes pointing to TASK-019 refinement.
User

OK, it sounds like we need to rethink things again. Do you have any thoughts on why the AUTO continuation is failing even though the Jacobian is not particularly badly conditioned? (The condition number was about 7 or 8 after the variable rescaling you did, I think.) I don't think that this could be to do with the piecewise smooth conditions in the model, since the start point for the continuation is not close to any of the non-smooth points in those (is that true?). What else could be happening here? The equilibrium from which we trying to continue is stable (we know that from the long integration we did), and there isn't anything obviously singular going on, so what's happening?

Assistant

Yes — I agree this no longer looks like “the equilibrium branch is singular” or “the physical model is near a bifurcation.” The failure pattern looks much more like an AUTO formulation / Jacobian / continuation-setup problem.

Key observations:

  1. The seed is not especially close to a piecewise kink
  • Seed altitude: z ≈ 9618 m
  • Nearest important profile kinks:

- humidity / eta at 10000 m: about 382 m away
- eta lower kink at 9000 m: about 618 m away
- updraft top z_W0=9000 m: about 618 m below

Show remaining 76 lines
  • TASK-012 Python W_a0 probe only moves altitude by about 55 m over W_a0=0.1–1.2, so the expected branch stays comfortably away from the 10 km kink.
  • So I do not think piecewise smoothness is the primary explanation.
  1. The AUTO Newton trace screams “bad augmented continuation system,” not physical singularity

In the restricted run, AUTO starts with a tiny predictor:

``text IT 0: PAR = 0.600305, L2-NORM = 9.5e-4 ``

Then Newton immediately jumps to:

``text IT 1: PAR = 0.474788, L2-NORM = 3.49 IT 2: PAR = 1.49853, L2-NORM = 4.75 IT 3: PAR = 3.35938, L2-NORM = 16.1 IT 4: PAR = -8.8e5, L2-NORM = 1.6e5 ``

That is not “the branch gently curves and Newton struggles.” That is “the correction equation is wrong or badly scaled in the augmented AUTO system.”

  1. The condition number ≈ 7 only covers part of the problem

TASK-018 measured the condition number of the state residual Jacobian:

\[
J_x = \partial F / \partial (Z,U,M)
\]

after scaling. That matrix is fine.

But AUTO’s continuation Newton solve uses an augmented system involving:

\[
[J_x \quad F_\lambda]
\]

plus a pseudo-arclength/tangent equation, parameter scaling, previous tangent, and whatever AUTO thinks the active continuation parameters are. So a well-conditioned J_x does not guarantee the augmented continuation correction is well behaved.

  1. My strongest suspicion: AUTO is seeing a wrong or incomplete continuation Jacobian/tangent

The immediate Newton blow-up suggests one of these:

  • DFDP / parameter derivatives are wrong, missing, ignored, or indexed differently than expected.
  • AUTO is finite-differencing parameters in a numerically bad way.
  • The ICP list includes diagnostic PVLS parameters in a way that confuses the augmented system.
  • The continuation parameter scaling is poor relative to the state variables despite the state residual scaling being good.
  • The FORTRAN residual/Jacobian matches Python at the seed but not off-seed.

The most concrete next check is: compare the exact Jacobian block AUTO should be using — both DFDU and DFDP — against Python finite differences at the seed and at the first predicted point.

  1. Physical stability is not enough to guarantee this restricted AUTO problem behaves

The long integration tells us the full 4D ODE equilibrium is stable.

But the restricted 3D residual is not literally the same dynamical system. We fixed w=0 and solve balances in (z,u,log m). Its Jacobian/eigenvalues are artificial diagnostics unless carefully mapped back to the full system.

In fact, AUTO printed a positive eigenvalue for the restricted scaled residual. That does not contradict the full-system stability, but it does mean AUTO’s internal equilibrium/eigenvalue machinery is being applied to a constructed vector field whose stability interpretation is not physical.

  1. I would simplify the AUTO problem aggressively before trusting any result

My next move would be to strip the setup down to the minimum:

  • NDIM=3
  • ICP = ['W_a0'] only
  • no PVLS diagnostic parameters
  • no eigenvalue/Hopf detection: ISP=0
  • try JAC=0 first, letting AUTO finite-difference everything
  • no UZR except maybe one nearby anchor
  • tiny DS, but also test whether DS sign/magnitude matters
  • compare with a Python pseudo-arclength continuation implementation on the same residual

If that minimal version works, then the bug is in diagnostics/Jacobian/parameter bookkeeping. If it still fails, then the issue is deeper in how AUTO handles this algebraic equilibrium formulation.

My current best hypothesis: the branch is real and smooth, but AUTO’s augmented Newton system is being given inconsistent derivative/parameter information or confused by the current ICP/PVLS/JAC setup. The evidence points more to a formulation/implementation issue than to the Berton equilibrium itself.

User

Did we ever verify that the Fortran version of the Berton model for AUTO matches the Python implementation? And did we ever verify the ancillary information that goes in the AUTO Fortran model? Is there any straightforward way to check the potential problems in #4 in your list here?

Assistant

Yes, but only partially.

What we already verified

  • Episode 04 / TASK-009: verified the original full AUTO Fortran RHS against the Python Berton implementation at validation samples.
  • TASK-015: verified the log-mass full-4D Fortran RHS against Python at the TASK-011 seed:
  • fortran_python_transformed_rhs_max_abs_diff < 1e-12
  • transformed eigenvalues matched Python physical-coordinate eigenvalues.

So: the core Fortran RHS has been spot-checked and likely matches Python near the seed.

Show remaining 100 lines

What we have not fully verified

We have not yet done the most relevant checks for the current failure:

  1. Restricted/scaled TASK-017 Fortran residual vs Python residual off-seed
  • We checked the seed via Python, but I don’t think we independently compiled the restricted Fortran FUNC and compared it to Python at:

- seed,
- first AUTO predictor,
- modest W_a0 perturbations,
- known TASK-012 Python probe points.

  1. AUTO-supplied DFDU vs finite-difference Python/Fortran
  • This is crucial. A wrong Jacobian would exactly explain the Newton explosion.
  1. AUTO-supplied DFDP vs finite differences
  • Also crucial for the augmented continuation system.
  • Even if J_x has condition number 7, a wrong F_W_a0 column can wreck pseudo-arclength correction.
  1. PVLS ancillary diagnostics
  • We have sanity-used them, but I don’t think we have a systematic Fortran-vs-Python test for every PVLS diagnostic field.
  • Less likely to cause Newton failure unless those diagnostic PARs are included in ICP in a way AUTO treats as active.

Straightforward checks for #4 from my list

Yes. I’d do a direct Fortran-driver validation script. It should compile the AUTO Fortran file outside AUTO and call:

CALL STPNT(...)
CALL FUNC(..., IJAC=2, F, DFDU, DFDP)
CALL PVLS(...)

Then compare against Python.

Concrete checks:

1. Restricted residual check

Evaluate Fortran FUNC at:

  • seed: U=(0,0,0), W_a0=0.6
  • tiny predictor-like perturbation: e.g. W_a0=0.6003, U≈O(1e-3)
  • Python probe equilibria converted into restricted coordinates for W_a0=0.5, 0.7, 1.0

Expected:

  • Fortran residual equals Python restricted/scaled residual to tight tolerance.
  • At Python probe equilibria, residual should be near zero.
2. DFDU check

Compare Fortran-returned DFDU against centered finite differences of the Fortran FUNC itself.

This isolates whether our DFDU implementation is self-consistent.

3. DFDP check

Compare Fortran-returned DFDP(:, W_a0) against finite differences in PAR(2).

This is probably the most important check.

Expected:

  • DFDP(:,2) should match finite difference.
  • If it doesn’t, that explains AUTO’s immediate Newton blow-up.
4. ICP minimization check

Run a deliberately stripped AUTO config:

ICP = ['W_a0']
ISP = 0
JAC = 0

No diagnostic parameters. No PVLS parameters in ICP. Let AUTO finite-difference everything.

If that works, the problem is almost certainly in our Jacobian/DFDP/ICP/PVLS bookkeeping rather than the branch.

5. PVLS check

Call PVLS, then compare PAR(60:) against Python local diagnostics at the same physical state.

This is useful, but I’d rank it below FUNC/DFDU/DFDP.

One thing I now strongly suspect

Our ICP lists include many diagnostic/PVLS parameters:

ICP = ['W_a0', 'z_W0', 'H_a3', 'z_phys', 'u_phys', 'm_phys', ...]

That may be too clever. If AUTO treats those as continuation-active or derivative-relevant rather than mere output columns, we may be confusing the augmented system.

So the fastest diagnostic is:

Run the restricted problem with ICP = ['W_a0'], ISP=0, JAC=0.

If that succeeds, the physical branch is fine and our AUTO metadata/Jacobian setup is the bug.

User

OK, please add two backlog tasks, one to run the "fastest diagnostic", and one to do the more systematic checks above (1-5).

Assistant

Created two backlog tasks:

  • TASK-021 — Run minimal AUTO W_a0 diagnostic for restricted Berton branch
  • Fast stripped config: only W_a0 in ICP, no PVLS/diagnostic parameters, ISP=0, JAC=0 first.
  • TASK-022 — Validate restricted Berton AUTO Fortran residuals Jacobians and PVLS diagnostics
  • Systematic standalone Fortran-vs-Python checks for FUNC, DFDU, DFDP, and PVLS.

Both are high priority and linked to the relevant prior tasks.

User

OK, please commit the current changes. Do not close TASK-017, since we'll come back to it after looking at these validation tasks.

Assistant

Committed current changes.

Commits now include:

  • d73f569 — Add TASK-017 restricted W_a0 sanity check artifacts
  • Backlog CLI also created separate commits for:
  • TASK-021
  • TASK-022
  • TASK-017 updates

TASK-017 remains In Progress and is not closed.

User

Please write implementation plans for TASK-021 and TASK-022.

Assistant

Wrote implementation plans for both tasks and set them In Progress / assigned to @pi:

  • TASK-021 — plan focuses on the stripped minimal AUTO diagnostic (ICP=['W_a0'], ISP=0, JAC=0, no diagnostic/PVLS parameters).
  • TASK-022 — plan focuses on standalone Fortran-vs-Python validation of FUNC, DFDU, DFDP, and PVLS, using seed/off-seed/probe samples.

No implementation started yet.