def main(): params, results = di.read_parameters_file() rosen_input = pack_rosen_parameters(params, results) rosen_output = rosenbrock_list(**rosen_input) results = pack_dakota_results(rosen_output, results) results.write()
# Alternatively, the ASV can be accessed by index in # function, gradient, hessian order #for i, bit in enumerate(results["obj_fn"].asv): # if bit: # active_set_vector += 1 << i # set a dictionary for passing to rosenbrock via Python kwargs rosen_params = {} rosen_params['cv'] = continuous_vars rosen_params['asv'] = [active_set_vector] rosen_params['functions'] = 1 # execute the rosenbrock analysis as a separate Python module print "Running rosenbrock..." from rosenbrock import rosenbrock_list rosen_results = rosenbrock_list(**rosen_params) print "Rosenbrock complete." # ---------------------------- # Return the results to Dakota # ---------------------------- # Insert functions from rosen into results # Results iterator provides an index, response name, and response for i, n, r in results: if r.asv.function: r.function = rosen_results['fns'][i] if r.asv.gradient: r.gradient = rosen_results['fnGrads'][i] if r.asv.hessian: r.hessian = rosen_results['fnHessians'][i]
# set up the data structures the rosenbrock analysis code expects # for this simple example, put all the variables into a single hardwired array continuous_vars = [ float(paramsdict['x1']), float(paramsdict['x2']) ] active_set_vector = [ int(paramsdict['ASV_1:obj_fn']) ] # set a dictionary for passing to rosenbrock via Python kwargs rosen_params = {} rosen_params['cv'] = continuous_vars rosen_params['asv'] = active_set_vector rosen_params['functions'] = 1 # execute the rosenbrock analysis as a separate Python module print "Running rosenbrock..." from rosenbrock import rosenbrock_list rosen_results = rosenbrock_list(**rosen_params) print "Rosenbrock complete." # ---------------------------- # Return the results to DAKOTA # ---------------------------- # write the results.out file for return to DAKOTA # this example only has a single function, so make some assumptions; # not processing DVV outfile = open('results.out.tmp', 'w') # write functions for func_ind in range(0, num_fns): if (active_set_vector[func_ind] & 1):