Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use HDF5 files for quantity logs. #72

Merged
merged 9 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
signac==2.1.0
signac-flow==0.26.1
h5py==3.10.0
gsd==3.2.0
numpy==1.26.1
PyYAML==6.0.1
gsd==3.2.0
signac==2.1.0
signac-flow==0.26.1
15 changes: 8 additions & 7 deletions hoomd_validation/alj_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ def alj_2d_nve_md_job(*jobs):
aggregator=analysis_aggregator)
def alj_2d_conservation_analyze(*jobs):
"""Analyze the output of NVE simulations and inspect conservation."""
import gsd.hoomd
import math
import matplotlib
import matplotlib.style
Expand All @@ -359,7 +358,7 @@ def alj_2d_conservation_analyze(*jobs):
print('starting alj_2d_conservation_analyze:', jobs[0])

sim_modes = ['nve_md_cpu']
if os.path.exists(jobs[0].fn('nve_md_gpu_quantities.gsd')):
if os.path.exists(jobs[0].fn('nve_md_gpu_quantities.h5')):
sim_modes.extend(['nve_md_gpu'])

timesteps = []
Expand All @@ -372,20 +371,22 @@ def alj_2d_conservation_analyze(*jobs):
job_linear_momentum = {}

for sim_mode in sim_modes:
log_traj = gsd.hoomd.read_log(job.fn(sim_mode + '_quantities.gsd'))
log_traj = util.read_log(job.fn(sim_mode + '_quantities.h5'))

job_timesteps[sim_mode] = log_traj['configuration/step']
job_timesteps[sim_mode] = log_traj['hoomd-data/Simulation/timestep']

job_energies[sim_mode] = (
log_traj[
'log/md/compute/ThermodynamicQuantities/potential_energy']
'hoomd-data/md/compute/ThermodynamicQuantities/potential_energy']
+ log_traj[
'log/md/compute/ThermodynamicQuantities/kinetic_energy'])
'hoomd-data/md/compute/ThermodynamicQuantities/kinetic_energy']
)
job_energies[sim_mode] = (
job_energies[sim_mode]
- job_energies[sim_mode][0]) / job.statepoint["num_particles"]

