<jupyter_start><jupyter_text>Mcpy MolSSI Summer School -- Domain Specific Project -- <NAME>, <NAME>, <NAME>, <NAME>, and <NAME> 2019-07-31  Import necessary modules<jupyter_code>import numpy as np
import mcpy.particles
import mcpy.box
import mcpy.pairwise
import mcpy.integrator
import mcpy.mcsimulation
from timeit import default_timer as timer<jupyter_output><empty_output><jupyter_text>Set up simulation parameters<jupyter_code>reduced_temperature = 0.9
reduced_density = 0.9
num_part = 500<jupyter_output><empty_output><jupyter_text>Initialize objects* Box -- holds the box dimensions and can manipulate periodic  points* Particles -- holds the particle's coordinates and number  with the potential to later aggregate other quantities* LJ -- computes the pairwise potential of a series of  points* Integrator -- Class that actually performs the displacement  trial move* MCSimulation -- Interfaces all the classes correctly together.<jupyter_code>box_dims = np.full(3, np.cbrt(num_part / reduced_density))
box = mcpy.box.Box(box_dims=box_dims)
part = mcpy.particles.Particles.from_random(num_particles=num_part,
                                            box_dims=box.box_dims)
lj = mcpy.pairwise.LJ(cutoff=3.)
intg = mcpy.integrator.Integrator(1/reduced_temperature)
mc = mcpy.mcsimulation.MCSimulation()<jupyter_output><empty_output><jupyter_text>Add objects to MCSimulation object<jupyter_code>mc.add_integrator(intg)
mc.add_box(box)
mc.add_particles(part)
mc.add_potential(lj)<jupyter_output><empty_output><jupyter_text>Runs Simulation for 1 Million Steps<jupyter_code>t1 = timer()
mc.run(1000000)
t2 = timer()
print("1 million steps in {:4d} sec".format(int(t2 - t1)))
print("{:5d} steps per second.".format(int(1e6/(t2 - t1))))<jupyter_output>1 million steps in  179 sec
 5559 steps per second.<jupyter_text>Original Script<jupyter_code>t1 = timer()
%run day_1.py
t2 = timer()
print("One hundred thousand steps in {:4d} sec".format(int(t2 - t1)))
print("{:5d} steps per second.".format(int(1e5/(t2 - t1))))<jupyter_output>One hundred thousand steps in  770 sec
  129 steps per second.<jupyter_text>Numpy Speedup<jupyter_code>print("Numpy code is {:6.2f} times faster.".format(5559/129))<jupyter_output>Numpy code is  43.09 times faster.<jupyter_text>Using C++ LJ Class<jupyter_code>## Need to reset kernel
!git checkout -f lj_cpp_class
import numpy as np
import mcpy.box
import mcpy.particles
import mcpy.integrator
import mcpy.mcsimulation
from mccpp.pairwise import LJ
from timeit import default_timer as timer
reduced_temperature = 0.9
reduced_density = 0.9
num_part = 500
box_dims = np.full(3, np.cbrt(num_part / reduced_density))
box = mcpy.box.Box(box_dims=box_dims)
part = mcpy.particles.Particles.from_random(num_particles=num_part,
                                            box_dims=box.box_dims)
lj = LJ(cutoff=3.)
intg = mcpy.integrator.Integrator(1/reduced_temperature)
mc = mcpy.mcsimulation.MCSimulation()
mc.add_integrator(intg)
mc.add_box(box)
mc.add_particles(part)
mc.add_potential(lj)
t1 = timer()
mc.run(1000000)
t2 = timer()
print("1 million steps in {:4d} sec".format(int(t2 - t1)))
print("{:5d} steps per second.".format(int(1e6/(t2 - t1))))<jupyter_output>1 million steps in  390 sec
 2563 steps per second.<jupyter_text>C++ Speedup<jupyter_code>print("C++ code is {:6.2f} times faster.".format(2563/129))
print("Numpy code is {:6.2f} times faster.".format(5559/2563))<jupyter_output>C++ code is  19.87 times faster.
Numpy code is   2.17 times faster.<jupyter_text>Simple Scaling Analysis*With numpy*<jupyter_code>num_part = np.logspace(2, 4, num=10, dtype=np.int)
lj = mcpy.pairwise.LJ(cutoff=3.)
intg = mcpy.integrator.Integrator(1/reduced_temperature)
times = []
for num in num_part:
    box_dims = np.full(3, np.cbrt(num / reduced_density))
    box = mcpy.box.Box(box_dims=box_dims)
    part = mcpy.particles.Particles.from_random(num_particles=num,
                                                box_dims=box.box_dims)
    mc = mcpy.mcsimulation.MCSimulation()
    mc.add_integrator(intg)
    mc.add_box(box)
    mc.add_particles(part)
    mc.add_potential(lj)
    t1 = timer()
    mc.run(100000)
    t2 = timer()
    times.append(t2 - t1)
import matplotlib.pyplot as plt
default_size = 20 
fig, ax = plt.subplots(figsize=(15,8))
ax.plot(num_part, times)
ax.set_xlabel(r"$N_p$ Number of Particles", size=default_size)
ax.set_ylabel("Seconds per 1e6 steps", size=default_size)
ax.set_title("Scaling Based on Particle Number", size=default_size + 10)
ax.tick_params(axis='both', which='major', labelsize=default_size - 5)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11955574912891986, 'fraction_numerical': 0.03571428571428571, 'mean_word_length': 4.972691807542263, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '86317', 'license': 'MIT', 'n_tokens_mistral': 1760, 'n_tokens_neox': 1656, 'n_words': 364, 'path': 'exampleSimulation.ipynb', 'repo_name': 'MolSSI-Education/mm_2019_sss_3', 'size': '4621'}