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

Make Model a Python class by moving Cython parts into a new _Graph class #179

Merged
merged 9 commits into from
Dec 5, 2024

Conversation

arcondello
Copy link
Member

@arcondello arcondello commented Dec 3, 2024

See also #174

Some highlights:

  • Most of the pure-Python methods have been moved to Model rather that _Graph
  • _Graph doesn't hold onto States, Model does
  • Several methods (e.g. .lock, .unlock, .minimize) have "basic" features implemented in Cython but some bits are implemented in Python.
  • Keep the cimport-ability of Model via some aliasing tricks (need to contemplate how much I like this one a little more)

@arcondello arcondello added the enhancement New feature or request label Dec 3, 2024
@arcondello arcondello requested a review from wbernoudy December 3, 2024 21:58
@arcondello
Copy link
Member Author

arcondello commented Dec 3, 2024

A few things left to do:

  • Better document the alias thing if we want to keep it
  • Add typing to model.py
  • Another pass over the docstrings for clarity

arcondello and others added 2 commits December 4, 2024 11:58
Thereby making Model a Python class rather than a Cython one.

Co-authored-by: William Bernoudy <[email protected]>
@arcondello arcondello force-pushed the feature/_graph.pyx-2 branch from 6657fb0 to 66e3ac3 Compare December 4, 2024 20:03
@arcondello
Copy link
Member Author

Upon reflection, I think it makes sense to keep Symbol.model as model rather than say renaming it Symbol._graph. Even if we were to add an Expression class calling expressions "model" is IMO not such a bad thing. If it later becomes confusing we can always do the rename in a different PR.

from dwave.optimization.symbols import BinaryVariable # avoid circular import
return BinaryVariable(self, shape)

def constant(self, array_like: numpy.typing.ArrayLike) -> Constant:
Copy link
Member

Choose a reason for hiding this comment

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

This and maybe to_networkx are the only methods I believe that we'll want to have on the future Expression class that we would duplicate. Considering how short this is and that to_networkx is not necessary for now (if ever) seems fine to me.

@arcondello arcondello marked this pull request as ready for review December 4, 2024 21:51
dwave/optimization/_graph.pyx Outdated Show resolved Hide resolved
@arcondello arcondello merged commit 0eb1ccc into dwavesystems:main Dec 5, 2024
35 checks passed
@arcondello arcondello deleted the feature/_graph.pyx-2 branch December 5, 2024 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants