Skip to content

Commit

Permalink
Merge pull request #411 from DarkEnergyScienceCollaboration/issue/369…
Browse files Browse the repository at this point in the history
…/Run3_phoSim_production

Issue/369/run3 pho sim production
  • Loading branch information
drphilmarshall authored Nov 16, 2016
2 parents 75eaf1e + 9248397 commit 1fc5c27
Show file tree
Hide file tree
Showing 12 changed files with 12,082 additions and 13,299 deletions.
8 changes: 4 additions & 4 deletions workflows/TW-phoSim-r3/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@

## phoSim (persistent) scratch space directory path
## SLAC: /lustre/ki/pfs/fermi_scratch/lsst/<task>/<subtask>/<stream>/<substream>
PHOSIMSCRATCH = os.path.join('/lustre/ki/pfs/fermi_scratch/lsst',os.environ['PIPELINE_TASKPATH'].replace('.','/'),os.environ['PIPELINE_STREAMPATH'].replace('.','/'))
PHOSIMPSCRATCH = os.path.join('/lustre/ki/pfs/fermi_scratch/lsst',os.environ['PIPELINE_TASKPATH'].replace('.','/'),os.environ['PIPELINE_STREAMPATH'].replace('.','/'))

PHOSIMCLEANUP = True

## SED files (from DM stack)
#SEDLIB = '/nfs/farm/g/desc/u1/LSST_Stack_2016-02-23/lsstsw/stack/Linux64/sims_sed_library/2016.01.26'
SEDLIB = '/lustre/ki/pfs/fermi_scratch/lsst/phosim/sims_sed_library/2016.01.26'
PHOSIMSEDS = '/lustre/ki/pfs/fermi_scratch/lsst/phosim/sims_sed_library'

#SEDLIB = '/nfs/farm/g/lsst/u1/software/redhat6-x86_64-64bit-gcc44/DMstack/v12_0/opt/lsst/sims_sed_library'

## Twinkles UW-FATBOY cache location
Expand All @@ -73,6 +73,6 @@
## Location of Twinkles git project and binary for instanceCatalog generation
#TWINKLES_ROOT = '/nfs/farm/g/desc/u1/software/redhat6-x86_64-64bit-devtoolset-3/Twinkles/...........'
#TWINKLES_ROOT = os.path.join(os.getenv('TW_ROOT'),'Twinkles.master')
TWINKLES_ROOT = '/nfs/farm/g/desc/u1/software/redhat6-x86_64-64bit-devtoolset-3/Twinkles/Run3-phoSim-v1'
TWINKLES_ROOT = '/nfs/farm/g/desc/u1/software/redhat6-x86_64-64bit-devtoolset-3/Twinkles/prod'
TWINKLES_BIN = TWINKLES_ROOT+'/bin'

2 changes: 1 addition & 1 deletion workflows/TW-phoSim-r3/helpers/TWsetup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ setup lsst_sims
export OM10_DIR=/nfs/farm/g/desc/u1/twinkles/OM10
export PYTHONPATH=${OM10_DIR}:${PYTHONPATH}
#setup -r /nfs/farm/g/desc/u1/Pipeline-tasks/TW-phoSim-r3/Twinkles.master -j
setup -r /nfs/farm/g/desc/u1/software/redhat6-x86_64-64bit-devtoolset-3/Twinkles/Run3-phoSim-v1 -j
setup -r /nfs/farm/g/desc/u1/software/redhat6-x86_64-64bit-devtoolset-3/Twinkles/prod -j
setup -r /nfs/farm/g/desc/u1/twinkles/Monitor -j
setup -r /nfs/farm/g/desc/u1/twinkles/pserv -j
PS1="[Twinkles] "
107 changes: 76 additions & 31 deletions workflows/TW-phoSim-r3/phoSimPrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,35 @@
##

import os,sys,shutil
import tarfile

## Insert task config area for python modules (insert as 2nd element in sys.path)
sys.path.insert(1,os.getenv('TW_CONFIGDIR'))
from config import *
import scratch


print '\n\nWelcome to phoSimPrep.py\n========================\n'

## Generate instanceCatalog on-the-fly

## Create scratch directory in (persistent) /lustre, if necessary.
## File path = PHOSIMSCRATCH (defined in config.py)
## Create persistent scratch directory in /lustre, if necessary.
## File path = PHOSIMPSCRATCH (defined in config.py)
if not os.path.exists(PHOSIMPSCRATCH): os.makedirs(PHOSIMPSCRATCH)

if not os.path.exists(PHOSIMSCRATCH): os.makedirs(PHOSIMSCRATCH)

## ### Until actual code is available, simply copy/link necessary files
## ### into pre-agreed scratch space.
## base = 'phosim_input_200'

## src = os.path.join(PHOSIMIN,base+'.txt.gz')
## dst = os.path.join(PHOSIMSCRATCH,'instanceCatalog.txt.gz')
## print 'Instance Catalog:'
## print 'src = ',src
## print 'dst = ',dst
## shutil.copy2(src,dst)

