Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies:
- bokeh=3.9
- click=8.4
- cmocean=4.0
- geopandas=1.1
- geopandas=1.2
- git-lfs=3.7
- gitpython=3.1
- h5py=3.16
Expand Down
2 changes: 1 addition & 1 deletion helpers/interim_report_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
parser.add_argument('--batch_name', '-b', type=str, default='', help='Prefix for batch of runs')
args = parser.parse_args()
# check if on hpc
hpc = True if (int(os.environ.get('REEDS_USE_SLURM',0))) else False
hpc = reeds.slurm.check_slurm()

# get list of cases with matching batch name
case_list = glob(os.path.join('runs', '*'))
Expand Down
2 changes: 1 addition & 1 deletion helpers/restart_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
f.writelines(line + '\n')

# Check if we are going to run this in parallel or not
hpc = True if (int(os.environ.get('REEDS_USE_SLURM',0))) else False
hpc = reeds.slurm.check_slurm()
if hpc and len(runs_failed) > 1:
# On HPC with multiple cases
cases_per_node = int(input('Number of simultaneous runs per node [integer]: '))
Expand Down
26 changes: 11 additions & 15 deletions hourlize/run_hourlize.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
import sys
import traceback
import copy_rev_folders
from pathlib import Path
from collections import OrderedDict
sys.path.append(str(Path(__file__).parent.parent))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

curious why we might need this...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Until we address #4 we have to add the parent of the reeds module folder to the path so it can be imported locally. We didn't use the reeds module in this script before, but now we need it for reeds.slurm.check_slurm() below.

import reeds


#%% ===========================================================================
### --- FUNCTIONS ---
Expand All @@ -26,16 +30,14 @@
def get_remote_path(local):
"""detect path to supply curve files either on the HPC or nrelnas01"""
# remote path for supply curves
hpc = True if ('NREL_CLUSTER' in os.environ) else False
hpc = reeds.slurm.check_slurm()
if hpc:
#For running hourlize on the HPC link to shared-projects folder
if os.environ.get('NREL_CLUSTER') == 'kestrel':
cluster = reeds.slurm.get_cluster()
if cluster == 'kestrel':
remotepath = '/kfs2/shared-projects/reeds'
elif os.environ.get('NREL_CLUSTER') == 'eagle':
remotepath = '/shared-projects/reeds'
else:
raise Exception(f"Detected {os.environ.get('NREL_CLUSTER')} as NLR Cluster; "
"only 'eagle' and 'kestrel' are supported")
raise ValueError(f"Unsupported cluster: {cluster}")
else:
# if not on the hpc running link to nrelnas01 and set local to true
remotepath = os.path.join(
Expand Down Expand Up @@ -165,13 +167,9 @@ def launch_batch_file(casename, configpath, outpath, args, copy_from_rev=False):
# setup script to run each case
ext = '.sh' if os.name == 'posix' else '.bat'
with open(os.path.join(outpath, casename + "_run" + ext), 'w+') as OPATH:
if os.environ.get('NREL_CLUSTER') == 'kestrel':
OPATH.writelines("source /nopt/nrel/apps/env.sh \n")
OPATH.writelines("module load anaconda3 \n")
OPATH.writelines("conda activate reeds \n\n")
elif os.environ.get('NREL_CLUSTER') == 'eagle':
OPATH.writelines("module load conda \n")
OPATH.writelines("conda activate reeds \n\n")
OPATH.writelines("source /nopt/nrel/apps/env.sh \n")
OPATH.writelines("module load anaconda3 \n")
OPATH.writelines("conda activate reeds \n\n")
# run hourlize
OPATH.writelines(f"cd {hourlize_path}\n")
callstring = f"python {args.mode}.py --config {configpath}"
Expand All @@ -182,8 +180,6 @@ def launch_batch_file(casename, configpath, outpath, args, copy_from_rev=False):
callstring += "\n"
OPATH.writelines(callstring)



# launch run locally or submit to hpc
if args.local:
if args.nosubmit:
Expand Down
2 changes: 1 addition & 1 deletion hourlize/write_site_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def check_negative_values(df, cost_cols):
)

