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

Implement QuadraticModelBase and BinaryQuadraticModel in C++ #818

Merged

Conversation

arcondello
Copy link
Member

First of several PRs breaking up one big one. This will replace the other dimod BQM C++ implementation. Also can be easily sub-classed for other types of quadratic models.

QuadraticModelBase can be subclassed in the future to encode
more generic types of quadratic models - with the vartype
tracked per variable.
@arcondello arcondello added the feature-request/enhancement New feature or request label May 3, 2021
@codecov-commenter
Copy link

codecov-commenter commented May 3, 2021

Codecov Report

Merging #818 (233a581) into main (b164b03) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #818   +/-   ##
=======================================
  Coverage   92.50%   92.50%           
=======================================
  Files          63       63           
  Lines        4658     4658           
=======================================
  Hits         4309     4309           
  Misses        349      349           

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 b164b03...233a581. Read the comment docs.

dimod/include/dimod/quadratic_model.h Outdated Show resolved Hide resolved
value_type operator*() { return value_type{*neighbor_it_, *bias_it_}; }

private:
bias_iterator bias_it_;

This comment was marked as resolved.

Copy link
Member Author

Choose a reason for hiding this comment

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

In c++ we follow google's style guide. In python you're right, the convention is to use a leading _. And cython who knows 😆

Copy link

Choose a reason for hiding this comment

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

Once an arguments name was say name, and the member was name_, i used name instead of name_, should not have happened if i had used _nameinstead of name_, this is an isolated rare case though :)

dimod/include/dimod/quadratic_model.h Outdated Show resolved Hide resolved
dimod/include/dimod/quadratic_model.h Outdated Show resolved Hide resolved
dimod/include/dimod/quadratic_model.h Outdated Show resolved Hide resolved
dimod/include/dimod/quadratic_model.h Outdated Show resolved Hide resolved
dimod/include/dimod/quadratic_model.h Outdated Show resolved Hide resolved
dimod/include/dimod/quadratic_model.h Outdated Show resolved Hide resolved
dimod/include/dimod/quadratic_model.h Show resolved Hide resolved
dimod/include/dimod/quadratic_model.h Outdated Show resolved Hide resolved
std::vector<bias_type> quadratic_biases;
};

template <class Bias, class Neighbor = std::int64_t>

Choose a reason for hiding this comment

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

I think the default type should be just, int, reasons.

  1. We save a huge amount of memory now that the vectors are not vectors of pairs and structures are not padded, so if we use bias type float using int will save 1/3rd memory and if bias type is double then it samves 1/4rth memory.

  2. We will never get close to using that many variables, and by the time we use that many variables we have to change the algorithms we use for adding biases together since the drift will be too large to handle.

  3. Moving to int from int_64t will not cause any precision bug until and unless we somehow use it in bias computation - something that I did and suffered lol.

using bias_type = Bias;

/// The type for variable indices
using index_type = std::ptrdiff_t;

Choose a reason for hiding this comment

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

I do not think we need a separate type for indexing, I mean class Neighbor could be just index_type, we will not index to anything that is larger than Neighbor , the only thing that may be larger than what Neighbor type can hold is num_interactions, so having separate index_type and Neighbor is just for aesthetic reasons, and I do not have any argument against that if it is not hard to remember and be consistent with the types.

One question,will it be easy for you to declare these functions which use index_type in cython ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, maybe I will just drop neighbor_type altogether and just use index_type to simplify it. And yes, cython can handle it just fine.

Copy link

@amahmudwave amahmudwave left a comment

Choose a reason for hiding this comment

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

LGTM , thanks.

@arcondello arcondello merged commit 1d13475 into dwavesystems:main May 4, 2021
@arcondello arcondello deleted the feature/reimplement-c++-bqm branch May 4, 2021 20:06
arcondello added a commit that referenced this pull request May 7, 2021
New Features
------------
* Support PEP518 for building the package #814
* Add `cyVariables.size()` and `.at(..)` to improve cython access to the `Variables` object
* Add new `QuadraticModelBase` and `BinaryQuadraticModel` implementation in c++ #818, #819

Fixes
-----
* Fix broken documentation links #815
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request/enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants