From 82ef10caa711bad3cfa8bf4a73b28a78facd1603 Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Wed, 1 Apr 2026 21:25:44 +0200 Subject: [PATCH 1/4] Fix NCDatasets extension for Julia 1.12 incremental compilation Replace __init__ + @eval pattern with a direct import and compile-time method definition for default_output_attributes. The old pattern broke incremental compilation on Julia 1.12 because eval into a closed module is no longer allowed. Requires Oceananigans >= 0.106.4 (CliMA/Oceananigans.jl#5469). Co-Authored-By: Claude Opus 4.6 (1M context) --- Project.toml | 2 +- ext/ClimaSeaIceNCDatasetsExt.jl | 19 +++++++------------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/Project.toml b/Project.toml index 4e6fd611..6a6f1bfa 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ClimaSeaIce" uuid = "6ba0ff68-24e6-4315-936c-2e99227c95a4" authors = ["Climate Modeling Alliance and contributors"] -version = "0.4.6" +version = "0.4.7" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" diff --git a/ext/ClimaSeaIceNCDatasetsExt.jl b/ext/ClimaSeaIceNCDatasetsExt.jl index 58d76c4e..1257eaf0 100644 --- a/ext/ClimaSeaIceNCDatasetsExt.jl +++ b/ext/ClimaSeaIceNCDatasetsExt.jl @@ -4,6 +4,8 @@ using NCDatasets using Oceananigans using ClimaSeaIce +import Oceananigans.OutputWriters: default_output_attributes + ##### ##### Variable attributes ##### @@ -20,7 +22,7 @@ default_horizontal_velocity_attributes(::OrthogonalSphericalShellGrid) = Dict( "u" => Dict("long_name" => "Velocity in the i-direction (+ = increasing i).", "units" => "m/s"), "v" => Dict("long_name" => "Velocity in the j-direction (+ = increasing j).", "units" => "m/s") ) - + default_horizontal_velocity_attributes(ibg::ImmersedBoundaryGrid) = default_horizontal_velocity_attributes(ibg.underlying_grid) default_sea_ice_attributes() = Dict( @@ -28,17 +30,10 @@ default_sea_ice_attributes() = Dict( "ℵ" => Dict("long_name" => "Sea ice concentration.", "units" => "-") ) -function __init__() - OCNE = Base.get_extension(Oceananigans, :OceananigansNCDatasetsExt) - if !isnothing(OCNE) - @eval begin - function $OCNE.default_output_attributes(model::SeaIceModel) - velocity_attrs = default_horizontal_velocity_attributes(model.grid) - tracer_attrs = default_sea_ice_attributes() - return merge(velocity_attrs, tracer_attrs) - end - end - end +function default_output_attributes(model::SeaIceModel) + velocity_attrs = default_horizontal_velocity_attributes(model.grid) + tracer_attrs = default_sea_ice_attributes() + return merge(velocity_attrs, tracer_attrs) end end From d786f1fd003b62d53cf62c6c1126a20a96586622 Mon Sep 17 00:00:00 2001 From: Gregory Wagner Date: Wed, 1 Apr 2026 14:54:06 -0600 Subject: [PATCH 2/4] Move default_output_attributes to main module Address review feedback: move default_output_attributes(::SeaIceModel) and helper functions from the NCDatasets extension to the main ClimaSeaIce module. With Oceananigans#5469, default_output_attributes is a stub in Oceananigans.OutputWriters, so the method can be defined at compile time without needing the NCDatasets extension. Uses qualified name instead of import. Co-Authored-By: Claude Opus 4.6 (1M context) --- ext/ClimaSeaIceNCDatasetsExt.jl | 36 --------------------------------- src/ClimaSeaIce.jl | 28 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 36 deletions(-) diff --git a/ext/ClimaSeaIceNCDatasetsExt.jl b/ext/ClimaSeaIceNCDatasetsExt.jl index 1257eaf0..80c2b729 100644 --- a/ext/ClimaSeaIceNCDatasetsExt.jl +++ b/ext/ClimaSeaIceNCDatasetsExt.jl @@ -1,39 +1,3 @@ module ClimaSeaIceNCDatasetsExt -using NCDatasets -using Oceananigans -using ClimaSeaIce - -import Oceananigans.OutputWriters: default_output_attributes - -##### -##### Variable attributes -##### - -default_horizontal_velocity_attributes(::RectilinearGrid) = Dict( - "u" => Dict("long_name" => "Velocity in the +x-direction.", "units" => "m/s"), - "v" => Dict("long_name" => "Velocity in the +y-direction.", "units" => "m/s")) - -default_horizontal_velocity_attributes(::LatitudeLongitudeGrid) = Dict( - "u" => Dict("long_name" => "Velocity in the zonal direction (+ = east).", "units" => "m/s"), - "v" => Dict("long_name" => "Velocity in the meridional direction (+ = north).", "units" => "m/s")) - -default_horizontal_velocity_attributes(::OrthogonalSphericalShellGrid) = Dict( - "u" => Dict("long_name" => "Velocity in the i-direction (+ = increasing i).", "units" => "m/s"), - "v" => Dict("long_name" => "Velocity in the j-direction (+ = increasing j).", "units" => "m/s") -) - -default_horizontal_velocity_attributes(ibg::ImmersedBoundaryGrid) = default_horizontal_velocity_attributes(ibg.underlying_grid) - -default_sea_ice_attributes() = Dict( - "h" => Dict("long_name" => "Sea ice thickness.", "units" => "m"), - "ℵ" => Dict("long_name" => "Sea ice concentration.", "units" => "-") -) - -function default_output_attributes(model::SeaIceModel) - velocity_attrs = default_horizontal_velocity_attributes(model.grid) - tracer_attrs = default_sea_ice_attributes() - return merge(velocity_attrs, tracer_attrs) -end - end diff --git a/src/ClimaSeaIce.jl b/src/ClimaSeaIce.jl index 71fdd2ab..ba80b00a 100644 --- a/src/ClimaSeaIce.jl +++ b/src/ClimaSeaIce.jl @@ -69,4 +69,32 @@ end # No diffusion timescale for sea ice for now cell_diffusion_timescale(model::SeaIceModel) = Inf +##### +##### Default output attributes for NetCDF output +##### + +default_horizontal_velocity_attributes(::RectilinearGrid) = Dict( + "u" => Dict("long_name" => "Velocity in the +x-direction.", "units" => "m/s"), + "v" => Dict("long_name" => "Velocity in the +y-direction.", "units" => "m/s")) + +default_horizontal_velocity_attributes(::LatitudeLongitudeGrid) = Dict( + "u" => Dict("long_name" => "Velocity in the zonal direction (+ = east).", "units" => "m/s"), + "v" => Dict("long_name" => "Velocity in the meridional direction (+ = north).", "units" => "m/s")) + +default_horizontal_velocity_attributes(::OrthogonalSphericalShellGrid) = Dict( + "u" => Dict("long_name" => "Velocity in the i-direction (+ = increasing i).", "units" => "m/s"), + "v" => Dict("long_name" => "Velocity in the j-direction (+ = increasing j).", "units" => "m/s")) + +default_horizontal_velocity_attributes(ibg::ImmersedBoundaryGrid) = default_horizontal_velocity_attributes(ibg.underlying_grid) + +default_sea_ice_attributes() = Dict( + "h" => Dict("long_name" => "Sea ice thickness.", "units" => "m"), + "ℵ" => Dict("long_name" => "Sea ice concentration.", "units" => "-")) + +function Oceananigans.OutputWriters.default_output_attributes(model::SeaIceModel) + velocity_attrs = default_horizontal_velocity_attributes(model.grid) + tracer_attrs = default_sea_ice_attributes() + return merge(velocity_attrs, tracer_attrs) +end + end # module From 62771381f80e3fa3bb3026a29594fea61614cb85 Mon Sep 17 00:00:00 2001 From: Gregory Wagner Date: Wed, 1 Apr 2026 14:55:13 -0600 Subject: [PATCH 3/4] Remove empty NCDatasets extension The extension has no code left after moving default_output_attributes to the main module. Remove the extension file, weakdep, and extension entry from Project.toml. Keep NCDatasets in [extras] for tests. Co-Authored-By: Claude Opus 4.6 (1M context) --- Project.toml | 7 +------ ext/ClimaSeaIceNCDatasetsExt.jl | 3 --- 2 files changed, 1 insertion(+), 9 deletions(-) delete mode 100644 ext/ClimaSeaIceNCDatasetsExt.jl diff --git a/Project.toml b/Project.toml index 6a6f1bfa..e20a63b7 100644 --- a/Project.toml +++ b/Project.toml @@ -12,12 +12,6 @@ RootSolvers = "7181ea78-2dcb-4de3-ab41-2b8ab5a31e74" Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665" SeawaterPolynomials = "d496a93d-167e-4197-9f49-d3af4ff8fe40" -[weakdeps] -NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab" - -[extensions] -ClimaSeaIceNCDatasetsExt = "NCDatasets" - [compat] Adapt = "3, 4" JLD2 = "0.6.2" @@ -30,6 +24,7 @@ julia = "1.10" [extras] MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195" +NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] diff --git a/ext/ClimaSeaIceNCDatasetsExt.jl b/ext/ClimaSeaIceNCDatasetsExt.jl deleted file mode 100644 index 80c2b729..00000000 --- a/ext/ClimaSeaIceNCDatasetsExt.jl +++ /dev/null @@ -1,3 +0,0 @@ -module ClimaSeaIceNCDatasetsExt - -end From c716b25f12eca8fd696278309a2c678d26eb38c4 Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Thu, 2 Apr 2026 15:15:36 +0200 Subject: [PATCH 4/4] retry tests --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index e20a63b7..35fd4590 100644 --- a/Project.toml +++ b/Project.toml @@ -16,7 +16,7 @@ SeawaterPolynomials = "d496a93d-167e-4197-9f49-d3af4ff8fe40" Adapt = "3, 4" JLD2 = "0.6.2" KernelAbstractions = "0.9" -Oceananigans = "0.104.1, 0.105, 0.106" +Oceananigans = "0.106, 0.107" RootSolvers = "0.3, 0.4, 1.0" Roots = "2" SeawaterPolynomials = "0.3.4"