JohannesBuchner / UltraNest

Fit and compare complex models reliably and rapidly. Advanced nested sampling.
https://johannesbuchner.github.io/UltraNest/
Other
142 stars 30 forks source link

Difficulty installing Ultranest versions prior to 3.6.2 #105

Closed jpl-jengelke closed 10 months ago

jpl-jengelke commented 1 year ago

Description

Due to the issue reported about installation failures post Cython update, recent versions of Ultranest do not install under normal circumstances. This issue is detailed in #102. In fact, due to the low-level nature of pyproject.toml metadata and Cython set in the requires block, it appears that no version between 3.4.3 (when pyproject.toml was added) and 3.6.1 will install.

What I Did

pip3 install ultranest==3.5.6
...
Using cached ultranest-3.5.6.tar.gz (21.5 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error
  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [38 lines of output]
      Error compiling Cython file:
      ------------------------------------------------------------
      ...
                  # only consider points in the same cluster
                  if clusterids[j] == clusterids[i]:
                      pair_dist = 0.0
                      for k in range(ndim):
                          pair_dist += (pts[i,k] - pts[j,k])**2
                      total_dist += pair_dist**0.5
                      ^
      ------------------------------------------------------------
      ultranest/mlfriends.pyx:180:16: Cannot assign type 'npy_double complex' to 'float_t'
      Compiling ultranest/mlfriends.pyx because it changed.
      Compiling ultranest/stepfuncs.pyx because it changed.
      [1/2] Cythonizing ultranest/mlfriends.pyx
      Traceback (most recent call last):
        File "/Users/workstation_user/Library/Python/3.9/lib/python/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/Users/workstation_user/Library/Python/3.9/lib/python/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/Users/workstation_user/Library/Python/3.9/lib/python/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
        File "/private/var/folders/4f/_sx0_jyn68lbtbf6_plcryq80000gq/T/pip-build-env-gh0s6nnw/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 341, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
        File "/private/var/folders/4f/_sx0_jyn68lbtbf6_plcryq80000gq/T/pip-build-env-gh0s6nnw/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 323, in _get_build_requires
          self.run_setup()
        File "/private/var/folders/4f/_sx0_jyn68lbtbf6_plcryq80000gq/T/pip-build-env-gh0s6nnw/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 487, in run_setup
          super(_BuildMetaLegacyBackend,
        File "/private/var/folders/4f/_sx0_jyn68lbtbf6_plcryq80000gq/T/pip-build-env-gh0s6nnw/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 338, in run_setup
          exec(code, locals())
        File "<string>", line 58, in <module>
        File "/private/var/folders/4f/_sx0_jyn68lbtbf6_plcryq80000gq/T/pip-build-env-gh0s6nnw/overlay/lib/python3.9/site-packages/Cython/Build/Dependencies.py", line 1134, in cythonize
          cythonize_one(*args)
        File "/private/var/folders/4f/_sx0_jyn68lbtbf6_plcryq80000gq/T/pip-build-env-gh0s6nnw/overlay/lib/python3.9/site-packages/Cython/Build/Dependencies.py", line 1301, in cythonize_one
          raise CompileError(None, pyx_file)
      Cython.Compiler.Errors.CompileError: ultranest/mlfriends.pyx
      [end of output]
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
...
jpl-jengelke commented 1 year ago

The following command (or similar) should allow the install to proceed by disabling build isolation:

pip3 install --no-cache-dir --no-build-isolation -c constraints.txt ultranest==3.5.6 

... with the constraints.txt file set to ...

Cython==0.29.36

Posted here for posterity.

JohannesBuchner commented 1 year ago

Thank you John, that is helpful!

jpl-jengelke commented 1 year ago

Build failures with Cython 3.x aren't unusual, see https://github.com/cython/cython/issues/5305. That's because amongst other very low-level changes, Cython used different compiler settings (language level 3 vs. language level 2). So it was not unique to experience a compile failure.

I just also want to point out that the changes are fairly extensive (version 0.x to 3.x) so any detailed testing that can be completed would be beneficial to validate with the updated library.

You could always pin Cython to a specific version in the pyproject.toml (Cython==0.29.36) if there was a very bad issue discovered but that won't repair previously released versions and also many of the Cython changes (especially those that support newer Python versions) look great.

JohannesBuchner commented 10 months ago

I am closing this for now, please reopen if there is more that should be done.