Skip to content

Commit

Permalink
minor fixes to hdf5 with multiple files + test
Browse files Browse the repository at this point in the history
  • Loading branch information
barakr committed Oct 31, 2023
1 parent 235aa22 commit d79e8fd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
2 changes: 2 additions & 0 deletions include/Statistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ class IMPNPCTRANSPORTEXPORT Statistics : public Object {
ParticleTransportStatisticsOSsMap;
ParticleTransportStatisticsOSsMap floaters_transport_stats_map_;

int update_calls_ = 0;

#ifndef SWIG
// distributions
typedef IMP_KERNEL_LARGE_UNORDERED_MAP< core::ParticleType,
Expand Down
5 changes: 2 additions & 3 deletions src/Statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,19 +659,18 @@ void Statistics::update
unsigned int nf_new)
{
IMP_OBJECT_LOG;
static int update_number = 0;
update_number++;
IMP_ALWAYS_CHECK(get_is_activated(), // TODO: would we rather a usage/always check?
"Cannot update a Statistics object that was not activated. Call Statistics::add_optimizer_states() first",
IMP::UsageException);
update_calls_++;
::npctransport_proto::Output output;
bool is_read= load_output_protobuf(output_file_name_, output);
IMP_ALWAYS_CHECK(is_read,
"Failed updating statistics to " << output_file_name_.c_str()
<< std::endl,
IMP::IOException);
std::string hdf5_file_name = output_file_name_
+ (get_sd()->get_is_multiple_hdf5s() ? "."+std::to_string(update_number) : "")
+ (get_sd()->get_is_multiple_hdf5s() ? "."+std::to_string(update_calls_) : "")
+ ".hdf5";
RMF::HDF5::File hdf5_file= RMF::HDF5::create_file(hdf5_file_name);
RMF::HDF5::Group hdf5_floater_xyz_hist_group;
Expand Down
43 changes: 23 additions & 20 deletions test/expensive_test_hdf5_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def get_95_conf(rate,time):

class Tests(IMP.test.TestCase):

def _make_sd(self, is_orientational=False):
def _make_sd(self, is_orientational=False, is_multiple_hdf5s=False):
cfg_file = self.get_tmp_file_name("my_config.pb")
assign_file = self.get_tmp_file_name("my_assign.pb")
print("Configuration file: " + cfg_file)
Expand All @@ -36,7 +36,8 @@ def _make_sd(self, is_orientational=False):
i.interaction_k.lower=0.18
else:
i.interaction_k.lower=0.45
cfg.is_multiple_hdf5s = True
cfg.is_multiple_hdf5s = is_multiple_hdf5s
cfg.output_statistics_interval_ns = 50.0
test_util.write_config_file(cfg_file, cfg)
num=IMP.npctransport.assign_ranges( cfg_file, assign_file, 0,
False, 10 );
Expand Down Expand Up @@ -72,24 +73,26 @@ def _test_xyz_stats(self, n_cycles, short_init_factor,
"""
test statistics of interaction between an FG and a kap
"""
# Non-orientational
sd=self._make_sd(is_orientational)
IMP.npctransport.initialize_positions( sd, [], False,
short_init_factor)
sd.get_bd().optimize(n_cycles) # still without stats
sd.get_bd().set_current_time(0.0);
sd.get_statistics().reset_statistics_optimizer_states();
sd.activate_statistics()
while n_trials>0:
try:
self._run_sd(sd, n_cycles)
self._process_xyz_stat(sd, is_orientational)
break
except AssertionError as e:
print("Failed -", n_trials, "left")
n_trials=n_trials-1
if(n_trials==0):
raise e
for is_multiple_hdf5s in [False, True]:
print("Multiple HDF5s" if is_multiple_hdf5s else "Single HDF5")
sd=self._make_sd(is_orientational=is_orientational,
is_multiple_hdf5s=is_multiple_hdf5s)
IMP.npctransport.initialize_positions( sd, [], False,
short_init_factor)
sd.get_bd().optimize(n_cycles) # still without stats
sd.get_bd().set_current_time(0.0);
sd.get_statistics().reset_statistics_optimizer_states();
sd.activate_statistics()
while n_trials>0:
try:
self._run_sd(sd, n_cycles)
self._process_xyz_stat(sd, is_orientational)
break
except AssertionError as e:
print("Failed -", n_trials, "left")
n_trials=n_trials-1
if(n_trials==0):
raise e

def test_hdf5_statistics(self):
if IMP.get_check_level() >= IMP.USAGE_AND_INTERNAL:
Expand Down

0 comments on commit d79e8fd

Please sign in to comment.