Skip to content

Commit

Permalink
HPC-fixes
Browse files Browse the repository at this point in the history
_tempTMY saves a file with the daydate now if available so it doesnt get overwritten/overreda.

importnat fix to sky generation on gendaylit1axis, because the for loop was going to endindex+1 before.

analysis1axis added input for daydate, so cumulative file adds for hte daydate. The other option is to turn off the cumulative file saving option for daydate? discuss

Main has the script to run the runJOB on multiprocessing. It's not worknig super good though. Summary:
1) 8 cores on my computer: It uses all cores on the computer
2) HPC: seems to be using both Nodes (for a 60 day simulatoin), but only starts printing stuff for one of the cores... the other one appears some of the results but later, does that means it's being assigned afterwards to the same initial node?
  • Loading branch information
shirubana committed Dec 28, 2019
1 parent 65df881 commit 48ef35b
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 16 deletions.
59 changes: 59 additions & 0 deletions bifacial_radiance/input.py
@@ -0,0 +1,59 @@
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 26 09:22:46 2019
@author: sayala
Input values for
"""

# Input/Output file addresses
testfolder = 'TEMP' # AWS
epwfile = r'EPWs\USA_WY_Jackson.Hole.AP.725776_TMY3.epw' # AWS
# Input/Output file addresses
#testfolder = '/scratch/sayala/RadianceScenes/Foo'
#epwfile='/scratch/sayala/EPWs/EGY_Cairo.Intl.Airport.623660_ETMY.epw'

simulationname='EUPVSEC'
moduletype = 'EUPVSEC'
hub_height = 1.5
numpanels = 1
torqueTube = False
tubetype='Round'
pitch = 6 # gcr - 0.25
albedo = 0.2 # ground albedo
gcr=0.3333

limit_angle = 60
diameter = 0.0
xgap=0.01 # 10 centimeters default
ygap=0.0
zgap = 0.0
sensorsy=100

# Variables that don't change
x= 1
y= 2 # module portrait dimension in meters
nMods=20
nRows=7
torqueTubeMaterial='Metal_Grey'
backtrack = True
cumulativesky = False
rewriteModule=True
cellLevelModule = False
hpc=True
axisofrotationTorqueTube=False
modWanted = 10
rowWanted = 4
axis_azimuth=180
angledelta=0.01
roundTrackerAngle= True
bifi=0.9



torqueTube = True
diameter = 0.10
zgap = 0.05
moduletype = 'EUPVSEC_TT'
torqueTubeMaterial = 'black'
101 changes: 85 additions & 16 deletions bifacial_radiance/main.py
Expand Up @@ -60,7 +60,7 @@
from subprocess import Popen, PIPE # replacement for os.system()
import pandas as pd
import numpy as np

from input import *

# Mutual parameters across all processes
#daydate=sys.argv[1]
Expand Down Expand Up @@ -674,14 +674,16 @@ def readEPW(self, epwfile=None, hpc=False, starttime=None, endtime=None, daydate
'ghi':'GHI'
}, inplace=True)

tempTMYtitle = 'epw_temp.csv'
# Hpc only works when daydate is passed through. Daydate gives single-
# day run option with zero GHI values removed.
if daydate is not None:
dd = re.split('_|/',daydate)
starttime = dd[0]+'_'+dd[1] + '_00'
endtime = dd[0]+'_'+dd[1] + '_23'
tempTMYtitle = 'epw_temp_'+dd[0]+'_'+dd[1]+'.csv'

tmydata_trunc = self._saveTempTMY(tmydata,'epw_temp.csv',
tmydata_trunc = self._saveTempTMY(tmydata,filename=tempTMYtitle,
starttime=starttime, endtime=endtime)
if daydate is not None: # also remove GHI = 0 for HPC daydate call.
tmydata_trunc = tmydata_trunc[tmydata_trunc.GHI > 0]
Expand Down Expand Up @@ -1175,7 +1177,7 @@ def gendaylit1axis(self, metdata=None, trackerdict=None, startdate=None,
count = 0 # counter to get number of skyfiles created, just for giggles

trackerdict2={}
for i in range(startindex,endindex+1):
for i in range(startindex,endindex):
time = metdata.datetime[i]
filename = str(time)[5:-12].replace('-','_').replace(' ','_')
self.name = filename
Expand Down Expand Up @@ -2076,7 +2078,8 @@ def makeScene1axis(self, trackerdict=None, moduletype=None, sceneDict=None,


def analysis1axis(self, trackerdict=None, singleindex=None, accuracy='low',
customname=None, modWanted=None, rowWanted=None, sensorsy=9):
customname=None, modWanted=None, rowWanted=None, sensorsy=9,
daydate=None):
"""
Loop through trackerdict and runs linescans for each scene and scan in there.
Expand Down Expand Up @@ -2116,6 +2119,9 @@ def analysis1axis(self, trackerdict=None, singleindex=None, accuracy='low',
if customname is None:
customname = ''

if daydate is None:
daydate = ''

if trackerdict == None:
try:
trackerdict = self.trackerdict
Expand Down Expand Up @@ -2180,14 +2186,14 @@ def analysis1axis(self, trackerdict=None, singleindex=None, accuracy='low',
# Save compiled results using _saveresults
if singleindex is None:

print ("Saving a cumulative-results file in the main simulatoin folder." +
print ("Saving a cumulative-results file in the main simulation folder." +
"This adds up by sensor location the irradiance over all hours " +
"or configurations considered." +
"\nWarning: This file saving routine does not clean results, so "+
"if your setup has ygaps, or 2+modules or torque tubes, doing "+
"a deeper cleaning and working with the individual results "+
"files in the results folder is highly suggested.")
cumfilename = 'cumulative_results_%s.csv'%(customname)
cumfilename = 'cumulative_results_%s.csv'%(daydate)
if self.cumulativesky is True:
frontcum = pd.DataFrame()
rearcum = pd.DataFrame()
Expand Down Expand Up @@ -3628,30 +3634,38 @@ def runJob(daydate):
#exit(1)

print("entering runJob on node %s" % slurm_nnodes)
metdata = demo.readEPW(epwfile=epwfile, hpc=hpc, daydate=daydate)

demo.readEPW(epwfile=epwfile, hpc=hpc, daydate=daydate)

print("1. Read EPW Finished")

trackerdict = demo.set1axis(cumulativesky=cumulativesky,
axis_azimuth=axis_azimuth,
limit_angle=limit_angle,
angledelta=angledelta,
backtrack=backtrack,
gcr=gcr)


print("2. set1axis Done")

trackerdict = demo.gendaylit1axis(hpc=hpc)

trackerdict = demo.makeScene1axis(trackerdict=trackerdict,
moduletype=moduletype,
sceneDict=sceneDict,
cumulativesky=cumulativesky,
hpc=hpc)
print("3. Gendalyit1axis Finished")

demo.makeScene1axis(moduletype=moduletype, sceneDict=sceneDict,
cumulativesky = cumulativesky, hpc = hpc)

print("4. MakeScene1axis Finished")

demo.makeOct1axis(trackerdict, hpc=True)

trackerdict = demo.analysis1axis(trackerdict,
modWanted=modWanted,
rowWanted=rowWanted,
sensorsy=sensorsy)

sensorsy=sensorsy, daydate=daydate)
print("5. Finished ", daydate)


def quickExample(testfolder=None):
"""
Example of how to run a Radiance routine for a simple rooftop bifacial system
Expand Down Expand Up @@ -3703,4 +3717,59 @@ def quickExample(testfolder=None):
print('Annual bifacial ratio average: %0.3f' %(
sum(analysis.Wm2Back) / sum(analysis.Wm2Front) ) )

return analysis
return analysis


if __name__ == "__main__":
'''
Example of how to run a Radiance routine for a simple rooftop bifacial system
'''
import multiprocessing as mp

# print("This is daydate %s" % (daydate))
demo = RadianceObj(simulationname,path=testfolder)
#epwfile = demo.getEPW(44, -110)
#print(epwfile)
demo.setGround(albedo)
# metdata = demo.readWeatherFile(epwfile)
# 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)

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
print ("This is cores", cores)

try:
nodeID = int(os.environ['SLURM_NODEID'])
except:
nodeID = 0
day_index = (36 * (nodeID))

# doing less days for testing
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.
#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.
date_generated = [start + datetime.timedelta(days=x) for x in range(0, (end-start).days)]

daylist = []
for date in date_generated:
daylist.append(date.strftime("%m_%d"))
# loop doesn't add last day :

# print (daylist)
for job in range(cores):
if day_index+job>=60: #len(daylist):
break
pool.apply_async(runJob, (daylist[day_index+job],))

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

0 comments on commit 48ef35b

Please sign in to comment.