def single_test(file_dir, config_name, pickle_name): cwd = os.getcwd() os.chdir(file_dir) config_file = config_name pickle_file = pickle_name new_pickle_file = 'test_out.pkl' new_log_file = 'test.log' new_diff_file = 'diff.txt' if os.path.isfile(new_pickle_file): os.remove(new_pickle_file) if os.path.isfile(new_log_file): os.remove(new_log_file) if os.path.isfile(new_diff_file): os.remove(new_diff_file) flags = ['-f', config_file, '--output_file', new_pickle_file, '-l', new_log_file, '-d', 'DEBUG'] runmureil.runmureil(flags) if os.path.isfile(new_pickle_file): exp_result = pickle.load(open(pickle_file, 'rb')) new_result = pickle.load(open(new_pickle_file, 'rb')) if 'best_gene_data' in exp_result: exp_bgd = exp_result['best_gene_data'] else: exp_bgd = exp_result['opt_data'] if 'best_gene_data' in new_result: new_bgd = new_result['best_gene_data'] else: new_bgd = new_result['opt_data'] # round the total cost to simplify regression comparisions # where internal rounding is an issue for i in range(len(exp_bgd)): exp_bgd[i][1] = round(exp_bgd[i][1], 0) for i in range(len(new_bgd)): new_bgd[i][1] = round(new_bgd[i][1], 0) match = (exp_bgd == new_bgd) if not match: f = open(file_dir + '/' + 'diff.txt', 'w') pp = pprint.PrettyPrinter(indent=4, stream=f) f.write('Expected best gene data\n') f.write('=======================\n') pp.pprint(exp_bgd) f.write('This run best gene data\n') f.write('=======================\n') pp.pprint(new_bgd) f.close() else: match = False os.chdir(cwd) return match
#copies or substantial portions of the Software. # #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE #SOFTWARE. # # """Script to call runmureil with extra_data read from the pickle file listed as the first argument, extracting 'best_gene' from the dict in there. This will cause the simulation to initialise all the genes to this sequence. """ import runmureil import sys import pickle if __name__ == '__main__': p = pickle.load(open(sys.argv[1], 'rb')) extra_data = {} if 'best_gene' in p: extra_data['start_gene'] = p['best_gene'] else: extra_data['start_gene'] = p['best_params'] runmureil.runmureil(sys.argv[2:], extra_data)
#The above copyright notice and this permission notice shall be included in all #copies or substantial portions of the Software. # #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE #SOFTWARE. # # """Script to call runmureil with extra_data read from the pickle file listed as the first argument, extracting 'best_gene' from the dict in there. This will cause the simulation to initialise all the genes to this sequence. """ import runmureil import sys import pickle if __name__ == '__main__': p = pickle.load(open(sys.argv[1], 'rb')) extra_data = {} if 'best_gene' in p: extra_data['start_gene'] = p['best_gene'] else: extra_data['start_gene'] = p['best_params'] runmureil.runmureil(sys.argv[2:], extra_data)
# Create the config files for solar_cost in solar_cost_list: filename = 'solar_{:d}_config.txt'.format(solar_cost) f = open(filename, 'w') f.write('[Solar]\n') f.write('capex: {:d}\n'.format(solar_cost)) f.write('[Master]\n') f.write('output_file: solar_{:d}.pkl\n'.format(solar_cost)) f.close() # Run the sims for solar_cost in solar_cost_list: filename = 'solar_{:d}_config.txt'.format(solar_cost) logname = 'solar_{:d}.log'.format(solar_cost) runmureil.runmureil(['-f', 'asst5_config.txt', '-f', filename, '-l', logname, '--iterations', '100']) # Collect the results for solar_cost in solar_cost_list: pkl_name = 'solar_{:d}.pkl'.format(solar_cost) p = pickle.load(open(pkl_name, 'rb')) costs = p['best_results']['cost'] total_cost = sum([pair[1] for pair in costs]) capacities = p['best_results']['capacity'] print '==========================================' print 'Solar Capex = {:d}'.format(solar_cost) print 'Total Cost $M = {:.2f}'.format(total_cost) print 'Capacities:' print capacities
# Create the config files for solar_cost in solar_cost_list: filename = 'solar_{:d}_config.txt'.format(solar_cost) f = open(filename, 'w') f.write('[Solar]\n') f.write('capex: {:d}\n'.format(solar_cost)) f.write('[Master]\n') f.write('output_file: solar_{:d}.pkl\n'.format(solar_cost)) f.close() # Run the sims for solar_cost in solar_cost_list: filename = 'solar_{:d}_config.txt'.format(solar_cost) logname = 'solar_{:d}.log'.format(solar_cost) runmureil.runmureil([ '-f', 'asst5_config.txt', '-f', filename, '-l', logname, '--iterations', '100' ]) # Collect the results for solar_cost in solar_cost_list: pkl_name = 'solar_{:d}.pkl'.format(solar_cost) p = pickle.load(open(pkl_name, 'rb')) costs = p['best_results']['cost'] total_cost = sum([pair[1] for pair in costs]) capacities = p['best_results']['capacity'] print '==========================================' print 'Solar Capex = {:d}'.format(solar_cost) print 'Total Cost $M = {:.2f}'.format(total_cost) print 'Capacities:' print capacities