def save_many_microscopically_optimal( metropolis_state, final_sweep, order_5_damping, order_6_damping, initial_sweep=0, save_every_n_sweeps=10 ): """ Runs a monte carlo simulation using the metropolis state (a class instance of a descendent class of metropolis). Performs final_sweep - initial_sweep sweeps. Every save_every_n_sweeps, checks to see if the microscopically optimal conditions are met. If they are, saves a sphere. Otherwise continues sweeping. Might be susceptible to crashes. Progress file is unnecessary. """ # Reset the current sweep metropolis_state.reset_current_sweep(initial_sweep) # Calculate the current time start_time = make_time_string() # Start the sweeps while metropolis_state.get_current_sweep() < final_sweep: metropolis_state.sweep(save_every_n_sweeps) v_count = st.vertex_count_selection_optimal(order_5_damping, order_6_damping, sd.vertex.instances.values()) if v_count.is_close_enough(): fname = metropolis_state.make_file_name_v4(final_sweep, start_time, order_5_damping, order_6_damping) write_sphere_to_file(fname + output_suffix) write_statistics_file(metropolis_state, v_count, fname + STATISTICS_SUFFIX) # Print a happy message print "All done! :)"
def stop_at_microscopically_optimal( metropolis_state, final_sweep, order_5_damping, order_6_damping, initial_sweep=0, save_every_n_sweeps=10 ): """ Runs a monte carlo simulation using the metropolis state (a class instance of a descendent class of metropolis). Saves to a single file, and stops when the sphere is close microscopically ideal, as defined by the functions in the vertex_count class and subclasses. We write a progress file anyway, despite there being no final sweep. initial_sweep and final sweep do nothing. They're in the parameters list for consistency. """ # Pretend final sweep. For the progress file. final_sweep = 0 # Reset the current sweep so that we start from 0. metropolis_state.reset_current_sweep(initial_sweep) # Calculate the file name fname = metropolis_state.make_file_name_v3(order_5_damping, order_6_damping) # Keep track of the number of vertexes of each order v_count = st.vertex_count_selection_optimal(order_5_damping, order_6_damping, sd.vertex.instances.values()) # Immediately save a file. write_sphere_to_file(fname + output_suffix) write_progress_file(metropolis_state, final_sweep, save_every_n_sweeps, fname + tracking_suffix) write_statistics_file(metropolis_state, v_count, fname + STATISTICS_SUFFIX) while not v_count.is_close_enough(): metropolis_state.sweep(save_every_n_sweeps) v_count = st.vertex_count_selection_optimal(order_5_damping, order_6_damping, sd.vertex.instances.values()) write_sphere_to_file(fname + output_suffix) write_statistics_file(metropolis_state, v_count, fname + STATISTICS_SUFFIX) write_progress_file(metropolis_state, final_sweep, save_every_n_sweeps, fname + tracking_suffix) # Print a happy message print "All done! :)"