momentum_vector = log_traj['log/md/Integrator/linear_momentum']
momentum_vector = log_traj[
'hoomd-data/md/Integrator/linear_momentum']
job_linear_momentum[sim_mode] = [
math.sqrt(v[0]**2 + v[1]**2 + v[2]**2)
/ job.statepoint["num_particles"] for v in momentum_vector
Expand Down
42 changes: 20 additions & 22 deletions hoomd_validation/hard_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,20 @@ def make_mc_simulation(job,
sdf = hoomd.hpmc.compute.SDF(xmax=0.02, dx=1e-4)

# log to gsd
logger_gsd = hoomd.logging.Logger(categories=['scalar', 'sequence'])
logger_gsd.add(mc, quantities=['translate_moves'])
logger_gsd.add(sdf, quantities=['betaP'])
logger_gsd.add(compute_density, quantities=['density'])
logger = hoomd.logging.Logger(categories=['scalar', 'sequence'])
joaander marked this conversation as resolved.
Show resolved Hide resolved
logger.add(mc, quantities=['translate_moves'])
logger.add(sdf, quantities=['betaP'])
logger.add(compute_density, quantities=['density'])
for loggable, quantity in extra_loggables:
logger_gsd.add(loggable, quantities=[quantity])
logger.add(loggable, quantities=[quantity])

# make simulation
sim = util.make_simulation(job=job,
device=device,
initial_state=initial_state,
integrator=mc,
sim_mode=sim_mode,
logger=logger_gsd,
logger=logger,
table_write_period=WRITE_PERIOD,
trajectory_write_period=LOG_PERIOD['trajectory'],
log_write_period=LOG_PERIOD['quantities'],
Expand Down Expand Up @@ -399,21 +399,20 @@ def run_nec_sim(job, device, complete_filename):
compute_density = ComputeDensity()

# log to gsd
logger_gsd = hoomd.logging.Logger(categories=['scalar', 'sequence'])
logger_gsd.add(mc,
quantities=[
'translate_moves', 'particles_per_chain',
'virial_pressure'
])
logger_gsd.add(compute_density, quantities=['density'])
logger = hoomd.logging.Logger(categories=['scalar', 'sequence'])
logger.add(mc,
quantities=[
'translate_moves', 'particles_per_chain', 'virial_pressure'
])
logger.add(compute_density, quantities=['density'])

# make simulation
sim = util.make_simulation(job=job,
device=device,
initial_state=initial_state,
integrator=mc,
sim_mode=sim_mode,
logger=logger_gsd,
logger=logger,
table_write_period=WRITE_PERIOD,
trajectory_write_period=LOG_PERIOD['trajectory'],
log_write_period=LOG_PERIOD['quantities'],
Expand Down Expand Up @@ -588,7 +587,6 @@ def sampling_operation(*jobs):
executable=CONFIG["executable"]))
def hard_disk_analyze(job):
"""Analyze the output of all simulation modes."""
import gsd.hoomd
import numpy
import matplotlib
import matplotlib.style
Expand All @@ -603,7 +601,7 @@ def hard_disk_analyze(job):
'npt_cpu',
]

if os.path.exists(job.fn('nvt_gpu_quantities.gsd')):
if os.path.exists(job.fn('nvt_gpu_quantities.h5')):
sim_modes.extend(['nvt_gpu'])

util._sort_sim_modes(sim_modes)
Expand All @@ -613,18 +611,18 @@ def hard_disk_analyze(job):
densities = {}

for sim_mode in sim_modes:
log_traj = gsd.hoomd.read_log(job.fn(sim_mode + '_quantities.gsd'))
log_traj = util.read_log(job.fn(sim_mode + '_quantities.h5'))

timesteps[sim_mode] = log_traj['configuration/step']
timesteps[sim_mode] = log_traj['hoomd-data/Simulation/timestep']

if 'nec' in sim_mode:
pressures[sim_mode] = log_traj[
'log/hpmc/nec/integrate/Sphere/virial_pressure']
'hoomd-data/hpmc/nec/integrate/Sphere/virial_pressure']
else:
pressures[sim_mode] = log_traj['log/hpmc/compute/SDF/betaP']
pressures[sim_mode] = log_traj['hoomd-data/hpmc/compute/SDF/betaP']

densities[sim_mode] = log_traj[
'log/custom_actions/ComputeDensity/density']
'hoomd-data/custom_actions/ComputeDensity/density']

# save averages
for mode in sim_modes:
Expand Down Expand Up @@ -683,7 +681,7 @@ def hard_disk_compare_modes(*jobs):
'npt_cpu',
]

if os.path.exists(jobs[0].fn('nvt_gpu_quantities.gsd')):
if os.path.exists(jobs[0].fn('nvt_gpu_quantities.h5')):
sim_modes.extend(['nvt_gpu'])

util._sort_sim_modes(sim_modes)
Expand Down
42 changes: 20 additions & 22 deletions hoomd_validation/hard_sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,20 @@ def make_mc_simulation(job,
sdf = hoomd.hpmc.compute.SDF(xmax=0.02, dx=1e-4)

# log to gsd
logger_gsd = hoomd.logging.Logger(categories=['scalar', 'sequence'])
logger_gsd.add(mc, quantities=['translate_moves'])
logger_gsd.add(sdf, quantities=['betaP'])
logger_gsd.add(compute_density, quantities=['density'])
logger = hoomd.logging.Logger(categories=['scalar', 'sequence'])
joaander marked this conversation as resolved.
Show resolved Hide resolved
logger.add(mc, quantities=['translate_moves'])
logger.add(sdf, quantities=['betaP'])
logger.add(compute_density, quantities=['density'])
for loggable, quantity in extra_loggables:
logger_gsd.add(loggable, quantities=[quantity])
logger.add(loggable, quantities=[quantity])

# make simulation
sim = util.make_simulation(job=job,
device=device,
initial_state=initial_state,
integrator=mc,
sim_mode=sim_mode,
logger=logger_gsd,
logger=logger,
table_write_period=WRITE_PERIOD,
trajectory_write_period=LOG_PERIOD['trajectory'],
log_write_period=LOG_PERIOD['quantities'],
Expand Down Expand Up @@ -311,21 +311,20 @@ def run_nec_sim(job, device, complete_filename):
compute_density = ComputeDensity()

# log to gsd
logger_gsd = hoomd.logging.Logger(categories=['scalar', 'sequence'])
logger_gsd.add(mc,
quantities=[
'translate_moves', 'particles_per_chain',
'virial_pressure'
])
logger_gsd.add(compute_density, quantities=['density'])
logger = hoomd.logging.Logger(categories=['scalar', 'sequence'])
joaander marked this conversation as resolved.
Show resolved Hide resolved
logger.add(mc,
quantities=[
'translate_moves', 'particles_per_chain', 'virial_pressure'
])
logger.add(compute_density, quantities=['density'])

# make simulation
sim = util.make_simulation(job=job,
device=device,
initial_state=initial_state,
integrator=mc,
sim_mode=sim_mode,
logger=logger_gsd,
logger=logger,
table_write_period=WRITE_PERIOD,
trajectory_write_period=LOG_PERIOD['trajectory'],
log_write_period=LOG_PERIOD['quantities'],
Expand Down Expand Up @@ -467,7 +466,6 @@ def sampling_operation(*jobs):
executable=CONFIG["executable"]))
def hard_sphere_analyze(job):
"""Analyze the output of all simulation modes."""
import gsd.hoomd
import numpy
import matplotlib
import matplotlib.style
Expand All @@ -482,7 +480,7 @@ def hard_sphere_analyze(job):
'npt_cpu',
]

if os.path.exists(job.fn('nvt_gpu_quantities.gsd')):
if os.path.exists(job.fn('nvt_gpu_quantities.h5')):
sim_modes.extend(['nvt_gpu'])

util._sort_sim_modes(sim_modes)
Expand All @@ -492,17 +490,17 @@ def hard_sphere_analyze(job):
densities = {}

for sim_mode in sim_modes:
log_traj = gsd.hoomd.read_log(job.fn(sim_mode + '_quantities.gsd'))
timesteps[sim_mode] = log_traj['configuration/step']
log_traj = util.read_log(job.fn(sim_mode + '_quantities.h5'))
timesteps[sim_mode] = log_traj['hoomd-data/Simulation/timestep']

if 'nec' in sim_mode:
pressures[sim_mode] = log_traj[
'log/hpmc/nec/integrate/Sphere/virial_pressure']
'hoomd-data/hpmc/nec/integrate/Sphere/virial_pressure']
else:
pressures[sim_mode] = log_traj['log/hpmc/compute/SDF/betaP']
pressures[sim_mode] = log_traj['hoomd-data/hpmc/compute/SDF/betaP']

densities[sim_mode] = log_traj[
'log/custom_actions/ComputeDensity/density']
'hoomd-data/custom_actions/ComputeDensity/density']

# save averages
for mode in sim_modes:
Expand Down Expand Up @@ -561,7 +559,7 @@ def hard_sphere_compare_modes(*jobs):
'npt_cpu',
]

if os.path.exists(jobs[0].fn('nvt_gpu_quantities.gsd')):
if os.path.exists(jobs[0].fn('nvt_gpu_quantities.h5')):
sim_modes.extend(['nvt_gpu'])

util._sort_sim_modes(sim_modes)
Expand Down
Loading