Example #1
0
def main(args):

    #First we need to set the path and environment
    home = os.path.expanduser('~')
    env = os.environ
    if os.getenv("PEGASUS_WF_UUID") is not None:
        print("Pegasus job detected - Pegasus will set up the env")
    elif platform.system() == 'Darwin':
        env["PATH"] = env["PATH"] + ':{}/bin'.format(home)
        env["PATH"] = env["PATH"] + ':{}/dakota/bin'.format(home)
    elif platform.system() == 'Linux':
        env["PATH"] = env["PATH"] + ':{}/bin'.format(home)
        env["PATH"] = env["PATH"] + ':{}/dakota/dakota-6.5/bin'.format(home)
    elif platform.system() == 'Windows':
        pass
    else:
        print("PLATFORM {} NOT RECOGNIZED".format(platform.system))

    parser = argparse.ArgumentParser()

    parser.add_argument('--filenameBIM')
    parser.add_argument('--filenameSAM')
    parser.add_argument('--filenameEVENT')
    parser.add_argument('--filenameEDP')
    parser.add_argument('--filenameSIM')
    
    parser.add_argument('--driverFile')
    
    parser.add_argument('--method', default="LHS")
    parser.add_argument('--samples', type=int, default=None)
    parser.add_argument('--seed', type=int, default=np.random.randint(1,1000))
    parser.add_argument('--ismethod', default=None)
    parser.add_argument('--dataMethod', default=None)

    parser.add_argument('--trainingSamples', type=int, default=None)
    parser.add_argument('--trainingSeed', type=int, default=None)
    parser.add_argument('--trainingMethod', default=None)
    parser.add_argument('--samplingSamples', type=int, default=None)
    parser.add_argument('--samplingSeed', type=int, default=None)
    parser.add_argument('--samplingMethod', default=None)
    
    parser.add_argument('--type')
    parser.add_argument('--concurrency', type=int, default=None)
    parser.add_argument('--keepSamples', default="True")
    parser.add_argument('--runType')
    
    args,unknowns = parser.parse_known_args()

    #Reading input arguments
    bimName = args.filenameBIM
    samName = args.filenameSAM
    evtName = args.filenameEVENT
    edpName = args.filenameEDP
    simName = args.filenameSIM
    driverFile = args.driverFile

    uqData = dict(
        method = args.method,
        
        samples = args.samples,
        seed = args.seed,
        ismethod = args.ismethod,
        dataMethod = args.dataMethod,

        samplingSamples = args.samplingSamples,
        samplingSeed = args.samplingSeed,
        samplingMethod = args.samplingMethod,
        trainingSamples = args.trainingSamples,
        trainingSeed = args.trainingSeed,
        trainingMethod = args.trainingMethod,

        concurrency = args.concurrency,
        keepSamples = args.keepSamples not in ["False", 'False', "false", 'false', False]
    )

    runDakota = args.runType

    myScriptDir = os.path.dirname(os.path.realpath(__file__))

    # desktop applications
    if uqData['samples'] is None: # this happens with new applications, workflow to change

        print("RUNNING PREPROCESSOR\n")
        osType = platform.system()
        preprocessorCommand = '"{}/preprocessDakota" {} {} {} {} {} {} {} {}'.format(myScriptDir, bimName, samName, evtName, edpName, simName, driverFile, runDakota, osType)
        subprocess.Popen(preprocessorCommand, shell=True).wait()
        print("DONE RUNNING PREPROCESSOR\n")

    else:

        scriptDir = os.path.dirname(os.path.realpath(__file__))
        numRVs = preProcessDakota(bimName, evtName, samName, edpName, simName, driverFile, runDakota, uqData)

        shutil.move(bimName, "bim.j")
        shutil.move(evtName, "evt.j")
        if os.path.isfile(samName): shutil.move(samName, "sam.j")
        shutil.move(edpName, "edp.j")        

    #Setting Workflow Driver Name
    workflowDriverName = 'workflow_driver'
    if ((platform.system() == 'Windows') and (runDakota == 'run')):
        workflowDriverName = 'workflow_driver.bat'

    #Change permision of workflow driver
    st = os.stat(workflowDriverName)
    os.chmod(workflowDriverName, st.st_mode | stat.S_IEXEC)

    # copy the dakota input file to the main working dir for the structure
    shutil.move("dakota.in", "../")

    # change dir to the main working dir for the structure
    os.chdir("../")

    if runDakota == "run":

        dakotaCommand = "dakota -input dakota.in -output dakota.out -error dakota.err"
        print('running Dakota: ', dakotaCommand)
        try:
            result = subprocess.check_output(dakotaCommand, stderr=subprocess.STDOUT, shell=True)
            returncode = 0
        except subprocess.CalledProcessError as e:
            result = e.output
            returncode = e.returncode
