Skip to content

Add ifail enum#4275

Open
chris-ashe wants to merge 7 commits into
mainfrom
add_ifail_enum
Open

Add ifail enum#4275
chris-ashe wants to merge 7 commits into
mainfrom
add_ifail_enum

Conversation

@chris-ashe

Copy link
Copy Markdown
Collaborator

Description

Checklist

I confirm that I have completed the following checks:

  • My changes follow the PROCESS style guide
  • I have justified any large differences in the regression tests caused by this pull request in the comments.
  • I have added new tests where appropriate for the changes I have made.
  • If I have had to change any existing unit or integration tests, I have justified this change in the pull request comments.
  • If I have made documentation changes, I have checked they render correctly.
  • I have added documentation for my change, if appropriate.

@chris-ashe chris-ashe added Convergence Solver or convergence-related problems Refactor labels May 27, 2026
@codecov-commenter

codecov-commenter commented May 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 41.66667% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.65%. Comparing base (616f749) to head (0f3cc80).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
process/core/scan.py 9.09% 10 Missing ⚠️
process/core/io/vary_run/tools.py 25.00% 3 Missing ⚠️
process/core/solver/solver_handler.py 25.00% 3 Missing ⚠️
process/core/io/plot/scans.py 33.33% 2 Missing ⚠️
process/core/io/vary_run/config.py 33.33% 2 Missing ⚠️
process/core/final.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4275      +/-   ##
==========================================
+ Coverage   48.63%   48.65%   +0.02%     
==========================================
  Files         151      151              
  Lines       29673    29686      +13     
==========================================
+ Hits        14432    14445      +13     
  Misses      15241    15241              

☔ 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.

@chris-ashe
chris-ashe marked this pull request as ready for review June 2, 2026 13:45
@chris-ashe
chris-ashe requested a review from a team as a code owner June 2, 2026 13:45
Copilot AI review requested due to automatic review settings June 2, 2026 13:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a typed IntEnum for solver ifail exit conditions (SolverOutputCondition) and updates several runtime and test call sites to use the enum instead of hard-coded numeric values, improving readability and consistency around solver status handling.

Changes:

  • Added SolverOutputCondition enum to centralize solver output (ifail) codes.
  • Replaced ifail == 1 / ifail != 1 checks with SolverOutputCondition.CONVERGED in core, tracking, and vary-run utilities.
  • Updated regression/integration tests to assert against the enum values.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tracking/tracking_data.py Uses SolverOutputCondition.CONVERGED for strict convergence checks when reading MFILEs.
tests/regression/test_process_input_files.py Updates regression assertion to use SolverOutputCondition.CONVERGED.
tests/integration/test_vmcon.py Replaces numeric ifail expectations with enum values.
process/data_structure/numerics.py Adds the new SolverOutputCondition IntEnum definition.
process/core/solver/solver_handler.py Uses enum values in VMCON retry logic and imports the enum.
process/core/scan.py Uses enum values in optimisation/solver status reporting and VMCON error handling.
process/core/io/vary_run/tools.py Uses enum values when determining feasibility/convergence from MFILE contents.
process/core/io/vary_run/config.py Uses enum values to report convergence status and generate README status messages.
process/core/final.py Uses enum value for final feasible/unfeasible output header selection.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread process/core/solver/solver_handler.py Outdated
Comment on lines 73 to 74
@@ -73,7 +74,7 @@ def run(self):
# to next attempt
Comment on lines +6 to +9
class SolverOutputCondition(IntEnum):
"""Enum for the possible conditions that can be returned by the solvers.
This is for the `ifail` condition
"""
Comment thread process/data_structure/numerics.py Outdated
Comment on lines +13 to +32
IMPROPER_INPUT = 0
"""Solver failed due to improper input (e.g. invalid parameters, or failure to
satisfy solver preconditions)"""
CONVERGED = 1
"""Solver converged successfully"""

MAX_ITERATIONS = 2
"""Solver failed to converge within the maximum number of iterations"""

MAX_LINE_SEARCHES = 3
"""Line search required 10 function calls without finding a better solution"""

UPHILL_SEARCH = 4
"""Uphill search direction was calculated"""

NO_SOLUTION = 5
"""No feasible solution or bad approximation of Hessian"""

SINGLE_MATRIX_OR_BOUNDS = 6
"""Singular matrix in quadratic subproblem or restriction by artificial bounds"""
@clmould clmould self-assigned this Jun 5, 2026

@clmould clmould left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some docs points:

Can the SolverOutputCondition enum be included in the vmcon page in the docs, eg something like

  • a brief sentence to say that the ifail values are now contained in this enum
  • an extra column in the ifail table to link the ifail values to the enum

Also the troubleshooting docs page mentions ifail = 3 - think it'd be worth adding a reference to the the enum for this value and adding a brief description of what this means here

Comment thread process/core/scan.py
)
process_output.oblnkl(constants.IOTTY)

logger.critical("Solver returns with ifail /= 1. %s", ifail)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the SolverOutputCondition also be incorporated into this error message as it would make the message more descriptive for a user to see

Comment thread process/data_structure/numerics.py
Comment thread process/data_structure/numerics.py Outdated
Comment thread process/core/solver/solver_handler.py
Comment thread process/data_structure/numerics.py
Comment thread process/data_structure/numerics.py
Comment thread process/data_structure/numerics.py Outdated
Comment on lines +24 to +28
MAX_LINE_SEARCHES = 3
"""Line search required 10 function calls without finding a better solution"""

UPHILL_SEARCH = 4
"""Uphill search direction was calculated"""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth noting that these are solver specific and won't always be raised (e.g. using fsolve or some custom solver)

@chris-ashe
chris-ashe requested a review from clmould July 9, 2026 14:18

@timothy-nunn timothy-nunn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. This method should be typed to return the enum

    def solve(self) -> int:

  2. The same with the VMCON solve method. I would then also update the setting of self.info in this method to use the enum:

    def solve(self) -> int:

  3. You can probably remove all references to UPHILL_SEARCH because it is not used anymore as far as I can tell

"""

USER_TERMINATED = -1
# Solver was terminated by the user (e.g. via a keyboard interrupt)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make these comments into docstrings so that they show up in the docs/IDE

# Uphill search direction was calculated

NO_SOLUTION = 5
# No feasible solution or bad approximation of Hessian

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# No feasible solution or bad approximation of Hessian
# No feasible solution or bad approximation of Hessian (in VMCON only).

Solvers that don't approximate the Hessian will only raise a 5 for no solution

Comment on lines +31 to +32
MAX_LINE_SEARCHES = 3
# Line search required 10 function calls without finding a better solution

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is solver specific, most solvers do not have an integrated line search

c1(x1,x2) = x1 + x2 - 3 = 0
c2(x1,x2) = -x1**2/4 - x2**2 + 1 >= 0

Note that this test is supposed to fail with ifail=5

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Note that this test is supposed to fail with ifail=SolverOutputCondition.NO_SOLUTION (ifail = 5)


<a name="table-1"></a>

| `ifail` | Description | Meaning | Recommendation |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this have a separate column for the SolverOutputCondition please? Otherwise the words are rendering across multiple lines so a new column would be easier to read:
Image

Comment thread process/core/scan.py
)
process_output.oblnkl(constants.IOTTY)

logger.critical("Solver returns with ifail /= 1. %s", ifail)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this message also incorporate the SolverOutputCondition please

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

Labels

Convergence Solver or convergence-related problems Refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants