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

scikit-survival: init at 0.11 #82410

Merged
merged 1 commit into from
Aug 12, 2021

Conversation

GuillaumeDesforges
Copy link
Contributor

@GuillaumeDesforges GuillaumeDesforges commented Mar 12, 2020

Motivation for this change

Add scikit-survival to nixpkgs

https://github.com/sebp/scikit-survival

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.

Motivation

scikit-survival was missing from nixpkgs

Notes

Had to PR the package because of requirements issues.
Will put back src on actual source when PR is merged.
See sebp/scikit-survival#98

@GuillaumeDesforges
Copy link
Contributor Author

@ofborg ofborg bot requested a review from drewrisinger March 18, 2020 14:08
@wd15
Copy link
Contributor

wd15 commented Mar 23, 2020

You'll probably need to collapse these 5 commits into 2, each with the correct commit message. Builds for me though.

Result of nixpkgs-review pr 82410 1

7 package failed to build:
  • python27Packages.osqp
  • python37Packages.cvxpy
  • python37Packages.osqp
  • python37Packages.scikit-survival
  • python38Packages.cvxpy
  • python38Packages.osqp
  • python38Packages.scikit-survival

Copy link
Contributor

@drewrisinger drewrisinger left a comment

Choose a reason for hiding this comment

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

Main suggestion is fetchFromGitHub, PR numbers, and note about reverting OSQP changes after version is bumped. Haven't tested build locally.

@GuillaumeDesforges
Copy link
Contributor Author

GuillaumeDesforges commented Mar 23, 2020

Thanks for the reviews. I'll work on it asap.

  • Fix points raised by drewrisinger
    • fetchFromGitHub
    • Typos
    • Formatting
  • Fix builds for Python != 3.7

@drewrisinger
Copy link
Contributor

  • Fix builds for Python != 3.7

If you're referring to @wd15 's failed builds above, those are probably due to an unfree dependency (mkl) of osqp not working with automated PR review.

@GuillaumeDesforges
Copy link
Contributor Author

If you're referring to @wd15 's failed builds above, those are probably due to an unfree dependency (mkl) of osqp not working with automated PR review.

Didn't think of that. Will check for Python 2 still, but thanks I'll keep that in mind!

