Skip to content

Conversation

@joewallwork
Copy link
Contributor

@joewallwork joewallwork commented Nov 4, 2025

Read input file to determine dimensions

Fixes #972
Merges into #968

Task List

  • Defined the tests that specify a complete and functioning change (It may help to create a design specification & test specification)
  • Implemented the source code change that satisfies the tests
  • Documented the feature by providing worked example
  • Updated the README or other documentation
  • Completed the pre-Request checklist below

Change Description

Currently, there are differences in how the serial, MPI-parallel, and XIOS configurations read dimensions. For greater consistency, this PR implements a setDimensionsFromFile member function for ModelMetadata. It gets called in Model.configureRestarts. It also gets called in ParaGridIO.getModelState (for consistency with the existing implementation).


Test Description

XIOS tests are updated to account for the fact that dimensions are set in Model.configureRestarts.


Documentation Impact

None


Pre-Request Checklist

  • The requirements of this pull request are fully captured in an issue or design specification and are linked and summarised in the description of this PR
  • No new warnings are generated
  • The documentation has been updated (or an issue has been created to track the corresponding change)
  • Methods and Tests are commented such that they can be understood without having to obtain additional context
  • This PR/Issue is labelled as a bug/feature/enhancement/breaking change
  • This change conforms to the conventions described in the README

@joewallwork joewallwork self-assigned this Nov 4, 2025
@joewallwork joewallwork added enhancement New feature or request ICCS Tasks or reviews for the ICCS team labels Nov 4, 2025
@joewallwork joewallwork force-pushed the issue972_initial-read branch from dcdf6b4 to 6aaebd5 Compare November 4, 2025 15:00
@joewallwork
Copy link
Contributor Author

[Rebased on top of updated base branch]

@joewallwork joewallwork linked an issue Nov 4, 2025 that may be closed by this pull request
Base automatically changed from issue850_xios-pruning to develop November 10, 2025 14:52
@joewallwork joewallwork force-pushed the issue972_initial-read branch from c60b3eb to f5428d5 Compare November 10, 2025 16:57
@joewallwork
Copy link
Contributor Author

[Rebased on top of develop again.]

@joewallwork joewallwork force-pushed the issue972_initial-read branch from f5428d5 to e45bfe1 Compare November 18, 2025 10:52
Comment on lines 86 to 88
// TODO: Do this once rather than with every read
ModelMetadata& metadata = ModelMetadata::getInstance();
metadata.setDimensionsFromFile(filePath);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Question for reviewer: Do we really want to set dimensions from file in every call to getModelState, as in the existing implementation? Would it not be better to do the following?

Suggested change
// TODO: Do this once rather than with every read
ModelMetadata& metadata = ModelMetadata::getInstance();
metadata.setDimensionsFromFile(filePath);
ModelMetadata& metadata = ModelMetadata::getInstance();
if (filePath /= metadata.initialFileName) {
metadata.setDimensionsFromFile(filePath);
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

How many calls to getModelState() are expected? In each model run, there should only be one call to SomethingGrid::getModelState() and within that one call to SomethingGridIO::getModelState() (where SomethingGrid is the name of the IStructureimplementing class). There are a few more examples around the code base for testing, but I believe that is all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair point, thanks. I removed the TODO in 17ea449 and will merge once tests pass.

@joewallwork joewallwork marked this pull request as ready for review November 18, 2025 10:57
Copy link
Collaborator

@timspainNERSC timspainNERSC left a comment

Choose a reason for hiding this comment

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

If we were calling getModelState() in the main model loop, the extra change would be worth adding. As it should only be called once per run, I'm not sure even the small amount of added complexity is worthwhile.

Comment on lines 86 to 88
// TODO: Do this once rather than with every read
ModelMetadata& metadata = ModelMetadata::getInstance();
metadata.setDimensionsFromFile(filePath);
Copy link
Collaborator

Choose a reason for hiding this comment

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

How many calls to getModelState() are expected? In each model run, there should only be one call to SomethingGrid::getModelState() and within that one call to SomethingGridIO::getModelState() (where SomethingGrid is the name of the IStructureimplementing class). There are a few more examples around the code base for testing, but I believe that is all.

@joewallwork
Copy link
Contributor Author

Actually, before merging I should check with @Thanduriel that this PR does what was requested and will be of use in the GPU port?

Copy link
Member

@Thanduriel Thanduriel left a comment

Choose a reason for hiding this comment

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

I solved my buffer initialization problem by doing it lazily on GPU, so as long as the CPU initialization still works it should be fine for me.

I noticed that you sometimes pass large objects (like std::string) by value. This is considered bad practice in general for performance reasons (see the CppCoreGuidelines). It does not really matter in the places I commented on, so you decide if you want to change it, but I think it is best to simply always follow the linked rule.

auto& metadata = ModelMetadata::getInstance();

// Initial read of the NetCDF file to deduce the dimensions
for (std::string filename : { inputFilename, forcingFilename }) {
Copy link
Member

Choose a reason for hiding this comment

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

Unnecessary copy.

for(const std::string& filename : ...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @Thanduriel, fixed in 7c27843.


#endif

void ModelMetadata::setDimensionsFromFile(const std::string filename)
Copy link
Member

Choose a reason for hiding this comment

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

Unnecessary copy, could be a reference.

void ModelMetadata::setDimensionsFromFile(const std::string& filename)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 7c27843.

* set. Otherwise, a consistency check is made against the dimensions read from file
* and already set.
*/
void setDimensionsFromFile(const std::string filename);
Copy link
Member

Choose a reason for hiding this comment

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

.

@joewallwork joewallwork merged commit 15538b6 into develop Dec 1, 2025
9 checks passed
@joewallwork joewallwork deleted the issue972_initial-read branch December 1, 2025 10:23
joewallwork added a commit that referenced this pull request Dec 2, 2025
# XIOS handler restructure

Fixes #850
Fixes #1000
~~Merges into #974~~

This will hopefully be the last major restructuring of the XIOS handler
class.

The PR includes some pruning:
* Remove unused `enableXios` function.
* Drop errors from the `ParaGridIO_Xios` member functions already thrown
in `Xios.read` and `Xios.write`.
* Cut down the `configGetX` member functions.
* Remove the `contextId` and `calendarType` arguments from the
constructor because they're now set in `iodef.xml` as of #993.

It also includes better modularisation:
* Extract a new `setupFiles` member function out of the constructor.
* Rename `parseInputFiles` as `setupFields`.
* Split the configuration into `setupClient`, `setupContext`, and
`setupCalendar` and have all of them called from `configure` alongside
`setupFiles` and `setupFields`.

Other misc changes:
* Additional checking of the calendar setup.
* Reordering of member functions to better group XIOS concepts together.
* Better use of references to avoid unnecessary copies.
* Use of `const` qualifier in more places.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request ICCS Tasks or reviews for the ICCS team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Initial read of input file to get dimensions

4 participants