Skip to content

Commit

Permalink
Merge pull request #1256 from arcondello/fix/CQM-from_file-weight-type
Browse files Browse the repository at this point in the history
Fix the weight type in CQMs with soft constraints loaded from files
  • Loading branch information
arcondello authored Sep 30, 2022
2 parents 91a3c94 + da529f8 commit ae74d3a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dimod/constrained.py
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ def from_file(cls,
label = deserialize_variable(json.loads(constraint))

try:
weight = np.frombuffer(zf.read(f"constraints/{constraint}/weight"))
weight = np.frombuffer(zf.read(f"constraints/{constraint}/weight"), np.float64)[0]
penalty = zf.read(f"constraints/{constraint}/penalty").decode('ascii')
except KeyError:
weight = None
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
Fix the type of soft constraint weights when loaded from files. The issue was
introduced in 0.11.6.dev1.
2 changes: 2 additions & 0 deletions tests/test_constrained.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import itertools
import json
import numbers
import unittest

from textwrap import dedent
Expand Down Expand Up @@ -1059,6 +1060,7 @@ def test_functional_soft(self):

for label, info in cqm._soft.items():
self.assertEqual(info.weight, new._soft[label].weight)
self.assertIsInstance(new._soft[label].weight, numbers.Number)
self.assertEqual(info.penalty, new._soft[label].penalty)

def test_header(self):
Expand Down

0 comments on commit ae74d3a

Please sign in to comment.