Skip to content

Develop#67

Merged
ocots merged 244 commits intomainfrom
develop
Mar 6, 2026
Merged

Develop#67
ocots merged 244 commits intomainfrom
develop

Conversation

@ocots
Copy link
Member

@ocots ocots commented Feb 11, 2026

No description provided.

ocots added 30 commits January 19, 2026 16:09
…ualify AbstractOptimizationSolver references
- Implement AbstractStrategy contract with type-level and instance-level methods
- Add StrategyMetadata for option specifications with validation
- Create StrategyRegistry for explicit dependency management
- Provide strategy builders and configuration utilities
- Include introspection API for metadata and option access
- Add comprehensive test suite (423 tests passing)
- Follow CTModels.jl patterns for consistency

Features:
- Two-level contract (type metadata + instance configuration)
- Immutable registry pattern for strategy lookup
- Option provenance tracking (user/default/computed)
- Alias resolution and suggestion utilities
- Full validation pipeline with detailed error messages
- Implement smart option routing with disambiguation support
- Add strategy-to-family mapping and option ownership detection
- Provide method-based strategy builders and introspection wrappers
- Support single and multi-strategy disambiguation syntax
- Include comprehensive test suite (79 tests passing)

Features:
- route_all_options() - main routing function with auto-routing
- extract_strategy_ids() - disambiguation syntax detection
- build_strategy_to_family_map() - strategy family mapping
- build_option_ownership_map() - option ownership detection
- build_strategy_from_method() - convenience strategy builders
- Detailed error messages with actionable suggestions

Disambiguation syntax:
- Single: backend = (:sparse, :adnlp)
- Multi: backend = ((:sparse, :adnlp), (:cpu, :ipopt))
- Auto-routing for unambiguous options
- Implement AbstractOptimizationProblem contract with builder interface
- Add concrete builder types for ADNLPModels and ExaModels backends
- Provide model and solution building functions (build_model, build_solution)
- Include solver info extraction utilities (extract_solver_infos)
- Add comprehensive test suite (139 tests passing)
- Update MadNLP extension with solver info extraction
- Migrate test problems from CTModels to CTSolvers

Features:
- AbstractOptimizationProblem contract with 4 required builder methods
- ADNLPModelBuilder and ExaModelBuilder callable builders
- ADNLPSolutionBuilder and ExaSolutionBuilder for solution conversion
- Type-stable builder patterns with proper error handling
- Integration with real test problems (Rosenbrock, Elec, etc.)
- Support for different numeric types (Float32, Float64)

Contract methods:
- get_adnlp_model_builder() / get_exa_model_builder()
- get_adnlp_solution_builder() / get_exa_solution_builder()
- build_model() / build_solution() for generic workflows
- extract_solver_infos() for standardized solver metadata
- Implement AbstractOptimizationModeler extending AbstractStrategy
- Add ADNLPModeler with comprehensive options and validation
- Add ExaModeler with type and backend flexibility
- Include robust validation functions and comprehensive tests (106 passing)

Features:
- ADNLPModeler: show_time, backend, matrix_free, name options
- Advanced backend overrides for expert users
- ExaModeler: base_type, backend options with KernelAbstractions support
- Full integration with Strategies and Options modules
- Generic option passing to backend builders
- Implement DiscretizedOptimalControlProblem type extending AbstractOptimizationProblem
- Provide contract implementation with ADNLP and ExaModel builders
- Include accessors for OCP model retrieval (ocp_model)
- Add convenient building functions (nlp_model, ocp_solution)
- Include comprehensive test suite (48 tests passing)

Features:
- DiscretizedOptimalControlProblem type with builder storage
- Full AbstractOptimizationProblem contract implementation
- Integration with CTModels.OCP.AbstractOptimalControlProblem
- Convenient API for model and solution building
- Type-safe accessors and builders
- Complete workflow testing with both backends

Contract methods:
- get_adnlp_model_builder() / get_exa_model_builder()
- get_adnlp_solution_builder() / get_exa_solution_builder()
- nlp_model() / ocp_solution() for convenient workflows
- ocp_model() for accessing original OCP
- Update end-to-end tests to use CTSolvers modules instead of CTModels
- Fix imports: CTModels.Optimization → CTSolvers.Optimization
- Fix imports: CTModels.DOCP → CTSolvers.DOCP
- Fix modeler references: CTModels.ADNLPModeler → Modelers.ADNLPModeler
- Fix modeler references: CTModels.ExaModeler → Modelers.ExaModeler
- Remove broken MadNLP extension tests (32 tests now passing)
- Add comprehensive end-to-end integration tests

Changes:
- test/suite/integration/test_end_to_end.jl: Updated for CTSolvers
- test/suite/extensions/: Cleaned up and fixed test structure
- All references now point to correct CTSolvers modules
- Modelers namespace properly qualified
- Integration tests verify complete workflows
- Fix Modelers namespace qualification in integration tests
- Ensure all modeler references use correct CTSolvers.Modelers module
- Update test structure for complete workflow verification
Phase A: Enriched exceptions
- Replace error() with Exceptions.IncorrectArgument in all solver validators
- Add detailed context to ExtensionError in solver stubs
- Update tests to expect new exception types

Phase B: DocStringExtensions
- Add  and  to all solver types
- Enhance documentation with structured sections and examples
- Document AbstractStrategy contracts and implementation notes

Phase C: Type stability
- Add comprehensive type stability tests (34 tests)
- Test @inferred for critical functions
- Verify type-stable solver construction and contract methods

All tests pass: 1112/1112
Production-ready code with full architectural compliance
- Add validator for linear_solver option with all 10 supported solvers
- Update docstring with detailed solver descriptions
- Include enriched exception messages with suggestions
- Reference Ipopt documentation for solver options

Supported solvers: ma27, ma57, ma77, ma86, ma97, pardiso, pardisomkl, spral, wsmp, mumps
- Add 3 new output options: print_timing_statistics, print_frequency_iter, print_frequency_time
- Enhanced validation with detailed error messages and usage suggestions
- Update docstring with structured Output Options section
- Maintain backward compatibility with existing options

New output options provide fine-grained control over solver verbosity
and timing information, following Ipopt documentation standards.

Note: Remember to add timing_statistics option for complete timing control.
- Add timing_statistics option in Algorithm Options section
- Enable measurement of time spent in Ipopt and NLP evaluation components
- Overall algorithm time remains unaffected by this option
- Add enriched validation with detailed error messages
- Update docstring with complete Algorithm Options documentation

Completes the timing control suite alongside print_timing_statistics option.
- Fix option names: max_iter→maxit, tol→feastol_abs+opttol_abs, outlev→print_level
- Add proper aliases for backward compatibility (max_iter, maxiter, outlev)
- Update docstring with correct option names and descriptions
- Fix examples to use correct option names
- Maintain enriched validation with detailed error messages

Options now correctly match the NLPModelsKnitro extension interface:
- maxit (max_iter, maxiter): Maximum iterations
- feastol_abs: Absolute feasibility tolerance
- opttol_abs: Absolute optimality tolerance
- print_level (outlev): Output verbosity level
- Add 7 termination options: maxit, maxtime, maxfevals, feastol_abs, opttol_abs, ftol, xtol
- Add 1 algorithm option: soltype for solution type selection
- Fix outlev option: correct name from print_level, update default to 2, and add range validation (0-6)
- Update docstring with detailed option descriptions based on Knitro documentation
- Organize options in clear sections: Termination, Algorithm, Output
- Maintain enriched validation with detailed error messages and suggestions

KnitroSolver now provides comprehensive control over:
- 7 termination options for convergence criteria
- Algorithm selection for solution type
- 6-level output verbosity control (0=no output to 6=all details)

