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

Add minimal CQM implementation #839

Merged
merged 4 commits into from
Jun 11, 2021

Conversation

arcondello
Copy link
Member

Allows the construction of binary constrained quadratic models.

@arcondello arcondello requested a review from randomir June 11, 2021 00:23
@arcondello
Copy link
Member Author

Still need to fix the windows bug obviously. This also will need a pretty serious second pass when we add QuadraticModel

@arcondello arcondello force-pushed the feature/constrained branch from 3b0a614 to d15798e Compare June 11, 2021 18:28
@arcondello arcondello marked this pull request as ready for review June 11, 2021 18:33
@codecov-commenter
Copy link

codecov-commenter commented Jun 11, 2021

Codecov Report

Merging #839 (d15798e) into main (a4bca10) will increase coverage by 0.25%.
The diff coverage is 88.44%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #839      +/-   ##
==========================================
+ Coverage   88.26%   88.52%   +0.25%     
==========================================
  Files          70       71       +1     
  Lines        5862     6046     +184     
==========================================
+ Hits         5174     5352     +178     
- Misses        688      694       +6     
Impacted Files Coverage Δ
dimod/constrained.py 87.77% <87.77%> (ø)
dimod/variables.py 89.85% <94.11%> (+0.30%) ⬆️
dimod/__init__.py 100.00% <100.00%> (ø)
dimod/binary/binary_quadratic_model.py 90.21% <0.00%> (+1.79%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a4bca10...d15798e. Read the comment docs.

Copy link
Member

@randomir randomir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from a few minor issues, LGTM!

dimod/constrained.py Outdated Show resolved Hide resolved
dimod/constrained.py Outdated Show resolved Hide resolved
dimod/constrained.py Outdated Show resolved Hide resolved
dimod/constrained.py Outdated Show resolved Hide resolved
dimod/constrained.py Outdated Show resolved Hide resolved
dimod/constrained.py Show resolved Hide resolved
header_data = json.dumps(data, sort_keys=True).encode('ascii')
header_data += b'\n'
header_data += b' '*(64 - (len(prefix) + 6 + len(header_data)) % 64)
header_len = np.dtype('<u4').type(len(header_data)).tobytes()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did just a quick check, but it looks .tobytes() in this setup actually always uses native byteorder. I believe your intention was to use little endian.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, excellent catch

In [6]: np.frombuffer(np.dtype('<u4').type(256).tobytes(), '<u4')
Out[6]: array([256], dtype=uint32)

In [7]: np.frombuffer(np.dtype('>u4').type(256).tobytes(), '<u4')
Out[7]: array([256], dtype=uint32)

In [8]: np.frombuffer(np.dtype('>u4').type(256).tobytes(), '>u4')
Out[8]: array([65536], dtype=uint32)

In [9]: np.frombuffer(np.dtype('<u4').type(256).tobytes(), '>u4')
Out[9]: array([65536], dtype=uint32)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see we have the same bug in BQM and DQM.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. Investigating

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have a fix I'll make in a followup PR.

@arcondello arcondello merged commit 4fd10b0 into dwavesystems:main Jun 11, 2021
@arcondello arcondello deleted the feature/constrained branch June 11, 2021 20:14
arcondello added a commit that referenced this pull request Jun 11, 2021
New Features
------------

* Add `add_bqm` method to C++ BinaryQuadraticModel #821, #823
* Add `Structured.valid_bqm_graph` method for verifying input problem structure #832
* Reimplement `BinaryQuadraticModel` to use new C++ code #828
* `BinaryQuadraticModel` can now be manipulated symbolically #834
* `load` function can now load all model types #841, #843
* `DiscreteQuadraticModel` now has an `.offset` attribute #838
* Add `ConstrainedQuadraticModel` class #839

Fix
---
* Fix type promotions in binary quadratic models with object biases #836
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants