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

Separate out Model class into cython _GraphManager and python Model #174

Closed
wants to merge 1 commit into from

Conversation

wbernoudy
Copy link
Member

@wbernoudy wbernoudy commented Nov 20, 2024

Move almost all functionality of the previously cython Model class into a new cython _GraphManager base class that has only private methods. The new python Model class chooses which of these methods to expose publicly. This will aid in adding the new Expression class which will expose a different set of the methods on _GraphManager (see #166).

Still TODO if we go with this approach:

  • Rewrite the docstrings on the now private _GraphManager methods
  • Clarify what should happen with States, Symbol, ArraySymbol etc that have now been moved to dwave.optimization.graph_manager

@arcondello arcondello assigned arcondello and unassigned arcondello Nov 20, 2024
@arcondello arcondello self-requested a review November 20, 2024 22:01
@arcondello arcondello added the enhancement New feature or request label Nov 20, 2024
@arcondello
Copy link
Member

arcondello commented Nov 20, 2024

So if I am understanding correctly, the idea (once we add Expression) is

  • _GraphManager manages ownership of a C++ Graph and the States
  • _Model is the Cython parts of Model
  • _Expression would be the Cython parts of Expression

right?

@wbernoudy
Copy link
Member Author

wbernoudy commented Nov 20, 2024

So if I am understanding correctly, the idea (once we add Expression) is

* `_GraphManager` manages ownership of a C++ `Graph` and the `States`

* `_Model` is the Cython parts of `Model`

* `_Expression` would be the Cython parts of `Expression`

right?

That's the idea. Though currently, I still have methods on _GraphManager that are common to both Expression and Model which we may also want to move into another Python class (e.g. to_networkx()).

@arcondello
Copy link
Member

arcondello commented Nov 21, 2024

IMO it might make sense to go from 5 to 3 by skipping _Model and _Expression. You've already made all of the methods private on _Model so I think it's OK if Expression has a _binary() method, but not a binary() method.

That way _GraphManager's scope becomes quite clear - to wrap the C++ methods in Python ones. And then the subclasses are simply choosing which to expose.

@wbernoudy wbernoudy force-pushed the refactor-model-class branch from f7f1604 to 7b740db Compare December 2, 2024 19:22
@wbernoudy wbernoudy changed the title Separate out Model class into cython _Model and _GraphManager Separate out Model class into cython _GraphManager and python Model Dec 2, 2024
@wbernoudy wbernoudy closed this Dec 4, 2024
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