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

Enable broadcasting with mismatched spaces. #80

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ version = "0.1.0"

[deps]
ClimaCore = "d414da3d-4745-48bb-8d80-42e94e092884"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
12 changes: 12 additions & 0 deletions src/ClimaCoupler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ Coupling module sufficient for initial atmos-ocean-land coupled simulation.
"""
module ClimaCoupler

using ClimaCore
import ClimaCore: Fields, Operators
import Logging

# Disable errors from broadcasting with mismatched spaces
Fields.allow_mismatched_diagonalized_spaces() = true
Operators.allow_mismatched_fd_spaces() = true
Comment on lines +13 to +14
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved into the test folder, it must be done at global scope.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest of the changes in this file can probably be deleted

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain your reasoning for both of these points? I was thinking we want to disable these errors anytime we are using the coupler. Maybe that is simply too broad? The benefit is that coupler users won't have to think about these levers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of like type piracy. We should probably avoid changing other packages default behavior under the hood. What's the issue with doing this at the global level? I'm fairly certain it'll work, it's simple, and more transparent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense to me r.e. transparency. I just wanted to allow the user to not have to think about this when coupling and these errors are something we will want to disable pretty much every time we are coupling, therefore something more automatic seemed warranted.

Maybe a method that redefines these would be a happy medium? Something like

function allow_mismatched_spaces()
    @eval Fields.allow_mismatched_diagonalized_spaces() = true
    @eval Operators.allow_mismatched_fd_spaces() = true
end

I just feel that allow_mismatched_diagonalized_spaces and allow_mismatched_fd_spaces are pretty niche.

Copy link
Member

@charleskawczynski charleskawczynski Jul 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted to allow the user to not have to think about this

This is not transparent.

I recommend not using @eval. My recommendation is to include this at the top level. That is by far the simplest way to handle this situation. We can hide it later if we want to make things pretty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend not using @eval. My recommendation is to include this at the top level. That is by far the simplest way to handle this situation. We can hide it later if we want to make things pretty.

Ok, I'm fine with holding off then.


function __init__()
Logging.disable_logging(Logging.Warn) # disable warnings (for broadcasting with mismatched spaces)
end
Comment on lines +16 to +18
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@charleskawczynski @simonbyrne is there a better way to prevent these warnings from printing?

One option is to remove the warning all together if we think that the error should only be disabled when coupling anyways.

Another is perhaps to change the @warn to @debug so that they are at the lowest logging level and hidden by default.

Any suggestions?


include("CoupledSimulations/clock.jl")
include("CoupledSimulations/coupled_simulation.jl")
include("CouplerState/coupler_state.jl")
Expand Down
31 changes: 31 additions & 0 deletions test/general_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Test
using ClimaCoupler
import ClimaCore: Fields, Domains, Topologies, Meshes, Spaces, Geometry
using IntervalSets

function spectral_space_2D(; n1 = 1, n2 = 1, Nij = 4)
domain = Domains.RectangleDomain(
Geometry.XPoint(-1.0) .. Geometry.XPoint(1.0),
Geometry.YPoint(-1.0) .. Geometry.YPoint(1.0),
x1periodic = false,
x2periodic = false,
x1boundary = (:east, :west),
x2boundary = (:south, :north),
)
mesh = Meshes.RectilinearMesh(domain, n1, n2)
grid_topology = Topologies.Topology2D(mesh)

quad = Spaces.Quadratures.GLL{Nij}()
space = Spaces.SpectralElementSpace2D(grid_topology, quad)
return space
end

@testset "Enable Mismatched Space Broadcasting" begin
space1 = spectral_space_2D()
space2 = spectral_space_2D()
field1 = ones(space1)
field2 = 2 .* ones(space2)
@test Fields.is_diagonalized_spaces(typeof(space1), typeof(space2))
@test_nowarn field1 .= field2
@test parent(field1) == parent(field2)
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include("general_tests.jl")
include("CoupledSimulations/clock.jl")
include("CouplerState/cplstate_interface.jl")
# include("CoupledSimulations/cplsolver.jl")