## src = os.path.join(PHOSIMIN,base+'.tar.gz')
## dst = os.path.join(PHOSIMSCRATCH,'SEDs.tar.gz')
## print 'SEDs:'
## print 'src = ',src
## print 'dst = ',dst
## shutil.copy2(src,dst)
## Create true scratch directory in /scratch
scr = scratch.scratch()
SCRATCH = scr.getScratch()
scr.statScratch()


## generate instance catalog and SED files for phoSim

# generatePhosimInput.py obsHistID [options]
destIC = os.path.join(PHOSIMSCRATCH,'instanceCatalog.txt')
destSEDdir = PHOSIMSCRATCH
destIC = os.path.join(PHOSIMPSCRATCH,'instanceCatalog.txt')
#destSEDdir = PHOSIMPSCRATCH
destSEDdir = SCRATCH
obsHistID = os.getenv('TW_OBSHISTID')
cacheDir = TW_CACHEDIR
opssimDir = TW_OPSSIMDIR
Expand Down Expand Up @@ -70,27 +61,52 @@
rc = os.system(cmd)
sys.stdout.flush()
print 'rc = ',rc
if rc > 255: rc = 1
if rc > 255:
rc = 1
print 'Awkward return code, redefining rc = ',rc
pass


## tar up the sprinkled SED files
print 'tar up the sprinkled SED files and store in /lustre'
workingdir = os.getcwd()
os.chdir(destSEDdir) ## Move to directory containing SED dir to feed tar relative paths

seddir = 'spectra_files' ## This is where the sprinkled SEDs are generated
tarinput = seddir
tarname = seddir+'.tar.gz'
taroutput = os.path.join(PHOSIMPSCRATCH,tarname) ## output goes into /lustre

tarobj = tarfile.open(name=taroutput,mode='w:gz')
tarobj.add(tarinput,recursive=True) ## add entire directory tree of SEDs to tar archive
tarobj.close()

os.chdir(workingdir)



## Protect scratch directory: rwxr-sr-t
cmd = 'chmod -R 3755 '+PHOSIMSCRATCH
print 'Protect scratch directory\n',cmd
cmd = 'chmod -R 3755 '+PHOSIMPSCRATCH
print 'Protect scratch directory and its contents\n',cmd

rc = os.system(cmd)
if rc != 0:
rc2 = os.system(cmd)
if rc2 != 0:
print "%ERROR: unable to execute command, ",cmd
sys.exit(1)
pass
pass




## Confirm working directory
cmd = 'ls -l '+destSEDdir
## Confirm working directory contents
cmd = 'ls -l '+PHOSIMPSCRATCH
print cmd
os.system(cmd)


## Clean up the local scratch space
scr.cleanScratch()
scr.statScratch()

## Run a trial phoSim to ensure all inputs+code respond reasonably?
## (not yet, if ever)

Expand All @@ -99,3 +115,32 @@
































16 changes: 10 additions & 6 deletions workflows/TW-phoSim-r3/phoSimPrep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ if [ $rc1 != 0 ]; then
fi

echo "Setup Twinkles environment"
cmd=" $TW_CONFIGDIR/helpers/TWsetup.sh"
## source /nfs/farm/g/desc/u1/twinkles/setup.sh ##### PRODUCTION
##source $TW_ROOT/newICgen/setup.sh ##### DEVELOPMENT/TESTING/DEBUGGING
cmd="/nfs/farm/g/desc/u1/software/redhat6-x86_64-64bit-devtoolset-3/setup.sh"
##cmd=" $TW_CONFIGDIR/helpers/TWsetup.sh"
##source /nfs/farm/g/desc/u1/twinkles/setup.sh
echo "source "$cmd
source $cmd ##### DEVELOPMENT/TESTING/DEBUGGING

echo "Return from setup, rc = " $?
source $cmd
rc2=$?
echo "Return from setup, rc = " $rc2
if [ $rc2 != 0 ]; then
echo "ERROR: failed to setup Twinkles environment"
exit $rc2
fi

## Redefine $HOME to prevent contention of /u/lt/lsstsim
cp -prv $HOME/.lsst $PWD
Expand Down
18 changes: 11 additions & 7 deletions workflows/TW-phoSim-r3/runPhoSim.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

log.info('Entering runPhoSim.py')

print 'PHOSIMSCRATCH = ',PHOSIMSCRATCH
print 'PHOSIMPSCRATCH = ',PHOSIMPSCRATCH

## ################################# DEBUG ############################
#sys.exit(1)
Expand Down Expand Up @@ -66,13 +66,14 @@

prep = setupPhoSimInput(icFile) ###########
#prep.inputRoot = PHOSIMIN
prep.inputRoot = PHOSIMSCRATCH
prep.inputRoot = PHOSIMPSCRATCH
prep.phosimInstDir = PHOSIMINST
prep.SEDlib = SEDLIB
prep.scratch = PHOSIMSCRATCH
prep.refCF = PHOSIMCF ## cmd file template may require editing
prep.SEDlib = PHOSIMSEDS ## production SEDs
prep.sedFile = 'spectra_files.tar.gz' ## sprinkled SEDs

