-
Notifications
You must be signed in to change notification settings - Fork 37
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
Write out a job script for suite and test cases during setup #376
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
eec8f46
Add a package from creating job scripts
xylar 307cfab
Write out job scripts during setup
xylar 00df6e2
Include job script in the docs
xylar 4cdbe8d
Set QOS to blank for Badger
xylar 66cb009
Set constraint for Cori-Haswell
xylar c68887e
Make `t22_ocean_time_step` default acct on Badger
xylar f536ace
Make badger default to no account
xylar 0dcc619
Add suite to script name, job name and compass run
xylar 17669fa
Clean up whitespace in the script
xylar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
from jinja2 import Template | ||
from importlib import resources | ||
import os | ||
import numpy as np | ||
|
||
|
||
def write_job_script(config, machine, target_cores, min_cores, work_dir, | ||
suite=''): | ||
""" | ||
|
||
Parameters | ||
---------- | ||
config : compass.config.CompassConfigParser | ||
Configuration options for this test case, a combination of user configs | ||
and the defaults for the machine and MPAS core | ||
|
||
machine : {str, None} | ||
The name of the machine | ||
|
||
target_cores : int | ||
The target number of cores for the job to use | ||
|
||
min_cores : int | ||
The minimum number of cores for the job to use | ||
|
||
work_dir : str | ||
The work directory where the job script should be written | ||
|
||
suite : str, optional | ||
The name of the suite | ||
""" | ||
|
||
if config.has_option('parallel', 'account'): | ||
account = config.get('parallel', 'account') | ||
else: | ||
account = '' | ||
|
||
cores_per_node = config.getint('parallel', 'cores_per_node') | ||
|
||
# as a rule of thumb, let's do the geometric mean between min and target | ||
cores = np.sqrt(target_cores*min_cores) | ||
nodes = int(np.ceil(cores/cores_per_node)) | ||
|
||
partition = config.get('job', 'partition') | ||
if partition == '<<<default>>>': | ||
if machine == 'anvil': | ||
# choose the partition based on the number of nodes | ||
if nodes <= 5: | ||
partition = 'acme-small' | ||
elif nodes <= 60: | ||
partition = 'acme-medium' | ||
else: | ||
partition = 'acme-large' | ||
elif config.has_option('parallel', 'partitions'): | ||
# get the first, which is the default | ||
partition = config.getlist('parallel', 'partitions')[0] | ||
else: | ||
partition = '' | ||
|
||
qos = config.get('job', 'qos') | ||
if qos == '<<<default>>>': | ||
if config.has_option('parallel', 'qos'): | ||
# get the first, which is the default | ||
qos = config.getlist('parallel', 'qos')[0] | ||
else: | ||
qos = '' | ||
|
||
constraint = config.get('job', 'constraint') | ||
if constraint == '<<<default>>>': | ||
if config.has_option('parallel', 'constraints'): | ||
# get the first, which is the default | ||
constraint = config.getlist('parallel', 'constraints')[0] | ||
else: | ||
constraint = '' | ||
|
||
job_name = config.get('job', 'job_name') | ||
if job_name == '<<<default>>>': | ||
if suite == '': | ||
job_name = 'compass' | ||
else: | ||
job_name = f'compass_{suite}' | ||
wall_time = config.get('job', 'wall_time') | ||
|
||
template = Template(resources.read_text( | ||
'compass.job', 'template.sh')) | ||
|
||
text = template.render(job_name=job_name, account=account, | ||
nodes=f'{nodes}', wall_time=wall_time, qos=qos, | ||
partition=partition, constraint=constraint, | ||
suite=suite) | ||
text = _clean_up_whitespace(text) | ||
if suite == '': | ||
script_filename = 'compass_job_script.sh' | ||
else: | ||
script_filename = f'compass_job_script.{suite}.sh' | ||
script_filename = os.path.join(work_dir, script_filename) | ||
with open(script_filename, 'w') as handle: | ||
handle.write(text) | ||
|
||
|
||
def _clean_up_whitespace(text): | ||
prev_line = None | ||
lines = text.split('\n') | ||
trimmed = list() | ||
# remove extra blank lines | ||
for line in lines: | ||
if line != '' or prev_line != '': | ||
trimmed.append(line) | ||
prev_line = line | ||
|
||
line = '' | ||
lines = list() | ||
# remove blank lines between comments | ||
for next_line in trimmed: | ||
if line != '' or not next_line.startswith('#'): | ||
lines.append(line) | ||
line = next_line | ||
|
||
# add the last line that we missed and an extra blank line | ||
lines.extend([trimmed[-1], '']) | ||
text = '\n'.join(lines) | ||
return text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
#SBATCH --job-name={{ job_name }} | ||
{% if account != '' -%} | ||
#SBATCH --account={{ account}} | ||
{%- endif %} | ||
#SBATCH --nodes={{ nodes }} | ||
#SBATCH --output={{ job_name }}.o%j | ||
#SBATCH --exclusive | ||
#SBATCH --time={{ wall_time }} | ||
{% if qos != '' -%} | ||
#SBATCH --qos={{ qos }} | ||
{%- endif %} | ||
{% if partition != '' -%} | ||
#SBATCH --partition={{ partition }} | ||
{%- endif %} | ||
{% if constraint != '' -%} | ||
#SBATCH --constraint={{ constraint }} | ||
{%- endif %} | ||
|
||
source load_compass_env.sh | ||
compass run {{suite}} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The geometric mean seems to be a good guess for what folks might want but I'm up for other suggestions for how to handle the node count.