Skip to content

Test suite fails with numpy 2.4 #5247

@duncanmmacleod

Description

@duncanmmacleod

When PyCBC 2.9.0 is installed alongside NumPy 2.4.0, the test suite fails:

 =========================== short test summary info ============================
 FAILED test/test_coordinates_space.py::TestParams::test_polarization - ValueError: setting an array element with a sequence.
 FAILED test/test_coordinates_space.py::TestParams::test_round_robin - ValueError: setting an array element with a sequence.
 FAILED test/test_transforms.py::TestTransforms::test_inverse - ValueError: setting an array element with a sequence.
 =========== 3 failed, 1486 passed, 179 warnings in 300.92s (0:05:00) ===========
Test output
 =================================== FAILURES ===================================
 _________________________ TestTransforms.test_inverse __________________________
 [gw5] linux -- Python 3.13.11 $PREFIX/bin/python
 TypeError: only 0-dimensional arrays can be converted to Python scalars
 The above exception was the direct cause of the following exception:
 self = <test_transforms.TestTransforms testMethod=test_inverse>
     def test_inverse(self):

         # set threshold how similar values must be
         threshold = 0.001

         # loop over forward CBC transforms
         for trans in transforms.common_cbc_forward_transforms:

             # check if inverse exists
             if trans.name in IGNORE:
                 continue
             if trans.name == 'spherical_to_cartesian':
                 # spherical to cartesian requires the cartesian and spherical
                 # parameter names to be specified, which we can get from
                 # the inputs and outputs
                 inv = trans.inverse(*trans._outputs+trans._inputs)
             else:
                 inv = trans.inverse()

             # generate some random points
             in_map = {p : numpy.random.uniform(*RANGES[p])
                       for p in trans.inputs}

             # transforms to and back from inverse transform
 >           intermediate_map = trans.transform(in_map)
                                ^^^^^^^^^^^^^^^^^^^^^^^
 test/test_transforms.py:89:
 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
 ../../../../../lib/python3.13/site-packages/pycbc/transforms.py:1760: in transform
     coordinates.lisa_to_ssb(
 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
 t_lisa = array([1.4344372e+09]), longitude_lisa = array([5.59191642])
 latitude_lisa = array([-0.98433729]), polarization_lisa = array([0.31400451])
 t0 = 7365189.431698299
     def lisa_to_ssb(t_lisa, longitude_lisa, latitude_lisa, polarization_lisa,
                     t0=TIME_OFFSET_20_DEGREES):
         """ Converting the arrive time, the sky localization, and the polarization
         from the LISA frame to the SSB frame.

         Parameters
         ----------
         t_lisa : float or numpy.array
             The time when a GW signal arrives at the origin of LISA frame.
             In the unit of 's'.
         longitude_lisa : float or numpy.array
             The longitude of a GW signal in LISA frame, in the unit of 'radian'.
         latitude_lisa : float or numpy.array
             The latitude of a GW signal in LISA frame, in the unit of 'radian'.
         polarization_lisa : float or numpy.array
             The polarization angle of a GW signal in LISA frame.
             In the unit of 'radian'.
         t0 : float
             The initial time offset of LISA, in the unit of 's',
             default is 7365189.431698299. This makes sure LISA is behind
             the Earth by 19-23 degrees.

         Returns
         -------
         (t_ssb, longitude_ssb, latitude_ssb, polarization_ssb) : tuple
         t_ssb : float or numpy.array
             The time when a GW signal arrives at the origin of SSB frame.
             In the unit of 's'.
         longitude_ssb : float or numpy.array
             The ecliptic longitude of a GW signal in SSB frame.
             In the unit of 'radian'.
         latitude_ssb : float or numpy.array
             The ecliptic latitude of a GW signal in SSB frame.
             In the unit of 'radian'.
         polarization_ssb : float or numpy.array
             The polarization angle of a GW signal in SSB frame.
             In the unit of 'radian'.
         """
         if not isinstance(t_lisa, np.ndarray):
             t_lisa = np.array([t_lisa])
         if not isinstance(longitude_lisa, np.ndarray):
             longitude_lisa = np.array([longitude_lisa])
         if not isinstance(latitude_lisa, np.ndarray):
             latitude_lisa = np.array([latitude_lisa])
         if not isinstance(polarization_lisa, np.ndarray):
             polarization_lisa = np.array([polarization_lisa])
         num = len(t_lisa)
         t_ssb, longitude_ssb = np.zeros(num), np.zeros(num)
         latitude_ssb, polarization_ssb = np.zeros(num), np.zeros(num)

         for i in range(num):
             if longitude_lisa[i] < 0 or longitude_lisa[i] >= 2*np.pi:
                 raise ValueError("Longitude should within [0, 2*pi).")
             if latitude_lisa[i] < -np.pi/2 or latitude_lisa[i] > np.pi/2:
                 raise ValueError("Latitude should within [-pi/2, pi/2].")
             if polarization_lisa[i] < 0 or polarization_lisa[i] >= 2*np.pi:
                 raise ValueError("Polarization angle should within [0, 2*pi).")
             k_lisa = localization_to_propagation_vector(
                         longitude_lisa[i], latitude_lisa[i], use_astropy=False)
             alpha = lisa_position_ssb(t_lisa[i], t0)[1]
             rotation_matrix_lisa = rotation_matrix_ssb_to_lisa(alpha)
             k_ssb = rotation_matrix_lisa @ k_lisa
 >           longitude_ssb[i], latitude_ssb[i] = \
             ^^^^^^^^^^^^^^^^
                 propagation_vector_to_localization(k_ssb, use_astropy=False)
 E           ValueError: setting an array element with a sequence.
 ../../../../../lib/python3.13/site-packages/pycbc/coordinates/space.py:469: ValueError
 _________________________ TestParams.test_polarization _________________________
 [gw12] linux -- Python 3.13.11 $PREFIX/bin/python
 TypeError: only 0-dimensional arrays can be converted to Python scalars
 The above exception was the direct cause of the following exception:
 self = <test_coordinates_space.TestParams testMethod=test_polarization>
 args = ()
 random_params = {'dec': array([-0.33639643,  0.80848746, -0.34438349,  1.19308762,  0.9189406 ,
        -0.82951919,  0.70142564,  0.79...10145772, 2.20570458, 3.84691496, 5.33162389,
        1.19861818, 3.64426802, 1.65732168, 4.46965912, 3.98506202]), ...}
     def setUp(self, *args):
         self.numtests = 1000
         self.precision = 1e-8

         # generate some random points
         random_params = {
             p : numpy.random.uniform(*RANGES[p], size=self.numtests)
             for p in RANGES.keys()}
         self.tc_ssb = random_params['tc_ssb']
         self.eclipticlongitude_ssb = random_params['eclipticlongitude_ssb']
         self.eclipticlatitude_ssb = random_params['eclipticlatitude_ssb']
         self.polarization_ssb = random_params['polarization_ssb']
         self.tc_lisa = random_params['tc_lisa']
         self.eclipticlongitude_lisa = random_params['eclipticlongitude_lisa']
         self.eclipticlatitude_lisa = random_params['eclipticlatitude_lisa']
         self.polarization_lisa = random_params['polarization_lisa']
         self.tc_geo = random_params['tc_geo']
         self.ra = random_params['ra']
         self.dec = random_params['dec']
         self.polarization_geo = random_params['polarization_geo']

         # calculate derived parameters from each

         self.tc_lisa_derived, self.eclipticlongitude_lisa_derived, \
         self.eclipticlatitude_lisa_derived, self.polarization_lisa_derived = \
 >           space.ssb_to_lisa(
                 self.tc_ssb, self.eclipticlongitude_ssb,
                 self.eclipticlatitude_ssb, self.polarization_ssb)
 test/test_coordinates_space.py:88:
 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
 t_ssb = array([1.33680141e+09, 1.29422756e+09, 1.14098455e+09, 1.40728069e+09,
        1.25838627e+09, 1.31188043e+09, 1.223583...1.29377547e+09, 1.12793644e+09, 1.40735977e+09,
        1.41904480e+09, 1.25491378e+09, 1.35304270e+09, 1.39808838e+09])
 longitude_ssb = array([2.60070338e-01, 5.48188188e+00, 4.38472288e+00, 1.58125393e+00,
        1.26761303e+00, 3.41903626e-01, 4.784304...5.20867626e+00, 2.71968959e+00, 2.35993473e+00,
        1.65422276e+00, 5.38213580e-01, 2.08200820e+00, 1.12469050e+00])
 latitude_ssb = array([ 5.84105573e-01,  1.40230022e+00, -1.11195725e-01,  1.31886908e+00,
         2.64627477e-01,  1.42831671e+00,  2...7173e+00,  6.65735854e-01,  1.40964481e+00,
         1.25257099e-01, -1.17945276e+00,  1.22031838e+00,  7.11912978e-01])
 polarization_ssb = array([5.73711568, 5.63964004, 3.89503573, 5.76020388, 3.50695097,
        4.73038906, 5.03744584, 3.27574113, 1.330592...4 , 2.09677429, 1.77985484, 4.55844081, 3.01370268,
        1.78801786, 3.73686422, 5.94181487, 4.60800551, 0.10870443])
 t0 = 7365189.431698299
     def ssb_to_lisa(t_ssb, longitude_ssb, latitude_ssb, polarization_ssb,
                     t0=TIME_OFFSET_20_DEGREES):
         """ Converting the arrive time, the sky localization, and the polarization
         from the SSB frame to the LISA frame.

         Parameters
         ----------
         t_ssb : float or numpy.array
             The time when a GW signal arrives at the origin of SSB frame.
             In the unit of 's'.
         longitude_ssb : float or numpy.array
             The ecliptic longitude of a GW signal in SSB frame.
             In the unit of 'radian'.
         latitude_ssb : float or numpy.array
             The ecliptic latitude of a GW signal in SSB frame.
             In the unit of 'radian'.
         polarization_ssb : float or numpy.array
             The polarization angle of a GW signal in SSB frame.
             In the unit of 'radian'.
         t0 : float
             The initial time offset of LISA, in the unit of 's',
             default is 7365189.431698299. This makes sure LISA is behind
             the Earth by 19-23 degrees.

         Returns
         -------
         (t_lisa, longitude_lisa, latitude_lisa, polarization_lisa) : tuple
         t_lisa : float or numpy.array
             The time when a GW signal arrives at the origin of LISA frame.
             In the unit of 's'.
         longitude_lisa : float or numpy.array
             The longitude of a GW signal in LISA frame, in the unit of 'radian'.
         latitude_lisa : float or numpy.array
             The latitude of a GW signal in LISA frame, in the unit of 'radian'.
         polarization_lisa : float or numpy.array
             The polarization angle of a GW signal in LISA frame.
             In the unit of 'radian'.
         """
         if not isinstance(t_ssb, np.ndarray):
             t_ssb = np.array([t_ssb])
         if not isinstance(longitude_ssb, np.ndarray):
             longitude_ssb = np.array([longitude_ssb])
         if not isinstance(latitude_ssb, np.ndarray):
             latitude_ssb = np.array([latitude_ssb])
         if not isinstance(polarization_ssb, np.ndarray):
             polarization_ssb = np.array([polarization_ssb])
         num = len(t_ssb)
         t_lisa, longitude_lisa = np.zeros(num), np.zeros(num)
         latitude_lisa, polarization_lisa = np.zeros(num), np.zeros(num)

         for i in range(num):
             if longitude_ssb[i] < 0 or longitude_ssb[i] >= 2*np.pi:
                 raise ValueError("Longitude should within [0, 2*pi).")
             if latitude_ssb[i] < -np.pi/2 or latitude_ssb[i] > np.pi/2:
                 raise ValueError("Latitude should within [-pi/2, pi/2].")
             if polarization_ssb[i] < 0 or polarization_ssb[i] >= 2*np.pi:
                 raise ValueError("Polarization angle should within [0, 2*pi).")
             t_lisa[i] = t_lisa_from_ssb(t_ssb[i], longitude_ssb[i],
                                         latitude_ssb[i], t0)
             k_ssb = localization_to_propagation_vector(
                         longitude_ssb[i], latitude_ssb[i], use_astropy=False)
             # Although t_lisa calculated above using the corrected LISA position
             # vector by adding t0, it corresponds to the true t_ssb, not t_ssb+t0,
             # we need to include t0 again to correct LISA position.
             alpha = lisa_position_ssb(t_lisa[i], t0)[1]
             rotation_matrix_lisa = rotation_matrix_ssb_to_lisa(alpha)
             k_lisa = rotation_matrix_lisa.T @ k_ssb
 >           longitude_lisa[i], latitude_lisa[i] = \
             ^^^^^^^^^^^^^^^^^
                 propagation_vector_to_localization(k_lisa, use_astropy=False)
 E           ValueError: setting an array element with a sequence.
 ../../../../../lib/python3.13/site-packages/pycbc/coordinates/space.py:391: ValueError
 _________________________ TestParams.test_round_robin __________________________
 [gw12] linux -- Python 3.13.11 $PREFIX/bin/python
 TypeError: only 0-dimensional arrays can be converted to Python scalars
 The above exception was the direct cause of the following exception:
 self = <test_coordinates_space.TestParams testMethod=test_round_robin>
 args = ()
 random_params = {'dec': array([ 2.90688847e-01, -1.05056870e+00, -6.30541678e-01,  4.19412930e-01,
         7.00950776e-02, -1.53758806...3835e+00, 4.10786242e+00, 8.84470662e-01,
        2.82540622e+00, 3.90863397e-01, 3.90993527e+00, 4.95435601e+00]), ...}
     def setUp(self, *args):
         self.numtests = 1000
         self.precision = 1e-8

         # generate some random points
         random_params = {
             p : numpy.random.uniform(*RANGES[p], size=self.numtests)
             for p in RANGES.keys()}
         self.tc_ssb = random_params['tc_ssb']
         self.eclipticlongitude_ssb = random_params['eclipticlongitude_ssb']
         self.eclipticlatitude_ssb = random_params['eclipticlatitude_ssb']
         self.polarization_ssb = random_params['polarization_ssb']
         self.tc_lisa = random_params['tc_lisa']
         self.eclipticlongitude_lisa = random_params['eclipticlongitude_lisa']
         self.eclipticlatitude_lisa = random_params['eclipticlatitude_lisa']
         self.polarization_lisa = random_params['polarization_lisa']
         self.tc_geo = random_params['tc_geo']
         self.ra = random_params['ra']
         self.dec = random_params['dec']
         self.polarization_geo = random_params['polarization_geo']

         # calculate derived parameters from each

         self.tc_lisa_derived, self.eclipticlongitude_lisa_derived, \
         self.eclipticlatitude_lisa_derived, self.polarization_lisa_derived = \
 >           space.ssb_to_lisa(
                 self.tc_ssb, self.eclipticlongitude_ssb,
                 self.eclipticlatitude_ssb, self.polarization_ssb)
 test/test_coordinates_space.py:88:
 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
 t_ssb = array([1.32494813e+09, 1.33140895e+09, 1.39047222e+09, 1.16851208e+09,
        1.23891304e+09, 1.20162314e+09, 1.234113...1.30286822e+09, 1.18806325e+09, 1.42458068e+09,
        1.26791445e+09, 1.12768237e+09, 1.25629650e+09, 1.35131650e+09])
 longitude_ssb = array([7.06679524e-01, 2.69784642e+00, 2.28026862e+00, 5.45533684e-01,
        4.32269135e+00, 4.69728903e+00, 2.287278...3.01613674e+00, 5.38055955e-01, 5.64080390e+00,
        5.73482375e+00, 3.18498501e+00, 2.23359563e+00, 5.42126872e+00])
 latitude_ssb = array([-1.42486079e+00,  1.02036376e-01,  3.94432200e-01,  1.11669860e+00,
         7.67397744e-01, -1.31178796e+00, -7...9308e-01,  6.98803791e-01,  2.72341355e-01,
         8.43162212e-01,  8.99034810e-01,  2.67883282e-01,  1.46943539e+00])
 polarization_ssb = array([6.16003300e+00, 3.89003801e+00, 3.12358857e-01, 8.47181277e-01,
        3.65420674e+00, 4.94634350e+00, 2.112959...2.90494507e+00, 9.93781085e-03, 4.63602878e+00,
        6.03675418e+00, 3.28364294e+00, 2.41583307e+00, 1.73933328e+00])
 t0 = 7365189.431698299
     def ssb_to_lisa(t_ssb, longitude_ssb, latitude_ssb, polarization_ssb,
                     t0=TIME_OFFSET_20_DEGREES):
         """ Converting the arrive time, the sky localization, and the polarization
         from the SSB frame to the LISA frame.

         Parameters
         ----------
         t_ssb : float or numpy.array
             The time when a GW signal arrives at the origin of SSB frame.
             In the unit of 's'.
         longitude_ssb : float or numpy.array
             The ecliptic longitude of a GW signal in SSB frame.
             In the unit of 'radian'.
         latitude_ssb : float or numpy.array
             The ecliptic latitude of a GW signal in SSB frame.
             In the unit of 'radian'.
         polarization_ssb : float or numpy.array
             The polarization angle of a GW signal in SSB frame.
             In the unit of 'radian'.
         t0 : float
             The initial time offset of LISA, in the unit of 's',
             default is 7365189.431698299. This makes sure LISA is behind
             the Earth by 19-23 degrees.

         Returns
         -------
         (t_lisa, longitude_lisa, latitude_lisa, polarization_lisa) : tuple
         t_lisa : float or numpy.array
             The time when a GW signal arrives at the origin of LISA frame.
             In the unit of 's'.
         longitude_lisa : float or numpy.array
             The longitude of a GW signal in LISA frame, in the unit of 'radian'.
         latitude_lisa : float or numpy.array
             The latitude of a GW signal in LISA frame, in the unit of 'radian'.
         polarization_lisa : float or numpy.array
             The polarization angle of a GW signal in LISA frame.
             In the unit of 'radian'.
         """
         if not isinstance(t_ssb, np.ndarray):
             t_ssb = np.array([t_ssb])
         if not isinstance(longitude_ssb, np.ndarray):
             longitude_ssb = np.array([longitude_ssb])
         if not isinstance(latitude_ssb, np.ndarray):
             latitude_ssb = np.array([latitude_ssb])
         if not isinstance(polarization_ssb, np.ndarray):
             polarization_ssb = np.array([polarization_ssb])
         num = len(t_ssb)
         t_lisa, longitude_lisa = np.zeros(num), np.zeros(num)
         latitude_lisa, polarization_lisa = np.zeros(num), np.zeros(num)

         for i in range(num):
             if longitude_ssb[i] < 0 or longitude_ssb[i] >= 2*np.pi:
                 raise ValueError("Longitude should within [0, 2*pi).")
             if latitude_ssb[i] < -np.pi/2 or latitude_ssb[i] > np.pi/2:
                 raise ValueError("Latitude should within [-pi/2, pi/2].")
             if polarization_ssb[i] < 0 or polarization_ssb[i] >= 2*np.pi:
                 raise ValueError("Polarization angle should within [0, 2*pi).")
             t_lisa[i] = t_lisa_from_ssb(t_ssb[i], longitude_ssb[i],
                                         latitude_ssb[i], t0)
             k_ssb = localization_to_propagation_vector(
                         longitude_ssb[i], latitude_ssb[i], use_astropy=False)
             # Although t_lisa calculated above using the corrected LISA position
             # vector by adding t0, it corresponds to the true t_ssb, not t_ssb+t0,
             # we need to include t0 again to correct LISA position.
             alpha = lisa_position_ssb(t_lisa[i], t0)[1]
             rotation_matrix_lisa = rotation_matrix_ssb_to_lisa(alpha)
             k_lisa = rotation_matrix_lisa.T @ k_ssb
 >           longitude_lisa[i], latitude_lisa[i] = \
             ^^^^^^^^^^^^^^^^^
                 propagation_vector_to_localization(k_lisa, use_astropy=False)
 E           ValueError: setting an array element with a sequence.
 ../../../../../lib/python3.13/site-packages/pycbc/coordinates/space.py:391: ValueError
 =============================== warnings summary ===============================
 ../../../../../lib/python3.13/site-packages/astropy/cosmology/core.py:30: 16 warnings
   $PREFIX/lib/python3.13/site-packages/astropy/cosmology/core.py:30: DeprecationWarning: The module `astropy.cosmology.core` is deprecated since v7.1 and will be removed in a future version. Import from `as
 tropy.cosmology` instead.
     warnings.warn(
 test/test_io_gracedb.py: 10 warnings
   $PREFIX/lib/python3.13/site-packages/pycbc/io/ligolw.py:267: DeprecationWarning: `row_stack` alias is deprecated. Use `np.vstack` directly.
     data = numpy.row_stack((
 test/test_io_gracedb.py: 10 warnings
   $PREFIX/lib/python3.13/site-packages/pycbc/io/ligolw.py:273: DeprecationWarning: `row_stack` alias is deprecated. Use `np.vstack` directly.
     data = numpy.row_stack((
 test/test_injection.py::TestInjection::test_injection_presence
   $PREFIX/lib/python3.13/site-packages/pycbc/waveform/waveform.py:372: DeprecationWarning: numpy.core is deprecated and has been renamed to numpy._core. The numpy._core namespace contains private NumPy inte
 rnals and its use is discouraged, as NumPy internals can change without warning in any release. In practice, most real-world usage of numpy.core is to access functionality in the public NumPy API. If that i
 s the case, use the public NumPy API. If not, you are using NumPy internals. If you would still like to access an internal attribute, use numpy._core.records.
     if isinstance(obj, numpy.core.records.record):
 test/test_infmodel.py::TestModels::test_brute_pol_phase_marg
 test/test_infmodel.py::TestWaveformErrors::test_brute_pol_phase_marg
 test/test_infmodel.py::TestMarginalizedPolModels::test_gaussian_models
   $PREFIX/lib/python3.13/site-packages/pycbc/inference/models/tools.py:136: DeprecationWarning: use marginalize_vector_samples rather than 'polarization_samples'
     warnings.warn("use marginalize_vector_samples rather "
 test/test_infmodel.py::TestModels::test_brute_pol_phase_marg
 test/test_infmodel.py::TestWaveformErrors::test_brute_pol_phase_marg
   $PREFIX/lib/python3.13/multiprocessing/popen_fork.py:67: DeprecationWarning: This process (pid=367286) is multi-threaded, use of fork() may lead to deadlocks in the child.
     self.pid = os.fork()
 test/test_infmodel.py::TestModels::test_relative_phase_marg
 test/test_infmodel.py::TestModels::test_relative_phase_marg
 test/test_infmodel.py::TestWaveformErrors::test_relative_phase_marg
   $PREFIX/lib/python3.13/site-packages/pycbc/inference/models/relbin.py:226: DeprecationWarning: __array__ implementation doesn't accept a copy keyword, so passing copy=False failed. __array__ must implemen
 t 'dtype' and 'copy' keyword arguments. To learn more, see the migration guide https://numpy.org/devdocs/numpy_2_0_migration_guide.html#adapting-to-changes-in-the-copy-keyword
     self.f[ifo] = numpy.array(d0.sample_frequencies)
 - Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions