def prepare_inputs(*inputs, **kwinputs):
"""Prepare the inputs for the simulator.
The signature follows that given in `elfi.tools.external_operation`. This function
appends kwinputs with unique and descriptive filenames and writes an input file for
the bdm executable.
"""
alpha, delta, tau, N = inputs
meta = kwinputs['meta']
# Organize the parameters to an array. The broadcasting works nicely with constant
# arguments.
param_array = np.row_stack(np.broadcast(alpha, delta, tau, N))
# Prepare a unique filename for parallel settings
filename = '{model_name}_{batch_index}_{submission_index}.txt'.format(**meta)
np.savetxt(filename, param_array, fmt='%.4f %.4f %.4f %d')
# Add the filenames to kwinputs
kwinputs['filename'] = filename
kwinputs['output_filename'] = filename[:-4] + '_out.txt'
# Return new inputs that the command will receive
return inputs, kwinputs
评论列表
文章目录