sha256 = "130frig5bznfacqp9jwbshmbqd2xw3ixdspsbkrwsvkdaab7kca7";
src = fetchgit {
url = "https://github.com/GuillaumeDesforges/osqp-python";
rev = "770ecc3b96a94b30344cf3721a2e0771ef5c8259";
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
rev = "770ecc3b96a94b30344cf3721a2e0771ef5c8259";
rev = "770ecc3b96a94b30344cf3721a2e0771ef5c8259";
  fatal: reference is not a tree: 770ecc3b96a94b30344cf3721a2e0771ef5c8259
  Unable to checkout 770ecc3b96a94b30344cf3721a2e0771ef5c8259 from https://github.com/GuillaumeDesforges/osqp-python.
cannot build derivation '/nix/store/z2c2zviawy62qbkzaqx4pbs44xpm4a2m-python2.7-osqp-unstable-2020-03-18.drv': 1 dependencies couldn't be built

@FRidh
Copy link
Member

FRidh commented Mar 29, 2020

@GrahamcOfBorg build python3Packages.scikit-survival

meta = with lib; {
description = "Survival analysis built on top of scikit-learn";
homepage = "https://github.com/sebp/scikit-survival";
license = licenses.gpl3;
Copy link
Member

Choose a reason for hiding this comment

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

licenses.gpl3 is deprecated, consider using licenses.gpl3Only or licenses.gpl3Plus.

@ryantm ryantm added 2.status: merge conflict This PR has merge conflicts with the target branch and removed 2.status: merge conflict This PR has merge conflicts with the target branch labels Oct 3, 2020
@alexvorobiev
Copy link
Contributor

According to Pypi, the current version is "0.15.0.post0". Should this PR be updated?

@GuillaumeDesforges
Copy link
Contributor Author

Sorry, I've left it aside for too long. I don't have the time to update it right now. Could you take over @alexvorobiev ?

@alexvorobiev
Copy link
Contributor

I have crude (e.g. tests disabled, etc.) nix derivations for about 20 non-nixpkgs python packages so this one would be at the end of the queue... Here is what I ended up doing for the latest version of scikit-survival:

{ lib
, buildPythonPackage
, fetchPypi
, ecos
, joblib
, numexpr
, numpy
, osqp
, pandas
, scipy
, scikitlearn
, cython
}:

buildPythonPackage rec {
  pname = "scikit-survival";
  version = "0.15.0.post0";

  src = fetchPypi {
    inherit pname version;
    sha256 = "572c3ac6818a9d0944fc4b8176eb948051654de857e28419ecc5060bcc6fbf37";
  };

  buildInputs = [
    cython
  ];

  propagatedBuildInputs = [
    ecos
    joblib
    numexpr
    numpy
    osqp
    pandas
    scipy
    scikitlearn
  ];

  doCheck = false;
  doInstallCheck = false;

  meta = with lib; {
    description = "Survival analysis built on top of scikit-learn";
    homepage = https://github.com/sebp/scikit-survival;
    license = licenses.gpl3Plus;
  };
}

@drewrisinger
Copy link
Contributor

I have crude (e.g. tests disabled, etc.) nix derivations for about 20 non-nixpkgs python packages so this one would be at the end of the queue... Here is what I ended up doing for the latest version of scikit-survival:

Mostly LGTM. Maybe open a separate PR for that?

Comments:

  • Tests, obviously
  • Needs maintainer
  • quotes on homepage URL
  • Add changelog if exists

@GuillaumeDesforges
Copy link
Contributor Author

Actually I can work on it this week

@GuillaumeDesforges
Copy link
Contributor Author

GuillaumeDesforges commented Apr 25, 2021

Tests fail, e.g.

$ nix-build . -A python3Packages.scikit-survival
...
_____________________ ERROR collecting tests/test_tree.py ______________________
ImportError while importing test module '/build/scikit-survival-0.15.0.post0/tests/test_tree.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/nix/store/q6gfck5czr67090pwm53xrdyhpg6bx67-python3-3.8.9/lib/python3.8/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_tree.py:13: in <module>
    from sksurv.tree import SurvivalTree
sksurv/tree/__init__.py:1: in <module>
    from .tree import SurvivalTree  # noqa: F401
sksurv/tree/tree.py:15: in <module>
    from ._criterion import LogrankCriterion
E   ModuleNotFoundError: No module named 'sksurv.tree._criterion'

Basically, it seems it does not cythonize. If I do

$ nix-shell . -A python3Packages.scikit-survival
[nix-shell] $ genericBuild

I can see that the .pyx do not get cynthonize (no .py files in build output, hence the import errors).

The setup.py does have a specific mechanism for extension, but editing it to display the list of extensions seem to show that they are defined and go through the cynthonize call.

I'm a but lost here, it's beyond what I know about nixpkgs/python/cython

@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Apr 25, 2021
@drewrisinger
Copy link
Contributor

The setup.py does have a specific mechanism for extension, but editing it to display the list of extensions seem to show that they are defined and go through the cynthonize call.

They definitely go through the cythonize call, as I observed while watching the build just now. They're even installed into the output /nix/store/... path:
image

I suspect this is a similar issue I had while packaging python3Packages.qiskit-terra. I think that pytest gets confused about the proper directory for the scikit-survival code, looks in /build/... for the cythonized files and doesn't find them, and then errors.

A few suggestions:

@GuillaumeDesforges
Copy link
Contributor Author

I think that pytest gets confused about the proper directory for the scikit-survival code, looks in /build/... for the cythonized files and doesn't find them, and then errors.

@drewrisinger thanks for sharing your fix, I'll try that :)

But isn't that a bigger issue that would need some more global fix in nixpkgs rather than a script to fix it per package? Or is it really package-specific? I mean, won't a lot of cythonized packages fail like this one in the future?

@SuperSandro2000
Copy link
Member

This is a semi-automatic executed nixpkgs-review with nixpkgs-review-checks extension. It is checked by a human on a best effort basis and does not build all packages (e.g. lumo, tensorflow or pytorch).
If you have any questions or problems please reach out to SuperSandro2000 on IRC.

Result of nixpkgs-review pr 82410 run on x86_64-linux 1

2 packages failed to build and are new build failures:
  • python38Packages.scikit-survival: plain log | pretty log
  • python39Packages.scikit-survival: log was empty

@drewrisinger
Copy link
Contributor

drewrisinger commented Apr 27, 2021

But isn't that a bigger issue that would need some more global fix in nixpkgs rather than a script to fix it per package? Or is it really package-specific? I mean, won't a lot of cythonized packages fail like this one in the future?

Not sure. Possibly. It seems to be restricted to packages that use both cython & pytest for tests, maybe also ones that run their tests only from the /build/source dir. This is only the second package (other than the Qiskit ones) that I've run across that's had the issue, so not sure if it's worth coming up with a universal solution.

EDIT: I just reviewed another PR where this is an issue #120909. I think you're right @GuillaumeDesforges that we need to start coming up with a better automatic solution.

@GuillaumeDesforges
Copy link
Contributor Author

I've included your fix, thanks @drewrisinger

@drewrisinger
Copy link
Contributor

drewrisinger commented Apr 28, 2021

@GuillaumeDesforges I've been running nix-review for about 45 mins, and the tests seem to be taking most of the runtime. Would you be able to figure out some of the slowest tests and disable them? The point of the nix tests isn't to comprehensively unittest the software, more to check that it isn't obviously broken, and I personally feel like it isn't worth the computational time running full tests for "leaf" packages like this which will likely only have a few users.

I suggestion:

  • running the build temporarily with pytestFlagsArray = [ ... "--durations=20" ];, nix-build -A python3Packages.scikit-survival
  • disable any obviously slow tests (i.e. disabledTests = [ "test_name_1" "test_name_2" ]. I commonly use a threshold of ~10 seconds, but up to you.

@GuillaumeDesforges
Copy link
Contributor Author

I personally feel like it isn't worth the computational time running full tests for "leaf" packages like this

Agreed 100%, hadn't thought about it. I'll patch it asap

Copy link
Contributor

@drewrisinger drewrisinger left a comment

Choose a reason for hiding this comment

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

  • Minor style points on diff
  • Commit LGTM
  • Builds via nix-review on x86-64-linux:
2 packages built:
python38Packages.scikit-survival python39Packages.scikit-survival

Copy link
Contributor

@drewrisinger drewrisinger left a comment

Choose a reason for hiding this comment

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

All comments addressed, LGTM. Tested w/ nix-review again, ran fine.

2 packages built:
python38Packages.scikit-survival python39Packages.scikit-survival

@GuillaumeDesforges
Copy link
Contributor Author

Thanks @drewrisinger for the review :) who should I poke for merge?

@drewrisinger
Copy link
Contributor

pinging @SuperSandro2000 for merge. I don't have merge permissions

@Artturin Artturin merged commit c108863 into NixOS:master Aug 12, 2021
@Artturin
Copy link
Member

btw there's a new release available

@marsam
Copy link
Contributor

marsam commented Aug 12, 2021

This caused evaluation errors when aliases are disabled. Fixed in #133576

@Artturin
Copy link
Member

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: python 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 1-10 10.rebuild-linux: 1-10 11.by: package-maintainer This PR was created by the maintainer of the package it changes needs_merger
Projects
None yet
Development

Successfully merging this pull request may close these issues.