All options follow Knitro documentation standards with proper validation.
- Source file now contains only: struct, Strategies.id(), tag dispatch stubs
- Extension contains: metadata with all options, constructor, callable interface
- Tag dispatch pattern: IpoptTag for clean separation
- Display handling in extension: print_level=0 when display=false
- All 13 Ipopt options with validation moved to extension

This follows the new architecture where sources have only abstract contracts
and extensions provide complete implementation.
- Source file now contains only: struct, Strategies.id(), tag dispatch stubs
- Removed all metadata (will be moved to extension)
- Added KnitroTag for tag dispatch pattern
- Constructor, callable, and metadata stubs throw ExtensionError

Next: Need to complete CTSolversKnitro extension with metadata and callable
- Extension now contains all 9 Knitro options with validation
- Termination: maxit, maxtime, maxfevals, feastol_abs, opttol_abs, ftol, xtol
- Algorithm: soltype
- Output: outlev (alias print_level)
- Constructor via tag dispatch: build_knitro_solver
- Callable with display handling: outlev=0 when display=false
- Backend interface: solve_with_knitro

KnitroSolver refactoring complete: source has only stubs, extension has full implementation
- Removed complex tag dispatch system for types/defaults
- Source file now contains only: struct, Strategies.id(), tag dispatch stubs
- Removed all metadata (will be moved to extension)
- Added MadNLPTag for tag dispatch pattern
- Constructor, callable, and metadata stubs throw ExtensionError

Next: Complete CTSolversMadNLP extension with proper options from old ext
- Extension now contains 4 MadNLP options from old extension
- max_iter (default: 3000), tol (default: 1e-8)
- print_level (MadNLP.LogLevels, default: MadNLP.INFO)
- linear_solver (Type{<:MadNLP.AbstractLinearSolver}, default: MadNLPMumps.MumpsSolver)
- Constructor via tag dispatch: build_madnlp_solver
- Callable with display handling: print_level=MadNLP.ERROR when display=false
- Backend interface: solve_with_madnlp
- Kept extract_solver_infos for MadNLP statistics

MadNLPSolver refactoring complete: source has only stubs, extension has full implementation
- Improved ExtensionError messages in all build_*_solver stubs
- Messages now clearly state: 'to create Solver, access options, and solve problems'
- Added explicit context: 'Load Extension first: using Package'
- Removed unnecessary callable and backend function stubs
- Removed unnecessary Strategies.metadata stubs (extension defines it directly)
- Simplified MadNCLSolver source file with tag dispatch pattern

All 4 solver source files now have clean, minimal stubs with helpful error messages
- Extension now contains 5 MadNCL options from old extension
- max_iter (default: 3000), tol (default: 1e-8)
- print_level (MadNLP.LogLevels, default: MadNLP.INFO)
- linear_solver (Type{<:MadNLP.AbstractLinearSolver}, default: MadNLPMumps.MumpsSolver)
- ncl_options (MadNCL.NCLOptions, default: NCLOptions with verbose=true, opt_tol=1e-8, feas_tol=1e-8)
- Constructor via tag dispatch: build_madncl_solver
- Callable with special display handling:
  * print_level=MadNLP.ERROR when display=false
  * ncl_options.verbose=false when display=false (reconstructs NCLOptions)
- Backend interface: solve_with_madncl

MadNCLSolver refactoring complete: source has only stubs, extension has full implementation
ALL 4 SOLVERS NOW REFACTORED: Ipopt, Knitro, MadNLP, MadNCL
- Remove obsolete migration_to_ctsolvers directory and files
- Clean up solver extension stubs
- Reorganize test problems and remove unused solution examples
- Update MadNLP solver info extraction tests
- Move old resources to archive directory
…ve API)

