From f0fe111578459a9828bd52b28c024138ecef5ab8 Mon Sep 17 00:00:00 2001 From: Alexander Harvey Nitz Date: Mon, 29 Jul 2024 21:52:52 -0400 Subject: [PATCH 1/9] allow numpy 2.0 to run --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 3128f18f0a3..709649b789b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ astropy>=2.0.3,!=4.2.1,!=4.0.5 Mako>=1.0.1 scipy>=0.16.0 matplotlib>=2.0.0 -numpy>=1.16.0,!=1.19.0,<2.0.0 +numpy>=1.16.0,!=1.19.0 pillow h5py>=3.0.0,!=3.7.0 jinja2 diff --git a/setup.py b/setup.py index 03e2dbf8e9b..83e30f2b5ac 100755 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ setup_requires = ['numpy>=1.16.0'] install_requires = setup_requires + [ 'cython>=0.29', - 'numpy>=1.16.0,!=1.19.0,<2.0.0', + 'numpy>=1.16.0,!=1.19.0', 'scipy>=0.16.0', 'astropy>=2.0.3,!=4.2.1,!=4.0.5', 'matplotlib>=1.5.1', From 04e3d65fc4f8f61a69fcef5055eef28f93fea054 Mon Sep 17 00:00:00 2001 From: Alexander Harvey Nitz Date: Wed, 4 Sep 2024 16:24:27 -0400 Subject: [PATCH 2/9] fix for np2 --- pycbc/conversions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pycbc/conversions.py b/pycbc/conversions.py index 3daf5c8a1b0..e442742c8cf 100644 --- a/pycbc/conversions.py +++ b/pycbc/conversions.py @@ -77,9 +77,9 @@ def ensurearray(*args): inputs was an array. """ input_is_array = any(isinstance(arg, numpy.ndarray) for arg in args) - args = numpy.broadcast_arrays(*args) + args = list(numpy.broadcast_arrays(*args)) args.append(input_is_array) - return args + return tuple(args) def formatreturn(arg, input_is_array=False): From 53d9f97c030e9c74e14a9d2d61e936274bd49c01 Mon Sep 17 00:00:00 2001 From: Alexander Harvey Nitz Date: Wed, 4 Sep 2024 16:57:43 -0400 Subject: [PATCH 3/9] fix np2 bug --- pycbc/events/eventmgr.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pycbc/events/eventmgr.py b/pycbc/events/eventmgr.py index d431bc9a54b..003956f89f4 100644 --- a/pycbc/events/eventmgr.py +++ b/pycbc/events/eventmgr.py @@ -149,8 +149,8 @@ def findchirp_cluster_over_window(times, values, window_length): indices = numpy.zeros(len(times), dtype=numpy.int32) tlen = len(times) - absvalues = numpy.array(abs(values), copy=False) - times = numpy.array(times, dtype=numpy.int32, copy=False) + absvalues = numpy.asarray(abs(values), copy=False) + times = numpy.asarray(times, dtype=numpy.int32) k = findchirp_cluster_over_window_cython(times, absvalues, window_length, indices, tlen) From 2871d816a694ee622aeb06f1deda06230932b3af Mon Sep 17 00:00:00 2001 From: Alexander Harvey Nitz Date: Wed, 4 Sep 2024 17:03:22 -0400 Subject: [PATCH 4/9] tmpltbank fixes --- pycbc/tmpltbank/coord_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pycbc/tmpltbank/coord_utils.py b/pycbc/tmpltbank/coord_utils.py index 429336d2153..4195ca728ce 100644 --- a/pycbc/tmpltbank/coord_utils.py +++ b/pycbc/tmpltbank/coord_utils.py @@ -440,7 +440,7 @@ def get_mu_params(lambdas, metricParams, fUpper): mus : list of floats or numpy.arrays Position of the system(s) in the mu coordinate system """ - lambdas = numpy.array(lambdas, copy=False) + lambdas = numpy.asarray(lambdas) # If original inputs were floats we need to make this a 2D array if len(lambdas.shape) == 1: resize_needed = True @@ -451,7 +451,7 @@ def get_mu_params(lambdas, metricParams, fUpper): evecs = metricParams.evecs[fUpper] evals = metricParams.evals[fUpper] - evecs = numpy.array(evecs, copy=False) + evecs = numpy.asarray(evecs) mus = ((lambdas.T).dot(evecs)).T mus = mus * numpy.sqrt(evals)[:,None] @@ -479,7 +479,7 @@ def get_covaried_params(mus, evecsCV): xis : list of floats or numpy.arrays Position of the system(s) in the xi coordinate system """ - mus = numpy.array(mus, copy=False) + mus = numpy.asarray(mus) # If original inputs were floats we need to make this a 2D array if len(mus.shape) == 1: resize_needed = True From 82ee2b6da4ec348d74fafa06c6e86149619f5a44 Mon Sep 17 00:00:00 2001 From: Alexander Harvey Nitz Date: Wed, 4 Sep 2024 17:29:55 -0400 Subject: [PATCH 5/9] fixes --- pycbc/events/eventmgr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pycbc/events/eventmgr.py b/pycbc/events/eventmgr.py index 003956f89f4..3cde84c3c4a 100644 --- a/pycbc/events/eventmgr.py +++ b/pycbc/events/eventmgr.py @@ -149,7 +149,7 @@ def findchirp_cluster_over_window(times, values, window_length): indices = numpy.zeros(len(times), dtype=numpy.int32) tlen = len(times) - absvalues = numpy.asarray(abs(values), copy=False) + absvalues = numpy.asarray(abs(values)) times = numpy.asarray(times, dtype=numpy.int32) k = findchirp_cluster_over_window_cython(times, absvalues, window_length, indices, tlen) From fc135de0403491f7ac2810b8baecb39e72a5e731 Mon Sep 17 00:00:00 2001 From: Alexander Harvey Nitz Date: Wed, 4 Sep 2024 18:43:14 -0400 Subject: [PATCH 6/9] fix string issue --- bin/all_sky_search/pycbc_coinc_statmap | 4 ++-- bin/all_sky_search/pycbc_sngls_statmap | 4 ++-- pycbc/io/record.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/all_sky_search/pycbc_coinc_statmap b/bin/all_sky_search/pycbc_coinc_statmap index 8bdbca8bd0f..a0ff2eabcbf 100755 --- a/bin/all_sky_search/pycbc_coinc_statmap +++ b/bin/all_sky_search/pycbc_coinc_statmap @@ -508,9 +508,9 @@ f.attrs['hierarchical_removal_iterations'] = h_iterations # Write whether hierarchical removals were removed against the # inclusive background or the exclusive background. Have to use -# numpy.string_ datatype. +# numpy.bytes_ datatype. if h_iterations != 0: hrm_method = args.hierarchical_removal_against - f.attrs['hierarchical_removal_method'] = numpy.string_(hrm_method) + f.attrs['hierarchical_removal_method'] = numpy.bytes_(hrm_method) logging.info("Done") diff --git a/bin/all_sky_search/pycbc_sngls_statmap b/bin/all_sky_search/pycbc_sngls_statmap index 074214dbdda..57a1c5197ec 100755 --- a/bin/all_sky_search/pycbc_sngls_statmap +++ b/bin/all_sky_search/pycbc_sngls_statmap @@ -436,10 +436,10 @@ f.attrs['hierarchical_removal_iterations'] = h_iterations # Write whether hierarchical removals were removed against the # inclusive background or the exclusive background. Have to use -# numpy.string_ datatype. +# numpy.bytes_ datatype. if h_iterations != 0: hrm_method = args.hierarchical_removal_against - f.attrs['hierarchical_removal_method'] = numpy.string_(hrm_method) + f.attrs['hierarchical_removal_method'] = numpy.bytes_(hrm_method) logging.info("Done") diff --git a/pycbc/io/record.py b/pycbc/io/record.py index c287c2e5cc0..1fbc73aa176 100644 --- a/pycbc/io/record.py +++ b/pycbc/io/record.py @@ -1507,7 +1507,7 @@ def _isstring(dtype): """Given a numpy dtype, determines whether it is a string. Returns True if the dtype is string or unicode. """ - return dtype.type == numpy.unicode_ or dtype.type == numpy.string_ + return dtype.type == numpy.unicode_ or dtype.type == numpy.bytes_ def aliases_from_fields(fields): From cfb0a2c8cfe0a7c7ec37a1e998110f59466a6721 Mon Sep 17 00:00:00 2001 From: Alexander Harvey Nitz Date: Thu, 5 Sep 2024 17:23:29 -0400 Subject: [PATCH 7/9] be explicit about types in cases where the input might use type prediction --- pycbc/events/stat.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pycbc/events/stat.py b/pycbc/events/stat.py index ff8da9a2f19..7b7cec3281f 100644 --- a/pycbc/events/stat.py +++ b/pycbc/events/stat.py @@ -641,13 +641,13 @@ def logsignalrate(self, stats, shift, to_shift): # Get reference ifo information rate = numpy.zeros(len(shift), dtype=numpy.float32) - ps = {ifo: numpy.array(stats[ifo]['coa_phase'], ndmin=1) + ps = {ifo: numpy.array(stats[ifo]['coa_phase'], dtype=numpy.float32, ndmin=1) for ifo in self.ifos} - ts = {ifo: numpy.array(stats[ifo]['end_time'], ndmin=1) + ts = {ifo: numpy.array(stats[ifo]['end_time'], dtype=numpy.float64, ndmin=1) for ifo in self.ifos} - ss = {ifo: numpy.array(stats[ifo]['snr'], ndmin=1) + ss = {ifo: numpy.array(stats[ifo]['snr'], dtype=numpy.float32, ndmin=1) for ifo in self.ifos} - sigs = {ifo: numpy.array(stats[ifo]['sigmasq'], ndmin=1) + sigs = {ifo: numpy.array(stats[ifo]['sigmasq'], dtype=numpy.float32, ndmin=1) for ifo in self.ifos} for ref_ifo in self.ifos: rtype = rtypes[ref_ifo] From 76d81d35b4cb93e03549e5290ceb8ba74e9fb887 Mon Sep 17 00:00:00 2001 From: Alexander Harvey Nitz Date: Thu, 5 Sep 2024 17:54:47 -0400 Subject: [PATCH 8/9] this place too --- pycbc/events/stat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pycbc/events/stat.py b/pycbc/events/stat.py index 7b7cec3281f..3a163b5e20e 100644 --- a/pycbc/events/stat.py +++ b/pycbc/events/stat.py @@ -506,7 +506,7 @@ def get_hist(self, ifos=None): # renormalise to PDF self.weights[ifo] = \ - weights[ifo] / (weights[ifo].sum() * bin_volume) + (weights[ifo] / (weights[ifo].sum() * bin_volume)).astype(numpy.float32) if param[ifo].dtype == numpy.int8: # Older style, incorrectly sorted histogram file From 5f6bf9cb9998534b7cca09c3c71adc8c1c6f7eaf Mon Sep 17 00:00:00 2001 From: Alexander Harvey Nitz Date: Thu, 5 Sep 2024 18:00:33 -0400 Subject: [PATCH 9/9] cc --- pycbc/events/stat.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pycbc/events/stat.py b/pycbc/events/stat.py index 3a163b5e20e..e04ba732cad 100644 --- a/pycbc/events/stat.py +++ b/pycbc/events/stat.py @@ -506,7 +506,8 @@ def get_hist(self, ifos=None): # renormalise to PDF self.weights[ifo] = \ - (weights[ifo] / (weights[ifo].sum() * bin_volume)).astype(numpy.float32) + (weights[ifo] / (weights[ifo].sum() * bin_volume)) + self.weights[ifo] = self.weights[ifo].astype(numpy.float32) if param[ifo].dtype == numpy.int8: # Older style, incorrectly sorted histogram file @@ -641,13 +642,17 @@ def logsignalrate(self, stats, shift, to_shift): # Get reference ifo information rate = numpy.zeros(len(shift), dtype=numpy.float32) - ps = {ifo: numpy.array(stats[ifo]['coa_phase'], dtype=numpy.float32, ndmin=1) + ps = {ifo: numpy.array(stats[ifo]['coa_phase'], + dtype=numpy.float32, ndmin=1) for ifo in self.ifos} - ts = {ifo: numpy.array(stats[ifo]['end_time'], dtype=numpy.float64, ndmin=1) + ts = {ifo: numpy.array(stats[ifo]['end_time'], + dtype=numpy.float64, ndmin=1) for ifo in self.ifos} - ss = {ifo: numpy.array(stats[ifo]['snr'], dtype=numpy.float32, ndmin=1) + ss = {ifo: numpy.array(stats[ifo]['snr'], + dtype=numpy.float32, ndmin=1) for ifo in self.ifos} - sigs = {ifo: numpy.array(stats[ifo]['sigmasq'], dtype=numpy.float32, ndmin=1) + sigs = {ifo: numpy.array(stats[ifo]['sigmasq'], + dtype=numpy.float32, ndmin=1) for ifo in self.ifos} for ref_ifo in self.ifos: rtype = rtypes[ref_ifo]