-
Notifications
You must be signed in to change notification settings - Fork 54
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
RuntimeWarning: divide by zero encountered in det #367
Comments
Hey @minseok1999! Can you please edit your post and include the output of the following:
You can put this in the "System information" box. It would also help if you could include the full error traceback 😄. |
I have edited as requested! |
Hmm... I'm not able to replicate the behaviour you're seeing. Here are my package versions:
Slightly different from yours. Can you try those versions and see if it works for you? |
Here is the list of libraries that I imported
and I have changed the package version as follows The Walrus: a Python library for for the calculation of hafnians, Hermite polynomials, and Gaussian boson sampling. Python version: 3.10.9 But I keep seeing this behavior
Can this be because of the specific property of the matrix that I fed into hafnium_sample_graph |
@minseok1999 Let's stick with the simpler example here:
Can you provide the entire error traceback when you try to run this? Don't leave anything out 😄 |
I have tried your simpler form and I got OMP: Info #276: omp_set_nested routine deprecated, please use omp_set_max_active_levels instead. without the division by zero error anymore. Why is this like this? Should I not be fidgeting with the fixed library? Only change I made to the library was to change the number of samples explicitly in the definition of hafnian_sample_graph itself 😅 |
He @minseok1999, I asked some other folks internally to try and replicate the behaviour you're getting, and nobody is able to — everyone can run this code without error. A couple things you can try:
Let me know if either of those work! |
I have tried google colab as you advised and this works cleanly without error. I wish I could figure out why this message |
Awesome! Glad you got this solved 😄. Sometimes virtual environments get "messed up" and need a refresh just like anything else would 😅. |
Before posting a bug report
Expected behavior
I first prepared arbitrary adjacency matrix of a graph as follows.
matrix = np.array(
[[1,1,1,1,1,1,0,0,0,0],
[1,1,1,1,1,1,0,0,0,0],
[1,1,1,1,1,1,0,0,0,0],
[1,1,1,1,1,1,0,0,1,0],
[1,1,1,1,1,1,0,1,0,0],
[1,1,1,1,1,1,1,0,0,0],
[0,0,0,0,0,1,1,0,0,0],
[0,0,0,0,1,0,0,1,0,0],
[0,0,0,1,0,0,0,0,1,1],
[0,0,0,0,0,0,0,0,1,1]]
)-np.eye(10)
And then I fed this matrix into the module
s=hafnian_sample_graph(matrix,6)
print(s)
to see the simulated result of photo count with mean photon number of 6 at the output Gaussian state.
I have only changed the number of sample parameter in the module as follows to generate 10 samples
def hafnian_sample_graph(
A, n_mean, samples=10, cutoff=5, max_photons=30, approx=False, approx_samples=1e5, pool=False
):
Actual behavior
But Implementing this line gave this error message
/Users/ryuminseok/anaconda3/lib/python3.10/site-packages/numpy/linalg/linalg.py:2154: RuntimeWarning: divide by zero encountered in det
r = _umath_linalg.det(a, signature=signature)
/Users/ryuminseok/anaconda3/lib/python3.10/site-packages/numpy/linalg/linalg.py:2154: RuntimeWarning: invalid value encountered in det
r = _umath_linalg.det(a, signature=signature)
/Users/ryuminseok/anaconda3/lib/python3.10/site-packages/numpy/linalg/linalg.py:2154: RuntimeWarning: divide by zero encountered in det
r = _umath_linalg.det(a, signature=signature)
/Users/ryuminseok/anaconda3/lib/python3.10/site-packages/numpy/linalg/linalg.py:2154: RuntimeWarning: invalid value encountered in det
r = _umath_linalg.det(a, signature=signature)
The code still generates output pattern, although I have to wait for quite a long time. But I doubt that this module of photo count pattern generation is reliable if it involves division by zero which can lead to numerical instability or incorrect result.
Reproduces how often
It occurs every time
System information
The Walrus: a Python library for for the calculation of hafnians, Hermite polynomials, and Gaussian boson sampling.
Copyright 2018-2021 Xanadu Quantum Technologies Inc.
Python version: 3.10.9
Platform info: macOS-13.4.1-arm64-arm-64bit
Installation path: /Users/ryuminseok/anaconda3/lib/python3.10/site-packages/thewalrus
The Walrus version: 0.20.0
Numpy version: 1.23.5
Scipy version: 1.10.0
SymPy version: 1.11.1
Numba version: 0.56.4
Source code
No response
Tracebacks
No response
Additional information
The text was updated successfully, but these errors were encountered: