Skip to content

Commit

Permalink
Fix HDF5 log readers.
Browse files Browse the repository at this point in the history
  • Loading branch information
joaander committed Nov 6, 2023
1 parent 54036ea commit b9012a0
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 27 deletions.
4 changes: 1 addition & 3 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 h5py
import math
import matplotlib
import matplotlib.style
Expand All @@ -372,8 +371,7 @@ def alj_2d_conservation_analyze(*jobs):
job_linear_momentum = {}

for sim_mode in sim_modes:
log_traj = h5py.File(mode='r',
name=job.fn(sim_mode + '_quantities.h5'))
log_traj = util.read_log(job.fn(sim_mode + '_quantities.h5'))

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

Expand Down
3 changes: 1 addition & 2 deletions hoomd_validation/hard_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,6 @@ def sampling_operation(*jobs):
executable=CONFIG["executable"]))
def hard_disk_analyze(job):
"""Analyze the output of all simulation modes."""
import h5py
import numpy
import matplotlib
import matplotlib.style
Expand All @@ -612,7 +611,7 @@ def hard_disk_analyze(job):
densities = {}

for sim_mode in sim_modes:
log_traj = h5py.File(mode='r', name=job.fn(sim_mode + '_quantities.h5'))
log_traj = util.read_log(job.fn(sim_mode + '_quantities.h5'))

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

Expand Down
3 changes: 1 addition & 2 deletions hoomd_validation/hard_sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,6 @@ def sampling_operation(*jobs):
executable=CONFIG["executable"]))
def hard_sphere_analyze(job):
"""Analyze the output of all simulation modes."""
import h5py
import numpy
import matplotlib
import matplotlib.style
Expand All @@ -491,7 +490,7 @@ def hard_sphere_analyze(job):
densities = {}

for sim_mode in sim_modes:
log_traj = h5py.File(mode='r', name=job.fn(sim_mode + '_quantities.h5'))
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:
Expand Down
11 changes: 3 additions & 8 deletions hoomd_validation/lj_fluid.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,6 @@ def sampling_operation(*jobs):
executable=CONFIG["executable"]))
def lj_fluid_analyze(job):
"""Analyze the output of all simulation modes."""
import h5py
import numpy
import math
import matplotlib
Expand Down Expand Up @@ -871,7 +870,7 @@ def lj_fluid_analyze(job):
linear_momentum = {}

for sim_mode in sim_modes:
log_traj = h5py.File(mode='r', name=job.fn(sim_mode + '_quantities.h5'))
log_traj = util.read_log(job.fn(sim_mode + '_quantities.h5'))

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

Expand Down Expand Up @@ -1085,7 +1084,6 @@ def lj_fluid_compare_modes(*jobs):
aggregator=analysis_aggregator)
def lj_fluid_distribution_analyze(*jobs):
"""Checks that MD follows the correct KE distribution."""
import h5py
import numpy
import matplotlib
import matplotlib.style
Expand Down Expand Up @@ -1144,8 +1142,7 @@ def lj_fluid_distribution_analyze(*jobs):
n_dof = num_particles * 3 - 3

print('Reading' + job.fn(sim_mode + '_quantities.h5'))
log_traj = h5py.File(mode='r',
name=job.fn(sim_mode + '_quantities.h5'))
log_traj = util.read_log(job.fn(sim_mode + '_quantities.h5'))

if 'md' in sim_mode:
ke = log_traj[
Expand Down Expand Up @@ -1376,7 +1373,6 @@ def lj_fluid_nve_md_job(*jobs):
aggregator=nve_analysis_aggregator)
def lj_fluid_conservation_analyze(*jobs):
"""Analyze the output of NVE simulations and inspect conservation."""
import h5py
import numpy
import math
import matplotlib
Expand All @@ -1400,8 +1396,7 @@ def lj_fluid_conservation_analyze(*jobs):
job_linear_momentum = {}

for sim_mode in sim_modes:
log_traj = h5py.File(mode='r',
name=job.fn(sim_mode + '_quantities.h5'))
log_traj = util.read_log(job.fn(sim_mode + '_quantities.h5'))

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

Expand Down
11 changes: 3 additions & 8 deletions hoomd_validation/lj_union.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,6 @@ def sampling_operation(*jobs):
executable=CONFIG["executable"]))
def lj_union_analyze(job):
"""Analyze the output of all simulation modes."""
import h5py
import numpy
import math
import matplotlib
Expand Down Expand Up @@ -930,7 +929,7 @@ def lj_union_analyze(job):
linear_momentum = {}

for sim_mode in sim_modes:
log_traj = h5py.File(mode='r', name=job.fn(sim_mode + '_quantities.h5'))
log_traj = util.read_log(job.fn(sim_mode + '_quantities.h5'))

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

Expand Down Expand Up @@ -1129,7 +1128,6 @@ def lj_union_compare_modes(*jobs):
aggregator=analysis_aggregator)
def lj_union_distribution_analyze(*jobs):
"""Checks that MD follows the correct KE distribution."""
import h5py
import numpy
import matplotlib
import matplotlib.style
Expand Down Expand Up @@ -1196,8 +1194,7 @@ def lj_union_distribution_analyze(*jobs):
n_rotate_dof = num_particles * 3

print('Reading' + job.fn(sim_mode + '_quantities.h5'))
log_traj = h5py.File(mode='r',
name=job.fn(sim_mode + '_quantities.h5'))
log_traj = util.read_log(job.fn(sim_mode + '_quantities.h5'))

if 'md' in sim_mode:
# https://doi.org/10.1371/journal.pone.0202764
Expand Down Expand Up @@ -1453,7 +1450,6 @@ def lj_union_nve_md_job(*jobs):
aggregator=nve_analysis_aggregator)
def lj_union_conservation_analyze(*jobs):
"""Analyze the output of NVE simulations and inspect conservation."""
import h5py
import math
import matplotlib
import matplotlib.style
Expand All @@ -1476,8 +1472,7 @@ def lj_union_conservation_analyze(*jobs):
job_linear_momentum = {}

for sim_mode in sim_modes:
log_traj = h5py.File(mode='r',
name=job.fn(sim_mode + '_quantities.h5'))
log_traj = util.read_log(job.fn(sim_mode + '_quantities.h5'))

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

Expand Down
3 changes: 1 addition & 2 deletions hoomd_validation/patchy_particle_pressure.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,6 @@ def sampling_operation(*jobs):
executable=CONFIG["executable"]))
def patchy_particle_pressure_analyze(job):
"""Analyze the output of all simulation modes."""
import h5py
import numpy
import matplotlib
import matplotlib.style
Expand All @@ -615,7 +614,7 @@ def patchy_particle_pressure_analyze(job):
densities = {}

for sim_mode in sim_modes:
log_traj = h5py.File(mode='r', name=job.fn(sim_mode + '_quantities.h5'))
log_traj = util.read_log(job.fn(sim_mode + '_quantities.h5'))

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

Expand Down
3 changes: 1 addition & 2 deletions hoomd_validation/simple_polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,6 @@ def sampling_operation(*jobs):
executable=CONFIG["executable"]))
def simple_polygon_analyze(job):
"""Analyze the output of all simulation modes."""
import h5py
import numpy
import matplotlib
import matplotlib.style
Expand All @@ -501,7 +500,7 @@ def simple_polygon_analyze(job):
densities = {}

for sim_mode in sim_modes:
log_traj = h5py.File(mode='r', name=job.fn(sim_mode + '_quantities.h5'))
log_traj = util.read_log(job.fn(sim_mode + '_quantities.h5'))

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

Expand Down
11 changes: 11 additions & 0 deletions hoomd_validation/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import numpy
import signac
import os
import h5py


def true_all(*jobs, key):
Expand Down Expand Up @@ -333,3 +334,13 @@ def plot_timeseries(ax,
def _sort_sim_modes(sim_modes):
"""Sort simulation modes for comparison."""
sim_modes.sort(key=lambda x: ('nvt' in x or 'nec' in x, 'md' in x, x))


def read_log(filename):
"""Read a HDF5 log as a dictionary of logged quantities."""
with h5py.File(mode='r', name=filename) as f:
keys = []
f.visit(lambda name: keys.append(name))
result = {key: numpy.array(f[key]) for key in keys}

return result

0 comments on commit b9012a0

Please sign in to comment.