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

Add KLU support to sundials #94930

Merged
merged 2 commits into from Sep 21, 2020
Merged

Conversation

GuillaumeDesforges
Copy link
Contributor

Motivation for this change

Add KLU support to sundials.
Needed for Haskell hmatrix-sparse for instance

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@GuillaumeDesforges
Copy link
Contributor Author

cc @idontgetoutmuch

@teto
Copy link
Member

teto commented Aug 8, 2020

I dont think it's linked but nixpkgs-review fails with

builder for '/nix/store/is15pq5q9s83qdzniasw5qcbl61gg0ah-python2.7-scikits.odes-2.6.1.drv' failed with exit code 2; last 10 log lines:
  ImportError while importing test module '/nix/store/2p2pbr3i0g66x802f9b2kgqccz42hc07-python2.7-scikits.odes-2.6.1/lib/python2.7/site-packages/scikits/odes/tests/test_user_return_vals_ida.py'.
  Hint: make sure your test modules/packages have valid Python names.
  Traceback:
  test_user_return_vals_ida.py:5: in <module>
      from ..sundials.ida import StatusEnumIDA
  scikits/odes/sundials/ida.pyx:1: in init scikits.odes.sundials.ida
      ???
  E   ImportError: No module named scikits.odes.sundials.common_defs
  !!!!!!!!!!!!!!!!!!! Interrupted: 8 errors during collection !!!!!!!!!!!!!!!!!!!!
  =========================== 8 error in 0.45 seconds ============================
[3 built (1 failed), 63 copied (465.4 MiB), 109.3 MiB DL]
error: error: --- Error --- nix-daemon
1 dependencies of derivation '/nix/store/6pf7pka6zgksbwbgnc1yxyr8j3wwq5ya-env.drv' failed to build
https://github.com/NixOS/nixpkgs/pull/94930
1 package failed to build:
python27Packages.scikits-odes

3 packages built:
python37Packages.scikits-odes python38Packages.scikits-odes sundials

Isn't adding suitesparse to buildInputs enough ?

@doronbehar
Copy link
Contributor

@GuillaumeDesforges you should rebase on latest master, for those that don't use nixpkgs-review :).

@teto with this patch:

diff --git i/pkgs/development/libraries/sundials/default.nix w/pkgs/development/libraries/sundials/default.nix
index 74907ee1cc9..d69b09ade07 100644
--- i/pkgs/development/libraries/sundials/default.nix
+++ w/pkgs/development/libraries/sundials/default.nix
@@ -15,7 +15,18 @@ stdenv.mkDerivation rec {
   pname = "sundials";
   version = "5.3.0";
 
-  buildInputs = [ python ] ++ stdenv.lib.optionals (lapackSupport) [ gfortran blas lapack ];
+  buildInputs = [
+    python
+  ]
+  ++ stdenv.lib.optionals (lapackSupport) [
+    gfortran
+    blas
+    lapack
+  ]
+  ++ stdenv.lib.optionals (kluSupport) [
+    suitesparse
+  ]
+  ;
   nativeBuildInputs = [ cmake ];
 
   src = fetchurl {
@@ -39,8 +50,8 @@ stdenv.mkDerivation rec {
     "-DLAPACK_LIBRARIES=${lapack}/lib/liblapack${stdenv.hostPlatform.extensions.sharedLibrary}"
   ] ++ stdenv.lib.optionals (kluSupport) [
     "-DKLU_ENABLE=ON"
-    "-DKLU_INCLUDE_DIR=${suitesparse.dev}/include"
-    "-DKLU_LIBRARY_DIR=${suitesparse}/lib"
+    # "-DKLU_INCLUDE_DIR=${suitesparse.dev}/include"
+    # "-DKLU_LIBRARY_DIR=${suitesparse}/lib"
   ];
 
   doCheck = true;

I got this cmake warnings:

CMake Warning at config/SundialsCMakeMacros.cmake:83 (message):
  ------------------------------------------------------------------------

  WARNING: KLU LIBRARIES NOT Found.  Please check library path



  ------------------------------------------------------------------------
Call Stack (most recent call first):
  config/SundialsKLU.cmake:72 (print_warning)
  CMakeLists.txt:1020 (include)


-- Looking for KLU libraries... FAILED

However, I'd still put suitesparse in buildInputs, although it's probably referenced anyway - to prevent ambiguity for cross compilations (experts might know that this is still not needed, but I'm not a NixOS' cross compiles expert :)).


Regarding scikit-odes' failure in tests - perhaps we should disable it for Python2 interpreters?

@idontgetoutmuch
Copy link
Contributor

Regarding scikit-odes' failure in tests - perhaps we should disable it for Python2 interpreters?

@doronbehar Agreed but I don't know how to do this. If I look in scikits-odes/default.nix I see nothing that specifies the version of python to use (or not use).

@doronbehar
Copy link
Contributor

git grep disabledIf

@GuillaumeDesforges
Copy link
Contributor Author

GuillaumeDesforges commented Aug 8, 2020

Got it rebased.

It was indeed required to explicit CMAKE flags.
I'll put it in buildInputs as well.

@idontgetoutmuch if I remember correctly there is a isPy3 attribute passed to buildPythonPackage, and one can set the attribute disabled.
I've looked at nixpkgs manual and did not find info about that, it must be missing.

EDIT: Ah got it

isPy3 = lib.strings.substring 0 1 pythonVersion == "3";

@doronbehar
Copy link
Contributor

You need disabledIf = python.isPy2.

@GuillaumeDesforges
Copy link
Contributor Author

I get an error stating

anonymous function at /home/arsleust/.cache/nixpkgs-review/rev-0d43a96e27f0f905b72c9d786de69e70a21c3565/nixpkgs/pkgs/development/python-modules/scikits-odes/default.nix:1:1 called without required argument 'isPy2'

Isn't isPy2 part of the passthru ?

@doronbehar
Copy link
Contributor

Github's actions marking this as failed are a false negative.

@GrahamcOfBorg build python2Packages.scikit-odes python3Packages.scikit-odes

Copy link
Contributor

@jonringer jonringer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise LGTM

pkgs/development/libraries/sundials/default.nix Outdated Show resolved Hide resolved
@doronbehar
Copy link
Contributor

@GrahamcOfBorg build python27Packages.scikits-odes python3Packages.scikits-odes

Copy link
Contributor

@doronbehar doronbehar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Diff LGTM, but I'd only kindly ask to make the last commit message a bit more precise:

python2Packages.scikits-odes: disable

Ever since we added KLU support to sundials (#94930),
it stopped building while the Python 3 versions didn't
break. Python 2 is EOL.

Copy link
Contributor

@doronbehar doronbehar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍.

, lapackSupport ? true }:
, suitesparse
, lapackSupport ? true
, kluSupport ? true }:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make the default false so as not to break other packages which might use this? For example, scikits-odes does not need kluSupport.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better is make kluSupport false when building scikits-odes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are the klu related packages likely to break the build?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is necessary to disable klu support in sundials for scikits-odes, since build+test is ok.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Via some conditionals, it could be disabled only for python2Packages.scikits-odes :) but TBH I wouldn't see benefit in this effort - according to git grep, there are no reverse dependencies of python2Packages.scikits-odes available, and Python 2 is EOL (!!). python3Packages.scikits-odes builds fine.