- test_solver_types.jl: Type hierarchy and Strategies.id() contracts (39 tests)
- test_extension_stubs.jl: ExtensionError stubs with concrete tags (24 tests)
- test_common_solve_api.jl: CommonSolve API with FakeSolver (19 tests)

All 82 tests pass. Structure follows testing rules with modules and qualification.
ocots added 27 commits March 4, 2026 14:09
…d extensions

- Harmonize file headers and section comments to English-only, consistent style
- Align all # Throws sections to CTBase.Exceptions.* (ExtensionError, NotImplemented)
- Convert all examples to conceptual style (remove line-by-line # comments)
- Add See also cross-references to main docstrings
- Correct factual errors in extract_solver_infos docstrings (objective sign, status codes)
- Add missing docstrings (_default_parameter functions)
- Ensure all docstrings follow docstrings.md standards

Files modified:
- src/Solvers/{abstract_solver.jl, Solvers.jl, common_solve_api.jl, ipopt.jl, madnlp.jl, madncl.jl, knitro.jl}
- ext/{CTSolversIpopt.jl, CTSolversMadNLP.jl, CTSolversMadNCL.jl, CTSolversKnitro.jl}
- Add test_helpers.jl to test extension helper functions
- Test base_type() extraction for MadNCL NCLOptions
- Test __madncl_default_linear_solver() for CPU/GPU
- Test __madnlp_default_linear_solver() for CPU/GPU
- Test ExtensionError when MadNLPGPU not loaded
- Test type stability of helper functions

Bug fixes:
- Remove unsupported 'suggestion' parameter from ExtensionError calls in MadNLP/MadNCL helpers
- ExtensionError only supports: message, feature, context (not suggestion)

All tests pass (9/9)
…onError

- Remove 'suggestion' parameter from __get_cuda_backend() ExtensionError call
- ExtensionError only supports: message, feature, context (not suggestion)
- Add unit test for __get_cuda_backend() ExtensionError path

Test coverage:
- Test ExtensionError when CUDA not loaded
- Skip functional test when CUDA is loaded (requires CUDA.functional())

All tests pass (13/13)
- Fix architecture.md: clarify AbstractDiscretizer is external (CTDirect.jl)
- Add Solvers.MadNCL to index.md module list
- Create comprehensive Strategy Parameters guide (CPU/GPU specialization)
- Add strategy parameters section to architecture.md with Mermaid diagram
- Update documentation build system to include new guide
- Add missing files to API reference (orchestration/builders.jl, strategies/contract/parameters.jl, strategies/api/bypass.jl)

This resolves documentation inconsistencies and introduces the previously undocumented
strategy parameters system for type-based specialization of strategy behavior.
- Make fallback _supported_parameters and _default_parameter throw NotImplemented
- Add comprehensive docstrings to all strategy parameter overloads
- Add parameter validation in stub metadata functions before ExtensionError
- Disallow non-parameterized strategies with IncorrectArgument
- Fix all tests to use Strategies._default_parameter and Strategies._supported_parameters
- Add comprehensive tests for parameter contract enforcement
- Ensure 100% test pass rate (3078/3078 tests)

All tests now pass with proper contract enforcement:
- Parameterized strategies must explicitly implement the contract
- Non-parameterized strategies are properly rejected
- Clear error messages guide users to correct implementation
- Full API documentation for all parameter-related functions
- Change KernelAbstractions.CUDABackend() to CUDA.CUDABackend()
- Update docstring to reflect correct CUDA module usage
- Ensure proper CUDA backend access for GPU execution
- Update version number for strategy parameter contract implementation
- Ready for merge into develop branch
- Document strategy parameter contract enforcement breaking changes
- Add comprehensive migration guide for parameterization
- Include examples for CPU/GPU specialization
- Document fallback method removal and new error messages
- Add benefits section explaining type safety and extensibility
Replace runtime validation using _supported_parameters() and
validate_supported_parameter() with compile-time type constraints
directly in struct definitions.

Changes:
- Update struct definitions to use specific type constraints:
  * CPU-only strategies: P<:CPU (ADNLP, Ipopt, Knitro)
  * CPU+GPU strategies: P<:Union{CPU, GPU} (Exa, MadNLP, MadNCL)
- Remove _supported_parameters() and validate_supported_parameter() functions
- Remove validation calls from constructors and metadata() functions
- Update extensions to remove validation calls
- Update tests to expect TypeError instead of IncorrectArgument
- Remove tests for deleted validation functions

Benefits:
- ~150 lines of code removed
- Earlier error detection (compile-time vs runtime)
- Simpler and more robust validation mechanism
- Clearer intent with type constraints visible in struct definitions

All 2895 tests pass successfully.
Simplify parameter validation with compile-time type constraints
- Re-enable 5 GPU tests for Max1MinusX2 across MadNLP and MadNCL extensions
- Tests were previously disabled due to ExaModels GPU maximization bug
- Now that GPU maximization is properly supported, activate all test variants:
  * MadNLP: CommonSolve, solve_with_madnlp, and Initial Guess tests
  * MadNCL: CommonSolve and solve_with_madncl tests
- Tests will only run when CUDA is functional via is_cuda_on() check
- Replace isdefined(Main, :CUDA) checks with proper method dispatch
- Add __get_cuda_backend(::Type{<:GPU}) stub in src/Modelers/exa.jl
- Add __consistent_backend() function with default implementation
- Create CTSolversCUDA extension with GPU-specific overrides
- Update Project.toml with CUDA weakdeps and extensions
- Add comprehensive @test_logs tests for consistency warnings
- Use proper dispatch on types (CPU/GPU + backend types)

This resolves the issue where consistency checks failed in tests due to
packages being imported in test modules rather than Main.
- Replace runtime isdefined() checks with Julia multiple dispatch
- Add prefixed stub functions: __madnlp_* and __madncl_*
- Implement type-specific consistency validators for CPU/GPU combinations
- Update CTSolversMadNLPGPU extension with GPU-specific overrides
- Add comprehensive tests with @test_logs for warning capture
- Include type stability tests with @inferred
- Test actual linear solver defaults and validation behavior

This completes the refactor of consistency checks for both MadNLP and MadNCL
solvers, following the same dispatch-based pattern as Exa modeler.
- Create madnlpsuite.jl with shared __madnlp_suite_* functions
- Remove duplicate functions from madnlp.jl and madncl.jl
- Eliminate redundant validators in CTSolversMadNCL.jl (inherited from MadNLP)
- Simplify CTSolversMadNLPGPU.jl by removing MadNLP/MadNCL duplication
- Update all references to use unified __madnlp_suite_* functions
- Reduce codebase by ~200 lines while maintaining all functionality
- All 34 tests continue to pass with clean dispatch-based validation

This creates a much cleaner architecture where MadNCL naturally inherits
MadNLP functionality through shared suite functions, eliminating the need
for separate prefixed implementations.
- Update test_helpers.jl to import CTSolvers.Solvers
- Replace CTSolversMadNLP.__madnlp_suite_* with Solvers.__madnlp_suite_*
- Fix all extension helper tests to access functions from correct module
- All 9 test_helpers tests now pass (was 3 passed, 2 failed, 3 errored)
- All 34 madnlp_gpu_linear_solver tests continue to pass

This resolves the UndefVarError issues caused by incorrect module references
after the architectural simplification with shared suite functions.
Enable GPU tests for Max1MinusX2 maximization problem
- Update version after completing MadNLP/MadNCL refactor
- Includes dispatch-based consistency checks and architectural simplification
- All tests passing with shared suite functions
@ocots ocots marked this pull request as ready for review March 6, 2026 07:51
@ocots ocots merged commit 34eb2d0 into main Mar 6, 2026
17 checks passed
@ocots ocots deleted the develop branch March 6, 2026 07:51
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