Remove dispatch on FT for Dual number support #197
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In order to enable automatic differentiation in
ClimaAtmos.jl
, we need to get rid of dispatch onFT
. For example, consider the definitionThis does not work when
ts
containsDual
numbers ande_pot
is a regularFloat32
orFloat64
, which occurs whents
depends on the prognostic state whilee_pot
is a constant. In general, it is hard to anticipate which of the values that come fromClimaAtmos.jl
will beDual
numbers, since the same value can be either prescribed or inferred from the prognostic state, depending on the model configuration. This is particularly significant for surface conditions, where the chain of computations can vary a lot between different surface parameterizations.In order to make this change easier to review, I'll split it up into several PRs. This PR removes all dispatch on
FT
fromrelations.jl
. In places whereFT
is necessary for type-stability (i.e., when we need to returnFT(0)
orFT(1)
from a conditional statement) or for obtaining machine epsilon (eps(FT)
), it is now inferred from the parameter set. As long as the parameter set does not contain anyDual
numbers, this ensures that "constant" values will always be represented asFloat32
s orFloat64
s.