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

BUG: sparse.linalg: Update SuperLU to fix unfilterable output for singular matrices #21172

Merged
merged 7 commits into from
Aug 16, 2024

Conversation

dschmitz89
Copy link
Contributor

@dschmitz89 dschmitz89 commented Jul 12, 2024

Reference issue

Closes gh-20993

What does this implement/fix?

Updates SuperLU to the head of their master branch. A recent commit should avoid printing to stdout for singular matrices.

Additional information

Locally, on WSL using Ubuntu and conda compilers, compilation fails due to a recent SuperLU update regarding complex numbers.

Edit: compilation also fails in CI. After some feedback, I will open an issue upstream.

@github-actions github-actions bot added scipy.sparse.linalg C/C++ Items related to the internal C/C++ code base labels Jul 12, 2024
@dschmitz89 dschmitz89 changed the title Update SuperLU to fix unfilterable output for singular matrices Update SuperLU to fix unfilterable output for singular matrices Jul 12, 2024
@dschmitz89 dschmitz89 requested a review from rgommers July 12, 2024 19:16
@dschmitz89
Copy link
Contributor Author

Using the second latest commit from SuperLU also results in another compilation failure 🙈 :

[129/188] Compiling C object scipy/sparse/linalg/_dsolve/libsuperlu_lib.a.p/SuperLU_SRC_sp_preorder.c.o
FAILED: scipy/sparse/linalg/_dsolve/libsuperlu_lib.a.p/SuperLU_SRC_sp_preorder.c.o
/home/tyrion/miniforge3/envs/scipy-dev/bin/x86_64-conda-linux-gnu-cc -Iscipy/sparse/linalg/_dsolve/libsuperlu_lib.a.p -Iscipy/sparse/linalg/_dsolve -I../scipy/sparse/linalg/_dsolve -I../scipy/sparse/linalg/_dsolve/SuperLU/SRC -fvisibility=hidden -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -std=c17 -O2 -g -Wno-unused-but-set-variable -Wno-unused-function -Wno-conversion -Wno-misleading-indentation -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /home/tyrion/miniforge3/envs/scipy-dev/include -DNDEBUG -D_FORTIFY_SOURCE=2 -O2 -isystem /home/tyrion/miniforge3/envs/scipy-dev/include -fPIC -DUSE_VENDOR_BLAS=1 -Wno-unused-variable -Wno-parentheses -Wno-unused-label -Wno-implicit-function-declaration -Wno-switch -Wno-unused-result -Wno-maybe-uninitialized -MD -MQ scipy/sparse/linalg/_dsolve/libsuperlu_lib.a.p/SuperLU_SRC_sp_preorder.c.o -MF scipy/sparse/linalg/_dsolve/libsuperlu_lib.a.p/SuperLU_SRC_sp_preorder.c.o.d -o scipy/sparse/linalg/_dsolve/libsuperlu_lib.a.p/SuperLU_SRC_sp_preorder.c.o -c ../scipy/sparse/linalg/_dsolve/SuperLU/SRC/sp_preorder.c
../scipy/sparse/linalg/_dsolve/SuperLU/SRC/sp_preorder.c: In function 'sp_preorder':
../scipy/sparse/linalg/_dsolve/SuperLU/SRC/sp_preorder.c:81:17: error: conflicting types for 'check_perm'; have 'void(char *, int,  int *)'
   81 |     extern void check_perm(char *what, int n, int *perm);
      |                 ^~~~~~~~~~
In file included from ../scipy/sparse/linalg/_dsolve/SuperLU/SRC/slu_ddefs.h:95,
                 from ../scipy/sparse/linalg/_dsolve/SuperLU/SRC/sp_preorder.c:16:
../scipy/sparse/linalg/_dsolve/SuperLU/SRC/slu_util.h:419:16: note: previous declaration of 'check_perm' with type 'int(char *, int,  int *)'
  419 | extern int     check_perm(char *what, int n, int *perm);
      |                ^~~~~~~~~~
