Skip to content

Restore liberal Newton continuation outside SPECTRE#495

Closed
krystophny wants to merge 8 commits into
agent/nonfatal-recovery-accounting-cleanfrom
agent/liberal-generic-newton-clean
Closed

Restore liberal Newton continuation outside SPECTRE#495
krystophny wants to merge 8 commits into
agent/nonfatal-recovery-accounting-cleanfrom
agent/liberal-generic-newton-clean

Conversation

@krystophny

Copy link
Copy Markdown
Member

Restores the historical default warning behavior for generic SIMPLE paths while keeping the policy explicit per integrator.

  • generic and near-axis tracing accepts every finite max-iteration iterate
  • strict mode remains opt-in
  • SPECTRE accepts near-converged iterates but rejects gross corrections for recovery
  • focused generic and SPECTRE policy tests

Stacked on the recovery/accounting PR so concerns remain reviewable.

## Risk tier

- [ ] T0: docs, comments, small build metadata
- [ ] T1: pure refactor, no behavior change intended
- [ ] T2: local numerical logic
- [x] T3: physics, output behavior, coordinate convention
- [ ] T4: parallelism, GPU, dependency, CI, or security-sensitive build
logic

## Correctness contract

### Intended behavior change

Add a side-effect-free Fortran API and a Python API that compute
canonical bounce/transit and mean toroidal angular frequencies for
trapped and passing guiding-centre orbits. Support one or multiple
completed poloidal cycles, return cycle spreads and explicit status
metadata, and expose interpolated tip/toroidal cut tracing through
Python.

### Behavior that must not change

Existing orbit tracing, classification, NetCDF output, and golden-record
results are unchanged. The core frequency routine copies the caller's
tracer and does no file I/O.

### Coordinate / unit conventions

The source-level Fortran routine accepts SIMPLE integration coordinates.
The flat/Python boundary accepts `[s, theta, phi, v/v0, lambda]` in
public reference coordinates and performs `ref_to_integ`. Angles and
displacements are radians, periods are seconds, and frequencies are
angular frequencies in rad/s. `omega_b` is positive; `omega_phi` is
signed.

### Numerical invariants

Trapped periods use successive negative-to-positive parallel-velocity
crossings. Passing periods use successive signed `2*pi` advances of
unwrapped poloidal angle. Event time and toroidal displacement are
interpolated within the crossing step. Multi-cycle results report means
and sample standard deviations.

## Tests added

- unit: Fortran invalid-option status and Python argument validation
- integration: native trapped/passing, three-cycle frequency computation
- system: Python trapped multi-cycle frequency and interpolated tip-cut
APIs
- golden record: unchanged

## Golden-record impact

- [x] unchanged
- [ ] changed

## Failure modes considered

Invalid options, orbit loss, integrator errors, and maximum-step
exhaustion return distinct statuses. Unknown orbit class remains
explicit. The cut wrapper rejects unsupported cut types and
non-symplectic integration.

## Manual validation

Validated trapped and passing VMEC seeds through the native API;
validated the Python frequency and cut interfaces against the compiled
f90wrap backend.

## Verification

- `make test TEST=^test_orbit_frequencies$ CONFIG=Fast VERBOSE=0`
- `make test TEST=^test_simple_api$ CONFIG=Fast VERBOSE=0` (24 API cases
pass)
- Full non-regression suite: 75/76 targets pass after installing the
optional plotting dependency. The remaining `test_orbit_macro` failure
is pre-existing: it accesses `pysimple._backend`, which current `main`
does not export.
- `git diff --check`
## Summary

- add the explicit target-order dependency required when
`diag_albert.f90` consumes `pyplot_module.mod` from the separate
`pyplot` target
- prevent clean parallel Ninja builds from compiling `diag_albert`
before the module file exists

## Evidence

The CGAL wall CI job on PR #499 failed in a clean parallel build with:

```
Fatal Error: Cannot open module file ‘pyplot_module.mod’
```

The existing link edge orders final linking but did not reliably order
compilation across targets. This PR adds no source or runtime behavior
change.

## Validation

- clean `fo build` passed
- `fo` passed all stages in 308.3 s
@krystophny

Copy link
Copy Markdown
Member Author

Closing after critical review: the generic accept_unbounded_newton_warning policy accepts arbitrarily large finite Newton iterates (the test explicitly uses huge()), and the Albert golden case then produces many false/invalid boundary outcomes with enormous or non-finite final radial coordinates. The dependent utility fixes are being restacked without this policy; the bounded recovery path remains in #494/#499.

@krystophny krystophny closed this Jul 17, 2026
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.

1 participant