#%%### Fixed inputs
if reeds.io.hpc:
if reeds.slurm.check_slurm():
remotepath = '/kfs2/shared-projects/reeds'
filepaths = {
'land': os.path.join(
Expand Down
2 changes: 1 addition & 1 deletion postprocessing/combine_runs/combine_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def main(reeds_path, batch_name, folder_name_suffix, runlist, keywords, local, d
combine_case = cases.loc[cases.scenario == scen].copy()
combine_case.to_csv(os.path.join(output_path, 'cases_combined.csv'), index=False)
# check if run should be submitted to HPC or run directly
hpc = True if ('NREL_CLUSTER' in os.environ) else False
hpc = reeds.slurm.check_slurm()
if hpc and local:
print(
"Note: you are on the HPC but are running locally on your current node. "
Expand Down
16 changes: 1 addition & 15 deletions postprocessing/run_pcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@


# %% Functions
def check_slurm(forcelocal=False):
"""Check whether to submit slurm jobs (if on HPC) or run locally"""
hpc = (
False
if forcelocal
else (
True
if int(os.environ.get('REEDS_USE_SLURM', 0)) and ('NREL_CLUSTER' in os.environ)
else False
)
)
return hpc


def solvestring_pcm(
batch_case,
sw,
Expand Down Expand Up @@ -367,7 +353,7 @@ def main(casepath, t, switch_mods=switch_mods_default, label='', overwrite=False
# bigmem = True

# %% Determine whether to submit slurm job
hpc = check_slurm(forcelocal=forcelocal)
hpc = reeds.slurm.check_slurm(forcelocal=forcelocal)

### Run it
if not hpc:
Expand Down
12 changes: 4 additions & 8 deletions postprocessing/run_reeds2pras.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
#%% Imports
import pandas as pd
import os
import sys
import site
import json
from glob import glob
import subprocess
### Local imports
reeds_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(reeds_path)
import reeds


#%%### Functions
def check_slurm(forcelocal=False):
"""Check whether to submit slurm jobs (if on HPC) or run locally"""
hpc = True if (int(os.environ.get('REEDS_USE_SLURM',0))) else False
hpc = False if forcelocal else hpc
return hpc


def submit_job(
case,
year=0,
Expand Down Expand Up @@ -241,7 +237,7 @@ def main(
# switch_mods = {}

#%% Determine whether to submit SLURM job
hpc = check_slurm(forcelocal=local)
hpc = reeds.slurm.check_slurm(forcelocal=local)

### Run it
if hpc:
Expand Down
1 change: 1 addition & 0 deletions reeds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from . import remote as remote
from . import report_utils as report_utils
from . import results as results
from . import slurm as slurm
from . import spatial as spatial
from . import techs as techs
from . import timeseries as timeseries
Expand Down
3 changes: 1 addition & 2 deletions reeds/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
if 'runs' in reeds_path.split(os.path.sep):
reeds_path = reeds_path[: reeds_path.index(os.sep + 'runs' + os.sep)]

hpc = True if ('NREL_CLUSTER' in os.environ) else False

# ######## ######## ### ########
# ## ## ## ## ## ## ##
Expand Down Expand Up @@ -756,7 +755,7 @@ def get_switches(case=None, **kwargs):
threads = get_param_value(fpath_opt, "threads", dtype=int)
sw['threads'] = threads
## Determine whether run is on HPC
sw['hpc'] = True if int(os.environ.get('REEDS_USE_SLURM', 0)) else False
sw['hpc'] = reeds.slurm.check_slurm()
## Add the run location
sw['casedir'] = case
sw['reeds_path'] = reeds_path if case is None else os.path.dirname(os.path.dirname(case))
Expand Down
26 changes: 26 additions & 0 deletions reeds/slurm.py

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Great to have this defined in only one spot and call if needed

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
### Imports
import os


### Functions
def get_cluster():
"""
Return the name of the HPC cluster if on a cluster.
If not on a cluster, return None.
"""
name_fields = ['NREL_CLUSTER', 'NLR_CLUSTER']
## Keep the first match in name_fields
for name_field in name_fields:
out = os.environ.get(name_field)
if out:
break
return out


def check_slurm(forcelocal=False):
"""Check whether to submit slurm jobs (if on HPC) or run locally"""
if forcelocal:
hpc = False
else:
hpc = True if get_cluster() else False
return hpc
31 changes: 11 additions & 20 deletions runreeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ def get_ivt_numclass(reeds_path, casedir, caseSwitches):
def get_rev_paths(revswitches):
# Expand on reV path based on where this run is happening
# when running on the HPC this links to the shared-projects folder
hpc = True if (int(os.environ.get('REEDS_USE_SLURM',0))) else False
if os.environ.get('NREL_CLUSTER') == 'kestrel':
hpc = reeds.slurm.check_slurm()
if reeds.slurm.get_cluster() == 'kestrel':
hpc_path = '/kfs2/shared-projects/reeds/Supply_Curve_Data'
else:
hpc_path = '/shared-projects/reeds/Supply_Curve_Data'
Expand Down Expand Up @@ -833,15 +833,13 @@ def setupEnvironment(
cases_suffix = str(input('Case Suffix: '))

#%% Check whether to submit slurm jobs (if on HPC) or run locally
hpc = True if (int(os.environ.get('REEDS_USE_SLURM',0))) else False
hpc = False if forcelocal else hpc
hpc = reeds.slurm.check_slurm(forcelocal=forcelocal)

### If on NLR HPC but NOT submitting slurm job, ask for confirmation
if ('NREL_CLUSTER' in os.environ) and (not hpc):
if reeds.slurm.get_cluster() and (not hpc):
print(
"It looks like you're running on the NLR HPC but the REEDS_USE_SLURM environment "
"variable is not set to 1, meaning the model will run locally rather than being "
"submitted as a slurm job. Are you sure you want to run locally?"
"It looks like you're running on the HPC login node instead of submitting a "
"slurm job. Are you sure you want to run locally (not recommended)?"
)
confirm_local = str(input('Run job locally? y/[n]: ') or 'n')
if confirm_local not in ['y','Y','yes','Yes','YES']:
Expand Down Expand Up @@ -1278,19 +1276,12 @@ def write_batch_script(
comment('Set up nodal environment for run', OPATH)
OPATH.writelines(". $HOME/.bashrc \n")
OPATH.writelines("module purge \n")

if os.environ.get('NREL_CLUSTER') == 'kestrel':
OPATH.writelines("source /nopt/nrel/apps/env.sh \n")
OPATH.writelines("module load anaconda3 \n")
OPATH.writelines("module use /nopt/nrel/apps/software/gams/modulefiles \n")
OPATH.writelines("module load gams \n")
OPATH.writelines("module load julia/1.12.1 \n")
else:
OPATH.writelines("module load conda \n")
OPATH.writelines("module load gams \n")

OPATH.writelines("module load anaconda3 \n")
OPATH.writelines("module use /nopt/nrel/apps/software/gams/modulefiles \n")
OPATH.writelines("module load gams \n")
OPATH.writelines("module load julia/1.12.1 \n")
OPATH.writelines("conda activate reeds \n")
OPATH.writelines('export R_LIBS_USER="$HOME/rlib" \n\n\n')
OPATH.writelines('\n\n')

#%% Write the input_processing script calls
big_comment('Input processing', OPATH)
Expand Down
2 changes: 1 addition & 1 deletion tests/get_subset_h5.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
]

# series of paths to updated county h5 files
hpc = True if ('NREL_CLUSTER' in os.environ) else False
hpc = reeds.slurm.check_slurm()
if hpc:
remotepath = '/kfs2/shared-projects/reeds' #kestrel
else:
Expand Down
Loading