dwavesystems / dwavesystems/dimod

`BinaryPolynomial.energies` throws `"ufunc 'add' output (typecode 'O') could not be coerced to provided output parameter (typecode 'd') according to the casting rule ''same_kind''`

Open
#990 0 comments 0 reactions 1 assignee Claimed by @arcondello View on GitHub
bug
Dominant language
Python
Stars
143
Forks
91
Avg merge
1h 24m
Merged PRs (30d)
3

Description

[HigherOrderComposite-bug.py.txt](https://github.com/dwavesystems/dimod/files/7132199/HigherOrderComposite-bug.py.txt)
[HigherOrderComposite-bug.pdf](https://github.com/dwavesystems/dimod/files/7132139/HigherOrderComposite-bug.pdf)
[HigherOrderComposite-bug.ipynb.remove-remaining-extensions.txt](https://github.com/dwavesystems/dimod/files/7132161/HigherOrderComposite-bug.ipynb.remove-remaining-extensions.txt)

**Description**
`BinaryPolynomial.energies` throws `"ufunc 'add' output (typecode 'O') could not be coerced to provided output parameter (typecode 'd') according to the casting rule ''same_kind''`

**Steps To Reproduce**

```
from pylab import *
from builtins import *
from functools import *
from itertools import *
import numpy as np
import math
import sympy

import dimod
from dwave.system import LeapHybridSampler
from dwave import system
import dwave

def literal(x):
v = sympy.Symbol('v'+str(abs(x)))
return v if x>0 else 1-v

def cnf2poly(clauses):
poly = sum(map(math.prod, map(partial(map, lambda x: 1-literal(x)), clauses)))
return sympy.Poly(poly)

toycnf = [[-1,2],[1]]
sympoly = cnf2poly(toycnf)
poly_strength=2
symvars = np.array(list(map(str,sympoly.gens)))
poly_dict = {tuple(symvars[np.where(x)]):c for x,c in sympoly.as_dict().items()}
bipoly = dimod.BinaryPolynomial(poly_dict, 'BINARY')
bqm = bqm = dimod.make_quadratic(bipoly, poly_strength, 'BINARY')

display((bqm.num_variables, bqm.num_interactions))
display(poly_dict)
display(bipoly)
display(bqm)

try:
samples1 = dimod.HigherOrderComposite(LeapHybridSampler()).sample_poly(bipoly, time_limit=5, penalty_strength=poly_strength)
except Exception as e:
print('!!!', e, '!!!')
else:
display(samples1.info)
display(samples1)
df1 = samples1.to_pandas_dataframe()#.describe()
display(df1)

samples2 = LeapHybridSampler().sample(bqm, time_limit=5)\ndisplay(samples2.info)

display(samples2)

df2 = samples2.to_pandas_dataframe()
display(df2)

bipoly.energies(samples2)
```

Both the HigherOrderComposite.sample_poly and BinaryPolynomial enries in the above script throw the error
`"ufunc 'add' output (typecode 'O') could not be coerced to provided output parameter (typecode 'd') according to the casting rule ''same_kind''`

See attached files for more information

**Expected Behavior**

Calls should run without error and return the expected results

**Environment**
- Ubuntu 20.04 LTS (under WSL)
- Python version: 3.8.11
- dimod 0.10.6
- dwave-system 1.7.0
- numpy 1.19.5

**Additional Context**
Add any other background information about the problem.

See attached files[](url)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.