are the klu related packages likely to break the build?

What do you mean @jonringer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The biggest argument against adding "optional" dependencies by default is that it makes more fragile since there's another point of potential failure (either the dependency doesn't build, or the dependency gets bumped and is no longer compatible).

That's the concern I'm expressing.

Unless the klu library is prone to breakages, we should probably add it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either the dependency doesn't build

suitesparse is what provides KLU support for sundials (IDK what that even means). Suitesparse seems well maintained to me, both upstream and at Nixpkgs.

or the dependency gets bumped and is no longer compatible

The best we can do is to trust Sundials to test it with the current versions of suitesparse we ship. @GuillaumeDesforges perhaps it'll be nice to note in a comment near the conditional kluSupport, that this feature is tested by upstream according to the INSTALL_GUIDE.pdf, section 1.1.4. Currently they write there:

The KLU libraries are part of SuiteSparse, a suite of sparse matrix software, available from the TexasA&M University website:http://faculty.cse.tamu.edu/davis/suitesparse.html.sundialshasbeen tested with SuiteSparse version 5.3.0

While we ship version 5.7.2 of suitesparse, so IDK 🙆‍♀️.

As a side note, I also support enabling this feature by default, for GNU Octave 6.0.0 which is about to be released. It will require this feature as well from this major version of sundials (5) . Currently Octave uses an old version of sundials with this feature enabled as well, see https://github.com/NixOS/nixpkgs/pull/79864/files#diff-a71f6e05947eac8bd8360ddb7faa9693 .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the issue. As with most nixpkgs packages, if sundials requires a bumped version of suitesparse we can just upgrade suitesparse, and if it breaks other packages we can create another bumped package like suitesparse_X_X_X (like in the Haskell infrastructure where multiple versions of a package live).

Suitesparse seems well maintained to me, both upstream and at Nixpkgs.

Agreed, I would have been more concerned if it wasn't the case but it seems we are relatively safe here

Guillaume Desforges added 2 commits August 19, 2020 10:33
Ever since we added KLU support to sundials (NixOS#94930),
it stopped building while the Python 3 versions didn't
break. Python 2 is EOL.
Copy link
Contributor

@doronbehar doronbehar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 on adding commenting the link to upstream's INSTALL_GUIDE.pdf.

@GuillaumeDesforges
Copy link
Contributor Author

@jonringer is there anything left to do in order for this to be merged ?

@doronbehar
Copy link
Contributor

@jonringer I'm now testing the release candidate of Octave 6 which needs sundials with this patch, otherwise:

configure: WARNING: SUNDIALS IDA library not configured with SUNLINSOL_KLU or sunlinksol_klu.h is not usable.  The solvers ode15i and ode15s will not support the sparse Jacobian feature.

Is there anything left here to do / any objections left?

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/openblas-vs-reference-blas-implementation/9086/1

@idontgetoutmuch
Copy link
Contributor

@flokli @FRidh @jonringer Can I help with anything to get this PR accepted?

Copy link
Contributor

@jonringer jonringer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Result of nixpkgs-review pr 94930 1

3 packages built:
  • python37Packages.scikits-odes
  • python38Packages.scikits-odes
  • sundials

@jonringer jonringer merged commit 4e888fb into NixOS:master Sep 21, 2020
@GuillaumeDesforges GuillaumeDesforges deleted the pr/sundials-klu branch September 22, 2020 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants