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

Define zero on some MatrixField types #2140

Merged
merged 1 commit into from
Jan 18, 2025
Merged

Conversation

charleskawczynski
Copy link
Member

This should allow us to use zero in ClimaTimesteppers, resulting in safer initialization. xref.

Does this need exercised anywhere else? I think this should work since it's recursive. I'm able to run CTS unit tests with this.

src/MatrixFields/field_matrix_solver.jl Outdated Show resolved Hide resolved
src/MatrixFields/field_matrix_with_solver.jl Outdated Show resolved Hide resolved
Comment on lines 185 to 193
function Base.zero(dict::FieldMatrix)
entries = unrolled_map(values(dict)) do entry
entry isa UniformScaling ? entry : zero(entry)
end
return FieldNameDict(keys(dict), entries)
end

Base.zero(dict::FieldNameDict) =
FieldNameDict(keys(dict), map(zero, values(dict)))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
function Base.zero(dict::FieldMatrix)
entries = unrolled_map(values(dict)) do entry
entry isa UniformScaling ? entry : zero(entry)
end
return FieldNameDict(keys(dict), entries)
end
Base.zero(dict::FieldNameDict) =
FieldNameDict(keys(dict), map(zero, values(dict)))
function Base.zero(dict::FieldNameDict)
entries = unrolled_map(values(dict)) do entry
entry isa UniformScaling ? entry : zero(entry)
end # TODO: Replace UniformScaling with mutable Ref to make this consistent
return FieldNameDict(keys(dict), entries)
end

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like the matrix-field method was needed after all: https://buildkite.com/clima/climaatmos-ci/builds/22412#01949b97-4f3c-477b-8ea5-b0a0e49491d7

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, wait, that build shows that it's not using the latest ClimaCore.

@charleskawczynski charleskawczynski force-pushed the ck/define_zero branch 2 times, most recently from 4eefa45 to e11d2fd Compare January 18, 2025 01:14
Define zero for some MatrixField structs
@charleskawczynski
Copy link
Member Author

Thanks for the suggestions, @dennisYatunin! It looks like these changes worked in ClimaTimesteppers CI 🙂

@charleskawczynski charleskawczynski merged commit 28b361a into main Jan 18, 2025
34 checks passed
@charleskawczynski charleskawczynski deleted the ck/define_zero branch January 18, 2025 03:23
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

Successfully merging this pull request may close these issues.

2 participants