From 2a4f1b49fe3cf2f31fe6095e0993e2c3299bdd0e Mon Sep 17 00:00:00 2001 From: "Jeremy M. G. Leung" <63817169+jeremyleung521@users.noreply.github.com> Date: Wed, 9 Aug 2023 14:52:28 -0400 Subject: [PATCH 1/2] Fix for istate_futures race condition (#334) * added a while block for mab_manager and binless_manager to wait for istates_futures * add in extra checks for futures * forgot the most obvious part of waiting and fetching the future * add in barebone tests for mab and binless sim_managers * replace logging.warn with logging.warning --- src/westpa/core/binning/binless_manager.py | 25 +++++- src/westpa/core/binning/mab.py | 4 +- src/westpa/core/binning/mab_manager.py | 25 +++++- src/westpa/core/h5io.py | 2 +- src/westpa/work_managers/zeromq/core.py | 2 +- tests/fixtures/odld/odld_system.py | 26 ++++++ tests/fixtures/odld/west_binless.cfg | 36 +++++++++ tests/fixtures/odld/west_mab.cfg | 36 +++++++++ tests/test_sim_manager.py | 94 ++++++++++++++++++++++ 9 files changed, 244 insertions(+), 6 deletions(-) create mode 100644 tests/fixtures/odld/west_binless.cfg create mode 100644 tests/fixtures/odld/west_mab.cfg diff --git a/src/westpa/core/binning/binless_manager.py b/src/westpa/core/binning/binless_manager.py index c3ace0c5a..d038c0630 100644 --- a/src/westpa/core/binning/binless_manager.py +++ b/src/westpa/core/binning/binless_manager.py @@ -75,8 +75,31 @@ def propagate(self): log.error('unknown future {!r} received from work manager'.format(future)) raise AssertionError('untracked future {!r}'.format(future)) + # Collectively assign all segments to their bins... self.we_driver.assign(self.segments.values()) - self.get_istate_futures() + + # For cases where we need even more istates for recycled trajectories + # futures should be empty at this point. + istate_gen_futures = self.get_istate_futures() + futures.update(istate_gen_futures) + + # Wait for istate_gen_futures and catch untracked futures. + while futures: + future = self.work_manager.wait_any(futures) + futures.remove(future) + + if future in istate_gen_futures: + istate_gen_futures.remove(future) + _basis_state, initial_state = future.get_result() + log.debug('received newly-prepared initial state {!r}'.format(initial_state)) + initial_state.istate_status = InitialState.ISTATE_STATUS_PREPARED + with self.data_manager.expiring_flushing_lock(): + self.data_manager.update_initial_states([initial_state], n_iter=self.n_iter + 1) + self.we_driver.avail_initial_states[initial_state.state_id] = initial_state + else: + log.error('unknown future {!r} received from work manager'.format(future)) + raise AssertionError('untracked future {!r}'.format(future)) + log.debug('done with propagation') self.save_bin_data() self.data_manager.flush_backing() diff --git a/src/westpa/core/binning/mab.py b/src/westpa/core/binning/mab.py index 0fe67299c..f491cfbe8 100644 --- a/src/westpa/core/binning/mab.py +++ b/src/westpa/core/binning/mab.py @@ -262,13 +262,13 @@ def __init__(self, nbins, direction=None, skip=None, bottleneck=True, pca=False, direction = [0] * ndim elif len(direction) != ndim: direction = [0] * ndim - log.warn("Direction list is not the correct dimensions, setting to defaults.") + log.warning("Direction list is not the correct dimensions, setting to defaults.") if skip is None: skip = [0] * ndim elif len(skip) != ndim: skip = [0] * ndim - log.warn("Skip list is not the correct dimensions, setting to defaults.") + log.warning("Skip list is not the correct dimensions, setting to defaults.") kwargs = dict(nbins_per_dim=nbins, direction=direction, skip=skip, bottleneck=bottleneck, pca=pca, mab_log=mab_log) # the following is neccessary because functional bin mappers need to "reserve" diff --git a/src/westpa/core/binning/mab_manager.py b/src/westpa/core/binning/mab_manager.py index 79e5c7984..fcb570520 100644 --- a/src/westpa/core/binning/mab_manager.py +++ b/src/westpa/core/binning/mab_manager.py @@ -75,8 +75,31 @@ def propagate(self): log.error('unknown future {!r} received from work manager'.format(future)) raise AssertionError('untracked future {!r}'.format(future)) + # Collectively assign all segments to their bins... self.we_driver.assign(self.segments.values()) - self.get_istate_futures() + + # For cases where we need even more istates for recycled trajectories + # futures should be empty at this point. + istate_gen_futures = self.get_istate_futures() + futures.update(istate_gen_futures) + + # Wait for istate_gen_futures and catch untracked futures. + while futures: + future = self.work_manager.wait_any(futures) + futures.remove(future) + + if future in istate_gen_futures: + istate_gen_futures.remove(future) + _basis_state, initial_state = future.get_result() + log.debug('received newly-prepared initial state {!r}'.format(initial_state)) + initial_state.istate_status = InitialState.ISTATE_STATUS_PREPARED + with self.data_manager.expiring_flushing_lock(): + self.data_manager.update_initial_states([initial_state], n_iter=self.n_iter + 1) + self.we_driver.avail_initial_states[initial_state.state_id] = initial_state + else: + log.error('unknown future {!r} received from work manager'.format(future)) + raise AssertionError('untracked future {!r}'.format(future)) + log.debug('done with propagation') self.save_bin_data() self.data_manager.flush_backing() diff --git a/src/westpa/core/h5io.py b/src/westpa/core/h5io.py index ed2941c2a..37cc532a2 100644 --- a/src/westpa/core/h5io.py +++ b/src/westpa/core/h5io.py @@ -220,7 +220,7 @@ def load_west(filename): raw_pcoord = iter_group['pcoord'][:] if raw_pcoord.ndim != 3: - log.warn('pcoord is expected to be a 3-d ndarray instead of {}-d'.format(raw_pcoord.ndim)) + log.warning('pcoord is expected to be a 3-d ndarray instead of {}-d'.format(raw_pcoord.ndim)) continue # ignore the first frame of each segment if raw_pcoord.shape[1] == traj.n_frames + 1: diff --git a/src/westpa/work_managers/zeromq/core.py b/src/westpa/work_managers/zeromq/core.py index 8c217d5a2..d93450ede 100644 --- a/src/westpa/work_managers/zeromq/core.py +++ b/src/westpa/work_managers/zeromq/core.py @@ -439,7 +439,7 @@ def message_validation(self, msg): self.log.error('message validation falied: {!s}'.format(e)) sys.exit(1) elif self.validation_fail_action == 'warn': - self.log.warn('message validation falied: {!s}'.format(e)) + self.log.warning('message validation falied: {!s}'.format(e)) def recv_message(self, socket, flags=0, validate=True, timeout=None): '''Receive a message object from the given socket, using the given flags. diff --git a/tests/fixtures/odld/odld_system.py b/tests/fixtures/odld/odld_system.py index 0d17b92b0..4e3d23010 100644 --- a/tests/fixtures/odld/odld_system.py +++ b/tests/fixtures/odld/odld_system.py @@ -4,6 +4,8 @@ from westpa.core.binning import RectilinearBinMapper from westpa.core.propagators import WESTPropagator from westpa.core.systems import WESTSystem +from westpa.core.binning.mab import MABBinMapper +from westpa.core.binning.binless import BinlessMapper PI = np.pi @@ -103,3 +105,27 @@ def initialize(self): self.bin_mapper = RectilinearBinMapper([list(np.arange(0.0, 10.1, 0.1))]) self.bin_target_counts = np.empty((self.bin_mapper.nbins,), np.int_) self.bin_target_counts[...] = 10 + + +class MABODLDSystem(WESTSystem): + def initialize(self): + self.pcoord_ndim = 1 + self.pcoord_dtype = pcoord_dtype + self.pcoord_len = pcoord_len + + # self.bin_mapper = RectilinearBinMapper([[0,1.3] + list(np.arange(1.4, 10.1, 0.1)) + [float('inf')]]) + self.bin_mapper = MABBinMapper([10]) + self.bin_target_counts = np.empty((self.bin_mapper.nbins,), np.int_) + self.bin_target_counts[...] = 10 + + +class BinlessODLDSystem(WESTSystem): + def initialize(self): + self.pcoord_ndim = 1 + self.pcoord_dtype = pcoord_dtype + self.pcoord_len = pcoord_len + + # self.bin_mapper = RectilinearBinMapper([[0,1.3] + list(np.arange(1.4, 10.1, 0.1)) + [float('inf')]]) + self.bin_mapper = BinlessMapper(ngroups=10, ndims=1, group_function='westpa.core.we_driver._group_walkers_identity') + self.bin_target_counts = np.empty((self.bin_mapper.nbins,), np.int_) + self.bin_target_counts[...] = 10 diff --git a/tests/fixtures/odld/west_binless.cfg b/tests/fixtures/odld/west_binless.cfg new file mode 100644 index 000000000..577b90c71 --- /dev/null +++ b/tests/fixtures/odld/west_binless.cfg @@ -0,0 +1,36 @@ +# The master WEST configuration file for a simulation. +# vi: set filetype=yaml : +--- +west: + system: + driver: odld_system.BinlessODLDSystem + module_path: $WEST_SIM_ROOT + propagation: + max_total_iterations: 100 + max_run_wallclock: 3:00:00 + propagator: odld_system.ODLDPropagator + gen_istates: true + block_size: 10000 + data: + west_data_file: west.h5 + aux_compression_threshold: 16384 # data sets bigger than this are compressed + # unless overridden by an entry in ``datasets`` below + datasets: # dataset storage options + - name: displacement # name used to refer to this in segment.data/env vars + #h5path: auxdata/displacement # HDF5 storage path, overrides default + #store: true # store when writing segment data (defaults to true) + #load: true # load when reading segment data (defaults to false) + store: false + load: false + dtype: float32 # numpy dtype + compression: false # whether to store compressed + scaleoffset: 4 # whether to store with scale/offset filter + chunks: null # custom chunking, or null for auto/no chunking + # - ignored if necessary for other options + - name: pcoord # you can mess CAREFULLY with pcoord as well + scaleoffset: 4 + + data_refs: # how to convert segments and states to paths, etc + segment: $WEST_SIM_ROOT/traj_segs/{segment.n_iter:06d}/{segment.seg_id:06d} + basis_state: $WEST_SIM_ROOT/bstates/{basis_state.auxref} + initial_state: $WEST_SIM_ROOT/istates/{initial_state.iter_created}/{initial_state.state_id}.gro diff --git a/tests/fixtures/odld/west_mab.cfg b/tests/fixtures/odld/west_mab.cfg new file mode 100644 index 000000000..e79ee7a12 --- /dev/null +++ b/tests/fixtures/odld/west_mab.cfg @@ -0,0 +1,36 @@ +# The master WEST configuration file for a simulation. +# vi: set filetype=yaml : +--- +west: + system: + driver: odld_system.MABODLDSystem + module_path: $WEST_SIM_ROOT + propagation: + max_total_iterations: 100 + max_run_wallclock: 3:00:00 + propagator: odld_system.ODLDPropagator + gen_istates: true + block_size: 10000 + data: + west_data_file: west.h5 + aux_compression_threshold: 16384 # data sets bigger than this are compressed + # unless overridden by an entry in ``datasets`` below + datasets: # dataset storage options + - name: displacement # name used to refer to this in segment.data/env vars + #h5path: auxdata/displacement # HDF5 storage path, overrides default + #store: true # store when writing segment data (defaults to true) + #load: true # load when reading segment data (defaults to false) + store: false + load: false + dtype: float32 # numpy dtype + compression: false # whether to store compressed + scaleoffset: 4 # whether to store with scale/offset filter + chunks: null # custom chunking, or null for auto/no chunking + # - ignored if necessary for other options + - name: pcoord # you can mess CAREFULLY with pcoord as well + scaleoffset: 4 + + data_refs: # how to convert segments and states to paths, etc + segment: $WEST_SIM_ROOT/traj_segs/{segment.n_iter:06d}/{segment.seg_id:06d} + basis_state: $WEST_SIM_ROOT/bstates/{basis_state.auxref} + initial_state: $WEST_SIM_ROOT/istates/{initial_state.iter_created}/{initial_state.state_id}.gro diff --git a/tests/test_sim_manager.py b/tests/test_sim_manager.py index 6b143eb8b..b3fdc2b17 100755 --- a/tests/test_sim_manager.py +++ b/tests/test_sim_manager.py @@ -178,3 +178,97 @@ def test_pre_we(self): def test_post_we(self): self.sim_manager.post_we() + + +class TestMABSimManager(TestSimManager): + def setUp(self): + parser = argparse.ArgumentParser() + westpa.rc.add_args(parser) + + here = os.path.dirname(__file__) + os.environ['WEST_SIM_ROOT'] = os.path.join(here, 'fixtures', 'odld') + + config_file_name = os.path.join(here, 'fixtures', 'odld', 'west_mab.cfg') + args = parser.parse_args(['-r={}'.format(config_file_name)]) + westpa.rc.process_args(args) + self.sim_manager = westpa.rc.get_sim_manager() + self.test_dir = tempfile.mkdtemp() + self.hdf5 = os.path.join(self.test_dir, "west.h5") + self.basis_states = [BasisState(label="label", probability=1.0)] + self.segments = [self.segment(0.0, 1.5, weight=0.125) for _i in range(4)] + [ + self.segment(1.5, 0.5, weight=0.125) for _i in range(4) + ] + self.sim_manager.we_driver.new_iteration() + self.sim_manager.we_driver.assign(self.segments) + self.sim_manager.we_driver.construct_next() + self.sim_manager.segments = {segment.seg_id: segment for segment in self.segments} + self.sim_manager.incomplete_segments = self.sim_manager.segments + self.sim_manager.current_iter_istates = self.sim_manager.segments + self.sim_manager.completed_segments = self.sim_manager.segments + self.sim_manager.report_bin_statistics = MagicMock(return_value=True) + + data = self.sim_manager.we_driver.rc.get_data_manager() + data.we_h5filename = self.hdf5 + data.prepare_backing() + data.create_ibstate_group([]) + data.create_initial_states(1) + data.save_target_states([]) + data.update_segments = MagicMock(return_value=None) + + n_iter = 0 + it_name = data.iter_group_name(n_iter) + for group in ["seg_index", "parents", "ibstates", "pcoord"]: + data.we_h5file.create_group(it_name + "/" + group) + data.get_new_weight_data = MagicMock(return_value=None) + data.get_segments = MagicMock(return_value=self.segments) + self.sim_manager.we_driver.rc.get_data_manager = MagicMock(return_value=data) + self.sim_manager.n_iter = n_iter + + +class TestBinlessSimManager(TestSimManager): + def setUp(self): + parser = argparse.ArgumentParser() + westpa.rc.add_args(parser) + + here = os.path.dirname(__file__) + os.environ['WEST_SIM_ROOT'] = os.path.join(here, 'fixtures', 'odld') + + config_file_name = os.path.join(here, 'fixtures', 'odld', 'west_binless.cfg') + args = parser.parse_args(['-r={}'.format(config_file_name)]) + westpa.rc.process_args(args) + self.sim_manager = westpa.rc.get_sim_manager() + self.test_dir = tempfile.mkdtemp() + self.hdf5 = os.path.join(self.test_dir, "west.h5") + self.basis_states = [BasisState(label="label", probability=1.0)] + self.segments = [self.segment(0.0, 1.5, weight=0.125) for _i in range(4)] + [ + self.segment(1.5, 0.5, weight=0.125) for _i in range(4) + ] + self.sim_manager.we_driver.new_iteration() + self.sim_manager.we_driver.assign(self.segments) + self.sim_manager.we_driver.construct_next() + self.sim_manager.segments = {segment.seg_id: segment for segment in self.segments} + self.sim_manager.incomplete_segments = self.sim_manager.segments + self.sim_manager.current_iter_istates = self.sim_manager.segments + self.sim_manager.completed_segments = self.sim_manager.segments + self.sim_manager.report_bin_statistics = MagicMock(return_value=True) + + data = self.sim_manager.we_driver.rc.get_data_manager() + data.we_h5filename = self.hdf5 + data.prepare_backing() + data.create_ibstate_group([]) + data.create_initial_states(1) + data.save_target_states([]) + data.update_segments = MagicMock(return_value=None) + + n_iter = 0 + it_name = data.iter_group_name(n_iter) + for group in ["seg_index", "parents", "ibstates", "pcoord"]: + data.we_h5file.create_group(it_name + "/" + group) + data.get_new_weight_data = MagicMock(return_value=None) + data.get_segments = MagicMock(return_value=self.segments) + self.sim_manager.we_driver.rc.get_data_manager = MagicMock(return_value=data) + self.sim_manager.n_iter = n_iter + + @pytest.mark.skip('Not configured') + def test_run(self): + self.sim_manager.run() From 661ee1aae1429434f26a0fc8e4d27a9acf50432c Mon Sep 17 00:00:00 2001 From: "Jeremy M. G. Leung" <63817169+jeremyleung521@users.noreply.github.com> Date: Fri, 11 Aug 2023 14:47:03 -0400 Subject: [PATCH 2/2] Pre commit version autoupdate (#338) * pre-commit autoupdate * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * flake8 update --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .flake8 | 21 ++++++++++++------- .pre-commit-config.yaml | 9 +++++--- examples/ex_graphtest.py | 6 +++--- src/westpa/cli/core/w_fork.py | 2 +- src/westpa/cli/core/w_init.py | 1 - src/westpa/cli/core/w_run.py | 1 - src/westpa/cli/core/w_states.py | 2 -- src/westpa/cli/core/w_succ.py | 2 +- src/westpa/cli/tools/w_assign.py | 1 - src/westpa/cli/tools/w_bins.py | 1 - src/westpa/cli/tools/w_dumpsegs.py | 2 +- src/westpa/cli/tools/w_eddist.py | 4 ---- src/westpa/cli/tools/w_ipa.py | 1 - src/westpa/cli/tools/w_multi_west.py | 2 +- src/westpa/cli/tools/w_pdist.py | 1 - src/westpa/cli/tools/w_red.py | 1 - src/westpa/core/_rc.py | 1 - src/westpa/core/binning/assign.py | 4 ++-- src/westpa/core/binning/binless_driver.py | 2 +- src/westpa/core/binning/binless_manager.py | 2 +- src/westpa/core/binning/mab.py | 1 - src/westpa/core/binning/mab_driver.py | 2 +- src/westpa/core/binning/mab_manager.py | 2 +- src/westpa/core/data_manager.py | 11 +++++----- src/westpa/core/h5io.py | 4 ---- src/westpa/core/propagators/__init__.py | 1 - src/westpa/core/propagators/executable.py | 4 +--- src/westpa/core/sim_manager.py | 7 +++---- src/westpa/core/we_driver.py | 14 ++++++------- src/westpa/oldtools/aframe/binning.py | 4 ++-- src/westpa/oldtools/aframe/data_reader.py | 7 +++---- src/westpa/oldtools/aframe/kinetics.py | 1 - src/westpa/oldtools/aframe/trajwalker.py | 2 +- src/westpa/oldtools/aframe/transitions.py | 4 +--- src/westpa/oldtools/cmds/w_ttimes.py | 6 ++---- src/westpa/tools/binning.py | 5 +---- src/westpa/tools/kinetics_tool.py | 3 --- src/westpa/tools/selected_segs.py | 1 - src/westpa/trajtree/trajtree.py | 2 -- .../westext/adaptvoronoi/adaptVor_driver.py | 2 -- .../hamsm_restarting/example_overrides.py | 1 - .../hamsm_restarting/restart_driver.py | 19 +---------------- .../westext/stringmethod/string_driver.py | 1 - .../westext/stringmethod/string_method.py | 2 -- src/westpa/westext/weed/weed_driver.py | 4 ++-- src/westpa/westext/wess/ProbAdjust.py | 1 - src/westpa/westext/wess/wess_driver.py | 4 ++-- src/westpa/work_managers/environment.py | 1 - src/westpa/work_managers/mpi.py | 7 ------- src/westpa/work_managers/zeromq/core.py | 4 ---- .../work_managers/zeromq/work_manager.py | 3 +-- src/westpa/work_managers/zeromq/worker.py | 1 - tests/fixtures/odld/odld_system.py | 1 - tests/refs/odld_system.py | 1 - tests/test_binning.py | 1 - tests/test_tools/common.py | 1 - tests/test_tools/h5diff.py | 12 +++-------- tests/test_tools/test_w_assign.py | 1 - tests/test_tools/test_w_direct.py | 2 -- tests/test_tools/test_w_ipa.py | 1 - tests/test_tools/test_w_trace.py | 2 -- tests/test_we_driver.py | 1 - .../test_zeromq/test_worker.py | 1 - tests/test_yamlfe.py | 1 + 64 files changed, 69 insertions(+), 153 deletions(-) diff --git a/.flake8 b/.flake8 index ed940a1da..f9c4b8960 100644 --- a/.flake8 +++ b/.flake8 @@ -1,10 +1,17 @@ [flake8] max-line-length = 132 ignore = - E203, # space before : (needed for how black formats slicing) - E266, # too many leading '#' for block comment - E501, # line lengths too long - W503, # line break before binary operator - W504, # line break after binary operator - E402, # module level import not at top of file - E731, # do not assign a lambda expression, use a def + # space before : (needed for how black formats slicing) + E203, + # too many leading '#' for block comment + E266, + # line lengths too long + E501, + # line break before binary operator + W503, + # line break after binary operator + W504, + # module level import not at top of file + E402, + # do not assign a lambda expression, use a def + E731, diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 144ee823f..4383f767f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.1.0 + rev: v4.4.0 hooks: - id: end-of-file-fixer types: [python] @@ -8,7 +8,7 @@ repos: types: [python] - repo: https://github.com/psf/black - rev: 22.3.0 + rev: 23.7.0 hooks: - id: black language_version: python3 @@ -19,7 +19,7 @@ repos: | doc ) - repo: https://github.com/pycqa/flake8 - rev: 4.0.1 + rev: 6.1.0 hooks: - id: flake8 exclude: > @@ -28,3 +28,6 @@ repos: | _version.py | doc ) + +ci: + autoupdate_branch: 'develop' diff --git a/examples/ex_graphtest.py b/examples/ex_graphtest.py index 0e35e66a2..0bfd2c933 100644 --- a/examples/ex_graphtest.py +++ b/examples/ex_graphtest.py @@ -56,9 +56,9 @@ def get_all_leaves(n_iter, iter_group): # print(leaves_by_branchpoint) print('there are {:d} branch points leading to approximately independent trajectory bundles'.format(len(leaves_by_branchpoint))) # for ((branch,node),leaves) in leaves_by_branchpoint.iteritems(): -for (branchnode, subtrees) in leaves_by_branchpoint.items(): +for branchnode, subtrees in leaves_by_branchpoint.items(): print(' branch point {}:{} has {} independent subtree(s)'.format(branchnode.n_iter, branchnode.seg_id, len(subtrees))) - for (subtree, leaves) in subtrees.items(): + for subtree, leaves in subtrees.items(): leaves = list(leaves) weights = np.fromiter((leaf.weight for leaf in leaves), dtype=np.float64) max_weight_node = leaves[np.argmax(weights)] @@ -71,7 +71,7 @@ def get_all_leaves(n_iter, iter_group): # print('subtree rooted at point ({},{}) contains {:d} leaves'.format(node.n_iter, node.seg_id,len(leaves))) # print(' of which ({},{}) has the highest weight ({!r})'.format(max_weight_node.n_iter, max_weight_node.seg_id, # max_weight_node.weight)) -for (root, leaves) in leftovers_by_root.items(): +for root, leaves in leftovers_by_root.items(): print('{} trajectories from root {}:{} pruned due to shared history'.format(len(leaves), root.n_iter, root.seg_id)) diff --git a/src/westpa/cli/core/w_fork.py b/src/westpa/cli/core/w_fork.py index 515395317..4c56b14cb 100644 --- a/src/westpa/cli/core/w_fork.py +++ b/src/westpa/cli/core/w_fork.py @@ -101,7 +101,7 @@ def entry_point(): state_map = np.empty((n_segments,), dtype=state_map_dtype) state_map['old_n_iter'] = n_iter - for (iseg, (index_row, pcoord)) in enumerate(zip(old_index, old_final_pcoords)): + for iseg, (index_row, pcoord) in enumerate(zip(old_index, old_final_pcoords)): istate = istates[iseg] istate.iter_created = 0 istate.iter_used = 1 diff --git a/src/westpa/cli/core/w_init.py b/src/westpa/cli/core/w_init.py index 71c85951e..4ff212697 100644 --- a/src/westpa/cli/core/w_init.py +++ b/src/westpa/cli/core/w_init.py @@ -18,7 +18,6 @@ def entry_point(): - parser = argparse.ArgumentParser( 'w_init', description='''\ diff --git a/src/westpa/cli/core/w_run.py b/src/westpa/cli/core/w_run.py index 8ec4da571..232ceddfb 100644 --- a/src/westpa/cli/core/w_run.py +++ b/src/westpa/cli/core/w_run.py @@ -30,7 +30,6 @@ def entry_point(): def run_simulation(): - work_manager = westpa.rc.work_manager = make_work_manager() # Load the sim manager and other drivers diff --git a/src/westpa/cli/core/w_states.py b/src/westpa/cli/core/w_states.py index a758f7c4c..b7033fe2a 100644 --- a/src/westpa/cli/core/w_states.py +++ b/src/westpa/cli/core/w_states.py @@ -102,7 +102,6 @@ def entry_point(): # TODO: This would benefit from a refactor to set default args to None, and replace some of those "if " clauses def initialize(mode, bstates, _bstate_file, tstates, _tstate_file): - work_manager = make_work_manager() system = westpa.rc.get_system_driver() @@ -116,7 +115,6 @@ def initialize(mode, bstates, _bstate_file, tstates, _tstate_file): assert mode in ('show', 'replace', 'append') if mode == 'show': - basis_states = data_manager.get_basis_states(n_iter) if basis_states: bstate_file = sys.stdout if not _bstate_file else open(_bstate_file, 'wt') diff --git a/src/westpa/cli/core/w_succ.py b/src/westpa/cli/core/w_succ.py index 7323e1a4a..aba2c17e8 100644 --- a/src/westpa/cli/core/w_succ.py +++ b/src/westpa/cli/core/w_succ.py @@ -57,7 +57,7 @@ def find_successful_trajs(self): # The above HDF5 selection always returns a vector; we want a 2-d array final_pcoords.shape = (len(recycled_seg_ids), pcoord_ndim) - for (ipc, seg_id) in enumerate(recycled_seg_ids): + for ipc, seg_id in enumerate(recycled_seg_ids): self.output_file.write('%8d %8d %20.14g' % (n_iter, seg_id, seg_index[seg_id]['weight'])) fields = [''] for field in final_pcoords[ipc]: diff --git a/src/westpa/cli/tools/w_assign.py b/src/westpa/cli/tools/w_assign.py index 877baf9e6..834c4862a 100644 --- a/src/westpa/cli/tools/w_assign.py +++ b/src/westpa/cli/tools/w_assign.py @@ -33,7 +33,6 @@ def parse_pcoord_value(pc_str): def _assign_label_pop( n_iter, lb, ub, mapper, nstates, state_map, last_labels, parent_id_dsspec, weight_dsspec, pcoord_dsspec, subsample ): - nbins = len(state_map) - 1 parent_ids = parent_id_dsspec.get_iter_data(n_iter, index_exp[lb:ub]) weights = weight_dsspec.get_iter_data(n_iter, index_exp[lb:ub]) diff --git a/src/westpa/cli/tools/w_bins.py b/src/westpa/cli/tools/w_bins.py index 99347bf86..0318e127b 100644 --- a/src/westpa/cli/tools/w_bins.py +++ b/src/westpa/cli/tools/w_bins.py @@ -68,7 +68,6 @@ def add_args(self, parser): rebin_parser.set_defaults(func=self.cmd_rebin) def process_args(self, args): - self.data_reader.process_args(args) self.data_reader.open(mode='r+') self.n_iter = getattr(args, 'n_iter', None) or self.data_reader.current_iteration diff --git a/src/westpa/cli/tools/w_dumpsegs.py b/src/westpa/cli/tools/w_dumpsegs.py index d67febd8b..23ad57668 100644 --- a/src/westpa/cli/tools/w_dumpsegs.py +++ b/src/westpa/cli/tools/w_dumpsegs.py @@ -64,7 +64,7 @@ def go(self): + '\n' ) pcoord_lines = ' pcoord[0] = {init_pcoord}\n pcoord[-1] = {final_pcoord}' + '\n' - for (_seg_id, segment) in enumerate(segments): + for _seg_id, segment in enumerate(segments): parents_str = '[' + ', '.join(map(str, sorted(segment.wtg_parent_ids))) + ']' init_pcoord_str = '[' + ', '.join('{pcval:<12.6g}'.format(pcval=float(pce)) for pce in segment.pcoord[0]) + ']' final_pcoord_str = '[' + ', '.join('{pcval:<12.6g}'.format(pcval=float(pce)) for pce in segment.pcoord[-1]) + ']' diff --git a/src/westpa/cli/tools/w_eddist.py b/src/westpa/cli/tools/w_eddist.py index e731e44c4..2325ef7de 100644 --- a/src/westpa/cli/tools/w_eddist.py +++ b/src/westpa/cli/tools/w_eddist.py @@ -68,7 +68,6 @@ def _remote_min_max(ndim, dset_dtype, n_iter, dsspec): def _remote_bin_iter(iiter, n_iter, dsspec, wt_dsspec, initpoint, binbounds, ignore_out_of_range): - iter_hist_shape = tuple(len(bounds) - 1 for bounds in binbounds) iter_hist = np.zeros(iter_hist_shape, dtype=np.float64) @@ -220,7 +219,6 @@ def __init__(self): self.compress_output = False def add_args(self, parser): - parser.add_argument( '-b', '--bins', @@ -300,7 +298,6 @@ def process_args(self, args): self.compress_output = args.compress or False def go(self): - pi = self.progress.indicator pi.operation = 'Initializing' with pi: @@ -334,7 +331,6 @@ def go(self): @staticmethod def parse_binspec(binspec): - namespace = {'numpy': np, 'np': np, 'inf': float('inf')} try: diff --git a/src/westpa/cli/tools/w_ipa.py b/src/westpa/cli/tools/w_ipa.py index 1ae218678..adb433fea 100644 --- a/src/westpa/cli/tools/w_ipa.py +++ b/src/westpa/cli/tools/w_ipa.py @@ -641,7 +641,6 @@ def future(self, value=None): return self._future class Future(WIPIDataset): - # This isn't a real fancy one. def __getitem__(self, value): if isinstance(value, str): diff --git a/src/westpa/cli/tools/w_multi_west.py b/src/westpa/cli/tools/w_multi_west.py index 30fe75f48..0ab01f00e 100644 --- a/src/westpa/cli/tools/w_multi_west.py +++ b/src/westpa/cli/tools/w_multi_west.py @@ -156,7 +156,7 @@ def total_number_of_walkers(self): # Sometimes, we're smaller or larger by one. Hm. try: self.total_walkers[:] += west['summary'][:-1]['n_particles'] - except (ValueError): + except ValueError: self.total_walkers[:] += west['summary'][:-1]['n_particles'][: len(self.total_walkers)] class Segment: diff --git a/src/westpa/cli/tools/w_pdist.py b/src/westpa/cli/tools/w_pdist.py index b46e147e2..6bfd078da 100644 --- a/src/westpa/cli/tools/w_pdist.py +++ b/src/westpa/cli/tools/w_pdist.py @@ -51,7 +51,6 @@ def _remote_min_max(ndim, dset_dtype, n_iter, dsspec): def _remote_bin_iter(iiter, n_iter, dsspec, wt_dsspec, initpoint, binbounds, ignore_out_of_range): - iter_hist_shape = tuple(len(bounds) - 1 for bounds in binbounds) iter_hist = np.zeros(iter_hist_shape, dtype=np.float64) diff --git a/src/westpa/cli/tools/w_red.py b/src/westpa/cli/tools/w_red.py index 3c01ca0fa..f3280c2ef 100644 --- a/src/westpa/cli/tools/w_red.py +++ b/src/westpa/cli/tools/w_red.py @@ -333,7 +333,6 @@ def _get_corrector(self): return self._dc def calc_rate(self, i_iter=None, red=False, **kwargs): - if i_iter is None: i_iter = self.n_iters diff --git a/src/westpa/core/_rc.py b/src/westpa/core/_rc.py index 214e45cd6..5f35cd51c 100644 --- a/src/westpa/core/_rc.py +++ b/src/westpa/core/_rc.py @@ -644,7 +644,6 @@ def get_work_manager(self): return self.work_manager def clear_state(self): - self._sim_manager = None self._system = None self._data_manager = None diff --git a/src/westpa/core/binning/assign.py b/src/westpa/core/binning/assign.py index fc8ec4d24..0c2683a94 100644 --- a/src/westpa/core/binning/assign.py +++ b/src/westpa/core/binning/assign.py @@ -429,7 +429,7 @@ def assign(self, coords, mask=None, output=None): # Which coordinates do we need to reassign, because they landed in # bins with embedded mappers? rmasks = {} - for (rindex, mapper) in self._recursion_targets.items(): + for rindex, mapper in self._recursion_targets.items(): omask = output == rindex mmask |= omask rmasks[rindex] = omask @@ -441,7 +441,7 @@ def assign(self, coords, mask=None, output=None): output_map(output, omap, mask & ~mmask) # do any recursive assignments necessary - for (rindex, mapper) in self._recursion_targets.items(): + for rindex, mapper in self._recursion_targets.items(): mapper.assign(coords, mask & rmasks[rindex], output) return output diff --git a/src/westpa/core/binning/binless_driver.py b/src/westpa/core/binning/binless_driver.py index 5bc4b6065..c3ef5f2e8 100644 --- a/src/westpa/core/binning/binless_driver.py +++ b/src/westpa/core/binning/binless_driver.py @@ -33,7 +33,7 @@ def assign(self, segments, initializing=False): final_binning = self.final_binning flux_matrix = self.flux_matrix transition_matrix = self.transition_matrix - for (segment, iidx, fidx) in zip(segments, initial_assignments, final_assignments): + for segment, iidx, fidx in zip(segments, initial_assignments, final_assignments): initial_binning[iidx].add(segment) final_binning[fidx].add(segment) flux_matrix[iidx, fidx] += segment.weight diff --git a/src/westpa/core/binning/binless_manager.py b/src/westpa/core/binning/binless_manager.py index d038c0630..78aa3a47d 100644 --- a/src/westpa/core/binning/binless_manager.py +++ b/src/westpa/core/binning/binless_manager.py @@ -155,7 +155,7 @@ def prepare_iteration(self): for iseg, segment in enumerate(segments.values()): initial_pcoords[iseg] = segment.pcoord[0] initial_assignments = self.system.bin_mapper.assign(initial_pcoords) - for (segment, assignment) in zip(iter(segments.values()), initial_assignments): + for segment, assignment in zip(iter(segments.values()), initial_assignments): initial_binning[assignment].add(segment) self.report_bin_statistics(initial_binning, [], save_summary=True) del initial_pcoords, initial_binning diff --git a/src/westpa/core/binning/mab.py b/src/westpa/core/binning/mab.py index f491cfbe8..a2e0e889f 100644 --- a/src/westpa/core/binning/mab.py +++ b/src/westpa/core/binning/mab.py @@ -212,7 +212,6 @@ def map_mab(coords, mask, output, *args, **kwargs): # the following are for the "linear" portion if not special: for n in range(ndim): - # if skipped, it's added to the same bin as the special walkers above if skip[n] != 0: holder = boundary_base + n diff --git a/src/westpa/core/binning/mab_driver.py b/src/westpa/core/binning/mab_driver.py index 96b4a6877..bc8fd704e 100644 --- a/src/westpa/core/binning/mab_driver.py +++ b/src/westpa/core/binning/mab_driver.py @@ -33,7 +33,7 @@ def assign(self, segments, initializing=False): final_binning = self.final_binning flux_matrix = self.flux_matrix transition_matrix = self.transition_matrix - for (segment, iidx, fidx) in zip(segments, initial_assignments, final_assignments): + for segment, iidx, fidx in zip(segments, initial_assignments, final_assignments): initial_binning[iidx].add(segment) final_binning[fidx].add(segment) flux_matrix[iidx, fidx] += segment.weight diff --git a/src/westpa/core/binning/mab_manager.py b/src/westpa/core/binning/mab_manager.py index fcb570520..f09167d03 100644 --- a/src/westpa/core/binning/mab_manager.py +++ b/src/westpa/core/binning/mab_manager.py @@ -158,7 +158,7 @@ def prepare_iteration(self): # Assign this iteration's segments' initial points to bins and report on bin population initial_binning = self.system.bin_mapper.construct_bins() initial_assignments = self.system.bin_mapper.assign(pcoords_with_weights) - for (segment, assignment) in zip(iter(segments.values()), initial_assignments): + for segment, assignment in zip(iter(segments.values()), initial_assignments): initial_binning[assignment].add(segment) self.report_bin_statistics(initial_binning, [], save_summary=True) del pcoords_with_weights, initial_binning diff --git a/src/westpa/core/data_manager.py b/src/westpa/core/data_manager.py index 78e256a69..56c416495 100644 --- a/src/westpa/core/data_manager.py +++ b/src/westpa/core/data_manager.py @@ -231,7 +231,7 @@ def expiring_flushing_lock(self): def process_config(self): config = self.rc.config - for (entry, type_) in [('iter_prec', int)]: + for entry, type_ in [('iter_prec', int)]: config.require_type_if_present(['west', 'data', entry], type_) self.we_h5filename = config.get_path(['west', 'data', 'west_data_file'], default=self.default_we_h5filename) @@ -263,7 +263,6 @@ def process_config(self): raise ValueError('cannot override pcoord storage location') def __init__(self, rc=None): - self.rc = rc or westpa.rc self.we_h5filename = self.default_we_h5filename @@ -854,7 +853,7 @@ def prepare_iteration(self, n_iter, segments): pcoord = np.empty((n_particles, pcoord_len, pcoord_ndim), pcoord_dtype) total_parents = 0 - for (seg_id, segment) in enumerate(segments): + for seg_id, segment in enumerate(segments): if segment.seg_id is not None: assert segment.seg_id == seg_id else: @@ -895,7 +894,7 @@ def prepare_iteration(self, n_iter, segments): wtgraph_ds = iter_group.create_dataset('wtgraph', (total_parents,), seg_id_dtype, compression='gzip', shuffle=True) parents = np.empty((total_parents,), seg_id_dtype) - for (seg_id, segment) in enumerate(segments): + for seg_id, segment in enumerate(segments): offset = seg_index_table[seg_id]['wtg_offset'] extent = seg_index_table[seg_id]['wtg_n_parents'] parent_list = list(segment.wtg_parent_ids) @@ -986,7 +985,7 @@ def update_segments(self, n_iter, segments): # read summary data so that we have valud parent and weight transfer information si_dsid.read(si_msel, si_fsel, seg_index_entries) - for (iseg, (segment, ientry)) in enumerate(zip(segments, seg_index_entries)): + for iseg, (segment, ientry) in enumerate(zip(segments, seg_index_entries)): ientry['status'] = segment.status ientry['endpoint_type'] = segment.endpoint_type or Segment.SEG_ENDPOINT_UNSET ientry['cputime'] = segment.cputime @@ -1021,7 +1020,7 @@ def update_segments(self, n_iter, segments): # Then we iterate over data sets and store data if dsets: - for (dsname, (shape, dtype)) in dsets.items(): + for dsname, (shape, dtype) in dsets.items(): # dset = self._require_aux_dataset(iter_group, dsname, n_total_segments, shape, dtype) try: dsopts = self.dataset_options[dsname] diff --git a/src/westpa/core/h5io.py b/src/westpa/core/h5io.py index 37cc532a2..878918fb0 100644 --- a/src/westpa/core/h5io.py +++ b/src/westpa/core/h5io.py @@ -101,7 +101,6 @@ def tostr(b): def is_within_directory(directory, target): - abs_directory = os.path.abspath(directory) abs_target = os.path.abspath(target) @@ -111,7 +110,6 @@ def is_within_directory(directory, target): def safe_extract(tar, path=".", members=None, *, numeric_owner=False): - for member in tar.getmembers(): member_path = os.path.join(path, member.name) if not is_within_directory(path, member_path): @@ -374,7 +372,6 @@ class WESTPAH5File(h5py.File): _this_fileformat_version = 8 def __init__(self, *args, **kwargs): - # These values are used for creating files or reading files where this # data is not stored. Otherwise, values stored as attributes on the root # group are used instead. @@ -919,7 +916,6 @@ def get_iter_data(self, n_iter, seg_slice=index_exp[:]): class IterBlockedDataset: @classmethod def empty_like(cls, blocked_dataset): - source = blocked_dataset.data if blocked_dataset.data is not None else blocked_dataset.dataset newbds = cls( diff --git a/src/westpa/core/propagators/__init__.py b/src/westpa/core/propagators/__init__.py index a51e0ee11..7cd526f2d 100644 --- a/src/westpa/core/propagators/__init__.py +++ b/src/westpa/core/propagators/__init__.py @@ -10,7 +10,6 @@ def blocked_iter(blocksize, iterable, fillvalue=None): class WESTPropagator: def __init__(self, rc=None): - # For maximum flexibility, the basis states and initial states valid # at the point in the simulation when the propgator is used must be # available in several routines, and it is inconvenient to pass them diff --git a/src/westpa/core/propagators/executable.py b/src/westpa/core/propagators/executable.py index d301b2664..692ae17b4 100644 --- a/src/westpa/core/propagators/executable.py +++ b/src/westpa/core/propagators/executable.py @@ -372,7 +372,7 @@ def exec_child(self, executable, environ=None, stdin=None, stdout=None, stderr=N return (rc, rusage) def exec_child_from_child_info(self, child_info, template_args, environ): - for (key, value) in child_info.get('environ', {}).items(): + for key, value in child_info.get('environ', {}).items(): environ[key] = self.makepath(value) return self.exec_child( executable=self.makepath(child_info['executable'], template_args), @@ -443,7 +443,6 @@ def update_args_env_segment(self, template_args, environ, segment): initial_state = self.initial_states[segment.initial_state_id] if initial_state.istate_type == InitialState.ISTATE_TYPE_START: - basis_state = BasisState( label=f"sstate_{initial_state.state_id}", pcoord=initial_state.pcoord, probability=0.0, auxref="" ) @@ -465,7 +464,6 @@ def update_args_env_segment(self, template_args, environ, segment): environ[self.ENV_PARENT_DATA_REF] = environ[self.ENV_BSTATE_DATA_REF] elif initial_state.istate_type == InitialState.ISTATE_TYPE_START: - # This points to the start-state PDB environ[self.ENV_PARENT_DATA_REF] = environ[self.ENV_BSTATE_DATA_REF] + '/' + initial_state.basis_auxref else: # initial_state.type == InitialState.ISTATE_TYPE_GENERATED diff --git a/src/westpa/core/sim_manager.py b/src/westpa/core/sim_manager.py index 9e4c32021..20264574b 100644 --- a/src/westpa/core/sim_manager.py +++ b/src/westpa/core/sim_manager.py @@ -37,7 +37,7 @@ class PropagationError(RuntimeError): class WESimManager: def process_config(self): config = self.rc.config - for (entry, type_) in [('gen_istates', bool), ('block_size', int), ('save_transition_matrices', bool)]: + for entry, type_ in [('gen_istates', bool), ('block_size', int), ('save_transition_matrices', bool)]: config.require_type_if_present(['west', 'propagation', entry], type_) self.do_gen_istates = config.get(['west', 'propagation', 'gen_istates'], False) @@ -136,7 +136,7 @@ def register_callback(self, hook, function, priority=0): def invoke_callbacks(self, hook, *args, **kwargs): callbacks = self._callback_table.get(hook, []) sorted_callbacks = sorted(callbacks) - for (priority, name, fn) in sorted_callbacks: + for priority, name, fn in sorted_callbacks: log.debug('invoking callback {!r} for hook {!r}'.format(fn, hook)) fn(*args, **kwargs) @@ -478,7 +478,7 @@ def prepare_iteration(self): for iseg, segment in enumerate(segments.values()): initial_pcoords[iseg] = segment.pcoord[0] initial_assignments = self.system.bin_mapper.assign(initial_pcoords) - for (segment, assignment) in zip(iter(segments.values()), initial_assignments): + for segment, assignment in zip(iter(segments.values()), initial_assignments): initial_binning[assignment].add(segment) self.report_bin_statistics(initial_binning, [], save_summary=True) del initial_pcoords, initial_binning @@ -733,7 +733,6 @@ def run(self): iter_elapsed = 0 while self.n_iter <= max_iter: - if max_walltime and time.time() + 1.1 * iter_elapsed >= run_killtime: self.rc.pstatus('Iteration {:d} would require more than the allotted time. Ending run.'.format(self.n_iter)) return diff --git a/src/westpa/core/we_driver.py b/src/westpa/core/we_driver.py index 427c5214e..93d432362 100644 --- a/src/westpa/core/we_driver.py +++ b/src/westpa/core/we_driver.py @@ -189,7 +189,7 @@ def current_iter_assignments(self): def recycling_segments(self): '''Segments designated for recycling''' if len(self.target_states): - for (ibin, tstate) in self.target_states.items(): + for ibin, tstate in self.target_states.items(): for segment in self.final_binning[ibin]: yield segment else: @@ -298,14 +298,14 @@ def new_iteration(self, initial_states=None, target_states=None, new_weights=Non init_pcoords = np.empty((len(new_weights), self.system.pcoord_ndim), dtype=self.system.pcoord_dtype) prev_init_pcoords = np.empty((len(new_weights), self.system.pcoord_ndim), dtype=self.system.pcoord_dtype) - for (ientry, entry) in enumerate(new_weights): + for ientry, entry in enumerate(new_weights): init_pcoords[ientry] = entry.new_init_pcoord prev_init_pcoords[ientry] = entry.prev_init_pcoord init_assignments = self.bin_mapper.assign(init_pcoords) prev_init_assignments = self.bin_mapper.assign(prev_init_pcoords) - for (entry, i, j) in zip(new_weights, prev_init_assignments, init_assignments): + for entry, i, j in zip(new_weights, prev_init_assignments, init_assignments): flux_matrix[i, j] += entry.weight transition_matrix[i, j] += 1 @@ -351,7 +351,7 @@ def assign(self, segments, initializing=False): final_binning = self.final_binning flux_matrix = self.flux_matrix transition_matrix = self.transition_matrix - for (segment, iidx, fidx) in zip(segments, initial_assignments, final_assignments): + for segment, iidx, fidx in zip(segments, initial_assignments, final_assignments): initial_binning[iidx].add(segment) final_binning[fidx].add(segment) flux_matrix[iidx, fidx] += segment.weight @@ -391,7 +391,7 @@ def _recycle_walkers(self): used_istate_ids = set() istateiter = iter(self.avail_initial_states.values()) - for (ibin, target_state) in self.target_states.items(): + for ibin, target_state in self.target_states.items(): target_bin = self.next_iter_binning[ibin] for segment in set(target_bin): initial_state = next(istateiter) @@ -657,7 +657,7 @@ def _run_we(self): # Then and only then adjust for correct particle count total_number_of_subgroups = 0 total_number_of_particles = 0 - for (ibin, bin) in enumerate(self.next_iter_binning): + for ibin, bin in enumerate(self.next_iter_binning): if len(bin) == 0: continue @@ -740,7 +740,7 @@ def populate_initial(self, initial_states, weights, system=None): # Create dummy segments segments = [] - for (seg_id, (initial_state, weight)) in enumerate(zip(initial_states, weights)): + for seg_id, (initial_state, weight) in enumerate(zip(initial_states, weights)): dummy_segment = Segment( n_iter=0, seg_id=seg_id, diff --git a/src/westpa/oldtools/aframe/binning.py b/src/westpa/oldtools/aframe/binning.py index 091d098f5..8a8698ded 100644 --- a/src/westpa/oldtools/aframe/binning.py +++ b/src/westpa/oldtools/aframe/binning.py @@ -92,7 +92,7 @@ def write_bin_labels(self, dest, header='# bin labels:\n', format='# bin {bin_in ''' dest.write(header or '') max_iwidth = len(str(self.mapper.nbins - 1)) - for (ibin, label) in enumerate(self.mapper.labels): + for ibin, label in enumerate(self.mapper.labels): dest.write(format.format(bin_index=ibin, label=label, max_iwidth=max_iwidth)) def require_binning_group(self): @@ -125,7 +125,7 @@ def assign_to_bins(self): westpa.rc.pstatus('Assigning to bins...') - for (iiter, n_iter) in enumerate(range(self.first_iter, self.last_iter + 1)): + for iiter, n_iter in enumerate(range(self.first_iter, self.last_iter + 1)): westpa.rc.pstatus('\r Iteration {:d}'.format(n_iter), end='') seg_index = self.get_seg_index(n_iter) pcoords = self.get_iter_group(n_iter)['pcoord'][...] diff --git a/src/westpa/oldtools/aframe/data_reader.py b/src/westpa/oldtools/aframe/data_reader.py index cad77a6d8..86c502439 100644 --- a/src/westpa/oldtools/aframe/data_reader.py +++ b/src/westpa/oldtools/aframe/data_reader.py @@ -135,7 +135,7 @@ def get_segments_by_id(self, n_iter, seg_ids, include_pcoords=True): if include_pcoords: pcoords = self.get_pcoords(n_iter, seg_ids) - for (isegid, seg_id) in enumerate(seg_ids): + for isegid, seg_id in enumerate(seg_ids): row = seg_index[seg_id] parents_offset = row['wtg_offset'] n_parents = row['wtg_n_parents'] @@ -313,7 +313,6 @@ def add_args(self, parser, upcall=True): ) def process_args(self, args, upcall=True): - if args.usecols: westpa.rc.pstatus('Using only the following columns from external input: {!s}'.format(args.usecols)) self.ext_input_usecols = args.usecols @@ -413,10 +412,10 @@ def text_to_h5dataset(self, fileobj, group, dsname, dtype=np.float64, skiprows=0 ) if usecols: - for (ifield, iifield) in enumerate(usecols): + for ifield, iifield in enumerate(usecols): databuffer[irow, ifield] = dtype(fields[iifield]) else: - for (ifield, field) in enumerate(fields): + for ifield, field in enumerate(fields): databuffer[irow, ifield] = dtype(field) nrows += 1 diff --git a/src/westpa/oldtools/aframe/kinetics.py b/src/westpa/oldtools/aframe/kinetics.py index 1ee474cff..8e49b8c47 100644 --- a/src/westpa/oldtools/aframe/kinetics.py +++ b/src/westpa/oldtools/aframe/kinetics.py @@ -47,7 +47,6 @@ def add_args(self, parser, upcall=True): ) def process_args(self, args, upcall=True): - self.dt = args.dt westpa.rc.pstatus('Assuming input data timestep of {:g}'.format(self.dt)) diff --git a/src/westpa/oldtools/aframe/trajwalker.py b/src/westpa/oldtools/aframe/trajwalker.py index 537aa263e..9b9d75f59 100644 --- a/src/westpa/oldtools/aframe/trajwalker.py +++ b/src/westpa/oldtools/aframe/trajwalker.py @@ -58,7 +58,7 @@ def get_initial_nodes(self, first_iter, last_iter, include_pcoords=True): # Convert to Segment objects segments = [] - for (n_iter, id_set) in root_ids.items(): + for n_iter, id_set in root_ids.items(): segments.extend(self.data_reader.get_segments_by_id(n_iter, id_set, include_pcoords=include_pcoords)) return segments diff --git a/src/westpa/oldtools/aframe/transitions.py b/src/westpa/oldtools/aframe/transitions.py index d3078464c..dd2c36cd2 100644 --- a/src/westpa/oldtools/aframe/transitions.py +++ b/src/westpa/oldtools/aframe/transitions.py @@ -200,9 +200,7 @@ def _accumulate_transitions(self, timepoints, assignments, weights, bin_pops, tr iibdisc = self.iibdisc iibins = self.iibins tdat_maxlen = self.max_acc - for (trans_ti, weight, ibin, fbin, ibinpops) in zip( - trans_timepoints, trans_weights, trans_ibin, trans_fbin, trans_ibinpops - ): + for trans_ti, weight, ibin, fbin, ibinpops in zip(trans_timepoints, trans_weights, trans_ibin, trans_fbin, trans_ibinpops): # Record this crossing event's data bin_pops_last_exit[ibin] = ibinpops[ibin] last_exit[ibin] = trans_ti diff --git a/src/westpa/oldtools/cmds/w_ttimes.py b/src/westpa/oldtools/cmds/w_ttimes.py index 3021b0699..6134844e6 100644 --- a/src/westpa/oldtools/cmds/w_ttimes.py +++ b/src/westpa/oldtools/cmds/w_ttimes.py @@ -85,7 +85,6 @@ def add_args(self, parser, upcall=True): self.add_common_output_args(output_options) def process_args(self, args, upcall=True): - self.ed_stats_filename = args.ed_stats self.fpt_stats_filename = args.fpt_stats self.flux_stats_filename = args.flux_stats @@ -201,7 +200,7 @@ def gen_stats(self): westpa.rc.pstatus() del trans_ibin - for (dsname, data) in (('duration', durations), ('fpt', fpts), ('flux', fluxes), ('rate', rates)): + for dsname, data in (('duration', durations), ('fpt', fpts), ('flux', fluxes), ('rate', rates)): try: del self.ttimes_group[dsname] except KeyError: @@ -234,7 +233,7 @@ def gen_stats(self): self.record_data_binhash(self.ttimes_group) def summarize_stats(self): - for (array, dsname, argname, title) in ( + for array, dsname, argname, title in ( (self.durations, 'duration', 'ed_stats_filename', 'event duration'), (self.fpts, 'fpt', 'fpt_stats_filename', 'first passage time'), (self.fluxes, 'flux', 'flux_stats_filename', 'flux'), @@ -259,7 +258,6 @@ def summarize_stats(self): ) def summarize_ci(self, filename, array, title, confidence, headers, labels): - format_2d = ( '{ibin:{mw}d} {fbin:{mw}d} {0:20.15g} {1:20.15g} {2:20.15g} {3:20.15g} {4:20.15g} {5:20.15g}\n' ) diff --git a/src/westpa/tools/binning.py b/src/westpa/tools/binning.py index f6704bc49..668d18ef6 100644 --- a/src/westpa/tools/binning.py +++ b/src/westpa/tools/binning.py @@ -209,7 +209,6 @@ def write_bin_info(mapper, assignments, weights, n_target_states, outfile=sys.st def write_bin_labels(mapper, dest, header='# bin labels:\n', fmt='# bin {index:{max_iwidth}d} -- {label!s}\n'): - '''Print labels for all bins in ``mapper`` to the file-like object``dest``. If provided, ``header`` is printed prior to any labels. A number of expansions @@ -229,7 +228,7 @@ def write_bin_labels(mapper, dest, header='# bin labels:\n', fmt='# bin {index:{ dest.write(header.format(mapper=mapper, classname=mapper.__class__.__name__, nbins=mapper.bins)) max_iwidth = len(str(mapper.nbins - 1)) - for (ibin, label) in enumerate(mapper.labels): + for ibin, label in enumerate(mapper.labels): dest.write(fmt.format(index=ibin, label=label, max_iwidth=max_iwidth)) @@ -277,7 +276,6 @@ class BinMappingComponent(WESTToolComponent): ''' def __init__(self): - # The final mapper self.mapper = None self.mapper_hash = None @@ -368,7 +366,6 @@ def add_target_count_args(self, parser, description='bin target count options'): ) def process_args(self, args): - # User may have suppressed any of these arguments bins_from_system = getattr(args, 'bins_from_system', None) bins_from_expr = getattr(args, 'bins_from_expr', None) diff --git a/src/westpa/tools/kinetics_tool.py b/src/westpa/tools/kinetics_tool.py index 0b8d20bfb..39c495332 100644 --- a/src/westpa/tools/kinetics_tool.py +++ b/src/westpa/tools/kinetics_tool.py @@ -95,7 +95,6 @@ def __init__(self, parent): self.kinetics_file = None def add_args(self, parser): - iogroup = parser.add_argument_group('input/output options') # self.default_kinetics_file will be picked up as a class attribute from the appropriate subclass # We can do this with the output file, too... @@ -261,7 +260,6 @@ def print_averages(self, dataset, header, dim=1): def run_calculation( self, pi, nstates, start_iter, stop_iter, step_iter, dataset, eval_block, name, dim, do_averages=False, **extra ): - # We want to use the same codepath to run a quick average as we do the longer evolution sets, so... if do_averages: start_pts = [start_iter, stop_iter] @@ -279,7 +277,6 @@ def run_calculation( # This is appropriate for bootstrapped quantities, I think. if True: - futures = [] for iblock, start in enumerate(start_pts): stop = min(start + step_iter, stop_iter) diff --git a/src/westpa/tools/selected_segs.py b/src/westpa/tools/selected_segs.py index 6afee8203..a1e250b91 100644 --- a/src/westpa/tools/selected_segs.py +++ b/src/westpa/tools/selected_segs.py @@ -30,7 +30,6 @@ def __contains__(self, pair): return tuple(pair) in self._segments def add(self, pair): - (n_iter, seg_id) = int(pair[0]), int(pair[1]) self._segments.add((n_iter, seg_id)) self._segs_by_iter.setdefault(n_iter, set()).add(seg_id) diff --git a/src/westpa/trajtree/trajtree.py b/src/westpa/trajtree/trajtree.py index 025290598..4254320a6 100644 --- a/src/westpa/trajtree/trajtree.py +++ b/src/westpa/trajtree/trajtree.py @@ -28,7 +28,6 @@ def get_root_indices(self): return np.squeeze(np.argwhere(self.trajtable['parent_offset'] == -1)) def trace_trajectories(self, visit, get_visitor_state=None, set_visitor_state=None, vargs=None, vkwargs=None): - if (get_visitor_state or set_visitor_state) and not (get_visitor_state and set_visitor_state): raise ValueError('either both or neither of get_visitor_state and set_visitor_state must be specified') @@ -67,7 +66,6 @@ def trace_trajectories(self, visit, get_visitor_state=None, set_visitor_state=No class FakeTrajTreeSet(TrajTreeSet): def __init__(self): - # _tt_dtype = np.dtype([('n_iter', np.uint32), # ('seg_id', np.int64), # ('parent_id', np.int64), diff --git a/src/westpa/westext/adaptvoronoi/adaptVor_driver.py b/src/westpa/westext/adaptvoronoi/adaptVor_driver.py index 9caaa6dd8..281faad02 100644 --- a/src/westpa/westext/adaptvoronoi/adaptVor_driver.py +++ b/src/westpa/westext/adaptvoronoi/adaptVor_driver.py @@ -31,7 +31,6 @@ class AdaptiveVoronoiDriver: ''' def __init__(self, sim_manager, plugin_config): - if not sim_manager.work_manager.is_master: return @@ -200,7 +199,6 @@ def update_centers(self, iter_group): self.centers = np.vstack((self.centers, curr_pcoords[max_ind[0][0]][-1])) def prepare_new_iteration(self): - n_iter = self.sim_manager.n_iter with self.data_manager.lock: diff --git a/src/westpa/westext/hamsm_restarting/example_overrides.py b/src/westpa/westext/hamsm_restarting/example_overrides.py index e0124b4f7..6c82cc0da 100644 --- a/src/westpa/westext/hamsm_restarting/example_overrides.py +++ b/src/westpa/westext/hamsm_restarting/example_overrides.py @@ -20,7 +20,6 @@ def processCoordinates(self, coords): return data if self.dimReduceMethod == "pca" or self.dimReduceMethod == "vamp": - ### NaCl dimensionality reduction log.warning("Hardcoded selection: Doing dim reduction for Na, Cl. This is only for testing!") indNA = self.reference_structure.topology.select("element Na") diff --git a/src/westpa/westext/hamsm_restarting/restart_driver.py b/src/westpa/westext/hamsm_restarting/restart_driver.py index a02ef5538..91e142d58 100644 --- a/src/westpa/westext/hamsm_restarting/restart_driver.py +++ b/src/westpa/westext/hamsm_restarting/restart_driver.py @@ -159,7 +159,6 @@ def prepare_coordinates(plugin_config, h5file, we_h5filename): n_iter = None for n_iter in tqdm.tqdm(range(1, model.maxIter + 1)): - nS = model.numSegments[n_iter - 1].astype(int) coords = np.zeros((nS, 2, model.nAtoms, 3)) dsetName = "/iterations/iter_%08d/auxdata/coord" % int(n_iter) @@ -530,7 +529,6 @@ def prepare_extension_run(self, run_number, restart_state, first_extension=False os.symlink(f'restart0/run{run_number}/seg_logs', 'seg_logs') if first_extension: - # Get lines to make a new west.cfg by extending west.propagation.max_total_iterations with open('west.cfg', 'r') as west_config: lines = west_config.readlines() @@ -578,7 +576,6 @@ def prepare_extension_run(self, run_number, restart_state, first_extension=False return def generate_plots(self, restart_directory): - model = self.model log.info("Producing flux-profile, pseudocommittor, and target flux comparison plots.") @@ -616,7 +613,6 @@ def generate_plots(self, restart_directory): # Get WE direct flux estimate for _file in model.fileList: - run = analysis.Run(_file) last_iter = run.num_iterations recycled = list(run.iteration(last_iter - 1).recycled_walkers) @@ -754,7 +750,6 @@ def prepare_new_we(self): # If we have more runs left to do in this marathon, prepare them elif not last_run: - log.info(f"Run {restart_state['runs_completed']}/{self.n_runs} completed.") # TODO: Initialize a new run, from the same configuration as this run was @@ -774,7 +769,6 @@ def prepare_new_we(self): # TODO: Implement this, and get rid of the initialization_file usage right below. Placeholder for now. if restart_state['runs_completed'] == 1: - # Get and write basis, target, start states and segs per state for this marathon to disk pass @@ -826,7 +820,6 @@ def prepare_new_we(self): # If we're doing an extension set # Instead of w_initting a new iteration, copy the files from restart0/runXX back into ./ elif doing_extension: - self.prepare_extension_run(run_number=restart_state['runs_completed'] + 1, restart_state=restart_state) return @@ -881,7 +874,6 @@ def prepare_new_we(self): ) for restart_number in usable_restarts: for run_number in range(1, 1 + restart_state['runs_completed']): - west_file_path = f"restart{restart_number}/run{run_number}/west.h5" marathon_west_files.append(west_file_path) @@ -902,12 +894,10 @@ def prepare_new_we(self): # If you reached the target, clean up from the extensions and then continue as normal # If extension_iters is set to 0, then don't do extensions. if target_reached or self.extension_iters == 0: - log.info("All runs reached target!") # Do some cleanup from the extension run if doing_extension and not self.extension_iters == 0: - # Remove the doing_extensions.lck lockfile os.remove(EXTENSION_LOCKFILE) @@ -918,7 +908,6 @@ def prepare_new_we(self): # If no runs reached the target, then we need to extend them elif not target_reached: - log.info("Target not reached. Preparing for extensions.") # Create the doing_extensions.lck "lockfile" to indicate we're in extend mode (or keep if exists) @@ -953,14 +942,12 @@ def prepare_new_we(self): flux_filename = f"{restart_directory}/JtargetSS.txt" with open(flux_filename, 'w') as fp: - log.debug(f"Writing flux to {flux_filename}") fp.write(str(model.JtargetSS)) fp.close() ss_filename = f"{restart_directory}/pSS.txt" with open(ss_filename, 'w') as fp: - log.debug(f"Writing pSS to {ss_filename}") np.savetxt(fp, model.pSS) fp.close() @@ -977,7 +964,6 @@ def prepare_new_we(self): # TODO: Include start states from previous runs sstates_filename = f"{restart_directory}/startstates.txt" with open(sstates_filename, 'w') as fp: - # Track the total number of segments iterated over seg_idx = 0 @@ -988,8 +974,7 @@ def prepare_new_we(self): total_bin_weights = [] # Loop over each set of (bin index, all the structures in that bin) - for (msm_bin_idx, structures) in tqdm.tqdm(model.cluster_structures.items()): - + for msm_bin_idx, structures in tqdm.tqdm(model.cluster_structures.items()): total_bin_weights.append(0) # Don't put structures in the basis or target @@ -1011,13 +996,11 @@ def prepare_new_we(self): # Write each structure to disk. Loop over each structure within a bin. msm_bin_we_weight_tracker = 0 for struct_idx, structure in enumerate(structures): - structure_filename = ( f"{struct_directory}/bin{msm_bin_idx}_" f"struct{struct_idx}.{STRUCT_EXTENSIONS[self.struct_filetype]}" ) with self.struct_filetype(structure_filename, 'w') as struct_file: - # One structure per segment seg_we_weight = model.cluster_structure_weights[msm_bin_idx][struct_idx] msm_bin_we_weight_tracker += seg_we_weight diff --git a/src/westpa/westext/stringmethod/string_driver.py b/src/westpa/westext/stringmethod/string_driver.py index c4592553e..c4681446f 100644 --- a/src/westpa/westext/stringmethod/string_driver.py +++ b/src/westpa/westext/stringmethod/string_driver.py @@ -214,7 +214,6 @@ def avgpos_cartesian(self, n_iter): return avg_pos, sum_bin_weight def prepare_new_iteration(self): - n_iter = self.sim_manager.n_iter with self.data_manager.lock: diff --git a/src/westpa/westext/stringmethod/string_method.py b/src/westpa/westext/stringmethod/string_method.py index 385aab26a..99c685097 100644 --- a/src/westpa/westext/stringmethod/string_method.py +++ b/src/westpa/westext/stringmethod/string_method.py @@ -21,7 +21,6 @@ class WESTStringMethod: - ___metaclass__ = ABCMeta def __init__(self, centers, **kwargs): @@ -218,7 +217,6 @@ def update_string_centers(self, avgcoords, binprob): avgcoords[idx] = pavg.mean(axis=0) for sid, si in enumerate(self._strindx): - x = avgcoords.copy()[si] centers = self.centers[si] occupied = np.nonzero(binprob[si[0]]) diff --git a/src/westpa/westext/weed/weed_driver.py b/src/westpa/westext/weed/weed_driver.py index dfa2b9096..41ac6483e 100644 --- a/src/westpa/westext/weed/weed_driver.py +++ b/src/westpa/westext/weed/weed_driver.py @@ -117,7 +117,7 @@ def prepare_new_iteration(self): for iseg, segment in enumerate(segments): pcoords[iseg] = segment.pcoord[0] assignments = mapper.assign(pcoords) - for (segment, assignment) in zip(segments, assignments): + for segment, assignment in zip(segments, assignments): bins[assignment].add(segment) westpa.rc.pstatus('\nReweighting using a different bin mapper than simulation:\n{}'.format(mapper)) @@ -169,7 +169,7 @@ def prepare_new_iteration(self): westpa.rc.pstatus('Empty bins assigned nonzero probability: {!s}.'.format(np.array_str(np.arange(n_bins)[z2nz_mask]))) else: westpa.rc.pstatus('\nBin populations after reweighting:\n{!s}'.format(binprobs)) - for (bin, newprob) in zip(bins, binprobs): + for bin, newprob in zip(bins, binprobs): bin.reweight(newprob) weed_global_group.attrs['last_reweighting'] = n_iter diff --git a/src/westpa/westext/wess/ProbAdjust.py b/src/westpa/westext/wess/ProbAdjust.py index 1835ac719..0a5ce59cc 100644 --- a/src/westpa/westext/wess/ProbAdjust.py +++ b/src/westpa/westext/wess/ProbAdjust.py @@ -57,7 +57,6 @@ def solve_steady_state(T, U, target_bins_index): def prob_adjust(binprob, rates, uncert, oldindex, targets=[]): - nbins = binprob.size result = solve_steady_state(rates, uncert, targets) diff --git a/src/westpa/westext/wess/wess_driver.py b/src/westpa/westext/wess/wess_driver.py index a3655bc25..9b523ea78 100644 --- a/src/westpa/westext/wess/wess_driver.py +++ b/src/westpa/westext/wess/wess_driver.py @@ -135,7 +135,7 @@ def prepare_new_iteration(self): for iseg, segment in enumerate(segments): pcoords[iseg] = segment.pcoord[0] assignments = mapper.assign(pcoords) - for (segment, assignment) in zip(segments, assignments): + for segment, assignment in zip(segments, assignments): bins[assignment].add(segment) target_states = list(we_driver.target_states.values()) @@ -193,7 +193,7 @@ def prepare_new_iteration(self): westpa.rc.pstatus('Empty bins assigned nonzero probability: {!s}.'.format(np.array_str(np.arange(n_bins)[z2nz_mask]))) else: westpa.rc.pstatus('\nBin populations after reweighting:\n{!s}'.format(binprobs)) - for (bin, newprob) in zip(bins, binprobs): + for bin, newprob in zip(bins, binprobs): if len(bin): bin.reweight(newprob) diff --git a/src/westpa/work_managers/environment.py b/src/westpa/work_managers/environment.py index 2133809ec..9a2774129 100644 --- a/src/westpa/work_managers/environment.py +++ b/src/westpa/work_managers/environment.py @@ -75,7 +75,6 @@ def get_val(self, name, default=None, type_=None): raise ValueError('cannot convert {!r} to {!r}: {!s}'.format(val, type_, e)) def add_wm_args(self, parser): - wm_group = parser.add_argument_group(self.group_title, self.group_description) wm_mutex = wm_group.add_mutually_exclusive_group() wm_mutex.add_argument( diff --git a/src/westpa/work_managers/mpi.py b/src/westpa/work_managers/mpi.py index c8ed93f51..2834233d2 100644 --- a/src/westpa/work_managers/mpi.py +++ b/src/westpa/work_managers/mpi.py @@ -174,11 +174,9 @@ def _dispatcher(self): assert threading.currentThread().getName() == "dispatcher" while not self.shutItDown: - req = [] # do we have work and somewhere to send it? while self.tasks and self.dests: - with self.lock: task = self.tasks.popleft() sendTo = self.dests.popleft() @@ -201,10 +199,8 @@ def _receiver(self): assert threading.currentThread().getName() == "receiver" while not self.shutItDown: - # are we waiting on any results? while self.nPending: - stat = MPI.Status() (tid, msg, val) = self.comm.recv(source=MPI.ANY_SOURCE, tag=self.result_tag, status=stat) log.debug('Manager._receiver received task: %s' % tid) @@ -278,7 +274,6 @@ def startup(self): """Clock the worker in for work.""" log.debug('Worker.startup() %s' % self.rank) if not self.running: - self.clockIn() self.running = True @@ -292,14 +287,12 @@ def clockIn(self): comm = self.comm while True: - stat = MPI.Status() task = comm.recv(source=self.managerID, tag=MPI.ANY_TAG, status=stat) tag = stat.Get_tag() if tag == self.task_tag: - log.debug('Worker %s received task: %s' % (self.rank, task.task_id)) # do the work diff --git a/src/westpa/work_managers/zeromq/core.py b/src/westpa/work_managers/zeromq/core.py index d93450ede..f9c22fdc1 100644 --- a/src/westpa/work_managers/zeromq/core.py +++ b/src/westpa/work_managers/zeromq/core.py @@ -93,7 +93,6 @@ class Message: idempotent_announcement_messages = {SHUTDOWN, TASKS_AVAILABLE, MASTER_BEACON} def __init__(self, message=None, payload=None, master_id=None, src_id=None): - if isinstance(message, Message): self.message = message.message self.payload = message.payload @@ -207,7 +206,6 @@ def __init__(self): self._indices = {} # indexes into durations/started, keyed by identifier def add_timer(self, identifier, duration): - if identifier in self._identifiers: raise KeyError('timer {!r} already present'.format(identifier)) @@ -266,7 +264,6 @@ def which_expired(self, at=None): class ZMQCore: - # The overall communication topology (socket layout, etc) # Cannot be updated without updating configuration files, command-line parameters, # etc. (Changes break user scripts.) @@ -332,7 +329,6 @@ def make_internal_endpoint(cls): return cls.make_tcp_endpoint() def __init__(self): - # Unique identifier of this ZMQ node self.node_id = uuid.uuid4() diff --git a/src/westpa/work_managers/zeromq/work_manager.py b/src/westpa/work_managers/zeromq/work_manager.py index 54db5dc90..ba2df69b7 100644 --- a/src/westpa/work_managers/zeromq/work_manager.py +++ b/src/westpa/work_managers/zeromq/work_manager.py @@ -161,7 +161,6 @@ def from_environ(cls, wmenv=None): if mode == 'master': instance = ZMQWorkManager(n_workers) else: # mode =='node' - upstream_info = {} if read_host_info: upstream_info.update(cls.read_host_info(read_host_info)) @@ -310,7 +309,7 @@ def submit_many(self, tasks): # We are shutting down raise ZMQWMEnvironmentError('work manager is shutting down') futures = [] - for (fn, args, kwargs) in tasks: + for fn, args, kwargs in tasks: future = WMFuture() task = Task(fn, args, kwargs, task_id=future.task_id) self.futures[task.task_id] = future diff --git a/src/westpa/work_managers/zeromq/worker.py b/src/westpa/work_managers/zeromq/worker.py index b43de1ad0..dd4cb43e2 100644 --- a/src/westpa/work_managers/zeromq/worker.py +++ b/src/westpa/work_managers/zeromq/worker.py @@ -282,7 +282,6 @@ def __init__(self, task_endpoint, result_endpoint): self.result_endpoint = result_endpoint def comm_loop(self): - task_socket = self.context.socket(zmq.PULL) result_socket = self.context.socket(zmq.PUSH) diff --git a/tests/fixtures/odld/odld_system.py b/tests/fixtures/odld/odld_system.py index 4e3d23010..3acef4faa 100644 --- a/tests/fixtures/odld/odld_system.py +++ b/tests/fixtures/odld/odld_system.py @@ -44,7 +44,6 @@ def gen_istate(self, basis_state, initial_state): return initial_state def propagate(self, segments): - A, B, C, x0 = self.A, self.B, self.C, self.x0 n_segs = len(segments) diff --git a/tests/refs/odld_system.py b/tests/refs/odld_system.py index d1a268fb7..4dc9829c9 100755 --- a/tests/refs/odld_system.py +++ b/tests/refs/odld_system.py @@ -44,7 +44,6 @@ def gen_istate(self, basis_state, initial_state): return initial_state def propagate(self, segments): - A, B, C, x0 = self.A, self.B, self.C, self.x0 n_segs = len(segments) diff --git a/tests/test_binning.py b/tests/test_binning.py index dbbff1a29..8120f4e0e 100644 --- a/tests/test_binning.py +++ b/tests/test_binning.py @@ -283,7 +283,6 @@ def testMegaComplexRecursion(self): # TODO: Fix this test @pytest.mark.xfail(reason="known error in assign") def test2dRectilinearRecursion(self): - ''' 0 1 2 +----------------------------+----------------------+ diff --git a/tests/test_tools/common.py b/tests/test_tools/common.py index 384a9e71d..80ca3488a 100755 --- a/tests/test_tools/common.py +++ b/tests/test_tools/common.py @@ -71,7 +71,6 @@ def check_args(self, outcome, errmsg, args): assert outcome, str(errmsg) def check_runs_with_args(self, **kwargs): - try: self.w.go() # Run tool with given args diff --git a/tests/test_tools/h5diff.py b/tests/test_tools/h5diff.py index b956b434d..dcb701c20 100755 --- a/tests/test_tools/h5diff.py +++ b/tests/test_tools/h5diff.py @@ -4,14 +4,12 @@ class H5Diff: def __init__(self, ref_file, test_file): - self.ref_file = h5py.File(ref_file, 'r') self.test_file = h5py.File(test_file, 'r') # TODO: I don't love that this is hardcoded to compare the test file against the ref file, but # to fix that I'd have to figure out how to pass an argument when I pass this as a callable to visititems() def check_in_ref(self, name, obj): - # print(f"\nDiffing {name}", end='\n') test_object = obj @@ -19,8 +17,7 @@ def check_in_ref(self, name, obj): assert ref_object is not None, f"Element {ref_object} did not exist in test file" # If it's a dataset, compare the actual contents - if type(test_object) == h5py._hl.dataset.Dataset: - + if isinstance(test_object, h5py._hl.dataset.Dataset): if name in self.excluded_datasets: return None @@ -35,7 +32,6 @@ def check_in_ref(self, name, obj): # HACK: This if statement evaluates to False if the test_object is a single value like a float or something, since # .dtype is referencing an attribute of a numpy array. if test_object[()].dtype.names is not None: - non_reference_test_elements = [ x for i, x in enumerate(test_object[()][0]) if not test_object[()].dtype.names[i] in ref_names ] @@ -59,7 +55,7 @@ def check_in_ref(self, name, obj): if type(non_reference_ref_elements) is ndarray and issubdtype(non_reference_ref_elements.dtype, floating): comparison = isclose(non_reference_test_elements, non_reference_ref_elements, atol=self.float_thresh) - if type(comparison) == bool: + if isinstance(comparison, bool): assert non_reference_test_elements == non_reference_ref_elements, f"Elements didn't match in {name}" else: try: @@ -73,7 +69,7 @@ def check_in_ref(self, name, obj): # If it's a group, do nothing # TODO: Is it sufficient to check only the datasets? The groups should just be organizational units - elif type(test_object) == h5py._hl.group.Group: + elif isinstance(test_object, h5py._hl.group.Group): pass # Returning None every loop makes visititems() iterate through every element. @@ -89,7 +85,6 @@ def check_in_ref(self, name, obj): # But if it's flipped, then if there's extra junk in the test file, that wouldn't be revealed. # This works for the time being, and as an **extremely** janky hack fix, you could do it both ways... def check(self, float_thresh=1e-8, excluded_datasets=[]): - self.float_thresh = float_thresh self.excluded_datasets = excluded_datasets self.test_file.visititems(self.check_in_ref) @@ -97,7 +92,6 @@ def check(self, float_thresh=1e-8, excluded_datasets=[]): # TODO: Add some simple argument handler here if __name__ == "__main__": - diff = H5Diff("./assign_ref.h5", "./analysis_tocompare.h5") diff.check() diff --git a/tests/test_tools/test_w_assign.py b/tests/test_tools/test_w_assign.py index 09650d789..6803c59c2 100755 --- a/tests/test_tools/test_w_assign.py +++ b/tests/test_tools/test_w_assign.py @@ -8,7 +8,6 @@ class Test_W_Assign: def test_run_w_assign(self, ref_50iter): - args = MockArgs( verbosity='debug', rcfile=self.cfg_filepath, diff --git a/tests/test_tools/test_w_direct.py b/tests/test_tools/test_w_direct.py index 3ef299748..e3150f17c 100755 --- a/tests/test_tools/test_w_direct.py +++ b/tests/test_tools/test_w_direct.py @@ -11,7 +11,6 @@ class Test_W_Direct(unittest.TestCase): - test_name = 'W_DIRECT' def test_run_w_direct(self): @@ -30,7 +29,6 @@ def test_run_w_direct(self): @pytest.mark.skip(reason="work-in-progress test that uses entry point") class Test_W_Direct_New: def test_run_w_direct(self, ref_50iter): - with mock.patch( target='argparse.ArgumentParser.parse_args', return_value=argparse.Namespace( diff --git a/tests/test_tools/test_w_ipa.py b/tests/test_tools/test_w_ipa.py index afc94cc7f..89853ca02 100755 --- a/tests/test_tools/test_w_ipa.py +++ b/tests/test_tools/test_w_ipa.py @@ -10,7 +10,6 @@ class Test_W_IPA(unittest.TestCase): - test_name = 'W_IPA' def test_run_w_ipa(self): diff --git a/tests/test_tools/test_w_trace.py b/tests/test_tools/test_w_trace.py index bc552dd72..311dfde9a 100755 --- a/tests/test_tools/test_w_trace.py +++ b/tests/test_tools/test_w_trace.py @@ -84,9 +84,7 @@ def test_args(self): return self.check_args, test_outcome, err, args def check_output(self, arg_idx): - with h5py.File(self.outfile) as f: - assert 'trajectories' in list(f.keys()), "'trajectories' group not in output file" traj_group = f['trajectories'] diff --git a/tests/test_we_driver.py b/tests/test_we_driver.py index 6487a34da..9e8f69586 100644 --- a/tests/test_we_driver.py +++ b/tests/test_we_driver.py @@ -222,7 +222,6 @@ def test_recycle(self): assert segments[0].endpoint_type == Segment.SEG_ENDPOINT_RECYCLED def test_multiple_merge(self): - # This weight and count combination is known to trigger a split to 51 # followed by a count adjustment to 50 (thanks to Josh Adelman) segment = self.segment(0.0, 0.5, weight=0.9999999999970001) diff --git a/tests/test_work_managers/test_zeromq/test_worker.py b/tests/test_work_managers/test_zeromq/test_worker.py index f59c2e1e4..3d4c52674 100644 --- a/tests/test_work_managers/test_zeromq/test_worker.py +++ b/tests/test_work_managers/test_zeromq/test_worker.py @@ -20,7 +20,6 @@ class TestZMQWorkerBasic(ZMQTestBase, unittest.TestCase): - # endpoint_type = 'tcp' '''Tests for the core task dispersal/retrieval and shutdown operations diff --git a/tests/test_yamlfe.py b/tests/test_yamlfe.py index 6c401dacb..b981907cc 100644 --- a/tests/test_yamlfe.py +++ b/tests/test_yamlfe.py @@ -26,6 +26,7 @@ def initialize(self): # - returns the correct system # given both + # A class to test both paths at the same time # if it works we assure we can load the driver # AND overwrite it properly