Skip to content

Comments

[WIP] [F32 Update] Fix for DelnFlux & DlenFluxNoSG#33

Closed
FlorianDeconinck wants to merge 5 commits intoNOAA-GFDL:developfrom
FlorianDeconinck:fix/DelnFlux_f32_support
Closed

[WIP] [F32 Update] Fix for DelnFlux & DlenFluxNoSG#33
FlorianDeconinck wants to merge 5 commits intoNOAA-GFDL:developfrom
FlorianDeconinck:fix/DelnFlux_f32_support

Conversation

@FlorianDeconinck
Copy link
Collaborator

@FlorianDeconinck FlorianDeconinck commented Dec 2, 2024

The Fortran calculate the negative flux by inverting the q and offset-ed q in the gradient calculation, while the original port of pyFV3 was using a negative u/v and the same gradient. This works at f64 but introduces errors at f32 for very small values advected.

Clean up of a few differences with Fortran that don't necessarily fail now but could with other data.

E.g.:

  • Replicate Fortran subtraction to reduce f32 errors
  • Use np.power to insure proper type casting of power op
  • Verbose the half damp calculation

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules
  • New check tests, if applicable, are included
  • Targeted model if this changed was triggered by a model need/shortcoming

Use `np.power` to insure proper type casting of power op
Verbose the half damp calculation
@FlorianDeconinck
Copy link
Collaborator Author

Though this work comes from the push to match GEOS @ f32 capacities, this should pass the f64 data set from FV3GFS and therefore be mergeable as-is.

@lharris4
Copy link

lharris4 commented Dec 3, 2024

Hi, @FlorianDeconinck Is this primarily to address round-off global mass errors?

@FlorianDeconinck
Copy link
Collaborator Author

This is to remap the calculation to Fortran so we narrow the difference at 32-bit.

Though the calculation is mathematically similar, at 32-bit the negative mult of del6_u means we lose one bit precision out - and on small gradient mult like we have after those stack up to bigger diff in D_SW

@FlorianDeconinck
Copy link
Collaborator Author

As always we have to follow the Fortran numerically up until we are confident our dynamics have reached feature parity so we can track any porting mistakes. With the introduction of the 32-bit float, we need to keep operations even closer than we did at 64-bit to be able to track numerical errors.

The larger plan call for full scientific simulation that should build confidence further than the narrow translate test

oelbert
oelbert previously approved these changes Dec 16, 2024
Copy link
Collaborator

@oelbert oelbert left a comment

Choose a reason for hiding this comment

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

I love floating point arithmetic...

"identical data shape and dims"
)
data = (damp_c.data * da_min) ** (nord.data + 1)
data = np.power((damp_c.data * da_min), (nord.data + 1), dtype=Float)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this get stencilized at some point?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It could. It lives in the init so it probably why. But it's flimsy because we rely on the transparency of numpy & cupy to do CPU/GPU, something that will bite us sooner or later

oelbert
oelbert previously approved these changes Mar 26, 2025
Copy link
Collaborator

@oelbert oelbert left a comment

Choose a reason for hiding this comment

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

As long as what you say about the toolchain respecting order-of-operations this is good with me

@gtscript.function
def fx_calculation_neg(q: FloatField, del6_v: FloatField):
return -del6_v * (q[-1, 0, 0] - q)
return del6_v * (q - q[-1, 0, 0])
Copy link
Collaborator

Choose a reason for hiding this comment

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

wow how dare you

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I dare.

@FlorianDeconinck
Copy link
Collaborator Author

This will be on hold until the GEOS-driven dynamics is stable

@oelbert
Copy link
Collaborator

oelbert commented May 5, 2025

What's the status of this? It looks like there are almost no differences anymore?

@FlorianDeconinck FlorianDeconinck changed the title [F32 Update] Fix for DelnFlux & DlenFluxNoSG [WIP] [F32 Update] Fix for DelnFlux & DlenFluxNoSG May 5, 2025
@FlorianDeconinck
Copy link
Collaborator Author

We just reached stability with 32-bit dycore. Delnflux has seen more changes not present here - I might close this and wait for the flurry of 32-bit PR to update

@FlorianDeconinck
Copy link
Collaborator Author

Closing this. There's an entire update to the dycore coming which is much bigger than this.

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.

4 participants