[134/188] Compiling C object scipy/sparse/linalg/_dsolve/libsuperlu_lib.a.p/SuperLU_SRC_smemory.c.o
ninja: build stopped: subcommand failed.
Build failed!

Guess we have to bite the bullet and get this fixed upstream then.

@dschmitz89
Copy link
Contributor Author

Locally things are working now, just need to properly recreate the patch file, messed that one up badly.

@lucascolley lucascolley changed the title Update SuperLU to fix unfilterable output for singular matrices MAINT: sparse.linalg: Update SuperLU to fix unfilterable output for singular matrices Aug 4, 2024
@lucascolley lucascolley added the maintenance Items related to regular maintenance tasks label Aug 4, 2024
@lucascolley lucascolley changed the title MAINT: sparse.linalg: Update SuperLU to fix unfilterable output for singular matrices BUG: sparse.linalg: Update SuperLU to fix unfilterable output for singular matrices Aug 4, 2024
@lucascolley lucascolley added defect A clear bug or issue that prevents SciPy from being installed or used as expected and removed maintenance Items related to regular maintenance tasks labels Aug 4, 2024
@dschmitz89
Copy link
Contributor Author

CC @nickodell would you have time to review?

@nickodell nickodell self-requested a review August 4, 2024 18:33
@nickodell
Copy link
Member

CC @nickodell would you have time to review?

Hi, I've verified two things.

What other things should I check?

@dschmitz89
Copy link
Contributor Author

CC @nickodell would you have time to review?

Hi, I've verified two things.

What other things should I check?

Thanks! What I am not quite sure about are the patches I added on top of SuperLU: https://github.com/scipy/scipy/blob/629e358b943818cbeac9fd26b0e79f0bd8655020/scipy/sparse/linalg/_dsolve/SuperLU/scipychanges.patch

Most of them are for singular matrix handling and our tests pass though.

@dschmitz89 dschmitz89 added this to the 1.14.1 milestone Aug 4, 2024
@dschmitz89 dschmitz89 added the backport-candidate This fix should be ported by a maintainer to previous SciPy versions. label Aug 4, 2024
@dschmitz89
Copy link
Contributor Author

Note that if this gets merged and backported to 1.14.1, it also comes with the SuperLU license fix, so we would not need to double backport.

@rgommers
Copy link
Member

rgommers commented Aug 4, 2024

What I am not quite sure about are the patches I added on top of SuperLU:

It would probably be useful to make a difference here between what we were already patching, and the new patches you added. Perhaps comment on each of those and why they need to be kept as SciPy patches rather than upstreamed?

@nickodell
Copy link
Member

Thanks! What I am not quite sure about are the patches I added on top of SuperLU: https://github.com/scipy/scipy/blob/629e358b943818cbeac9fd26b0e79f0bd8655020/scipy/sparse/linalg/_dsolve/SuperLU/scipychanges.patch

Many of these changes to the patch file seem unrelated to what's being fixed. Can you explain why the patch file is changing at all? We're updating the file being patched - we shouldn't need to change the patch file, right?

It might help if you explained the process here for how the SuperLU update is being done. I'm guessing you're diffing our modified SuperLU against the old upstream unmodified SuperLU to generate the patch, then applying the patch to the upstream updated SuperLU to generate a modified version. Is that right?

Comment on lines +435 to +436
-#define HAVE_METIS TRUE
+/*#define HAVE_METIS FALSE */
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Commenting this out is necessary. Otherwise, at runtime we get errors about missing METIS symbols.

Copy link
Member

Choose a reason for hiding this comment

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

This change seems fine. Enabling this unconditionally is probably not a good thing to do upstream (that's what build system checks are for), but let's not worry about it too much for now since the patch is harmless.

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 thought the same. Unfortunately, setting it to FALSE is also not enough. Commented upstream here: xiaoyeli/superlu@6f7ea89#r145014670

@dschmitz89
Copy link
Contributor Author

Thanks! What I am not quite sure about are the patches I added on top of SuperLU: https://github.com/scipy/scipy/blob/629e358b943818cbeac9fd26b0e79f0bd8655020/scipy/sparse/linalg/_dsolve/SuperLU/scipychanges.patch

Many of these changes to the patch file seem unrelated to what's being fixed. Can you explain why the patch file is changing at all? We're updating the file being patched - we shouldn't need to change the patch file, right?

It might help if you explained the process here for how the SuperLU update is being done. I'm guessing you're diffing our modified SuperLU against the old upstream unmodified SuperLU to generate the patch, then applying the patch to the upstream updated SuperLU to generate a modified version. Is that right?

The patch is against the used SuperLU source files. The only new patch is commenting out METIS stuff, see my last comment here. As for the other patches, I tried to stay faithful to what we had before but had to juggle with more if. CC @rgommers

@dschmitz89
Copy link
Contributor Author

One more thing that came to mind is that we should probably better document which commit of SuperLU we used when the code was copied. Looking through PR comments can be tedious. So far we probably only ever used releases, so this was not an issue.

@rgommers
Copy link
Member

rgommers commented Aug 5, 2024

Thanks @dschmitz89. Adding the exact commit we're pointing at sounds good. I suggest adding a README.scipy file, mirroring what we do for ARPACK and QHull.

@dschmitz89
Copy link
Contributor Author

dschmitz89 commented Aug 8, 2024

This is ready to merge from my side, CI failures are unrelated.

Copy link
Member

@nickodell nickodell left a comment

Choose a reason for hiding this comment

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

LGTM. I'm not sure I understand this code well enough to spot potential problems, but I don't see any issues.

@dschmitz89 dschmitz89 mentioned this pull request Aug 12, 2024
5 tasks
Copy link
Member

@rgommers rgommers left a comment

Choose a reason for hiding this comment

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

The file mc64ad.c was incorrectly added. Can you please remove it again, squash the history so it is really gone from all commits, and add to README.scipy the procedure for keeping it out?

That file isn't license-compatible. See gh-12243 for a previous discussion on this.

@rgommers
Copy link
Member

The CI failures are because an unintentional update of the array_api_compat git submodule snuck in here.

@dschmitz89
Copy link
Contributor Author

Argh, will try to fix after work. I wish there was a pre commit that warns for submodule changes.

@dschmitz89
Copy link
Contributor Author

Submodule update reverted. Commits should still be squashed as they are not clean.

Copy link
Member

@rgommers rgommers left a comment

Choose a reason for hiding this comment

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

LGTM now, thanks a lot @dschmitz89! Time to give this a go:) And thanks for the review @nickodell

@rgommers rgommers merged commit e007717 into scipy:main Aug 16, 2024
38 of 39 checks passed
@rgommers
Copy link
Member

@tylerjereddy I'll leave the backport label for you to decide. It seems okay to do if it cherry-picks cleanly, but it's a large diff and the bug this fixes isn't super critical, so leaving it out would also be reasonable I think.

tylerjereddy pushed a commit to tylerjereddy/scipy that referenced this pull request Aug 16, 2024
@tylerjereddy
Copy link
Contributor

The cherry-pick was clean and passed tests locally on ARM mac so I've tentatively added it to the backport PR, thanks

@dschmitz89 dschmitz89 deleted the superlu_update branch August 16, 2024 19:20
@tylerjereddy tylerjereddy removed the backport-candidate This fix should be ported by a maintainer to previous SciPy versions. label Aug 20, 2024
anushkasuyal pushed a commit to anushkasuyal/scipy that referenced this pull request Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C/C++ Items related to the internal C/C++ code base defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.sparse.linalg
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: spsolve prints "dgstrf info" to stdout on singular matrices
5 participants