results: register defaults, YieldHandling key formats, and root exports - #76
Open
qci-amos wants to merge 3 commits into
Open
results: register defaults, YieldHandling key formats, and root exports#76qci-amos wants to merge 3 commits into
qci-amos wants to merge 3 commits into
Conversation
Both fell back to get_default_register, which lists every qubit in the circuit whether or not it was measured, so an unmeasured qubit was padded into the bitstring and read as an outcome. They now default to get_measurements_register and fall back to every qubit only when nothing was measured at all. Passing get_default_register explicitly still gets the padded register. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
apply() tested keys with `"*" not in k`, which raises TypeError on the integer keys count_measurements produces for key_format=None, and built its all-erasures fallback key with str.replace. Only string keys can hold a splat, so the erasure test now checks for that and the fallback key falls back to 0 for a non-string key. An empty distribution raised StopIteration from the fallback, which is not a useful error for a counts dict that post selection emptied; it now raises ValueError. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The user guide refers to these as dwave.gate.Result and dwave.gate.YieldHandling, which did not resolve. They are re-exported from the package root and remain importable from dwave.gate.results, which is still where they are defined, so __module__ does not move. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #76 +/- ##
==========================================
+ Coverage 90.18% 90.71% +0.53%
==========================================
Files 31 31
Lines 5317 5377 +60
==========================================
+ Hits 4795 4878 +83
+ Misses 522 499 -23 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of splitting #71 into reviewable pieces. This is the non-QCDL half —
dwave.gate.results— and is independent of the other four PRs.Three independent fixes, one commit each.
1.
get_memory/get_countsdefault to the measured registerBoth fell back to
get_default_register, which lists every qubit in thecircuit whether or not it was measured. An unmeasured qubit was therefore
padded into the bitstring with
unmeasured_valueand read as an outcome:a three-qubit circuit measuring only
q1andq2returned{"01_": 3}.They now default to
get_measurements_register, falling back to every qubitonly when nothing was measured at all.
get_default_registeris unchanged andstill available — pass it explicitly to get the padded register back — and its
docstring now says which methods use it and when.
Compatibility: this changes the default output shape for any circuit with
unmeasured qubits. Callers passing an explicit
registerare unaffected.2.
YieldHandling.applyhandles every counts key formatapplytested keys with"*" not in k.count_measurements(..., key_format=None)produces integer keys, so composing the two — which is the obvious thing to
do — raised
TypeError: argument of type 'int' is not iterable. Theall-erasures fallback had the same assumption, building its zeros key with
str.replace.Only the string key formats can hold a splat, so the erasure test now checks
for that, and the fallback key falls back to
0for a non-string key.An empty distribution raised
StopIterationout of that fallback, which is nota useful error for a counts dict that post-selection emptied; it now raises
ValueError.applyalso picked up the docstring it never had.3. Export
ResultandYieldHandlingfrom the package rootThe user guide refers to these as
dwave.gate.Resultanddwave.gate.YieldHandling, which did not resolve. They are re-exported fromthe package root and remain importable from
dwave.gate.results, which isstill where they are defined — a test asserts
__module__does not move, sinceSphinx and pickle both key off it.
Testing
pytest tests/passes.tests/test_results.pycovers the register default(including the explicit-register and nothing-measured paths),
applyagainstevery key format
count_measurementsproduces, and the import paths.🤖 Generated with Claude Code