Example #2
0
def main(args):

    #First we need to set the path and environment
    home = os.path.expanduser('~')
    env = os.environ
    if os.getenv("PEGASUS_WF_UUID") is not None:
        print("Pegasus job detected - Pegasus will set up the env")
    elif platform.system() == 'Darwin':
        env["PATH"] = env["PATH"] + ':{}/bin'.format(home)
        env["PATH"] = env["PATH"] + ':{}/dakota/bin'.format(home)
    elif platform.system() == 'Linux':
        env["PATH"] = env["PATH"] + ':{}/bin'.format(home)
        env["PATH"] = env["PATH"] + ':{}/dakota/dakota-6.5/bin'.format(home)
    elif platform.system() == 'Windows':
        pass
    else:
        print("PLATFORM {} NOT RECOGNIZED".format(platform.system))

    parser = argparse.ArgumentParser()

    parser.add_argument('--filenameBIM')
    parser.add_argument('--filenameSAM')
    parser.add_argument('--filenameEVENT')
    parser.add_argument('--filenameEDP')
    parser.add_argument('--filenameSIM')

    parser.add_argument('--driverFile')

    parser.add_argument('--method', default="LHS")
    parser.add_argument('--samples', type=int, default=None)
    parser.add_argument('--seed', type=int, default=randrange(1,1000))
    parser.add_argument('--samples2', type=int, default=None)
    parser.add_argument('--seed2', type=int, default=None)
    parser.add_argument('--ismethod', default=None)
    parser.add_argument('--dataMethod', default=None)
    parser.add_argument('--dataMethod2', default=None)

    parser.add_argument('--type')
    parser.add_argument('--concurrency', type=int, default=None)
    parser.add_argument('--keepSamples', default="True")
    parser.add_argument('--runType')

    args,unknowns = parser.parse_known_args()

    #Reading input arguments
    bimName = args.filenameBIM
    samName = args.filenameSAM
    evtName = args.filenameEVENT
    edpName = args.filenameEDP
    simName = args.filenameSIM
    driverFile = args.driverFile

    uqData = dict(
        method = args.method,

        samples = args.samples,
        samples2 = args.samples2,
        seed = args.seed,
        seed2 = args.seed2,
        ismethod = args.ismethod,
        dataMethod = args.dataMethod,
        dataMethod2 = args.dataMethod2,

        concurrency = args.concurrency,
        keepSamples = args.keepSamples not in ["False", 'False', "false", 'false', False]
    )

    if uqData['samples'] is None: # this happens when the uq details are stored at the wrong place in the BIM file
        with open(bimName) as data_file:
            uq_info = json.load(data_file)['UQ_Method']

        if 'samplingMethodData' in uq_info.keys():
            uq_info = uq_info['samplingMethodData']
            for attribute in uqData.keys():
                if attribute not in ['concurrency', 'keepSamples']:
                    uqData[attribute] = uq_info.get(attribute, None)

    runDakota = args.runType

    #Run Preprocess for Dakota
    scriptDir = os.path.dirname(os.path.realpath(__file__))
    numRVs = preProcessDakota(bimName, evtName, samName, edpName, simName, driverFile, runDakota, uqData)

    #Setting Workflow Driver Name
    workflowDriverName = 'workflow_driver'
    if ((platform.system() == 'Windows') and (runDakota == 'run')):
        workflowDriverName = 'workflow_driver.bat'

    #Create Template Directory and copy files
    st = os.stat(workflowDriverName)
    os.chmod(workflowDriverName, st.st_mode | stat.S_IEXEC)
    #shutil.copy(workflowDriverName, "templatedir")
    #shutil.copy("{}/dpreproSimCenter".format(scriptDir), os.getcwd())
    shutil.move(bimName, "bim.j")
    shutil.move(evtName, "evt.j")
    if os.path.isfile(samName): shutil.move(samName, "sam.j")
    shutil.move(edpName, "edp.j")
    #if os.path.isfile(simName): shutil.move(simName, "sim.j")

    # copy the dakota input file to the main working dir for the structure
    shutil.move("dakota.in", "../")

    # change dir to the main working dir for the structure
    os.chdir("../")

    if runDakota == "run":

        dakotaCommand = "dakota -input dakota.in -output dakota.out -error dakota.err"
        print('running Dakota: ', dakotaCommand)
        try:
            result = subprocess.check_output(dakotaCommand, stderr=subprocess.STDOUT, shell=True)
            returncode = 0
        except subprocess.CalledProcessError as e:
            result = e.output
            returncode = e.returncode
