From 0f14cd3964173de0223179b5566b9675c994c88a Mon Sep 17 00:00:00 2001 From: ChrisRackauckas Date: Tue, 9 Sep 2025 08:07:07 -0400 Subject: [PATCH] Fix Sophia optimizer: add Random import to resolve randn! error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 #1004 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- Project.toml | 1 + src/Optimization.jl | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index a9b308511..1848ad312 100644 --- a/Project.toml +++ b/Project.toml @@ -14,6 +14,7 @@ LoggingExtras = "e6f89c97-d47a-5376-807f-9c37f3926c36" OptimizationBase = "bca83a33-5cc9-4baa-983d-23429ab6bcbb" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" ProgressLogging = "33c8b6b6-d38a-422a-b730-caa89a2f386c" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" diff --git a/src/Optimization.jl b/src/Optimization.jl index 8d0257dd1..0f6c0a4d6 100644 --- a/src/Optimization.jl +++ b/src/Optimization.jl @@ -12,7 +12,7 @@ if !isdefined(Base, :get_extension) end using Logging, ProgressLogging, ConsoleProgressMonitor, TerminalLoggers, LoggingExtras -using ArrayInterface, Base.Iterators, SparseArrays, LinearAlgebra +using ArrayInterface, Base.Iterators, SparseArrays, LinearAlgebra, Random import OptimizationBase: instantiate_function, OptimizationCache, ReInitCache import SciMLBase: OptimizationProblem,