Skip to content

Commit

Permalink
Prepare for NumPy 2.0 (#2845)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulromano committed Mar 26, 2024
1 parent ce7efa4 commit 9fee653
Show file tree
Hide file tree
Showing 22 changed files with 74 additions and 72 deletions.
2 changes: 1 addition & 1 deletion openmc/data/correlated.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def to_hdf5(self, group):
HDF5 group to write to
"""
group.attrs['type'] = np.string_(self._name)
group.attrs['type'] = np.bytes_(self._name)

dset = group.create_dataset('energy', data=self.energy)
dset.attrs['interpolation'] = np.vstack((self.breakpoints,
Expand Down
14 changes: 7 additions & 7 deletions openmc/data/energy_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def to_hdf5(self, group):
"""

group.attrs['type'] = np.string_('maxwell')
group.attrs['type'] = np.bytes_('maxwell')
group.attrs['u'] = self.u
self.theta.to_hdf5(group, 'theta')

Expand Down Expand Up @@ -410,7 +410,7 @@ def to_hdf5(self, group):
"""

group.attrs['type'] = np.string_('evaporation')
group.attrs['type'] = np.bytes_('evaporation')
group.attrs['u'] = self.u
self.theta.to_hdf5(group, 'theta')

Expand Down Expand Up @@ -556,7 +556,7 @@ def to_hdf5(self, group):
"""

group.attrs['type'] = np.string_('watt')
group.attrs['type'] = np.bytes_('watt')
group.attrs['u'] = self.u
self.a.to_hdf5(group, 'a')
self.b.to_hdf5(group, 'b')
Expand Down Expand Up @@ -728,7 +728,7 @@ def to_hdf5(self, group):
"""

group.attrs['type'] = np.string_('madland-nix')
group.attrs['type'] = np.bytes_('madland-nix')
group.attrs['efl'] = self.efl
group.attrs['efh'] = self.efh
self.tm.to_hdf5(group)
Expand Down Expand Up @@ -846,7 +846,7 @@ def to_hdf5(self, group):
"""

group.attrs['type'] = np.string_('discrete_photon')
group.attrs['type'] = np.bytes_('discrete_photon')
group.attrs['primary_flag'] = self.primary_flag
group.attrs['energy'] = self.energy
group.attrs['atomic_weight_ratio'] = self.atomic_weight_ratio
Expand Down Expand Up @@ -945,7 +945,7 @@ def to_hdf5(self, group):
"""

group.attrs['type'] = np.string_('level')
group.attrs['type'] = np.bytes_('level')
group.attrs['threshold'] = self.threshold
group.attrs['mass_ratio'] = self.mass_ratio

Expand Down Expand Up @@ -1074,7 +1074,7 @@ def to_hdf5(self, group):
"""

group.attrs['type'] = np.string_('continuous')
group.attrs['type'] = np.bytes_('continuous')

dset = group.create_dataset('energy', data=self.energy)
dset.attrs['interpolation'] = np.vstack((self.breakpoints,
Expand Down
6 changes: 3 additions & 3 deletions openmc/data/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def to_hdf5(self, group, name='xy'):
"""
dataset = group.create_dataset(name, data=np.vstack(
[self.x, self.y]))
dataset.attrs['type'] = np.string_(type(self).__name__)
dataset.attrs['type'] = np.bytes_(type(self).__name__)
dataset.attrs['breakpoints'] = self.breakpoints
dataset.attrs['interpolation'] = self.interpolation

Expand Down Expand Up @@ -460,7 +460,7 @@ def to_hdf5(self, group, name='xy'):
"""
dataset = group.create_dataset(name, data=self.coef)
dataset.attrs['type'] = np.string_(type(self).__name__)
dataset.attrs['type'] = np.bytes_(type(self).__name__)

@classmethod
def from_hdf5(cls, dataset):
Expand Down Expand Up @@ -592,7 +592,7 @@ def to_hdf5(self, group, name='xy'):
"""
sum_group = group.create_group(name)
sum_group.attrs['type'] = np.string_(type(self).__name__)
sum_group.attrs['type'] = np.bytes_(type(self).__name__)
sum_group.attrs['n'] = len(self.functions)
for i, f in enumerate(self.functions):
f.to_hdf5(sum_group, f'func_{i+1}')
Expand Down
2 changes: 1 addition & 1 deletion openmc/data/kalbach_mann.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def to_hdf5(self, group):
HDF5 group to write to
"""
group.attrs['type'] = np.string_('kalbach-mann')
group.attrs['type'] = np.bytes_('kalbach-mann')

dset = group.create_dataset('energy', data=self.energy)
dset.attrs['interpolation'] = np.vstack((self.breakpoints,
Expand Down
2 changes: 1 addition & 1 deletion openmc/data/multipole.py
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ def export_to_hdf5(self, path, mode='a', libver='earliest'):

# Open file and write version.
with h5py.File(str(path), mode, libver=libver) as f:
f.attrs['filetype'] = np.string_('data_wmp')
f.attrs['filetype'] = np.bytes_('data_wmp')
f.attrs['version'] = np.array(WMP_VERSION)

g = f.create_group(self.name)
Expand Down
2 changes: 1 addition & 1 deletion openmc/data/nbody.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def to_hdf5(self, group):
HDF5 group to write to
"""
group.attrs['type'] = np.string_('nbody')
group.attrs['type'] = np.bytes_('nbody')
group.attrs['total_mass'] = self.total_mass
group.attrs['n_particles'] = self.n_particles
group.attrs['atomic_weight_ratio'] = self.atomic_weight_ratio
Expand Down
2 changes: 1 addition & 1 deletion openmc/data/neutron.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def export_to_hdf5(self, path, mode='a', libver='earliest'):

# Open file and write version
with h5py.File(str(path), mode, libver=libver) as f:
f.attrs['filetype'] = np.string_('data_neutron')
f.attrs['filetype'] = np.bytes_('data_neutron')
f.attrs['version'] = np.array(HDF5_VERSION)

# Write basic data
Expand Down
2 changes: 1 addition & 1 deletion openmc/data/photon.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ def export_to_hdf5(self, path, mode='a', libver='earliest'):
"""
with h5py.File(str(path), mode, libver=libver) as f:
# Write filetype and version
f.attrs['filetype'] = np.string_('data_photon')
f.attrs['filetype'] = np.bytes_('data_photon')
if 'version' not in f.attrs:
f.attrs['version'] = np.array(HDF5_VERSION)

Expand Down
4 changes: 2 additions & 2 deletions openmc/data/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ def to_hdf5(self, group):
HDF5 group to write to
"""
group.attrs['particle'] = np.string_(self.particle)
group.attrs['emission_mode'] = np.string_(self.emission_mode)
group.attrs['particle'] = np.bytes_(self.particle)
group.attrs['emission_mode'] = np.bytes_(self.emission_mode)
if self.decay_rate > 0.0:
group.attrs['decay_rate'] = self.decay_rate

Expand Down
4 changes: 2 additions & 2 deletions openmc/data/reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,9 +920,9 @@ def to_hdf5(self, group):

group.attrs['mt'] = self.mt
if self.mt in REACTION_NAME:
group.attrs['label'] = np.string_(REACTION_NAME[self.mt])
group.attrs['label'] = np.bytes_(REACTION_NAME[self.mt])
else:
group.attrs['label'] = np.string_(self.mt)
group.attrs['label'] = np.bytes_(self.mt)
group.attrs['Q_value'] = self.q_value
group.attrs['center_of_mass'] = 1 if self.center_of_mass else 0
group.attrs['redundant'] = 1 if self.redundant else 0
Expand Down
7 changes: 3 additions & 4 deletions openmc/data/resonance_covariance.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,14 @@ def sample(self, n_samples):
samples = []

# Handling MLBW/SLBW sampling
rng = np.random.default_rng()
if formalism == 'mlbw' or formalism == 'slbw':
params = ['energy', 'neutronWidth', 'captureWidth', 'fissionWidth',
'competitiveWidth']
param_list = params[:mpar]
mean_array = parameters[param_list].values
mean = mean_array.flatten()
par_samples = np.random.multivariate_normal(mean, cov,
size=n_samples)
par_samples = rng.multivariate_normal(mean, cov, size=n_samples)
spin = parameters['J'].values
l_value = parameters['L'].values
for sample in par_samples:
Expand Down Expand Up @@ -277,8 +277,7 @@ def sample(self, n_samples):
param_list = params[:mpar]
mean_array = parameters[param_list].values
mean = mean_array.flatten()
par_samples = np.random.multivariate_normal(mean, cov,
size=n_samples)
par_samples = rng.multivariate_normal(mean, cov, size=n_samples)
spin = parameters['J'].values
l_value = parameters['L'].values
for sample in par_samples:
Expand Down
6 changes: 3 additions & 3 deletions openmc/data/thermal.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def to_hdf5(self, group, name):
"""
dataset = group.create_dataset(name, data=np.vstack(
[self.bragg_edges, self.factors]))
dataset.attrs['type'] = np.string_(type(self).__name__)
dataset.attrs['type'] = np.bytes_(type(self).__name__)

@classmethod
def from_hdf5(cls, dataset):
Expand Down Expand Up @@ -294,7 +294,7 @@ def to_hdf5(self, group, name):
"""
data = np.array([self.bound_xs, self.debye_waller])
dataset = group.create_dataset(name, data=data)
dataset.attrs['type'] = np.string_(type(self).__name__)
dataset.attrs['type'] = np.bytes_(type(self).__name__)

@classmethod
def from_hdf5(cls, dataset):
Expand Down Expand Up @@ -464,7 +464,7 @@ def export_to_hdf5(self, path, mode='a', libver='earliest'):
"""
# Open file and write version
with h5py.File(str(path), mode, libver=libver) as f:
f.attrs['filetype'] = np.string_('data_thermal')
f.attrs['filetype'] = np.bytes_('data_thermal')
f.attrs['version'] = np.array(HDF5_VERSION)

# Write basic data
Expand Down
10 changes: 5 additions & 5 deletions openmc/data/thermal_angle_energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def to_hdf5(self, group):
HDF5 group to write to
"""
group.attrs['type'] = np.string_('coherent_elastic')
group.attrs['type'] = np.bytes_('coherent_elastic')
self.coherent_xs.to_hdf5(group, 'coherent_xs')

@classmethod
Expand Down Expand Up @@ -104,7 +104,7 @@ def to_hdf5(self, group):
HDF5 group to write to
"""
group.attrs['type'] = np.string_('incoherent_elastic')
group.attrs['type'] = np.bytes_('incoherent_elastic')
group.create_dataset('debye_waller', data=self.debye_waller)

@classmethod
Expand Down Expand Up @@ -146,7 +146,7 @@ def to_hdf5(self, group):
HDF5 group to write to
"""
group.attrs['type'] = np.string_('incoherent_elastic_discrete')
group.attrs['type'] = np.bytes_('incoherent_elastic_discrete')
group.create_dataset('mu_out', data=self.mu_out)

@classmethod
Expand Down Expand Up @@ -203,7 +203,7 @@ def to_hdf5(self, group):
HDF5 group to write to
"""
group.attrs['type'] = np.string_('incoherent_inelastic_discrete')
group.attrs['type'] = np.bytes_('incoherent_inelastic_discrete')
group.create_dataset('energy_out', data=self.energy_out)
group.create_dataset('mu_out', data=self.mu_out)
group.create_dataset('skewed', data=self.skewed)
Expand Down Expand Up @@ -266,7 +266,7 @@ def to_hdf5(self, group):
HDF5 group to write to
"""
group.attrs['type'] = np.string_('mixed_elastic')
group.attrs['type'] = np.bytes_('mixed_elastic')
coherent_group = group.create_group('coherent')
self.coherent.to_hdf5(coherent_group)
incoherent_group = group.create_group('incoherent')
Expand Down
2 changes: 1 addition & 1 deletion openmc/data/uncorrelated.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def to_hdf5(self, group):
HDF5 group to write to
"""
group.attrs['type'] = np.string_('uncorrelated')
group.attrs['type'] = np.bytes_('uncorrelated')
if self.angle is not None:
angle_group = group.create_group('angle')
self.angle.to_hdf5(angle_group)
Expand Down
2 changes: 1 addition & 1 deletion openmc/deplete/stepresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def _write_hdf5_metadata(self, handle):
# Store concentration mat and nuclide dictionaries (along with volumes)

handle.attrs['version'] = np.array(VERSION_RESULTS)
handle.attrs['filetype'] = np.string_('depletion results')
handle.attrs['filetype'] = np.bytes_('depletion results')

mat_list = sorted(self.mat_to_hdf5_ind, key=int)
nuc_list = sorted(self.index_nuc)
Expand Down
8 changes: 4 additions & 4 deletions openmc/mgxs_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -1964,17 +1964,17 @@ def to_hdf5(self, file):
grp.attrs['fissionable'] = self.fissionable

if self.representation is not None:
grp.attrs['representation'] = np.string_(self.representation)
grp.attrs['representation'] = np.bytes_(self.representation)
if self.representation == REPRESENTATION_ANGLE:
if self.num_azimuthal is not None:
grp.attrs['num_azimuthal'] = self.num_azimuthal

if self.num_polar is not None:
grp.attrs['num_polar'] = self.num_polar

grp.attrs['scatter_shape'] = np.string_("[G][G'][Order]")
grp.attrs['scatter_shape'] = np.bytes_("[G][G'][Order]")
if self.scatter_format is not None:
grp.attrs['scatter_format'] = np.string_(self.scatter_format)
grp.attrs['scatter_format'] = np.bytes_(self.scatter_format)
if self.order is not None:
grp.attrs['order'] = self.order

Expand Down Expand Up @@ -2516,7 +2516,7 @@ def export_to_hdf5(self, filename='mgxs.h5', libver='earliest'):

# Create and write to the HDF5 file
file = h5py.File(filename, "w", libver=libver)
file.attrs['filetype'] = np.string_(_FILETYPE_MGXS_LIBRARY)
file.attrs['filetype'] = np.bytes_(_FILETYPE_MGXS_LIBRARY)
file.attrs['version'] = [_VERSION_MGXS_LIBRARY, 0]
file.attrs['energy_groups'] = self.energy_groups.num_groups
file.attrs['delayed_groups'] = self.num_delayed_groups
Expand Down
4 changes: 2 additions & 2 deletions openmc/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,11 +465,11 @@ def colorize(self, geometry, seed=1):
domains = geometry.get_all_cells().values()

# Set the seed for the random number generator
np.random.seed(seed)
rng = np.random.RandomState(seed)

# Generate random colors for each feature
for domain in domains:
self.colors[domain] = np.random.randint(0, 256, (3,))
self.colors[domain] = rng.randint(0, 256, (3,))

def to_xml_element(self):
"""Save common plot attributes to XML element
Expand Down
2 changes: 1 addition & 1 deletion openmc/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ def write_source_file(
# Write array to file
kwargs.setdefault('mode', 'w')
with h5py.File(filename, **kwargs) as fh:
fh.attrs['filetype'] = np.string_("source")
fh.attrs['filetype'] = np.bytes_("source")
fh.create_dataset('source_bank', data=arr, dtype=source_dtype)


Expand Down

0 comments on commit 9fee653

Please sign in to comment.