Example #3
0
#Reading input arguments
bimName = sys.argv[2]
samName = sys.argv[4]
evtName = sys.argv[6]
edpName = sys.argv[8]
simName = sys.argv[10]
driverFile = sys.argv[12]

runDakota = sys.argv[13]

#Run Preprocess for Dakota
scriptDir = os.path.dirname(os.path.realpath(__file__))
# preProcessArgs = ["python", "{}/preprocessJSON.py".format(scriptDir), bimName, evtName,\
# samName, edpName, lossName, simName, driverFile, scriptDir, bldgName]
# subprocess.call(preProcessArgs)
numRVs = preProcessDakota(bimName, evtName, samName, edpName, simName,
                          driverFile)

#Setting Workflow Driver Name
workflowDriverName = 'workflow_driver'
if platform.system() == 'Windows':
    workflowDriverName = 'workflow_driver.bat'

#Create Template Directory and copy files
templateDir = "templatedir"
#if os.path.exists(templateDir):
#    shutil.rmtree(templateDir)

#os.mkdir(templateDir)
st = os.stat(workflowDriverName)
os.chmod(workflowDriverName, st.st_mode | stat.S_IEXEC)
shutil.copy(workflowDriverName, templateDir)
Example #4
0
#setting workflow driver name based on platform
workflowDriver = 'workflow_driver'
if platform.system() == 'Windows':
    workflowDriver = 'workflow_driver.bat'

#Removing working directory for the current building, if it exists
if os.path.exists(bldgName) and os.path.isdir(bldgName):
    shutil.rmtree(bldgName)

os.mkdir(bldgName)

#Run Preprocess for Dakota
scriptDir = os.path.dirname(os.path.realpath(__file__))
numRVs = preProcessDakota(bimName, evtName, samName, edpName, lossName,
                          simName, driverFile, bldgName, numSamples, rngSeed,
                          concurrency)

#Create Template Directory and copy files
templateDir = "{}/templatedir".format(bldgName)
os.mkdir(templateDir)
bldgWorkflowDriver = "{}/{}".format(bldgName, workflowDriver)
st = os.stat(bldgWorkflowDriver)
os.chmod(bldgWorkflowDriver, st.st_mode | stat.S_IEXEC)
shutil.copy(bldgWorkflowDriver, "{}/{}".format(templateDir, workflowDriver))
shutil.copy("{}/dpreproSimCenter".format(scriptDir), templateDir)
shutil.copy(bimName, "{}/bim.j".format(templateDir))
shutil.copy(evtName, "{}/evt.j".format(templateDir))
shutil.copy(samName, "{}/sam.j".format(templateDir))
shutil.copy(edpName, "{}/edp.j".format(templateDir))
shutil.copy(simName, "{}/sim.j".format(templateDir))
bldgName = bimName[:-9]

#setting workflow driver name based on platform
workflowDriver = 'workflow_driver'
if platform.system == 'Windows':
    workflowDriver = 'workflow_driver.bat'

#Removing working directory for the current building, if it exists
if os.path.exists(bldgName) and os.path.isdir(bldgName):
    shutil.rmtree(bldgName)

os.mkdir(bldgName)

#Run Preprocess for Dakota
scriptDir = os.path.dirname(os.path.realpath(__file__))
numRVs = preProcessDakota(bimName, evtName, samName, edpName, lossName,
                          simName, driverFile, bldgName, numSamples)

#Create Template Directory and copy files
templateDir = "{}/templatedir".format(bldgName)
os.mkdir(templateDir)
bldgWorkflowDriver = "{}/{}".format(bldgName, workflowDriver)
st = os.stat(bldgWorkflowDriver)
os.chmod(bldgWorkflowDriver, st.st_mode | stat.S_IEXEC)
shutil.copy(bldgWorkflowDriver, "{}/{}".format(templateDir, workflowDriver))
shutil.copy("{}/dpreproSimCenter".format(scriptDir), templateDir)
shutil.copy(bimName, "{}/bim.j".format(templateDir))
shutil.copy(evtName, "{}/evt.j".format(templateDir))
shutil.copy(samName, "{}/sam.j".format(templateDir))
shutil.copy(edpName, "{}/edp.j".format(templateDir))
shutil.copy(simName, "{}/sim.j".format(templateDir))