Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial documentation example graphics failing #327

Open
waywardpidgeon opened this issue Jan 11, 2025 · 12 comments
Open

Initial documentation example graphics failing #327

waywardpidgeon opened this issue Jan 11, 2025 · 12 comments

Comments

@waywardpidgeon
Copy link
Contributor

waywardpidgeon commented Jan 11, 2025

The call to heatmap following a successful simulation fails with axis_str. This is in the file
Oceananigans.jl/ext/OceananigansMakieExt.jl
at line 50 for ImmersedBoundaryGrid and called by _create_plot at line 71.

The example code line is

using GLMakie
fig,ax,hm = heatmap(view(speed, :, :, ocean.model.grid.Nz), colorrange=(0, 0.5), colormap=:magma, nan_color=:lightgray)
Colorbar(fig[:,end+1],hm)

The error is

ERROR: LoadError: MethodError: no method matching axis_str(::ImmersedBoundaryGrid{Float64, Periodic, Bounded, Bounded, LatitudeLongitudeGrid{Float64, Periodic, Bounded, Bounded, Oceananigans.Grids.StaticVerticalCoordinate{OffsetArrays.OffsetVector{Float64, StepRangeLen{Float64, 
....

The stacktrace is

 [1] _create_plot(F::Function, attributes::Dict{Symbol, Any}, f::Field{Face, Center, Center, Oceananigans.AbstractOperations.UnaryOperation{Face, Center, Center, typeof(sqrt), Oceananigans.AbstractOperations.BinaryOperation{Face, Center, Center, typeof(+), Oceananigans.AbstractOperations.BinaryOperation{Face, Center, Center, typeof(^), Field{Face, Center, Center, Nothing, ImmersedBoundaryGrid{Float64, Periodic, Bounded, Bounded, LatitudeLongitudeGrid{Float64, Periodic, Bounded, Bounded, Oceananigans.Grids.StaticVerticalCoordinate{OffsetArrays.OffsetVector{Float64, StepRangeLen{

==========a very long expression =================

Oceananigans.BoundaryConditions.Flux, Nothing}}, Nothing, Oceananigans.Fields.FieldBoundaryBuffers{Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}})
   @ OceananigansMakieExt C:\Users\kab\.julia\packages\Oceananigans\GXAdX\ext\OceananigansMakieExt.jl:67
 [2] #heatmap#42
   @ C:\Users\kab\.julia\packages\MakieCore\EU17Y\src\recipes.jl:510 [inlined]
 [3] top-level scope
   @ C:\Users\kab\cc\ccex01\ClimaOcean.jl\myexamples\ClimaOceanDoc.jl:70
in expression starting at C:\Users\kab\cc\ccex01\ClimaOcean.jl\myexamples\ClimaOceanDoc.jl:70

This code was working and gave reasonable answers in early December 2024. Maybe I need to install a different version of Oceananigans.jl, but the status for julia gives v0.95.5 and according to github that is the latest version for Oceananigans.jl.
Thanks. I will try the related example near_global_simulation.jl again.

@glwagner
Copy link
Member

can you give a complete script that reproduces the error? We can then use that to solve the problem

@navidcy
Copy link
Collaborator

navidcy commented Jan 11, 2025

oh.. this might have been a bug introduced by CliMA/Oceananigans.jl#4023?
would be great to see a complete script to reproduce it.

@navidcy
Copy link
Collaborator

navidcy commented Jan 11, 2025

What version of Oceananigans you are using to get this error?

@navidcy
Copy link
Collaborator

navidcy commented Jan 12, 2025

The docs are build fine using the latest Oceananigans version; see https://clima.github.io/ClimaOceanDocumentation/dev/literated/near_global_ocean_simulation/

@waywardpidgeon
Copy link
Contributor Author

waywardpidgeon commented Jan 13, 2025 via email

@waywardpidgeon
Copy link
Contributor Author

waywardpidgeon commented Jan 13, 2025 via email

@waywardpidgeon
Copy link
Contributor Author

waywardpidgeon commented Jan 13, 2025 via email

@StevePny
Copy link
Contributor

I'm also getting this error for the example in the README.md, using this script after the "dates" fix from issue #224 :

using Oceananigans
using Oceananigans.Units
using Dates, CFTime
import ClimaOcean

arch = CPU() #GPU()
grid = LatitudeLongitudeGrid(arch,
                             size = (1440, 560, 10),
                             halo = (7, 7, 7),
                             longitude = (0, 360),
                             latitude = (-70, 70),
                             z = (-3000, 0))

bathymetry = ClimaOcean.regrid_bathymetry(grid) # builds gridded bathymetry based on ETOPO1
grid = ImmersedBoundaryGrid(grid, GridFittedBottom(bathymetry))

# Build an ocean simulation initialized to the ECCO state estimate on Jan 1, 1993
ocean = ClimaOcean.ocean_simulation(grid)
dates  = DateTimeProlepticGregorian(1993, 1, 1)
set!(ocean.model, T = ClimaOcean.ECCOMetadata(:temperature; dates),
                  S = ClimaOcean.ECCOMetadata(:salinity; dates))

# Build and run an OceanSeaIceModel (with no sea ice component) forced by JRA55 reanalysis
atmosphere = ClimaOcean.JRA55PrescribedAtmosphere(arch)
coupled_model = ClimaOcean.OceanSeaIceModel(ocean; atmosphere)
simulation = Simulation(coupled_model, Δt=5minutes, stop_time=1hours)
run!(simulation)


# Plot it
using GLMakie

u, v, w = ocean.model.velocities
speed = Field(sqrt(u^2 + v^2))
compute!(speed)

heatmap(view(speed, :, :, ocean.model.grid.Nz), colorrange=(0, 0.5), colormap=:magma, nan_color=:lightgray)

Output:

[ Info:     ... initial time step complete (3.187 minutes).
[ Info: Simulation is stopping after running for 22.896 minutes.
[ Info: Simulation time 1 hour equals or exceeds stop time 1 hour.
ERROR: LoadError: MethodError: no method matching axis_str(::ImmersedBoundaryGrid{…}, ::Int64)
The function `axis_str` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  axis_str(::LatitudeLongitudeGrid, ::Any)
   @ OceananigansMakieExt ~/.julia/packages/Oceananigans/GXAdX/ext/OceananigansMakieExt.jl:48
  axis_str(::RectilinearGrid, ::Any)
   @ OceananigansMakieExt ~/.julia/packages/Oceananigans/GXAdX/ext/OceananigansMakieExt.jl:47

Stacktrace:
 [1] _create_plot(F::Function, attributes::Dict{…}, f::Field{…})
   @ OceananigansMakieExt ~/.julia/packages/Oceananigans/GXAdX/ext/OceananigansMakieExt.jl:67
 [2] #heatmap#42
   @ ~/.julia/packages/MakieCore/EU17Y/src/recipes.jl:510 [inlined]
 [3] top-level scope
   @ ~/Code/ClimaOcean/climatest.jl:37
 [4] include(fname::String)
   @ Main ./sysimg.jl:38
 [5] top-level scope
   @ REPL[1]:1
in expression starting at /Users/spenny/Code/ClimaOcean/climatest.jl:37
Some type information was truncated. Use `show(err)` to see complete types.

Using julia version 1.11.2 and:

(@v1.11) pkg> status ClimaOcean Oceananigans
Status `~/.julia/environments/v1.11/Project.toml`
  [0376089a] ClimaOcean v0.3.2 `https://github.com/CliMA/ClimaOcean.jl.git#main`
⌃ [9e8cae18] Oceananigans v0.95.5
Info Packages marked with ⌃ have new versions available and may be upgradable.

Perhaps the README.md just needs to be updated.

@glwagner
Copy link
Member

I think that upgrading Oceananigans to 0.95.6 will fix this issue, because the method is there:

https://github.com/CliMA/Oceananigans.jl/blob/2b601f1ab052b6b257c5f273511efe46e20db5f3/ext/OceananigansMakieExt.jl#L50

When issues with the plotting extension crop up (which seems to happen somewhat often) then the easy fix is to use interior rather than view when making the plot:

heatmap(interior(speed, :, :, ocean.model.grid.Nz), colorrange=(0, 0.5), colormap=:magma, nan_color=:lightgray)

the difference is that view returns a "WindowedField" (a field representing a slice of the whole domain), whereas interior returns a SubArray (a more primitive Julia array type representing the same data).

@StevePny
Copy link
Contributor

Upgrading to v0.95.6 does not resolve the aforementioned error:

(@v1.11) pkg> status Oceananigans
Status `~/.julia/environments/v1.11/Project.toml`
  [9e8cae18] Oceananigans v0.95.6

It still gives:

[ Info: Initializing simulation...
[ Info:     ... simulation initialization complete (9.521 seconds)
[ Info: Executing initial time step...
┌ Warning: Simulation stopped during initialization.
└ @ Oceananigans.Simulations ~/.julia/packages/Oceananigans/GXAdX/src/Simulations/run.jl:135
[ Info:     ... initial time step complete (1.824 minutes).
[ Info: Simulation is stopping after running for 7.814 hours.
[ Info: Simulation time 1 day equals or exceeds stop time 1 day.
ERROR: LoadError: MethodError: no method matching axis_str(::ImmersedBoundaryGrid{…}, ::Int64)
The function `axis_str` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  axis_str(::LatitudeLongitudeGrid, ::Any)
   @ OceananigansMakieExt ~/.julia/packages/Oceananigans/GXAdX/ext/OceananigansMakieExt.jl:48
  axis_str(::RectilinearGrid, ::Any)
   @ OceananigansMakieExt ~/.julia/packages/Oceananigans/GXAdX/ext/OceananigansMakieExt.jl:47

Stacktrace:
 [1] _create_plot(F::Function, attributes::Dict{…}, f::Field{…})
   @ OceananigansMakieExt ~/.julia/packages/Oceananigans/GXAdX/ext/OceananigansMakieExt.jl:67
 [2] #heatmap#42
   @ ~/.julia/packages/MakieCore/EU17Y/src/recipes.jl:510 [inlined]
 [3] top-level scope
   @ ~/Code/ClimaOcean/climatest.jl:49
 [4] include(fname::String)
   @ Main ./sysimg.jl:38
 [5] top-level scope
   @ REPL[4]:1
in expression starting at /Users/spenny/Code/ClimaOcean/climatest.jl:49
Some type information was truncated. Use `show(err)` to see complete types.

Changing from 'view' to 'interior' does allow the plot to be generated. This is a 24-hour integration (took about 8 hours wall clock time on a laptop). I assume the striping is an issue with the visualization(?):
Screen Shot 2025-01-15 at 12 59 04 PM

@glwagner
Copy link
Member

Thank you @StevePny! Epic to run this on a laptop.

About the stripes: I think the visualization is correct. We also see stripes in the near-global ocean simulation example:

Image

They dissipate eventually but it takes some time. In the example it seems to take upwards of 30 days (hard to say actually, since the example movie is lacking time information, meh).

A guess about their origin: the stripes may be associated with an "initialization shock"; eg our initial conditions is (a) interpolated from the relatively coarse 1 deg ECCO data (which itself is interpolated to a lat-lon grid from the native ECCO grid) and (b) only uses T, S and not velocities, so it's out of geostrophic balance. That still doesn't explain (to me) why the stripes have so much structure... perhaps there is something about how the ECCO data is interpolated from it's native grid that explains it...

We might be able to investigate that hypothesis by using ECCO2 for the initial conditions (which is 1/6th degree? so closer to the resolution of this simulation).

On the error, I am puzzled because I think our examples (like the near-global simulation example) are successfully using the Makie extension with ImmersedBoundaryGrid, but it could be worth digging into that a bit more. Another possible explanation is that the simulation is somehow being run in a different environment than the global (v1.11) environment that Oceananigans was updated in (as indicated by the "@v.1.11" prefix here: (@v1.11) pkg> status Oceananigans).

@waywardpidgeon
Copy link
Contributor Author

I tried the initial documentation example of ClimaOcean again last night. The simulation took 6.252 hrs on a NVIDIA RTX A2000 6GB GPU running Windows 11, Julia 1.11.2, ClimaOcean 0.3.3 and Oceananigans 0.95.7. That's good news and a wall-time improvement over the previous successful simulations for this processor.

For the graphics, using interior rather than view in the heatmap call gave

Image

Using the original view call gave

Image

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

No branches or pull requests

4 participants