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

Library hard crashing when computing BBFG permanent with a 0x0 matrix #319

Closed
1 task done
GregoryMorse opened this issue Jan 17, 2022 · 4 comments · Fixed by #320
Closed
1 task done

Library hard crashing when computing BBFG permanent with a 0x0 matrix #319

GregoryMorse opened this issue Jan 17, 2022 · 4 comments · Fixed by #320
Labels
bug Something isn't working

Comments

@GregoryMorse
Copy link
Contributor

GregoryMorse commented Jan 17, 2022

Before posting a bug report

  • I have searched exisisting GitHub issues to make sure the issue does not already exist.

Expected behavior

Returning one (1+0j)

Actual behavior

Native code hard crashing Python in Windows/Linux with "overflow to inf" output

Reproduces how often

Always

System information

Python 3.6-3.8, Windows/Linux version 0.16.1

Source code

import numpy as np
from thewalrus.libwalrus import perm_BBFG_complex
perm_BBFG_complex(np.zeros((0, 0))+np.zeros((0, 0)) * 1j)

Tracebacks

overflow to inf

Additional information

Probably the real number case has the same bug.
perm_complex returns 0 instead of 1+0j so it is also bugged.  None of the 0x0 dimension permanents are working correctly.
@GregoryMorse GregoryMorse added the bug Something isn't working label Jan 17, 2022
@nquesada
Copy link
Collaborator

Hi @GregoryMorse --- Could you tell us which version of thewalrus are you using?

@GregoryMorse
Copy link
Contributor Author

GregoryMorse commented Jan 17, 2022

Hi @nquesada, version 0.16.1, the one in PyPi

@thisac
Copy link
Contributor

thisac commented Jan 17, 2022

Thanks for bringing this to our attention @GregoryMorse. As of the latest release (v0.18.0), The Walrus no longer uses libwalrus for any calculations. The function corresponding to thewalrus.libwalrus.perm_BBFG_complex is now thewalrus.perm.

The equivalent code to your example above would be:

import numpy as np
import thewalrus as tw

mat = np.zeros((0, 0))+np.zeros((0, 0)) * 1j
tw.perm(mat, method="bbfg")

With that said, it seems like this function has the same issue, so a fix would still be needed to make sure that the permanent function returns 1 for an empty matrix. We will look into fixing this in an upcoming release!

@nquesada
Copy link
Collaborator

or, alternatively, @GregoryMorse , you are most welcome to do a PR fixing it and become a contributor! You can use the example of how this is solved in the hafnian function here

if matshape == (0, 0):

GregoryMorse added a commit to GregoryMorse/thewalrus that referenced this issue Jan 17, 2022
Fix issue XanaduAI#319 by checking 0 size matrices and returning one in permanent computations
@sduquemesa sduquemesa linked a pull request Jan 17, 2022 that will close this issue
thisac added a commit that referenced this issue Jan 24, 2022
* Fix size-0 matrix permanents

Fix issue #319 by checking 0 size matrices and returning one in permanent computations

* Update test_permanent.py

* Update test_permanent.py

remove unnecessary whitespace

* Update _permanent.py

Fixed formatting

* Update test_permanent.py

* Update ACKNOWLEDGMENTS.md

* Update CHANGELOG.md

* Update _permanent.py

* Update .github/CHANGELOG.md

* Update .github/CHANGELOG.md

Co-authored-by: Theodor <theodor.isacsson@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants