<jupyter_start><jupyter_text>Monte Carlo Sim in NumPy<jupyter_code># Set simulation parameters
reduced_temperature = 0.9
num_steps = 50000
max_displacement = 0.1
cutoff = 3
    #how often to print an update
freq = 5000

# Calculated quantities
beta = 1 / reduced_temperature
num_particles = len(coordinates)

start= time.time()

# Energy calculations
total_energy = calculate_total_energy_np(coordinates, box_length, cutoff)
print(total_energy)
total_correction = calculate_tail_correction(num_particles, box_length, cutoff)
print(total_correction)
total_energy += total_correction


for step in range(num_steps):
    # 1. Randomly pick one of the particles.
    random_particle = random.randrange(num_particles)
    
    # 2. Calculate the interaction energy of the selected particle with the system.
    current_energy = calculate_pair_energy_np(coordinates, random_particle, box_length, cutoff)
    
    # 3. Generate a random x, y, z displacement.
    rand_np=np.random.uniform(-max_displacement, max_displacement, 3)
    
    # 4. Modify the coordinate of Nth particle by generated displacements.
    coordinates[random_particle]= coordinates[random_particle] + rand_np
    
    # 5. Calculate the interaction energy of the moved particle with the system and store this value.
    proposed_energy = calculate_pair_energy_np(coordinates, random_particle, box_length, cutoff)
    delta_energy = proposed_energy - current_energy
    # 6. Calculate if we accept the move based on energy difference.
    accept = accept_or_reject(delta_energy, beta)
    # 7. If accepted, move the particle.
    if accept:
        total_energy += delta_energy
        #Move not accepted, roll back coordinates
    else:
        coordinates[random_particle]= coordinates[random_particle] - rand_np    
    
    # 8. Print the energy if step is a multiple of freq.
    if step % freq == 0:
        print(step, total_energy/num_particles)
        
end=time.time()

elapsed= end-start
print(f'elasped time is {elapsed}')
#standard Monte Carlo

start= time.time()

# Energy calculations
total_energy = calculate_total_energy(coordinates, box_length, cutoff)
print(total_energy)
total_correction = calculate_tail_correction(num_particles, box_length, cutoff)
print(total_correction)
total_energy += total_correction


for step in range(num_steps):
    # 1. Randomly pick one of the particles.
    random_particle = random.randrange(num_particles)
    
    # 2. Calculate the interaction energy of the selected particle with the system.
    current_energy = calculate_pair_energy(coordinates, random_particle, box_length, cutoff)
    
    # 3. Generate a random x, y, z displacement.
    x_rand = random.uniform(-max_displacement, max_displacement)
    y_rand = random.uniform(-max_displacement, max_displacement)
    z_rand = random.uniform(-max_displacement, max_displacement)
    
    # 4. Modify the coordinate of Nth particle by generated displacements.
    coordinates[random_particle][0] += x_rand
    coordinates[random_particle][1] += y_rand
    coordinates[random_particle][2] += z_rand
    
    # 5. Calculate the interaction energy of the moved particle with the system and store this value.
    proposed_energy = calculate_pair_energy(coordinates, random_particle, box_length, cutoff)
    delta_energy = proposed_energy - current_energy
    
    # 6. Calculate if we accept the move based on energy difference.
    accept = accept_or_reject(delta_energy, beta)
    
    # 7. If accepted, move the particle.
    if accept:
        total_energy += delta_energy
    else:
        #Move not accepted, roll back coordinates
        coordinates[random_particle][0] -= x_rand
        coordinates[random_particle][1] -= y_rand
        coordinates[random_particle][2] -= z_rand
    
    # 8. Print the energy if step is a multiple of freq.
    if step % freq == 0:
        print(step, total_energy/num_particles)
        
end=time.time()

elapsed= end-start
print(f'elasped time is {elapsed}')<jupyter_output>-4301.087170798704
-198.4888837441566
0 -5.624470068178576
5000 -5.648099419851301
10000 -5.652214767664284
15000 -5.651771009550226
20000 -5.644552001814466
25000 -5.62221929770912
30000 -5.633485606653184
35000 -5.651582605816895
40000 -5.6739233482280635
45000 -5.631236794104752
elasped time is 258.8847312927246<jupyter_text>For 50000 steps, standard monte carlo simulation of our system took 258.9 seconds, where the numpy inplementation of the monte carlo simulation took 7.4 seconds. This means that the numpy implementation observed and 97% reduction in time elasped.<jupyter_code>1-(7.4/258.9)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0739939420164431, 'fraction_numerical': 0.06771960190393769, 'mean_word_length': 4.113938053097345, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '370908', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1624, 'n_tokens_neox': 1401, 'n_words': 412, 'path': 'homework/day_4/Day_4_Homework_Kevin_Fong.ipynb', 'repo_name': 'msse-2021-bootcamp/team2-project', 'size': '4622'}