Skip to content

Exit the pTg Newton iteration when its line search cannot reduce the residual - #2096

Closed
aliencaocao wants to merge 1 commit into
MFlowCode:masterfrom
aliencaocao:fix/ptg-stall
Closed

aliencaocao wants to merge 1 commit into
MFlowCode:masterfrom
aliencaocao:fix/ptg-stall

Conversation

@aliencaocao

@aliencaocao aliencaocao commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

please ignore this PR - i will open a new one once I have visualization on the result to prove correctness.

A cell whose equilibrium is single phase has no two-phase root. Its line search fails all 30 halvings on every iteration, and the loop runs to max_iter = 100000. On the GPU one stalled thread holds its whole block, which makes the relaxation extremely long and appears hang. With the analytic Jacobian the Newton step is a descent direction, so a line search that no halving improves means the bound blocked the step or the residual is at round-off. Further iterations do not converge in either case. All 18 phase-change golden cases are unchanged.

A 1D phase-change example runs 3.97 s to 0.146 s per pass on one H200.

Addresses the latch observed in #1927

…residual

A cell whose equilibrium is single phase has no two-phase root. Its line
search fails all 30 halvings on every iteration, and the loop runs to
max_iter = 100000. On the GPU one stalled thread holds its whole block,
which makes the relaxation the entire run time. With the analytic Jacobian
the Newton step is a descent direction, so a line search that no halving
improves means the bound blocked the step or the residual is at round-off.
Further iterations do not converge in either case. All 18 phase-change
golden cases are unchanged.

A 1D phase-change example runs 3.97 s to 0.146 s per pass on one H200.
@aliencaocao
aliencaocao requested a review from a team as a code owner October 20, 2026 15:18
@aliencaocao
aliencaocao requested review from sbryngelson and removed request for a team October 20, 2026 15:18
@aliencaocao
aliencaocao marked this pull request as draft October 20, 2026 15:19
@github-actions

Copy link
Copy Markdown

Lines of Code

File Lines Diff
src/common/m_phase_change.fpp 288 +3
Directory Lines Diff
common 10529 +3
total 47593 +3

@github-actions

Copy link
Copy Markdown

Claude Code Review

Head SHA: 361acd6

Files changed:

  • 1
  • src/common/m_phase_change.fpp

Findings:

  • high src/common/m_phase_change.fpp: The new line_search_gained flag is set but never acted on, and the comment "A step that cannot lower the residual ends the iteration at the accepted state" contradicts the code. The Newton loop has no if (.not. line_search_gained) exit after the trial state is accepted. When the last backtrack (ls == ptg_ls_max) exits without a decrease, the code still takes the worse state (resnorm = resnorm_try) and continues iterating. That can raise the residual, and each iteration then spends ptg_ls_max more residual evaluations to no effect. Fix: either (a) restore the best state and exit when .not. line_search_gained. Because TS, mCP, mQ and the other outputs were overwritten by the last trial call, this means keeping the previous state or recomputing the residual at the old (ml, pS) before the exit. Or (b) accept the trial state and exit if you want the stated behavior. Alternatively, remove the flag and the comment. I am confident the flag is dead code and the comment is wrong. Which fix is intended is a judgement call.

@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.89%. Comparing base (3ef5e1e) to head (361acd6).

Files with missing lines Patch % Lines
src/common/m_phase_change.fpp 33.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2096      +/-   ##
==========================================
- Coverage   61.89%   61.89%   -0.01%     
==========================================
  Files          86       86              
  Lines       22888    22890       +2     
  Branches     3372     3372              
==========================================
+ Hits        14166    14167       +1     
- Misses       6220     6221       +1     
  Partials     2502     2502              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant