Skip to content

Commit

Permalink
remove HPCExample from main.py, add HPCExample Tutorial Notebook
Browse files Browse the repository at this point in the history
remove HPCExample from main.py, add HPCExample Tutorial Notebook.
It was not working as an internal function nayways it was mostly for demonstration. Now as a journal it almost does stuff... still need to debug why it's not going into runJob().
Improves coverage by 2% (now at 64!)
  • Loading branch information
shirubana committed Nov 27, 2019
1 parent 76c2767 commit bedea2a
Show file tree
Hide file tree
Showing 2 changed files with 275 additions and 107 deletions.
107 changes: 0 additions & 107 deletions bifacial_radiance/main.py
Expand Up @@ -3665,114 +3665,7 @@ def runJob(daydate):
modWanted=modWanted,
rowWanted=rowWanted,
sensorsy=sensorsy)

def hpcExample():
"""
Example of HPC Job call
This allocates the day_dates generated to the different codes in as many nodes are available.
Works inside and outside of slurm for testing (but set FullYear to False so it only does two days)
Full year takes 1 min in 11 Nodes.
Variables stored in input_bf.py. First configure this on top:
.. code-block :: python
if __name__ == "__main__": #in case this is run as a script not a module.
from readepw import readepw
from load import loadTrackerDict
from input_bf import *
else: # module imported or loaded normally
from bifacial_radiance.readepw import readepw # epw file reader from pvlib development forums #module load format
from bifacial_radiance.load import loadTrackerDict
from bifacial_radiance.input_bf import *
Procedure for a Full Year Run (~1 min in 11 nodes of 36 cores each > 365 days):
.. code-block :: python
Connect to Eagle
- $ cd bifacial_radiance/bifacial_radiance
- $ srun -A pvsoiling -t 5 -N 11 --pty bash
- $ module load conda
- $ . activate py3
- $ srun bifacial_radiance2.py
Procedure for testing before joining SLURM:
.. code-block :: python
change fullYear to False.
- $ cd bifacial_radiance/bifacial_radiance
- $ module load conda
- $ . activate py3
- $ nano bifacial_radiance.py
- $ python bifacial_radiance2.py
.. warning::
Do not load conda twice nor activate .py3 twice.
(following above) Either activate conda or .py3 in the login node
or on the slurm
"""

import multiprocessing as mp

daylist = []

fullYear = True # running faster testing on HPC ~ only 2 days.

if fullYear:
start = datetime.datetime.strptime("01-01-2014", "%d-%m-%Y")
end = datetime.datetime.strptime("31-12-2014", "%d-%m-%Y") # 2014 not a leap year.
daylist.append('12_31') # loop doesn't add last day. Adding it at the beginning because why not.
daylimit = 365
else:
start = datetime.datetime.strptime("14-02-2014", "%d-%m-%Y")
end = datetime.datetime.strptime("26-02-2014", "%d-%m-%Y") # 2014 not a leap year.
daylimit = 1
date_generated = [start + datetime.timedelta(days=x) for x in range(0, (end-start).days)]
for date in date_generated:
daylist.append(date.strftime("%m_%d"))

# print("This is daydate %s" % (daydate))
demo = RadianceObj(simulationname,path=testfolder)
demo.setGround(albedo)
# HPC IMPORTANT NOTE:
# Multiple Nodes get confused when trying to write the JSON at the same time,
# so make sure moduletype is created before running slurm job for it to work.
# 2 DO: Fix at some point of course.
# moduleDict=demo.makeModule(name=moduletype,x=x,y=y,bifi=bifi,
# torquetube=torqueTube, diameter = diameter, tubetype = tubetype,
# material = torqueTubeMaterial, zgap = zgap, numpanels = numpanels, ygap = ygap,
# rewriteModulefile = True, xgap=xgap,
# axisofrotationTorqueTube=axisofrotationTorqueTube, cellLevelModule=cellLevelModule,
# numcellsx=numcellsx, numcellsy = numcellsy)
sceneDict = {'module_type':moduletype, 'pitch': pitch, 'hub_height':hub_height, 'nMods':nMods, 'nRows':nRows}

cores = mp.cpu_count()
pool = mp.Pool(processes=cores)
res = None

try:
nodeID = int(os.environ['SLURM_NODEID'])
except KeyError:
nodeID = 0 # in case testing for hpc not on slurm yet.

hpccores = 36 # this is valid for Eagle. Find out how many cores are in each node of your HPC to make this work.

day_index = (hpccores * (nodeID))

for job in range(cores):
if day_index+job>=len(daylist): # this makes sure no days above 356 are attempted:
break
pool.apply_async(runJob, (daylist[day_index+job],))

pool.close()
pool.join()
pool.terminate()

def quickExample():
"""
Example of how to run a Radiance routine for a simple rooftop bifacial system
Expand Down
@@ -0,0 +1,275 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 10 - Advanced topics: High Performance Computing Examplel\n",
"\n",
" \n",
"### STILL UNDER CONSTRUCTION\n",
" \n",
"This allocates the day_dates generated to the different codes in as many nodes are available. \n",
"Works inside and outside of slurm for testing (but set FullYear to False so it only does two days)\n",
"Full year takes 1 min in 11 Nodes.\n",
"\n",
" Variables stored in input_bf.py. First configure this on top:\n",
" \n",
" .. code-block :: python\n",
" \n",
" if __name__ == \"__main__\": #in case this is run as a script not a module.\n",
" from readepw import readepw \n",
" from load import loadTrackerDict\n",
" from input_bf import *\n",
"\n",
" else: # module imported or loaded normally\n",
" from bifacial_radiance.readepw import readepw # epw file reader from pvlib development forums #module load format\n",
" from bifacial_radiance.load import loadTrackerDict\n",
" from bifacial_radiance.input_bf import *\n",
" \n",
" Procedure for a Full Year Run (~1 min in 11 nodes of 36 cores each > 365 days):\n",
"\n",
" .. code-block :: python\n",
"\n",
" Connect to Eagle\n",
" - $ cd bifacial_radiance/bifacial_radiance\n",
" - $ srun -A pvsoiling -t 5 -N 11 --pty bash \n",
" - $ module load conda\n",
" - $ . activate py3\n",
" - $ srun bifacial_radiance2.py\n",
" \n",
" Procedure for testing before joining SLURM:\n",
" \n",
" .. code-block :: python\n",
"\n",
" change fullYear to False.\n",
" - $ cd bifacial_radiance/bifacial_radiance\n",
" - $ module load conda\n",
" - $ . activate py3\n",
" - $ nano bifacial_radiance.py \n",
" - $ python bifacial_radiance2.py \n",
" \n",
" .. warning::\n",
" Do not load conda twice nor activate .py3 twice.\n",
" (following above) Either activate conda or .py3 in the login node\n",
" or on the slurm"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"from bifacial_radiance import *\n",
"import multiprocessing as mp\n",
"import datetime\n",
"import os"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### INPUT FILE:\n",
"To pytest the HPC routine and or try it here in the Jupyter Tutorial, we had to add this next cell with all input variables. \n",
"\n",
"The way it usually works for us on HPC: We generate automatically input files (.py extension, ie. inputvariablefile.py) \n",
"with all the variables for the multiple permutations of simulations we run, and then import them at the beginning of our HPC main.py (same as any other main.py, it just has \"import inputvariablefile.py) \n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"testfolder = r'C:\\Users\\sayala\\Documents\\GitHub\\bifacial_radiance\\tests'# os.path.dirname(__file__) # this folder\n",
"epwfile = r'C:\\Users\\sayala\\Documents\\GitHub\\bifacial_radiance\\tests\\USA_CO_Boulder.724699_TMY2.epw'\n",
"simulationname='PVMC_0'\n",
"moduletype = 'PVPMC_0'\n",
"numpanels = 1\n",
"torqueTube = False\n",
"tubetype='Round'\n",
"pitch = 8 # gcr - 0.25\n",
"hub_height = 2.0\n",
"limit_angle = 60 \n",
"diameter = 0.1\n",
"xgap=0.01 \n",
"ygap=0.0\n",
"zgap = 0.05\n",
"sensorsy=100\n",
"x= 1\n",
"y = 2\n",
"nMods=20\n",
"nRows=7\n",
"torqueTubeMaterial='Metal_Grey'\n",
"backtrack = True\n",
"cumulativesky = False\n",
"rewriteModule=True\n",
"cellLevelModule = False\n",
"hpc=True \n",
"axisofrotationTorqueTube=True\n",
"gcr = 0.25\n",
"albedo = 0.28\n",
"modWanted = 10\n",
"rowWanted = 4\n",
"axis_azimuth=180\n",
"angledelta=0.01\n",
"roundTrackerAngle= True\n",
"bifi=0.9"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Run FIRST, before entering Slurm mode \n",
"\n",
"Multiple Nodes get confused when trying to write the JSON at the same time,\n",
"so make sure moduletype is created before running slurm job for it to work.\n",
"2 DO: Fix at some point of course.\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"path = C:\\Users\\sayala\\Documents\\GitHub\\bifacial_radiance\\tests\n",
"\n",
"Module Name: PVPMC_0\n",
"Module file did not exist before, creating new module file\n",
"Module PVPMC_0 successfully created\n"
]
}
],
"source": [
"demo = RadianceObj(simulationname,path=testfolder)\n",
"demo.setGround(albedo)\n",
"moduleDict=demo.makeModule(name=moduletype,x=x,y=y,bifi=bifi,\n",
" torquetube=torqueTube, diameter = diameter, tubetype = tubetype,\n",
" material = torqueTubeMaterial, zgap = zgap, numpanels = numpanels, ygap = ygap,\n",
" rewriteModulefile = True, xgap=xgap,\n",
" axisofrotationTorqueTube=axisofrotationTorqueTube)\n",
"sceneDict = {'module_type':moduletype, 'pitch': pitch, 'hub_height':hub_height, 'nMods':nMods, 'nRows':nRows}\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Run on HPC Slurm Mode now: (or your computer with multiple cores. It'll be okay).\n",
"\n",
"Tested on a DELL Laptop, Core i7vPro 8th Gen."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"path = C:\\Users\\sayala\\Documents\\GitHub\\bifacial_radiance\\tests\n",
"Seems you are testing outside of slurm or on a reg. computer. It's okay, go on\n",
"Assigning 0\n",
"Assigning 1\n"
]
}
],
"source": [
"daylist = []\n",
"\n",
"fullYear = True # running faster testing on HPC ~ only 2 days.\n",
"\n",
"if fullYear:\n",
" start = datetime.datetime.strptime(\"01-01-2014\", \"%d-%m-%Y\")\n",
" end = datetime.datetime.strptime(\"31-12-2014\", \"%d-%m-%Y\") # 2014 not a leap year.\n",
" daylist.append('12_31') # loop doesn't add last day. Adding it at the beginning because why not.\n",
" daylimit = 365\n",
"else:\n",
" start = datetime.datetime.strptime(\"14-02-2014\", \"%d-%m-%Y\")\n",
" end = datetime.datetime.strptime(\"26-02-2014\", \"%d-%m-%Y\") # 2014 not a leap year.\n",
" daylimit = 1\n",
"date_generated = [start + datetime.timedelta(days=x) for x in range(0, (end-start).days)]\n",
"for date in date_generated:\n",
" daylist.append(date.strftime(\"%m_%d\"))\n",
"\n",
"demo = RadianceObj(simulationname,path=testfolder)\n",
"demo.setGround(albedo)\n",
"# HPC IMPORTANT NOTE:\n",
"# Multiple Nodes get confused when trying to write the JSON at the same time,\n",
"# so make sure moduletype is created before running slurm job for it to work.\n",
"# 2 DO: Fix at some point of course.\n",
"# moduleDict=demo.makeModule(name=moduletype,x=x,y=y,bifi=bifi,\n",
"# torquetube=torqueTube, diameter = diameter, tubetype = tubetype,\n",
"# material = torqueTubeMaterial, zgap = zgap, numpanels = numpanels, ygap = ygap,\n",
"# rewriteModulefile = True, xgap=xgap,\n",
"# axisofrotationTorqueTube=axisofrotationTorqueTube, cellLevelModule=cellLevelModule,\n",
"# numcellsx=numcellsx, numcellsy = numcellsy)\n",
"sceneDict = {'module_type':moduletype, 'pitch': pitch, 'hub_height':hub_height, 'nMods':nMods, 'nRows':nRows}\n",
"\n",
"cores = mp.cpu_count()\n",
"pool = mp.Pool(processes=cores)\n",
"res = None\n",
"\n",
"try:\n",
" nodeID = int(os.environ['SLURM_NODEID'])\n",
"except KeyError: # in case testing for hpc not on slurm yet.\n",
" nodeID = 0 \n",
" print(\"Seems you are testing outside of slurm or on a reg. computer. It's okay, go on\") \n",
"\n",
" \n",
"hpccores = 36 # this is valid for Eagle. Find out how many cores are in each node of your HPC to make this work.\n",
"\n",
"day_index = (hpccores * (nodeID))\n",
"\n",
"for job in range(cores):\n",
" print (\"Assigning\", day_index+job)\n",
" if day_index+job>=1: # Short version, running 1 days only.For the year do: len(daylist): # this makes sure no days above 356 are attempted:\n",
" break\n",
" pool.apply_async(bifacial_radiance.main.runJob, (daylist[day_index+job],)) # on the hpc we run this from inside of main.py script, \n",
" #so we just do \"runJob\" instead of \"main.runJob\"\n",
" \n",
"pool.close()\n",
"pool.join()\n",
"pool.terminate()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### We are still debugging this part, it's not really going into the runJob function for some reason in this tutorial, but this works for a charm for NREL and SNL......"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit bedea2a

Please sign in to comment.