-
Notifications
You must be signed in to change notification settings - Fork 65
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
Include chain break points in returned embedding context #447
base: master
Are you sure you want to change the base?
Include chain break points in returned embedding context #447
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this!
A few comments on the code.
Once that's sorted there might be a few more formatting comments on the docstring.
dwave/embedding/chain_breaks.py
Outdated
"""Identify breakpoints in each chain. | ||
|
||
Args: | ||
samples (array_like): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be expanded to samples like. You can use array, labels = dimod.as_samples(samples_like)
to get the numpy array.
The reason I say this is because in Ocean you can get embeddings that look like {'a': ['b', 'c']}
. The QPU (currently) only uses integer labels for its qubits, but that might change in the future.
Should add a test for this as well.
dwave/embedding/chain_breaks.py
Outdated
|
||
Args: | ||
samples (array_like): | ||
Samples as a nS x nV array_like object where nS is the number of samples and nV is the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should also specify that the samples should be for the embedded problem
dwave/embedding/chain_breaks.py
Outdated
for sample in samples: | ||
bps = {} | ||
for node in embedding.keys(): | ||
chain_edges = embedding.chain_edges(node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to avoid some confusing errors, you probably want
try:
chain_edges = embedding.chain_edges(nodes)
except AttributeError:
raise TypeError("'embedding' must be a dwave.embedding.EmbeddedStructure") from None
@@ -289,7 +290,8 @@ def async_unembed(response): | |||
if return_embedding: | |||
sampleset.info['embedding_context'].update( | |||
embedding_parameters=embedding_parameters, | |||
chain_strength=embedding.chain_strength) | |||
chain_strength=embedding.chain_strength, | |||
break_points=break_points(response, embedding)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a non-trivial performance hit. IMO we either should not do this by default or we need to write a more performant implementation of break_points
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, ideally this would be a lazy proxy.
But FWIW, return_embedding
does default to False
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true, unless for instance the inspector is imported.
My inclination is to not include this in the embedding composite for now, but document how to use the TrackingComposite
to get the information in the docstring of break_points()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the PR according to feedback except for this comment. Should I move the statistic to TrackingComposite
instead?
I think the lazy proxy approach would require storing response
. For a more performant implementation, I can wrap it in numba. Any suggestions for writing a more performant implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the best thing is just to remove the statistic from the embedding composite altogether. I would then add an example to the break_points
docstring showing how to calculate it, using the TrackingComposite
to retrieve the relevant information.
Codecov Report
@@ Coverage Diff @@
## master #447 +/- ##
==========================================
- Coverage 90.52% 87.57% -2.96%
==========================================
Files 22 22
Lines 1520 1521 +1
==========================================
- Hits 1376 1332 -44
- Misses 144 189 +45
Continue to review full report at Codecov.
|
Example of "chain break points":
a chain with +++: no break points.
a chain with +--: break point at (0,1)
a chain with +-+: break points at (0,1) and (1,2)