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

BQM.subbqm or similar #538

Open
arcondello opened this issue Oct 2, 2019 · 7 comments
Open

BQM.subbqm or similar #538

arcondello opened this issue Oct 2, 2019 · 7 comments
Labels
enhancement New feature or request

Comments

@arcondello
Copy link
Member

arcondello commented Oct 2, 2019

Something similar to NetworkX's Graph.subgraph would be good. Would obviously need a BQMView object to implement that version though.

Note this is distinct from induced subgraphs as in dwave-hybrid's bqm_induced_by function.

@arcondello arcondello added the enhancement New feature or request label Oct 2, 2019
@randomir
Copy link
Member

randomir commented Oct 3, 2019

When you say distinct from hybrid.bqm_induced_by/hybrid.bqm_reduced_to, you mean values for boundary nodes would not be fixed, right?

In that case, how would you determine energy offset for the sub bqm?

Otherwise, how would BQM.subbqm be different from:

bqm = ...
subnodes = [...]

subbqm = bqm.from_networkx_graph(
    bqm.to_networkx_graph().subgraph(subnodes), vartype=bqm.vartype)

@arcondello
Copy link
Member Author

Yes that is what I mean, so it would be the same. The difference would be convenience (one method, no dependency on NetworkX) and performance (no intermediate objects and implementation as a view rather than a copy).

I would expect the offset, because it is not associated with any variables, to be 0 on a subbqm defined by a subset of the variables. We could I suppose allow it to be included as a kwarg. Though how we would handle offsets with bqm views is an interesting question in-and-of-itself. E.g. I might expect to be able to

>>> bqm = dimod.BQM.from_ising({}, {'ab':-1}
>>> bqm.linear['a']
0
>>> bqm.subbqm(['a']).linear['a'] = 6  # set on the view
>>> bqm.linear['a']
6

but doing the same thing with the offset would not make sense (assuming we set it to 0 for views). One obvious approach would be to just not allow the views to be modified.

@randomir
Copy link
Member

randomir commented Oct 3, 2019

I agree, setting offset=0 for a sub bqm would make sense. But it is also incompatible with a current syntax for BQM construction (which requires explicit offset value).

@arcondello
Copy link
Member Author

I don't understand what you mean. When do we need to construct the subbqm with an offset?

@randomir
Copy link
Member

randomir commented Oct 3, 2019

BQM constructor requires offset <=> SubBQM constructor sets offset to zero.

@arcondello
Copy link
Member Author

I don't understand what is incompatible. There are many says to construct a BQM without explicitly providing an offset, e.g. BQM.from_ising(h, J). Do you mean it's incompatible because the user does not have a path to set it? We could easily mitigate that by allowing the user to include it, e.g. bqm.subbqm(vars, include_offset=True) which they might want to do if say dividing it into disconnected components and wanted one to include the offset.

@randomir
Copy link
Member

randomir commented Oct 3, 2019

That was a typo, I meant inconsistent.

What I would consider consistent is, for example, offset always optional, and set to zero by default. In BQM.__init__, BQM.from_ising (current behavior), ..., and BQM.subbqm (proposed above).

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

No branches or pull requests

2 participants