Replace RecursiveApply functions with AutoBroadcaster wrappers#2417
Merged
dennisYatunin merged 1 commit intomainfrom May 1, 2026
Merged
Replace RecursiveApply functions with AutoBroadcaster wrappers#2417dennisYatunin merged 1 commit intomainfrom
dennisYatunin merged 1 commit intomainfrom
Conversation
cc7a736 to
0b0cbe1
Compare
4 tasks
e603f47 to
5430722
Compare
30377bd to
92cf627
Compare
2bd7d7c to
52d17a0
Compare
8553df5 to
264d4d2
Compare
Member
nefrathenrici
left a comment
There was a problem hiding this comment.
This looks good to me. It's nice to get rid of RecursiveApply. I didn't have any significant comments.
4 tasks
4 tasks
imreddyTeja
reviewed
Apr 23, 2026
Member
imreddyTeja
left a comment
There was a problem hiding this comment.
I left some comments and questions, but this looks mostly good to me
imreddyTeja
approved these changes
Apr 24, 2026
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Purpose
This replaces the
RecursiveApplymodule with a new interface that follows the opposite design pattern: instead of defining functions forTuples andNamedTuples that need to be called inFields,Operators,MatrixFields, and external libraries likeClimaAtmos, we can now use a wrapper forTuples andNamedTuples that behaves the same way when passed to standard math functions. The number of places where this interface needs to be explicitly used is quite small, making it possible to decouple iteration over field variables from most of ClimaCore's internals.Content
AutoBroadcasterwrapper, which triggersnested_broadcast(an analogue of the oldRecursiveApply.rmap) when passed to any common math function or constructorRecursiveApplyfunctions in ClimaCore's source code with standard math operationsTby defining the methodis_auto_broadcastable(::T) = true, as long asTis compatible with UnrolledUtilitiesRecursiveApplyimplementationRecursiveApplymodule that defines the same functions as the old version, but as simple wrappers aroundadd_auto_broadcastersanddrop_auto_broadcastersauto_broadcastedfunction that automatically introduces calls to eitheradd_auto_broadcastersordrop_auto_broadcastersinBroadcastedexpressions, allowing ClimaCore operators to be used in the same expressions as user-defined functions that are incompatible withAutoBroadcasters (e.g., functions that dispatch on non-AutoBroadcastertypes)broadcastableform of anyAbstractDataorFieldhasadd_auto_broadcastersapplied to its valuesBase.broadcastedtriggersauto_broadcastedinstead of the standardBroadcastedconstructoreltypeis the output ofunsafe_eltype, which acts as an unrolled version ofBase.Broadcast.combine_eltypessimilaruses the output ofsafe_eltype, which can identify the first point during inference where a non-concrete type appears in a broadcast expression (essentially a simplified and corrected version of the oldcall_with_first)newto avoid segfaults and other errors when dealing withDataTypefieldsdeformation_flow.jlexample by removing all loops over field variables, adding several missing cases, and clarifying precisely what needs to be tested