Skip to content

Reduce use of ᶜspecific #3857

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Reduce use of ᶜspecific #3857

wants to merge 6 commits into from

Conversation

charleskawczynski
Copy link
Member

No description provided.

@charleskawczynski charleskawczynski force-pushed the ck/slim_cache4 branch 5 times, most recently from cf2a81a to 8edcb24 Compare June 16, 2025 16:51
@charleskawczynski charleskawczynski marked this pull request as ready for review June 16, 2025 17:34
@charleskawczynski charleskawczynski requested review from tapios, dennisYatunin and trontrytel and removed request for tapios June 16, 2025 17:34
@charleskawczynski charleskawczynski force-pushed the ck/slim_cache4 branch 2 times, most recently from 19c86c9 to 4c89018 Compare June 17, 2025 15:56
@charleskawczynski
Copy link
Member Author

charleskawczynski commented Jun 17, 2025

@tapios, I tried lumping everything into the one function, but I'm getting an error:

ERROR: LoadError: The function body AST defined by this @generated function is not pure. This likely means it contains a closure, a comprehension or a generator.
  | Stacktrace:
  | [1] macro expansion
  | @ /central/scratch/esm/slurm-buildkite/climaatmos-ci/24693/climaatmos-ci/src/prognostic_equations/hyperdiffusion.jl:245 [inlined]
  |  

Is it alright if I break this back down into smaller function calls (which worked) and only do the generated function where it's needed? Or maybe @dennisYatunin has a better idea?

@tapios
Copy link
Contributor

tapios commented Jun 17, 2025

@tapios, I tried lumping everything into the one function, but I'm getting an error:

ERROR: LoadError: The function body AST defined by this @generated function is not pure. This likely means it contains a closure, a comprehension or a generator.
  | Stacktrace:
  | [1] macro expansion
  | @ /central/scratch/esm/slurm-buildkite/climaatmos-ci/24693/climaatmos-ci/src/prognostic_equations/hyperdiffusion.jl:245 [inlined]
  |  

Is it alright if I break this back down into smaller function calls (which worked) and only do the generated function where it's needed? Or maybe @dennisYatunin has a better idea?

I'd like to understand what fails here. The problem is in hyperdiffusion, l. 245. Nothing here needs to change if what we use is the old specific_gs. It looks like the problem is with the changes from specific_gs to all_specific_gs (which weren't needed here from what I know).

I'm fine with breaking this down into smaller functions, but I'm afraid the problem is something else. @dennisYatunin can weigh in.

@@ -168,6 +168,33 @@ omitted from the result.
return :(NamedTuple{$specific_gs_names}(($(specific_gs_values...),)))
end

"""
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to remove the duplicative specific_gs above. It should be the same thing as all_specific_gs.

Copy link
Member Author

Choose a reason for hiding this comment

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

I recommend we leave the duplicate definition until we are able to fully remove ᶜspecific from the cache, at which point we can remove specific_gs trivially (as nothing will depend on it). If I were to try to remove it right now, it would take me some time to figure out how to make all_specific_gs be able to return a field (all_specific_gs returns a NamedTuple of Broadcasted objects) like specific_gs does.

@tapios
Copy link
Contributor

tapios commented Jun 18, 2025

@tapios, I tried lumping everything into the one function, but I'm getting an error:

ERROR: LoadError: The function body AST defined by this @generated function is not pure. This likely means it contains a closure, a comprehension or a generator.
  | Stacktrace:
  | [1] macro expansion
  | @ /central/scratch/esm/slurm-buildkite/climaatmos-ci/24693/climaatmos-ci/src/prognostic_equations/hyperdiffusion.jl:245 [inlined]
  |  

Is it alright if I break this back down into smaller function calls (which worked) and only do the generated function where it's needed? Or maybe @dennisYatunin has a better idea?

Isn't the right thing to do here is using the same logic of looping over scalar names that you used several times in #3858?

@charleskawczynski
Copy link
Member Author

Is it alright if I break this back down into smaller function calls (which worked) and only do the generated function where it's needed? Or maybe @dennisYatunin has a better idea?

@dennisYatunin ?

@tapios
Copy link
Contributor

tapios commented Jun 20, 2025

Is it alright if I break this back down into smaller function calls (which worked) and only do the generated function where it's needed? Or maybe @dennisYatunin has a better idea?

@dennisYatunin ?

As I mentioned, you'd want to use a (corrected form) of foreach_tracer here, restricted to grid-scale variables. Then this issue will disappear.

@charleskawczynski
Copy link
Member Author

As I mentioned, you'd want to use a (corrected form) of foreach_tracer here, restricted to grid-scale variables. Then this issue will disappear.

It's not clear to me how to use foreach_tracer in this function. Are you suggesting to scrap the function altogether and just use foreach_tracer? If so, we'll need foreach_tracer to emit both ρχ_name and χ_symbol, as both are needed in the hyperdiffusion. Specifically, how do we use foreach_tracer for:

    for χ_name in propertynames(ᶜ∇²specific_tracers)
        @. ᶜ∇²specific_tracers.:($$χ_name) = wdivₕ(gradₕ(ᶜspecific.:($$χ_name)))
    end

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants