Skip to content

Conversation

@ChrisRackauckas-Claude
Copy link

Summary

This PR fixes issue #1004 where the Sophia optimizer was throwing UndefVarError: randn! not defined in Optimization when used.

Problem

The Sophia optimizer calls randn!(u) on line 155 of src/sophia.jl to generate random vectors for the Hutchinson trace estimator, but Random was not imported into the Optimization module namespace.

Solution

  • Added Random as a dependency in Project.toml
  • Added using Random to the imports in src/Optimization.jl

Testing

  • Created test cases that successfully trigger the randn! call without errors
  • The fix resolves the original issue while maintaining compatibility with existing functionality

The changes are minimal and focused, only adding the necessary Random import to resolve the missing function error.

Test plan

  • Verified the fix resolves the original randn! error
  • Confirmed existing Sophia functionality still works
  • No breaking changes to the public API

Fixes #1004

🤖 Generated with Claude Code

The Sophia optimizer calls randn!() on line 155 of src/sophia.jl but
Random was not imported. This caused UndefVarError when using Sophia.

Changes:
- Add Random to dependencies in Project.toml
- Import Random in src/Optimization.jl

Fixes SciML#1004

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

Co-Authored-By: Claude <noreply@anthropic.com>
@ChrisRackauckas ChrisRackauckas merged commit 302d6f1 into SciML:master Sep 9, 2025
50 of 71 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.

Sophia: undefined reference to rand!

2 participants