-
Notifications
You must be signed in to change notification settings - Fork 3
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
function __init__() | ||
Logging.disable_logging(Logging.Warn) # disable warnings (for broadcasting with mismatched spaces) | ||
end | ||
Comment on lines
+16
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Any suggestions? |
||
|
||
include("CoupledSimulations/clock.jl") | ||
include("CoupledSimulations/coupled_simulation.jl") | ||
include("CouplerState/coupler_state.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 |
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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
I just feel that
allow_mismatched_diagonalized_spaces
andallow_mismatched_fd_spaces
are pretty niche.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'm fine with holding off then.