Skip to content

Conversation

ChrisRackauckas-Claude
Copy link

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Oct 8, 2025

Summary

Fixes #712

This PR adds a clear error message when users attempt to use the iterator interface (init/step!) with Simple algorithms from SimpleNonlinearSolve.jl.

Problem

Previously, when users tried to use Simple algorithms with the iterator interface, they received a confusing error about a missing force_stop field. This made it unclear what the actual problem was.

Solution

Added an override of SciMLBase.init() for AbstractSimpleNonlinearSolveAlgorithm that throws a descriptive error message explaining:

  • Simple algorithms don't support the iterator interface
  • The iterator interface is only available for full-featured algorithms from NonlinearSolve.jl
  • Users should either use algorithms like NewtonRaphson(), TrustRegion(), etc., or use solve(prob, alg) directly

Changes

  • lib/SimpleNonlinearSolve/src/SimpleNonlinearSolve.jl: Added SciMLBase.init() override with clear error message (lines 127-148)
  • lib/SimpleNonlinearSolve/test/core/iterator_interface_tests.jl: Added tests to verify error behavior using @test_throws pattern

Testing

The test file uses the @testitem macro with tags=[:core], which means it's automatically discovered and run by @run_package_tests in runtests.jl.

All Simple algorithms tested:

  • ✅ SimpleNewtonRaphson
  • ✅ SimpleBroyden
  • ✅ SimpleTrustRegion
  • ✅ SimpleDFSane
  • ✅ SimpleKlement
  • ✅ SimpleLimitedMemoryBroyden

Tests verify:

  • Error is thrown when calling init(prob, alg) using @test_throws
  • Error message contains helpful guidance (checked via err.value)
  • solve(prob, alg) still works correctly

Example Error Message

julia> init(prob, SimpleNewtonRaphson())
ERROR: The Simple algorithms from SimpleNonlinearSolve.jl do not support the iterator interface (init/step!).

The iterator interface is only available for the full-featured algorithms from NonlinearSolve.jl.

If you need the iterator interface, please use one of the following algorithms instead:
- NewtonRaphson()
- TrustRegion()
- LevenbergMarquardt()
- And other algorithms from NonlinearSolve.jl

If you want to solve the problem directly, use `solve(prob, alg)` instead of `init(prob, alg)`.

Algorithm attempted: SimpleNewtonRaphson{Nothing}

Test Plan

Run the core tests:

julia --project=lib/SimpleNonlinearSolve -e 'using Pkg; Pkg.test(test_args=["GROUP=core"])'

🤖 Generated with Claude Code

ChrisRackauckas and others added 2 commits October 8, 2025 06:05
This commit addresses issue SciML#712 by adding a clear error message when users
attempt to use the iterator interface (init/step!) with Simple algorithms
from SimpleNonlinearSolve.jl.

Previously, users would get a confusing error about a missing 'force_stop'
field when trying to use Simple algorithms with the iterator interface.
Now they receive a helpful error message explaining that:
- Simple algorithms don't support the iterator interface
- They should use full-featured algorithms from NonlinearSolve.jl instead
- They can use solve(prob, alg) if they just want to solve the problem

Changes:
- Added SciMLBase.init override for AbstractSimpleNonlinearSolveAlgorithm
  that throws a descriptive error message
- Added test file to verify error message works correctly
- All Simple algorithms (SimpleNewtonRaphson, SimpleBroyden, SimpleTrustRegion,
  SimpleDFSane, SimpleKlement, SimpleLimitedMemoryBroyden) are covered

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Replaced try-catch blocks with @test_throws pattern
- Simplified error message verification by using err.value
- Test is automatically discovered by @run_package_tests in runtests.jl

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@ChrisRackauckas-Claude
Copy link
Author

Updated the test to use @test_throws pattern instead of try-catch blocks, as requested. The test is automatically discovered by @run_package_tests in runtests.jl via the @testitem macro with tags=[:core].

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.

Proper error message for "Simple" implementations

2 participants