Repository navigation
Add Thwaites UQ study framework - #488
Conversation
f9470db to
25022ed
Compare
| [deploy] | ||
|
|
||
| # the name of the machine | ||
| machine = cori-haswell |
There was a problem hiding this comment.
@xylar , based on our discussion last week, I made changes to this PR to use the standard compass job generation function instead of having a special copy in this test case. I was able to do that with only one change to compass framework, which is this line letting the config know the machine name being used. This is because the write_job_script function requires machine as an input argument, and I could not see anywhere that the machine is saved and made accessible other than through the compass setup call stack (which was not accessible from my step's setup method).
I could imagine there are other ways this problem could be resolved, so I want to get your feedback on my adding this line to the machine .cfg file before I add the corresponding lines to the other machine cfg files. You certainly would not want users to modify this cfg entry, but there are a number of other entries that have the same situation (e.g. compiler). On the other hand, I could imagine other uses for saving the machine name (e.g. a test case wanting to do things differently depending on which machine it is being run on).
Commit f894a04 explains why this was needed and shows how it was used to solve my problem.
There was a problem hiding this comment.
@matthewhoffman, I think it might be better to just add the machine name in code during setup. That way, it doesn't have to be included by hand in each machine's config file, especially because it's redundant.
I would add the following here in the code:
https://github.com/matthewhoffman/compass/blob/7b02c0c924ee77babe975afea4bf48e846360733/compass/setup.py#L434-L437
# add the compass machine config file
if machine is None:
machine = 'default'
config.add_from_package('compass.machines', f'{machine}.cfg')
if machine is not None:
config.set('deploy', 'machine', machine)There was a problem hiding this comment.
@xylar , yes I agree that sound cleaner. I'll add that. Thanks for the feedback.
| # Steps need to be defined in TestCase.__init__ | ||
| # But we want to keep operations to a minimum | ||
|
|
||
| self.nRuns = 20 # number of runs in ensemble |
There was a problem hiding this comment.
@xylar , in our discussion, I believe you suggested the number of runs could come from the config file. But my understanding is the config is not parsed until the configure/setup step. Can you explain or point me to an example of how best to get this value from the config here in the constructor?
There was a problem hiding this comment.
You can (and I think should in this circumstance) pass a user config file with -f as part of compass setup. That would be the config file that sets a config option. This config option could default to 20 (or 1 or whatever makes sense as a default). Ideally, users would also use the config file to set other properties of the ensemble before setting it up. This would be qualitatively similar to the config file required for the ismip6_forcing test cases.
There was a problem hiding this comment.
@xylar , I agree with the idea of having a cfg file where some user adjustments are expected prior to setting up the test case for this. I took a look at the ismip6_forcing test group again, but I can't find an example of where the config is parsed in the constructor. In order to init the steps for the, say, 20 runs, we need to know the number of runs in the test case constructor, but standard practice is that the config object is not parsed and available until setup. From what I can tell, the ismip6_forcing group follows that standard practice, but I might be missing something.
(BTW, you may have noticed this comment thread only appears in the conversation tab of the PR, because I have subsequently changed this line of code for other reasons.)
There was a problem hiding this comment.
The config file is never parsed in the constructor. That's not possible because that happens even for compass list. It must happen in the setup() method. You have to move this stuff from the constructor to configure().
There was a problem hiding this comment.
Take a look at the cosine bell test case for an example of this:
https://github.com/MPAS-Dev/compass/blob/main/compass/ocean/tests/global_convergence/cosine_bell/__init__.py
We start with a default set of steps based on the default value of the config option resolutions, but then we throw away those steps at configure() and make a new set based on a modified set of resolutions (if necessary).
There was a problem hiding this comment.
In your case, I wouldn't bother with the stuff in __init__() because you should be fine with there being zero steps in the test case by default (e.g. in compss list --verbose). You can just add the steps within configure().
There was a problem hiding this comment.
Ah, I see. I was so focused on trying to get the steps finalized in the constructor. I know you keep referring me to the cosine bell test, and now I understand that aspect of it. I had understood that steps_to_run could be changed at setup time, but I hadn't made the connection that the actual set of steps that are part of the test case could be entirely adjusted during setup. I'll take a closer look and implement that when I have time to get back to this. Thanks for the explanation.
| self.config.set('job', 'job_name', f'uq_{self.name}') | ||
| machine = self.config.get('deploy', 'machine') | ||
| write_job_script(self.config, machine, | ||
| target_cores=self.ntasks, min_cores=self.min_tasks, | ||
| work_dir=self.work_dir) |
There was a problem hiding this comment.
Setting [job]/job_name might have unintended consequences (like setting the name of the job for the whole suite to the last uq name). One better option would be to copy the config options to a new config object just to pass to write_job_script(), see http://mpas-dev.github.io/MPAS-Tools/stable/generated/mpas_tools.config.MpasConfigParser.copy.html#mpas_tools.config.MpasConfigParser.copy.
But I think a better option would just be to add another keyword argument to write_job_script(..., job_name=None). Then, we would use the argument if it's not None and the current behavior if it's None.
There was a problem hiding this comment.
I'll take a look at including a new optional argument to write_job_script. I had started doing that yesterday, but chose this route for some reason I'm not recalling.
TestingTested with Testing need to be done on Cori to have access to the input file specified in the cfg file and the forcing files hardcoded in the streams files. This PR is meant to merge the basic ensemble capability, and more PRs are expected in the future to build out details. Thus, I consider simple ensuring a user can set up and submit an ensemble is sufficient testing for this branch. This test group/test case will not be added to an integration suite. I will be writing up documentation next before requesting review. |
|
@xylar and @trhille , this is ready for review. As I've mentioned to both of you, the goal for this PR is to merge a basic ensemble functionality that can be checkpointed and then built out further as the project progresses. @xylar , I think a review by inspection, plus more critically looking at the (small) framework and docs changes should suffice from you, but you are welcome to review and/or run at whatever level of detail you wish. Your initial review helped a lot with the design and structure. @trhille , for you, I suggest reading the docs and then trying to set up and submit a small ensemble. (By default it only sets up 4 runs, but you can also kill them after they're submitted if you don't actually want to run them.) You can look at the output path for https://acme-climate.atlassian.net/wiki/spaces/FAN/pages/3656220835/Thwaites+UQ+test+4 if you want to browse/plot a larger ensemble. You may need to touch base with me on how to customize a cfg for a test, but I think the default will more or less work fine for testing purposes. Note that the history is fairly convoluted, so it's probably easier to look at the final file changes than follow along the history. I originally created this as a test case within the thwaites test group, but at the end decided it should be its own test group, with the thwaites application as its first test case. It would be extensible to other applications and is in general not unique to the thwaites configuration. You can view the docs changes here, where I've moved temporarily for review:
|
xylar
left a comment
There was a problem hiding this comment.
A few very minor comments but this looks good to me as long as it works in @matthewhoffman and @trhille's testing.
| # store name of machine so tests have access to it if needed | ||
| if machine is not None: | ||
| config.set('deploy', 'machine', machine) | ||
|
|
There was a problem hiding this comment.
I think this is great! There is also a $COMPASS_MACHINE environment variable set in the load script, so that would have been another way that maybe I didn't think of at the time.
| from compass.landice.tests.thwaites.restart_test import RestartTest | ||
| from compass.landice.tests.thwaites.high_res_mesh import HighResMesh | ||
|
|
||
|
|
There was a problem hiding this comment.
This extra newline is standard in PEP8. Please put it back when you get a chance.
There was a problem hiding this comment.
I've added it back in.
| obs_discharge_thwaites = np.array([82.42, 83.25, 84.08, 84.90, 85.73, 86.56, 87.39, 88.22, 89.04, 89.87, 90.70, 91.40, 92.10, 92.80, 93.50, 94.20, 94.90, 95.60, 95.90, 96.20, 96.50, 96.80, 97.10, 97.40, 97.75, 98.10, 101.60, 101.40, 102.80, 104.30, 109.70, 114.10, 115.80, 118.70, 121.60, 123.80, 117.20, 115.10, 119.68]) | ||
| obs_discharge_haynes = np.array([10.10, 10.25, 10.40, 10.55, 10.70, 10.85, 11.00, 11.15, 11.30, 11.45, 11.60, 11.49, 11.37, 11.26, 11.14, 11.03, 10.91, 10.80, 10.93, 11.07, 11.20, 11.33, 11.47, 11.60, 11.35, 11.10, 12.20, 11.90, 12.50, 12.11, 12.80, 12.80, 12.90, 12.80, 13.90, 14.70, 12.30, 11.60, 12.53]) |
There was a problem hiding this comment.
Please reformat these to stick with the 79 character line length and with just one space between entries. Maybe consider having them in a data file and loading them instead of having them hard coded here.
There was a problem hiding this comment.
I've fixed for formatting, but left it hardcoded for now. This script is run as a symlink from various places, so having this small amount of data hardcoded avoids issues of pointing to a data file.
There was a problem hiding this comment.
Hmm, if you can symlink the script, can't you symlink a data file in the same way? But I'm okay with you doing this your way.
| #axfltArea = fig.add_subplot(nrow, ncol, 4) | ||
| #plt.title(f'Floating area change at year {targetYear} (km$^2$)') | ||
| #plt.xlabel('von Mises stress threshold (kPa)') | ||
| #plt.ylabel('basal friction law exponent') | ||
| #plt.grid() | ||
| #plt.scatter(vmThresh, fricExp, s=markerSize, c=fltAreaChangeAll, plotnonfinite=False) | ||
| #badIdx = np.nonzero(np.isnan(fltAreaChangeAll))[0] | ||
| #plt.plot(vmThresh[badIdx], fricExp[badIdx], 'kx') | ||
| #plt.colorbar() |
There was a problem hiding this comment.
I will leave this up to you all but I prefer not to have commented-out code unless there is a high likelihood that it will be added back soon. It would be better to have a config option to plot this, and have it set to False by default.
c4a05e2 to
5a3e0b1
Compare
This commit starts putting together a framework for setting up and running a basic Thwaites UQ study. It creates a set number of ensemble members with parameter values randomly selected from pre-set ranges. Currently, only the von Mises stress threshold and speed limit are included as parameters. It currently sets up the runs, but I have not yet been able to successfully run them due to an Albany runtime library issue. A number of shortcuts have been made that may need to be generalized in the future: * input file locations are hard-coded * numTasks is hard coded for Cori * we may want parameter vectors to come from a file instead of being generated within the test case * it's unclear if it's possible to create job scripts for each run. currently, compass run would only be able to run these 20 tests in serial
This is modifed from the compass framework job.py module. For now I have commented out the machine variable, because it's not clear to me how to determine that from this point in the code.
This commit adds an additional step for a run manager that can determine if individual runs need to be started/continued and submit them as separate batch jobs. The concept works, but compass requires `compass run` commands to be issued from compute nodes, so this step can only be run from an interactive node or batch job itself, which is otherwise unnecessary. It might be better to have the run manager be a separate script called from outside the compass system.
This could be moved into its own step, but I'm not sure yet that it's worth it.
The individual run and run manager classes/steps have been renamed for clarity. It also was useful to have the run (now ensemble) manager workdir to not start with 'run' to make globbing the run directories easier.
This allows cases/steps to know what machine they are on, Added just to cori-haswell for now, but will add to remaining machines cfg files.
This commit removes the job module and template specific to this test case and uses the standard compass job module and template instead. To enable this, I needed to: * add the name of the machine to the machine cfg file in the previous commit * set the job name in the config from within the step setup so that the job script generation function will find it there * create a symlink to the compass load script in the step work_dir, because compass does not create one and the job script template assumes the load script is in the dir the job is being run from
Also fix variable naming convention of run_num
Just the vm threshold stress for now, because code needs to be written to set up gamma0.
Copied from a tool in MPAS-Tools that Trevor wrote. Needs some clean up yet.
This includes: * updating parameter vector * modifying muFriction for updated exponent. This makes use of a new general extrapolate module added at the shared landice level. It also switches to first copying the input file to the run work_dir so that it can be modified in place. The input file path is now specified in the config file, though we may want to move it to the database. * modifying exponent value in yaml file. This required directly copying the yaml file instead of using 'add_input_file' so that the yaml contents could be modified within the setup method. It also makes use of a yaml parser to modify an entry. The yaml parser changes the ordering, which might not be desired. * Commenting a hanging level of the yaml file, as the yaml parser writes its value out as Null, which Albany does not like. Note: we may add the calving speed limit back in later, but for now we want to restrict ourselves to two parameters.
It caused some areas of the mu field to not be able to be modified, which led to garbage.
Also, replace floatingArea plot with groundingLineFlux.
Move the ensemble test case to its own group with thwaites as a test case (instead of in the thwaites test group with uq_ensemble as the test case). There is little about this framework that is specific to Thwaites Glacier, and it will be more flexible and less confusing to have a dedicated ensemble test group. This commit moves/renames the files and modules and does a little cleanup. A bit more cleanup is necessary to make the new ensemble test group not specific to Thwaites. I confirmed the test case runs and can set up an ensemble same as before.
They currently are not varied, but the machinery to allow them be varying parameters was added. Docs updated accordingly. I also moved the ntasks option to the cfg file, rather than having it hardcoded in the python code.
This is to avoid potential confusion if a user attempted to use it for something else (not recommended).
Co-authored-by: Xylar Asay-Davis <[email protected]>
d1bdf8d to
7ea4ecf
Compare
7ea4ecf to
2b66289
Compare
|
@matthewhoffman, as you'll notice here, I added a code linter If you rerun (See https://github.com/MPAS-Dev/compass/actions/runs/4245474450/jobs/7381031296#step:6:83) It'll presumably fix a few more things, so run it again. When it stops fixing things and start complaining about code not following PEP8 or having incorrect typing, that's when you have to actually start fixing the code. It's going to be nasty and tedious this time because a lot of code is affected at once. Once we have this going all the time, it'll get easier since only a small amount of code will be involved. Polaris has this going on all the code committed there so far and everything that moves there will need to have this clean up so it might as well start in compass now. |
|
@matthewhoffman, before I forget about it, please add |
|
Updated docs have been generated for perusal here:
|
This is required for this test case to function properly from the conda package.
|
@trhille , I've completed cleanup on this PR, including adding to the docs and doing all the PEP8 delinting. See links above for relevant parts of compiled documentation. It's ready for you to test and review whenever NERSC is sufficiently operational again. @xylar , I took care of the items you identified yesterday. You are welcome to review again if you'd like, but I don't think that's necessary. |
There was a problem hiding this comment.
@matthewhoffman , this is excellent! Thanks for creating this useful new tool. I tested on Perlmutter, and was able to easily create and submit a Thwaites ensemble.
I added some very minor comments on the documentation (mostly fixing typos), but I'm approving so this can be merged as soon as possible.
I also visually checked the diagnostic solve for the first four runs to make sure the recalculated basal friction law exponent is producing a good velocity field:

|
@trhille , thanks for testing this out, checking the results, and the feedback on the docs. I'm excited to have this merged and ready to build off of. |

This merge creates a framework for setting up and running a basic Thwaites UQ study. It sets up a user-defined number of simulations with parameter values selected from a Sobol sequence. It is set up to consider the basal friction exponent and the von Mises stress threshold as the two parameters varied. There also is plumbing to consider the gamma0, deltaT, and calving speed limit as additional or alternative parameters.
Each ensemble member is a step of the test case. A slurm job script is created for each job, so that they can be submitted and run in parallel. There is also an additional step called the ensemble manager that submits each run with sbatch. Due to the requirement that compass run only occurs on a compute node, this step has to be submitted via a batch script or interactive job. (This may be addressed in the future.) There is a visualization script that performs basic analysis on the results of the ensemble. It will be further developed in the future, but provides a basic assessment of results.
A config file specifies the location of the input file, the basal friction exponent used in the input file, the name of the parameter vector file to use, and the start and end run numbers to set up. The ensemble manager can set up and run additional runs with a different range of run numbers after being run initially. This allows one to perform a small ensemble (e.g. 2-10 runs) to make sure results look as expected before spending time on a larger ensemble. This also allows one to add more ensemble members from the Sobol sequence later if UQ analysis indicates the original sample size was insufficient.
The design philosophy is to balance generalizability with simplicity. The test group is set up to fairly easily add other ensemble configurations with minimal effort. On the other hand, in the specific thwaites test included now, there are assumptions about running on Cori, etc. These could be generalized in the future if desired. Because this will not be included in suites, it is intended for expert users and it is expected that it will typically be run with a customized cfg file.
A number of issues remain that may be addressed in future branches:
compass runby identifying runs that had not reached the stop time and only resubmitting those jobs (as restarts). This has not been an issue yet, because the configuration currently specified is short enough to not require restarts.There is a small compass framework change to setup.py that stores the machine name in the config so a test case has access to it. This was necessary to make use of the framework job script generation script, which requires the machine name as an input.
Checklist
api.rst) has any new or modified class, method and/or functions listedTestingin this PR) any testing that was used to verify the changes