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

Enable starting driver from Fortran restart files for TC case #339

Merged
merged 145 commits into from
Oct 19, 2022

Conversation

ajdas1
Copy link
Contributor

@ajdas1 ajdas1 commented Sep 20, 2022

Purpose

Allows a start from fortran restart files as needed to run the tropical cyclone initialization case.

Code changes:

  • Added GeneratedGridConfig and SerialboxGridConfig to pace.driver
  • Added grid_config attribute to DriverConfig, used to select grid initialization approach instead of relying on the state initialization to do so
  • Added FortranRestartConfig for state initialization
  • Can now use fortran restart files to initialize the model (tc case)
  • Possibility for grid transformation that allows for local refinement.
  • removed unused "ks" variable from fv3core and dataclass containers
  • added grid variables ee1, ee2, es1, and ew2 to GridData as they are needed by fv3core for baroclinic initialization
  • deleted difficult-to-maintain mock-based driver tests, they are difficult to maintain and don't add much coverage past the driver tests which actually run the code
  • removed unused stretch_grid attribute from Namelist class since Namelist is never used when defining grid initialization configuration
  • fv3core grid dataclasses now use Quantity instead of gt4py storages

Checklist

Before submitting this PR, please make sure:

  • You have followed the coding standards guidelines established at Code Review Checklist.
  • Docstrings and type hints are added to new and updated routines, as appropriate
  • All relevant documentation has been updated or added (e.g. README, CONTRIBUTING docs)
  • For each public change and fix in pace-util, HISTORY has been updated
  • Unit tests are added or updated for non-stencil code changes

Additionally, if this PR contains code authored by new contributors:

  • The names of all the new contributors have been added to CONTRIBUTORS.md

Comment on lines +165 to +166
*.png
*.nc
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we actually want to ignore all png and nc files?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Technically no, I think we do have one of each committed into the repo that should be there. But adding to the gitignore doesn't prevent from adding files manually, and our scripts produce a fair bit of these that we don't want to commit. I could go either way but I'd lean towards having this in the gitignore, what do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm okay with leaving it like this, just wanted to be careful when we do actually want to commit a png/nc file.

Comment on lines +137 to +138
"lat": grid_data.lat,
"lon": grid_data.lon,
Copy link
Collaborator

Choose a reason for hiding this comment

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

👏

Comment on lines +326 to +327
@dataclasses.dataclass()
class RestartConfig:
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the reason behind this being inside driver.py?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It should probably go in another file, I only put it here because all its code/logic was previously contained in this file. I'll see about splitting it out.

Copy link
Collaborator

Choose a reason for hiding this comment

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

When I went to do this I remembered the reason is this is tightly coupled with DriverConfig, due to the fact that it writes an updated DriverConfig when writing the restart. Must be located in the same file.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fair enough.

Comment on lines +645 to 653
def cleanup(self):
logger.info("cleaning up driver")
self.config.restart_config.write_final_if_enabled(
state=self.state,
comm=self.comm,
restart_path=restart_path,
)
self.restart.write_restart_config(
comm=self.comm,
time=self.time,
driver_config=self.config,
restart_path=restart_path,
restart_path="RESTART",
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks to me that some of these don't need to be part of dace call back, not sure if this changes the behavior of dace.

Copy link
Collaborator

Choose a reason for hiding this comment

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

There's a dace inhibitor only because if we do call this from dace it should be escaped in a callback, I don't think this is actually called from dace currently. Added it for safety. I can remove it if you would still prefer.

@dataclasses.dataclass
class GeneratedGridConfig(GridInitializer):
"""
Configuration for baroclinic initialization.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Configuration for baroclinic initialization.
Grid calculated using metric terms

Copy link
Collaborator

Choose a reason for hiding this comment

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

Adding something slightly different.

Comment on lines 181 to 183
is_fortran_restart = False
restart_files = fs.ls(path)
is_fortran_restart = any(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to default to False first?

Copy link
Collaborator

Choose a reason for hiding this comment

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

No. Updated.

Comment on lines 486 to 517
# lon=self.bgrid1,
# lat=self.bgrid2,
# lon_agrid=self.agrid1,
# lat_agrid=self.agrid2,
# area=self.area,
# area_64=self.area_64,
# rarea=self.rarea,
# rarea_c=self.rarea_c,
# dx=self.dx,
# dy=self.dy,
# dxc=self.dxc,
# dyc=self.dyc,
# dxa=self.dxa,
# dya=self.dya,
# rdx=self.rdx,
# rdy=self.rdy,
# rdxc=self.rdxc,
# rdyc=self.rdyc,
# rdxa=self.rdxa,
# rdya=self.rdya,
# ee1=self.ee1,
# ee2=self.ee2,
# es1=self.es1,
# ew2=self.ew2,
# a11=self.a11,
# a12=self.a12,
# a21=self.a21,
# a22=self.a22,
# edge_w=self.edge_w,
# edge_e=self.edge_e,
# edge_s=self.edge_s,
# edge_n=self.edge_n,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Delete this

Copy link
Collaborator

Choose a reason for hiding this comment

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

Deleted.

Comment on lines 694 to 703
# self.cosa,
# self.cosa_u,
# self.cosa_v,
# self.cosa_s,
# self.sina_u,
# self.sina_v,
# self.rsina,
# self.rsin_u,
# self.rsin_v,
# self.rsin2,
Copy link
Collaborator

Choose a reason for hiding this comment

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

delete this

Comment on lines 756 to 763
# self.sin_sg1,
# self.sin_sg2,
# self.sin_sg3,
# self.sin_sg4,
# self.cos_sg1,
# self.cos_sg2,
# self.cos_sg3,
# self.cos_sg4,
Copy link
Collaborator

Choose a reason for hiding this comment

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

delete this

)

quantity_factory = QuantityFactory.from_backend(sizer=sizer, backend="numpy")
restart_dir = os.path.join(DIR, "../../../util/tests/data/c12_restart")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be better to define pace dir at the top and use that throughout this file?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Updated.

@mcgibbon mcgibbon changed the title Feature/fortran restart Enable starting driver from Fortran restart files for TC case Oct 18, 2022
@mcgibbon mcgibbon enabled auto-merge (squash) October 18, 2022 22:54
@mcgibbon mcgibbon merged commit 243ff24 into main Oct 19, 2022
@mcgibbon mcgibbon deleted the feature/fortran_restart branch October 19, 2022 00:53
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.

3 participants