Skip to content

Commit

Permalink
Merge pull request #72 from glotzerlab/log-hdf5
Browse files Browse the repository at this point in the history
Use HDF5 files for quantity logs.
  • Loading branch information
joaander authored Nov 9, 2023
2 parents e6ce7b1 + 257f435 commit af73bc6
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 186 deletions.
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
44 changes: 20 additions & 24 deletions hoomd_validation/hard_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,20 @@ def make_mc_simulation(job,
compute_density = ComputeDensity()
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'])
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 @@ -398,22 +397,20 @@ def run_nec_sim(job, device, complete_filename):
# compute the density
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 +585,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 +599,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 +609,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 +679,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
44 changes: 20 additions & 24 deletions hoomd_validation/hard_sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,21 +159,20 @@ def make_mc_simulation(job,
compute_density = ComputeDensity()
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'])
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 @@ -310,22 +309,20 @@ def run_nec_sim(job, device, complete_filename):
# compute the density
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 @@ -467,7 +464,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 +478,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 +488,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 +557,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

0 comments on commit af73bc6

Please sign in to comment.