class SequentialIterationSuite: """ An example benchmark that times the performance of various kinds of iterating over dictionaries in Python. """ timeout=1000 params = ['python', 'njit', 'njit_parallel'] def setup(self, engine): np.random.seed(0) self.sim = Simulation({}, 108, 100, 1e-6, file_path=None, m=1, T=0, dx=1, save_every_x_iters=1, gpu=False, shape='fcc', engine=engine) def time_run(self, engine): self.sim.run()
def test_run(simulation_params): np.random.seed(4) d = Simulation(**simulation_params).run() df = d.diagnostic_df() for key, tolerance in tolerances.items(): fitting = np.allclose(df.iloc[0][key], df.iloc[-1][key], atol=tolerance) if not fitting: df.plot("t", ["kinetic_energy", "potential_energy"]) plt.show() break if not fitting: raise ValueError() shutil.rmtree(os.path.dirname(simulation_params["file_path"])) return d
def test_gpu_run(simulation_params): simulation_params["N"] = 256 simulation_params["file_path"] = "/tmp/nbody_gpu_test_run/data{0:08d}.h5" simulation_params["gpu"] = True d = Simulation(**simulation_params).run().diagnostic_values for key in ["kinetic_energy", "potential_energy"]: assert np.isclose(d[min(d)][key], d[max(d)][key]) shutil.rmtree(os.path.dirname(gpu_simulation_params["file_path"])) return d
def simulation_numba(request): np.random.seed(0) sim = Simulation( {}, 108, 100, 1e-6, file_path=None, m=1, T=0, dx=1, save_every_x_iters=1, gpu=False, shape="fcc", engine=request.param, ) sim.run() return sim
def simulation_python(): np.random.seed(0) sim = Simulation( {}, 108, 100, 1e-6, file_path=None, m=1, T=0, dx=1, save_every_x_iters=1, gpu=False, shape="fcc", engine="python", ) sim.run() return sim
def setup(n): np.random.seed(0) sim = Simulation({}, n, 100, 1e-6, file_path=None, m=1, T=0, dx=1, save_every_x_iters=1, gpu=False, shape='fcc') return sim
def unstable_simulation(request): sim = Simulation( {}, 2, 100, request.param, file_path=None, m=1, T=0, dx=1, save_every_x_iters=1, gpu=False, ) sim.r = np.array([[0, 0, 0], [1, 0, 0]], dtype=float) sim.extrapolate_old_r() sim.run() return sim
def test_well_initialized(): np.random.seed(4) d = Simulation(**simulation_params) # 32 unique positions assert np.unique(d.r, axis=0).shape[0] == d.N
def setup(self, engine): np.random.seed(0) self.sim = Simulation({}, 108, 100, 1e-6, file_path=None, m=1, T=0, dx=1, save_every_x_iters=1, gpu=False, shape='fcc', engine=engine)