dwavesystems / dwavesystems/dimod
TypeError: No matching signature found when building Ising model from numpy arrays
- Dominant language
- Python
- Stars
- 143
- Forks
- 91
- Avg merge
- 1h 24m
- Merged PRs (30d)
- 3
Description
**Description**
As detailed in the title and MWE example, this code is failing.
**Steps To Reproduce**
This is a MWE
```
import dimod
import numpy as np
N = 10 # Number of variables
np.random.seed(42) # Fixing the random seed to get the same result
J = np.random.rand(N, N)
# We only consider upper triangular matrix ignoring the diagonal
J = np.triu(J, 1)
h = np.random.rand(N, 1)
print(h.dtype)
print(J.dtype)
model_random = dimod.BinaryQuadraticModel.from_ising(h, J, offset=0.0)
```
Which prints:
```
float64
float64
Traceback (most recent call last):
File "/home/bernalde/scratch.py", line 14, in
model_random = dimod.BinaryQuadraticModel.from_ising(h, J, offset=0.0)
File "/home/bernalde/miniconda3/envs/quipml/lib/python3.9/site-packages/dimod/binary/binary_quadratic_model.py", line 1191, in from_ising
return cls(h, J, offset, Vartype.SPIN)
File "/home/bernalde/miniconda3/envs/quipml/lib/python3.9/site-packages/dimod/binary/binary_quadratic_model.py", line 193, in __init__
self._init_components(*args, dtype=dtype)
File "/home/bernalde/miniconda3/envs/quipml/lib/python3.9/site-packages/dimod/binary/binary_quadratic_model.py", line 259, in _init_components
self.add_linear_from_array(linear)
File "/home/bernalde/miniconda3/envs/quipml/lib/python3.9/site-packages/dimod/binary/binary_quadratic_model.py", line 783, in add_linear_from_array
self.data.add_linear_from_array(np.asarray(ldata))
File "dimod/binary/cybqm/cybqm_template.pyx.pxi", line 223, in dimod.binary.cybqm.cybqm_float64.cyBQM_template.__pyx_fused_cpdef
TypeError: No matching signature found
```
I have debugged it down to line 223 in the `cybqm_template.pyx.pxi`
` cpdef Py_ssize_t add_linear_from_array(self, ConstNumeric[:] linear) except -1: `...
**Expected Behavior**
In previous versions of Python, it works well, so my guess is that Python 3.9 makes some type assumptions that are leading to this error.
Something along this [post](https://stackoverflow.com/questions/61532286/typeerror-no-matching-signature-found-when-tryint-to-pivot-dataframe) in Stack overflow.
**Environment**
- OS: Ubuntu 20.04.3 LTS
- Python version: Python 3.9.7, fresh ocean-sdk pip installation
- dimod 0.10.7 pypi_0 pypi
**Additional Context**
Add any other background information about the problem.
Contributor guide
Assessment
This issue has not been assessed yet.