Skip to content

Conversation

@akturner
Copy link
Collaborator

In creating new partition files for the sea ice model I have found the need to write out the cellMap variable to a text file during cell culling. This PR adds this capability to the cell culler. getopt is now used to handle program options. Input and output grid files are now specified with the -i and -o options. The original -i (invert) option is changed to -v. Writing out the cellMap variable is specified with the -n option. The -h option now prints the usage. This PR attempts to implement comments from @xylar on a previous attempt to implement this functionality.

Changed cellCuller options to use getopt
Added -n option to output cellMap variable to a text file
Added -i/-o options to input and output filename options
Changed the -i option to be -v since -i seemed better to use with input filenames
Added -h option to output usage
}

// default for input
if (in_name == "") {
Copy link
Collaborator

@xylar xylar Nov 18, 2016

Choose a reason for hiding this comment

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

@akturner, to be consistent with print_usage, and to be backwards compatible with existing ocean test cases that assume default values of the arguments this and the next two if statements should be removed (in_name and out_name should be given their default values, not be read in from stdin). In ocean test cases, we assume that the input and/or output arguments will be the defaults and we definitely do not want the script to prompt for a file name when we're running a script that includes calls to the cell culler.

In general, I think these tools need to avoid using stdin (cin) because we plan to use them as part of automated scripts.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@xylar The intent here was to make this as similar to the original code as possible. Using getopt it doesnt appear the exact behavior of the original code is exactly reproducible. Personally, I dont see the utility in using stdin and cin and am happy to remove it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see. Weird. So the original code would ask for an input file name if you didn't give one (so that argument wasn't actually optional) but didn't to that for the output argument. I don't think that makes any sense.

I would strongly recommend getting rid of anything to do with cin.

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 have removed the ability to read in the filenames from the stdin.

cout << "\t\t-m/-i:" << endl;
cout << "\t\t\tIf not specified, it defaults to culled_mesh.nc." << endl;
cout << "\t\t-m/-v/-p:" << endl;
cout << "\t\t\tThis argument controls how a set of masks is used when culling a mesh." << endl;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should now be "These arguments"

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've corrected this.

cout << "\t\t\tThe -i argument applies the inverse mask to cull based on (i.e. where the mask is 0, the mesh will be culled)." << endl;
cout << "\t\t\tThe -v argument applies the inverse mask to cull based on (i.e. where the mask is 0, the mesh will be culled)." << endl;
cout << "\t\t\tThe -p argument forces any marked cells to not be culled." << endl;
cout << "\t\t\tIf this argument is specified, the masks_name argument is required" << endl;
Copy link
Collaborator

@xylar xylar Nov 18, 2016

Choose a reason for hiding this comment

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

Should be "For each of these arguments that is specified," (since multiple of these can be specified at once).

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've corrected this.

cout << "\t\t\tThe -v argument applies the inverse mask to cull based on (i.e. where the mask is 0, the mesh will be culled)." << endl;
cout << "\t\t\tThe -p argument forces any marked cells to not be culled." << endl;
cout << "\t\t\tIf this argument is specified, the masks_name argument is required" << endl;
cout << "\t\t\tIf one of the mask options are specified both the input and output filenames must be explicitly specified." << endl;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I do not think this is a requirement, since they will default to "grid.nc" and "culled_mesh.nc" if they are not specified.

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've corrected this.


int main ( int argc, char *argv[] ) {
int error;
string out_name = "culled_mesh.nc";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why change this behavior when you use a pair of if statements to do the same below?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removing stdin greatly simplified the options and set the defaults to grid.nc and culled_mesh.nc if -i or -o are not specified

}

if (out_name == "") {
out_name = "culled.nc";
Copy link
Collaborator

@xylar xylar Nov 18, 2016

Choose a reason for hiding this comment

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

This is not the default name given in print_usage. It is also not the default name expected by a large number of ocean test cases that use the cell culler. I would prefer that it remain 'culled_mesh.nc' for backwards compatibility.

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've corrected this.

@xylar
Copy link
Collaborator

xylar commented Nov 18, 2016

@akturner, I haven't had a chance to test the code so far, but I'll get to that shortly. None of my comments so far relate to the normal usage of the code, just to print_usage and the behavior when the input and/or output file names are not specified.

@xylar
Copy link
Collaborator

xylar commented Nov 18, 2016

Since almost every ocean test case uses the cell culler, we will need a PR into ocean/develop to make all test cases compatible with the new -i and -o flags when they get merged from develop to ocean/develop. I will take care of that when the time comes.


// need explicit input and output names if mask flags specified
if (cullMasks and (in_name == "" or out_name == "")) {
printf ("ERROR: Need explicit input and output names if mask flags specified.\n", c);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The second argument to printf (c) isn't needed (and is giving me warnings when I compile the code).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This has been removed.

@xylar
Copy link
Collaborator

xylar commented Nov 18, 2016

I verified that this version of the cell culler works fine with the ocean/global_ocean/QU_240km/performance_test test case on ocean/develop when I add the -i and -o flags, and change the existing -i to a -v flag for calls to the cell culler in the init_step1.py script.

Removed the ability to read in filenames from stdin. The code now defaults to grid.nc for input and culled_mesh.nc for output.
Corrected the default output to culled_mesh.nc
Updated the usage statement.
@akturner
Copy link
Collaborator Author

@xylar Thanks for these suggestions. I've corrected the code as requested. Thanks for reviewing this.

@akturner
Copy link
Collaborator Author

Would there be utility in updating the mask_creator and mesh_converter to use getopt and to be consistent with the usage of -i and -o here?

@xylar
Copy link
Collaborator

xylar commented Nov 18, 2016

Would there be utility in updating the mask_creator and mesh_converter to use getopt and to be consistent with the usage of -i and -o here?

@akturner, I think that would be a very good idea. It would make the 3 tools less confusing, especially for new users. Also, if we want to make this change, it would be good to do so for all the tools at once. That way I can update all the ocean test cases to the new flags in one go.

@xylar
Copy link
Collaborator

xylar commented Nov 18, 2016

The code looks great to me now.

By the way, I verified that the code writes out a list of cell indices to a text file. Since I don't have any tools that would make use of this mapping, I didn't have a way of verifying that they are the correct indices, but given how dead simple the code is for writing them out, I'm inclined to believe they're what you want.

@xylar
Copy link
Collaborator

xylar commented Nov 18, 2016

I'll wait for updates on the mask creator and mesh converter, and then I'll be happy to re-check and merge as soon as I've got the go-ahead from @matthewhoffman , @mgduda and @mark-petersen.

@mark-petersen
Copy link
Collaborator

@xylar thank you for your review and testing of this PR. It is particularly helpful now that I have responsibilities coordinating both MPAS and ACME pull requests.

@xylar
Copy link
Collaborator

xylar commented Nov 18, 2016

@mark-petersen, happy to do my part.

@akturner
Copy link
Collaborator Author

akturner commented Nov 18, 2016

I will work on modifying the other two tools. I will also need to update the README.

Are the test input files for the mesh converter and the mask creator I can use for testing?

@xylar
Copy link
Collaborator

xylar commented Nov 18, 2016

I will also need to update the README.

Good call.

Are the test input files for the mesh converter and the mask creator I can use for testing?

I'll generate some for you using one of the ocean test cases.

@xylar
Copy link
Collaborator

xylar commented Nov 18, 2016

@akturner, you should be able to find what you need in the folder:

/lustre/scratch3/turquoise/xylar/mpas_runs/baseline/ocean/global_ocean/QU_240km/performance_test/init_step1

Good tests would be to see if you can reproduce the following sequence of commands (this is the syntax of the old tools) with the new tools, and if you get bit-for-bit identical results (on wolf) to the files I got. You could tar up the contents of the directory and untar it somewhere in your scratch directory, move all the output files (land_mask.nc critical_passages_mask.nc culled_mesh.nc seed_mask.nc culled_mesh_final.nc critical_passages_mask_final.nc test.nc) to a temporary directory to make it easier to do bit-for-bit checks on them, e.g. with diff, and run the tests below.

./MpasMaskCreator.x  base_mesh.nc land_mask.nc -f land_coverage.geojson
./MpasMaskCreator.x  base_mesh.nc critical_passages_mask.nc -f critical_passages.geojson
./MpasCellCuller.x  base_mesh.nc culled_mesh.nc -m land_mask.nc -p critical_passages_mask.nc
./MpasMaskCreator.x  culled_mesh.nc seed_mask.nc -s seed_points.geojson
./MpasCellCuller.x  culled_mesh.nc culled_mesh_final.nc -i seed_mask.nc
./MpasMaskCreator.x  culled_mesh_final.nc critical_passages_mask_final.nc -f critical_passages.geojson
./MpasMeshConverter.x culled_mesh_final.nc test.nc

All these steps except the last one are part of our standard setup for realistic ocean test cases.

Note, I built the tools with intel compilers, so that would make a difference. I could redo with gnu if necessary.

You should have permission to read these files but let me know if that's not the case.

Mesh converter and mask converter now use getopt for command line options. Input and output filenames are specifid with -i and -o flags now.
README has been updated to reflect changes
Updated print usage statements.
Removed trailing whitespace.
@akturner
Copy link
Collaborator Author

@xylar I performed those tests and the modified code gave zero differences with ncdiff. I modified the README to reflect the new functionality and removed trailing whitespace.

@xylar
Copy link
Collaborator

xylar commented Nov 22, 2016

@mgduda and @matthewhoffman, do you use these tools as part of the workflow of your respective components? If not, could you let me know so I don't wait for your response. If so, could you run a test for each tool you use to make sure @akturner's changes don't break anything for you?

@matthewhoffman
Copy link
Member

We use these tools, and these changes are fine with me. I don't like having to update our test cases for the syntax change, but it's not hard and in the long run I can see how these changes will be worthwhile.

Note (as is probably obvious) that changes like this reveal one of the remaining vulnerabilities in the test case infrastructure - this change requires ensuring two different repos (MPAS and MPAS-Tools) are synced across this change, otherwise tests break. This might make regression tests or git bisect painful for a little while.

@xylar
Copy link
Collaborator

xylar commented Nov 22, 2016

I don't like having to update our test cases for the syntax change, but it's not hard and in the long run I can see how these changes will be worthwhile.

I agree on both points. It's going to be a pain on the ocean side, too, for a bit. But we'll make due.

Note (as is probably obvious) that changes like this reveal one of the remaining vulnerabilities in the test case infrastructure - this change requires ensuring two different repos (MPAS and MPAS-Tools) are synced across this change, otherwise tests break. This might make regression tests or git bisect painful for a little while.

That's right. I had been thinking somehow that there would be a merge (like develop to ocean/develop) at which point we could synchronize these changes. That's not the case. Which means that I don't actually think we can merge these changes until after an ACME v1 release branch is created from ocean/develop. Otherwise, we're going to have to make another merge into ocean/develop to be compatible with these changes.

@mark-petersen (and anyone else), what are your thoughts?

@xylar
Copy link
Collaborator

xylar commented Nov 23, 2016

cc @mark-petersen

I made a PR (MPAS-Dev/MPAS#1148) with the idea that it and this PR should be fulfilled essentially simultaneously. @matthewhoffman, we will want a similar branch and PR for landice/develop.

Again, the question remains whether we need to create release branches of this repo, ocean/develop and landice/develop before making these changes. ACME should be unaffected but the policy has been essentially not to make unnecessary changes in the develop branches until we have a release branch...

@matthewhoffman
Copy link
Member

@xylar , another short term solution would be to avoid updating any local checkouts of MPAS-Tools (i.e. continue using the current HEAD). That would eliminate the need to update the MPAS CORE/develop branches immediately - at least until some new feature in MPAS-Tools is required.

I apologize for not reading the details of this PR carefully, but do you think it is possible to implement the new command line flags while still retaining backward compatibility with the existing argument usage?

@akturner
Copy link
Collaborator Author

@matthewhoffman No, its not possible with getopt to retain the original usage. I didnt realize this would create so many issues, when all I needed was to add a single functionality to one of the tools. If you want to roll back the previous commit and just carry on as the tools are feel free.

@xylar
Copy link
Collaborator

xylar commented Nov 23, 2016

@akturner and @matthewhoffman, I'll let the two of you decide if we want to proceed with this PR. The syntax does seem better and more similar to other tools we use with this PR. But it is also a big pain to make these changes, since we lose backwards compatibility.

@akturner, it should be possible to add your one flag using @douglasjacobsen's old syntax instead of getopt, which would make the whole PR a lot easier to merge (if less clean).

@matthewhoffman
Copy link
Member

@akturner & @xylar , I don't feel particularly strongly - the landice core is fairly stable at the moment, but I'm more worried about the ocean core where the ACME v1 finalization work has been a bit fragile.

As an aside, I had a thought that once we 'finalize' a place and name for the test case infrastructure, we could investigate adding MPAS-Tools as a git submodule within the testing infrastructure directory. Then versions of the test_case infrastructure could be tied to versions of MPAS, and it could also simplify where to find the individual tools and what their names are. For users who don't have access to the MPAS-Tools repo, the submodule would just not update (but we'd have to look into how that looks/operates). There are other complications, like how to get the individual tools in the submodule built without having to do in manually. So I'm not sure this a great idea, but give it some thought (unrelated to this PR).

In the meantime, I'm on the fence about what to do here. @mark-petersen , as another regular user of the test case infrastructure on the ocean side, do you have an opinion? We could wait and discuss this on Monday's telecon, depending on how urgent this is for @akturner.

@akturner
Copy link
Collaborator Author

@matthewhoffman This is not urgent at all. I think we should just roll everything back to how it was. I apologize for wasting everyones time.

@xylar
Copy link
Collaborator

xylar commented Nov 23, 2016

I had a thought that once we 'finalize' a place and name for the test case infrastructure, we could investigate adding MPAS-Tools as a git submodule within the testing infrastructure directory. Then versions of the test_case infrastructure could be tied to versions of MPAS, and it could also simplify where to find the individual tools and what their names are. For users who don't have access to the MPAS-Tools repo, the submodule would just not update (but we'd have to look into how that looks/operates). There are other complications, like how to get the individual tools in the submodule built without having to do in manually. So I'm not sure this a great idea, but give it some thought (unrelated to this PR).

I think that's a great idea. Presumably MPAS versions could be released with associated versions of the tools, so there shouldn't be anyone that doesn't have permission to get the tools they would need to set up MPAS test cases. Presumably some tweaks to the makefiles (along the lines of #136) would make it easier to build the tools as part of setting up test cases. Most of the tools we use on the ocean side are python-based at this point anyway.

@xylar
Copy link
Collaborator

xylar commented Nov 23, 2016

@akturner, are you sure you don't just want to change this PR to add the one flag you wanted in the first place? That way you at least get the index map you need.

@akturner
Copy link
Collaborator Author

@xylar I might do that later but for now lets just roll back and I'll submit a new PR later

@xylar
Copy link
Collaborator

xylar commented Nov 23, 2016

There's not anything to roll back. You just close the PR and delete the branch (unless you want to keep it)

@xylar
Copy link
Collaborator

xylar commented Dec 4, 2016

@akturner, should I go ahead and close this PR?

@akturner
Copy link
Collaborator Author

akturner commented Dec 5, 2016

Yes please, Xylar. Thanks

@xylar xylar closed this Dec 5, 2016
@xylar xylar deleted the cellCuller/output_culler_cellmap branch December 5, 2016 20:09
@xylar
Copy link
Collaborator

xylar commented Dec 5, 2016

@akturner, I also deleted the remote branch. You can restore it if you would rather keep it. But make sure you do so soon before it's gone for good...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants