Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

NumPy2 support fix #374

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ exclude = '''
)
)
'''

8 changes: 4 additions & 4 deletions src/westpa/cli/tools/w_assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,17 +474,17 @@ def go(self):

# Recursive mappers produce a generator rather than a list of labels
# so consume the entire generator into a list
labels = [np.string_(label) for label in self.binning.mapper.labels]
labels = [np.bytes_(label) for label in self.binning.mapper.labels]

self.output_file.create_dataset('bin_labels', data=labels, compression=9)

if self.states:
nstates = len(self.states)
state_map[:] = nstates # state_id == nstates => unknown state
state_labels = [np.string_(state['label']) for state in self.states]
state_labels = [np.bytes_(state['label']) for state in self.states]

for istate, sdict in enumerate(self.states):
assert state_labels[istate] == np.string_(sdict['label']) # sanity check
assert state_labels[istate] == np.bytes_(sdict['label']) # sanity check
state_assignments = assign(sdict['coords'])
for assignment in state_assignments:
state_map[assignment] = istate
Expand Down Expand Up @@ -558,7 +558,7 @@ def go(self):
shuffle=True,
chunks=h5io.calc_chunksize(pops_shape, weight_dtype),
)
h5io.label_axes(pops_ds, [np.string_(i) for i in ['iteration', 'state', 'bin']])
h5io.label_axes(pops_ds, [np.bytes_(i) for i in ['iteration', 'state', 'bin']])

pi.new_operation('Assigning to bins', iter_stop - iter_start)
last_labels = None # mapping of seg_id to last macrostate inhabited
Expand Down
4 changes: 2 additions & 2 deletions src/westpa/core/data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@
# dsopts['file'] = str(dsopts['file']).format(n_iter=n_iter)
h5_auxfile = h5io.WESTPAH5File(dsopts['file'].format(n_iter=n_iter))
h5group = group
if not ("iter_" + str(n_iter).zfill(8)) in h5_auxfile:
if ("iter_" + str(n_iter).zfill(8)) not in h5_auxfile:

Check warning on line 1548 in src/westpa/core/data_manager.py

View check run for this annotation

Codecov / codecov/patch

src/westpa/core/data_manager.py#L1548

Added line #L1548 was not covered by tests
h5_auxfile.create_group("iter_" + str(n_iter).zfill(8))
group = h5_auxfile[('/' + "iter_" + str(n_iter).zfill(8))]

Expand Down Expand Up @@ -1648,7 +1648,7 @@
if 'file' in list(dsopts.keys()):
import h5py

if not dsopts['h5path'] in h5group:
if dsopts['h5path'] not in h5group:

Check warning on line 1651 in src/westpa/core/data_manager.py

View check run for this annotation

Codecov / codecov/patch

src/westpa/core/data_manager.py#L1651

Added line #L1651 was not covered by tests
h5group[dsopts['h5path']] = h5py.ExternalLink(
dsopts['file'].format(n_iter=n_iter), ("/" + "iter_" + str(n_iter).zfill(8) + "/" + dsopts['h5path'])
)
Expand Down
4 changes: 2 additions & 2 deletions src/westpa/core/h5io.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,10 @@
if len(units) and len(units) != len(labels):
raise ValueError('number of units labels does not match number of axes')

h5object.attrs['axis_labels'] = np.array([np.string_(i) for i in labels])
h5object.attrs['axis_labels'] = np.array([np.bytes_(i) for i in labels])

if len(units):
h5object.attrs['axis_units'] = np.array([np.string_(i) for i in units])
h5object.attrs['axis_units'] = np.array([np.bytes_(i) for i in units])

Check warning on line 348 in src/westpa/core/h5io.py

View check run for this annotation

Codecov / codecov/patch

src/westpa/core/h5io.py#L348

Added line #L348 was not covered by tests


NotGiven = object()
Expand Down
2 changes: 1 addition & 1 deletion src/westpa/core/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BasisState:
'''

def __init__(self, label, probability, pcoord=None, auxref=None, state_id=None):
self.label = str(label, encoding="UTF-8") if type(label) is bytes else label
self.label = str(label, encoding="UTF-8") if isinstance(label, bytes) else label
self.probability = probability
self.pcoord = np.atleast_1d(pcoord)
self.auxref = auxref
Expand Down
2 changes: 1 addition & 1 deletion src/westpa/westext/stringmethod/string_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
ud[2:] = -self._kappan[ulen]
ld[:-2] = -self._kappan[ulen]

self._A[ulen] = np.mat([ud, d, ld])
self._A[ulen] = np.asmatrix([ud, d, ld])

Check warning on line 179 in src/westpa/westext/stringmethod/string_method.py

View check run for this annotation

Codecov / codecov/patch

src/westpa/westext/stringmethod/string_method.py#L179

Added line #L179 was not covered by tests

else:
self._A[ulen] = np.eye(ulen)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_tools/h5diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ def check_in_ref(self, name, obj):
# .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
x for i, x in enumerate(test_object[()][0]) if test_object[()].dtype.names[i] not in ref_names
]

non_reference_ref_elements = [
x for i, x in enumerate(ref_object[()][0]) if not ref_object[()].dtype.names[i] in ref_names
x for i, x in enumerate(ref_object[()][0]) if ref_object[()].dtype.names[i] not in ref_names
]

else:
Expand Down