prep.refCF = PHOSIMCF ## cmd file template (may require editing)
prep.persistentScratch = True ## dynamically generated instance catalog + SEDs
prep.cleanupFlag = False ## DEBUG - keep contents of scratch (/lustre)
prep.cleanupFlag = False ## DEBUG - keep contents of scratch

(work1,ic,seds,cFile) = prep.run()

Expand Down Expand Up @@ -115,7 +116,8 @@

## Prepare phoSim command
log.info('Prepare phoSim command')
cmd = 'time '+PHOSIMINST+'/phosim.py '+ic+' -c '+cFile+' -s '+sensor+' '+PHOSIMOPTS+' --sed '+seds+' -w '+workDir+' -o '+outDir
cmd = PHOSIMINST+'/phosim.py '+ic+' -c '+cFile+' -s '+sensor+' '+PHOSIMOPTS+' --sed '+seds+' -w '+workDir+' -o '+outDir
#cmd = 'time '+PHOSIMINST+'/phosim.py '+ic+' -c '+cFile+' -s '+sensor+' '+PHOSIMOPTS+' --sed '+seds+' -w '+workDir+' -o '+outDir
#cmd = 'time '+PHOSIMINST+'/phosim.py '+ic+' -c '+cFile+' -s '+sensor+' '+PHOSIMOPTS+' -w '+workDir+' -o '+outDir
print 'cmd = ',cmd
sys.stdout.flush()
Expand All @@ -137,6 +139,8 @@
print 'phoSim rc = ',rc,', type(rc) = ',type(rc)
if len(yak[1]) > 0:
print '\n\n$WARNING: phoSim stderr output:\n',yak[1]
print 'TERMINATING...'
sys.exit(1)
# if rc == 0:
# print '\nphoSim returned error output but a zero return code...setting rc=1'
# rc = 1
Expand Down
93 changes: 93 additions & 0 deletions workflows/TW-phoSim-r3/scratch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/nfs/farm/g/lsst/u1/software/redhat6-x86_64-64bit-gcc44/anaconda/2.3.0/bin/python

## scratch.py - Manage local /scratch space


import os,sys,shutil,socket

class scratch(object):
def __init__(self):
self.scratch = None
self.prefix = 'LSSTSIM'
self.scratches = ['/scratch']
self.scrMode = 0o3755
self.cleanupFlag = True
self.host = socket.gethostname()
self.trace = False
return

def getScratch(self):
## Set up scratch space
if self.trace: print 'Entering getScratch().'
if self.scratch == None:
scratchRoot = ''
for scratch in self.scratches:
if os.path.isdir(scratch):
scratchRoot = scratch
break
pass

if scratchRoot == '':
print "Unable to find suitable scratch space."
print self.scratches
sys.exit(1)

## Define scratch directory
## Naming convention for scratch directories:
## Standalone job: /scratch/PID-<processID>
## Ordinary batch job: /scratch/LSF-<jobID>
## Pipeline batch job: /scratch/LSSTSIM/<taskName>/<subtaskName>/<StreamNum>/<jobID>
## Naming convention for scratch directories:
jobid = os.path.join(self.prefix,'PID-'+str(os.getpid()))
if os.environ.get('LSB_JOBID') != None:
jobid=os.path.join(self.prefix,'LSF-'+os.environ['LSB_JOBID'])
if os.environ.get('PIPELINE_TASKPATH') != None:
jobid = os.path.join(self.prefix,os.environ.get('PIPELINE_TASKPATH').replace('.','/'),os.environ.get('PIPELINE_STREAMPATH').split('.')[0],os.environ.get('LSB_JOBID'))
pass
pass

self.scratch = os.path.join(scratchRoot,str(jobid))
print 'defined self.scratch = ',self.scratch

## Create scratch directory
if os.path.exists(self.scratch):
print 'WARNING: scratch directory already exists. Removing...'
shutil.rmtree(self.scratch)
pass
os.makedirs(self.scratch,self.scrMode)
pass
else:
print 'WARNING: scratch already defined - ',self.scratch
pass

return self.scratch


def cleanScratch(self):
## Cleanup the 'scratch' space
if self.trace: print 'Entering cleanScratch().'

if self.scratch != None:
## Now obliterate the scratch space
if self.cleanupFlag:
print "Cleaning up scratch area"
shutil.rmtree(self.scratch)
self.scratch = None
else:
print "Retaining scratch area"
pass
pass
return

def statScratch(self):
print '\n\n====================================================='
print 'Status of scratch space'
print ' scratch = ',self.scratch
print ' prefix = ',self.prefix
print ' scratches = ',self.scratches
print ' scrMode = ',oct(self.scrMode)
print ' host = ',self.host
print ' cleanupFlag = ',self.cleanupFlag
print ' trace = ',self.trace
print '=======================================================\n\n'
return
Loading

0 comments on commit 1fc5c27

Please sign in to comment.