def run_list(driver,inputs): if driver.TestMotor: # test the motor design instead of an external model outputs = [] for i in inputs: outputs.append(motorDesign.motor(i, len(driver.outputNames))) elif driver.UseParametersCSV: outputs = [] with open('parameters.csv', 'r') as f: # read log file of inputs and outputs f.readline() #skip past the line specifying the names of inputs and outputs for line in f: output = [] for num in line.split(',')[-len(driver.outputNames):]: # get list of outputs from line (in string form) output.append(float(num)) outputs.append(output) f.close() else: driver.DOEgenerator.SetInputs(inputs) driver.recorders = [ListCaseRecorder(),] if UseParallel: driver.sequential = False if UseCluster: print 'Using remote cluster.' driver.sequential = False # This is necessary more often than it should be. driver.ignore_egg_requirements = True # Force use of only cluster hosts by adding this requirement. driver.extra_resources = dict(allocator='PCCCluster') super(driver.__class__, driver).execute() outputs = [] for c in driver.recorders[0].get_iterator(): output = [] for n in driver.outputNames: if c.__contains__(n): output.append(c.get_output(n)) else: raise Exception,'No outputs from simulator matching requested output \'{0}\'. Available outputs: {1}'.format(n,c.get_outputs()) outputs.append(output) if not driver.UseParametersCSV: with open('parameters.csv', 'w') as f: # write log file of inputs and outputs f.write(','.join(driver.inputNames)+','+','.join(driver.outputNames)+'\n') for x,i in enumerate(inputs): f.write(','.join(str(y) for y in inputs[x])) if x<len(outputs): f.write(','+','.join(str(y) for y in outputs[x])) f.write('\n') f.close() if len(outputs) != len(inputs): raise Exception,'Simulator returned only {0} results of a requested {1}. See parameters.csv for details.'.format(len(outputs),len(inputs)) return asarray(outputs)
def run_list(driver, inputs): if driver.TestMotor: # test the motor design instead of an external model outputs = [] for i in inputs: outputs.append(motorDesign.motor(i, len(driver.outputNames))) elif driver.UseParametersCSV: outputs = [] with open('parameters.csv', 'r') as f: # read log file of inputs and outputs f.readline() # skip past the line specifying the names of inputs and outputs for line in f: output = [] for num in line.split(',')[-len(driver.outputNames):]: # get list of outputs from line (in string form) output.append(float(num)) outputs.append(output) f.close() else: recorder = InMemoryRecorder() recorder.startup(driver.root) driver.recorders.append(recorder) driver.runlist = [zip(driver.inputNames, input) for input in inputs] if UseParallel: driver.sequential = False if UseCluster: print 'Using remote cluster.' driver.sequential = False # This is necessary more often than it should be. driver.ignore_egg_requirements = True # Force use of only cluster hosts by adding this requirement. driver.extra_resources = dict(allocator='PCCCluster') super(driver.__class__, driver).run(driver) outputs = [] for c in recorder.iters: unknowns = c['unknowns'] output = [] missing = object() for name in driver.outputNames: unknown = unknowns.get(name, missing) if unknown is missing: raise Exception('No outputs from simulator matching requested output \'{0}\'. Available outputs: {1}'.format(name, unknowns.keys())) if unknown is None: # FIXME upgrade OpenMDAO, and the testbench should throw AnalysisException raise Exception('No value from simulator matching requested output \'{0}\'. Perhaps the testbench failed') if not isinstance(unknown, float): # FIXME should really be a float. TODO fix post_processing_class.py update_metrics_in_report_json in all models everywhere... # warnings.warn('Unknown \'{0}\' produced from a TestBench is not a float'.format(name)) unknown = float(unknown) output.append(unknown) outputs.append(output) driver.recorders._recorders.remove(recorder) if not driver.UseParametersCSV: with open('parameters.csv', 'w') as f: # write log file of inputs and outputs f.write(','.join(driver.inputNames)+','+','.join(driver.outputNames)+'\n') for x, i in enumerate(inputs): f.write(','.join(str(y) for y in inputs[x])) if x < len(outputs): f.write(','+','.join(str(y) for y in outputs[x])) f.write('\n') f.close() if len(outputs) != len(inputs): raise Exception('Simulator returned only {0} results of a requested {1}. See parameters.csv for details.'.format(len(outputs), len(inputs))) return asarray(outputs)
def run_list(problem, driver, inputs): if driver.TestMotor: # test the motor design instead of an external model outputs = [] for i in inputs: outputs.append(motorDesign.motor(i, len(driver.outputNames))) elif driver.UseParametersCSV: outputs = [] with open('parameters.csv', 'r') as f: # read log file of inputs and outputs f.readline( ) # skip past the line specifying the names of inputs and outputs for line in f: output = [] for num in line.split( ',' )[-len(driver.outputNames ):]: # get list of outputs from line (in string form) output.append(float(num)) outputs.append(output) f.close() else: recorder = InMemoryRecorder() recorder.startup(driver.root) driver.recorders.append(recorder) problem.setup() driver.runlist = [zip(driver.inputNames, input) for input in inputs] if UseParallel: driver.sequential = False if UseCluster: print 'Using remote cluster.' driver.sequential = False # This is necessary more often than it should be. driver.ignore_egg_requirements = True # Force use of only cluster hosts by adding this requirement. driver.extra_resources = dict(allocator='PCCCluster') super(driver.__class__, driver).run(problem) outputs = [] for c in recorder.iters: unknowns = c['unknowns'] output = [] missing = object() for name in driver.outputNames: path = name.split(".") if len(path) > 1 and path[0] in driver.subproblem_output_meta: real_name = driver.subproblem_output_meta[path[0]][path[1]] real_path = "{}.{}".format(path[0], real_name) else: real_path = name unknown = unknowns.get(real_path, missing) if unknown is missing: raise Exception( 'No outputs from simulator matching requested output \'{0}\'. Available outputs: {1}' .format(real_path, unknowns.keys())) if unknown is None: # FIXME upgrade OpenMDAO, and the testbench should throw AnalysisException raise Exception( 'No value from simulator matching requested output \'{0}\'. Perhaps the testbench failed' ) if not isinstance(unknown, float): # FIXME should really be a float. TODO fix post_processing_class.py update_metrics_in_report_json in all models everywhere... # warnings.warn('Unknown \'{0}\' produced from a TestBench is not a float'.format(name)) unknown = float(unknown) output.append(unknown) outputs.append(output) driver.recorders._recorders.remove(recorder) if not driver.UseParametersCSV: with open('parameters.csv', 'w') as f: # write log file of inputs and outputs f.write(','.join(driver.inputNames) + ',' + ','.join(driver.outputNames) + '\n') for x, i in enumerate(inputs): f.write(','.join(str(y) for y in inputs[x])) if x < len(outputs): f.write(',' + ','.join(str(y) for y in outputs[x])) f.write('\n') f.close() if len(outputs) != len(inputs): raise Exception( 'Simulator returned only {0} results of a requested {1}. See parameters.csv for details.' .format(len(outputs), len(inputs))) return asarray(outputs)