Skip to content

Conversation

ChrisRackauckas-Claude
Copy link

Summary

This PR moves SparseMatrixColorings from a direct dependency to a weak dependency in NonlinearSolve.jl, reducing the dependency footprint for users who don't need sparse automatic differentiation support.

Motivation

  • SparseArrays is already a weakdep (only used in the PETSc extension)
  • SparseMatrixColorings was only imported for re-export purposes to support sparse AD
  • The actual implementation is in NonlinearSolveBase where it's already a weakdep with an extension
  • Many users don't need sparse AD support and shouldn't have to load these dependencies

Changes

  • Moved SparseMatrixColorings from [deps] to [weakdeps] in Project.toml
  • Removed the using SparseMatrixColorings: SparseMatrixColorings import from src/NonlinearSolve.jl
  • Added SparseMatrixColorings to test extras to ensure tests can still use it when needed

Impact

  • Breaking change: No, this is non-breaking. Users who need sparse AD support just need to explicitly using SparseMatrixColorings before using sparse AD features
  • Performance: Reduces load time and memory usage for users who don't need sparse support
  • Functionality: All functionality remains available - the extension in NonlinearSolveBase will activate when SparseMatrixColorings is loaded

Testing

  • Package loads successfully without SparseMatrixColorings
  • Extension properly activates when SparseMatrixColorings is loaded
  • Tests can still access SparseMatrixColorings functionality

This follows the same pattern already established with SparseArrays being a weakdep.

🤖 Generated with Claude Code

@ChrisRackauckas-Claude ChrisRackauckas-Claude force-pushed the sparsematrixcolorings-extension branch from 797e0a6 to 42d183e Compare August 20, 2025 22:40
@ChrisRackauckas-Claude
Copy link
Author

Updated per feedback: Completely removed SparseMatrixColorings as a dependency instead of moving it to weakdeps.

Since SparseMatrixColorings was only imported but never actually used in NonlinearSolve.jl (the real implementation is in NonlinearSolveBase where it's already an extension), we can just remove it entirely.

The package is still available in test extras for testing the automatic sparse differentiation functionality.

@ChrisRackauckas-Claude
Copy link
Author

The CI failure appears to be unrelated to this PR. The error is occurring in test/runtests.jl line 24 where it's trying to parse CPU core count from Hwloc.num_physical_cores() which seems to be returning an empty value in the macOS CI environment.

This is affecting the main branch as well (recent CI runs are also failing). The issue is not related to removing SparseMatrixColorings as a dependency.

@ChrisRackauckas-Claude
Copy link
Author

Added the Hwloc fix from ModelingToolkit.jl (SciML/ModelingToolkit.jl@d7f7ed0) to handle CI environments where Hwloc.num_physical_cores() returns 0.

This should resolve the CI failures.

claude added 2 commits August 21, 2025 14:59
SparseMatrixColorings was only imported in NonlinearSolve.jl but never actually used.
The actual implementation is in NonlinearSolveBase where it's already a weakdep with
an extension.

Changes:
- Removed the `using SparseMatrixColorings` import from src/NonlinearSolve.jl
- Removed SparseMatrixColorings from deps and weakdeps
- Kept it in test extras since it's needed for testing automatic sparse differentiation

This reduces the dependency load for all users. Those who need sparse AD support will
get it through NonlinearSolveBase's extension when they load SparseMatrixColorings.

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

Co-Authored-By: Claude <[email protected]>
Apply the same fix from ModelingToolkit.jl (d7f7ed0) to handle cases where
Hwloc.num_physical_cores() and Hwloc.num_virtual_cores() return 0 in certain
CI environments.

This prevents the "input string is empty" parse error by ensuring we always
have at least 1 core.

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

Co-Authored-By: Claude <[email protected]>
@ChrisRackauckas-Claude ChrisRackauckas-Claude force-pushed the sparsematrixcolorings-extension branch from 5cd5d9c to bff0f24 Compare August 21, 2025 18:59
@ChrisRackauckas-Claude
Copy link
Author

Rebased on latest master to pick up recent CI fixes. The changes are still:

  1. Removed SparseMatrixColorings as a dependency (not needed, implementation is in NonlinearSolveBase)
  2. Fixed Hwloc CPU core detection for CI environments

The PR should be ready now.

The previous fix didn't properly handle the Windows case where
ifelse(Sys.iswindows(), 0, ...) would return 0, causing the min()
to always select 0, leading to an empty string parse error.

Now we ensure at least 1 core even on Windows by wrapping the entire
ifelse expression with max(..., 1).

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

Co-Authored-By: Claude <[email protected]>
@ChrisRackauckas-Claude
Copy link
Author

Fixed the Windows CI issue - the problem was that on Windows, the code was still producing 0 which led to an empty string. Now properly ensuring at least 1 core even on Windows.

@ChrisRackauckas ChrisRackauckas merged commit a450eec into SciML:master Aug 22, 2025
41 of 49 checks passed
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.

3 participants