-
Notifications
You must be signed in to change notification settings - Fork 617
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
[BUG] Confusing counts labels for list of MCMs including a postselected MCM #5513
Closed
1 task done
Labels
bug 🐛
Something isn't working
Comments
dwierichs
changed the title
[BUG]
[BUG] Confusing counts labels for list of MCMs including a postselected MCM
Apr 15, 2024
mudit2812
added a commit
that referenced
this issue
Apr 18, 2024
**Context:** [sc-61314] Issue #5513 was being caused by samples that were converted to decimals to be cast to `int8`. This caused overflow with 8 or more wires, resulting in negative values being present in the counts dictionary. **Description of the Change:** * Update `qml.counts.process_samples` and `QubitDevice._samples_to_counts` to cast to `int64` instead of `int8`. **Benefits:** No more overflow issues with `qml.counts`. **Possible Drawbacks:** **Related GitHub Issues:** #5513
Just noting here that this issue is still not resolved with #5544 because circuits with more than 64 qubits will have this behaviour still |
mudit2812
added a commit
that referenced
this issue
Apr 23, 2024
**Context:** `qml.counts` was converting samples to integers and using f-strings to format as binary strings, however, it caused wires > 64 to have overflow. Without the changes in this PR: ```python import pennylane as qml import numpy as np np.random.seed(582) num_wires = 70 wires = list(range(num_wires)) dev = qml.device("default.clifford", wires=wires, shots=100) @qml.qnode(dev) # @qml.defer_measurements def circuit(): [qml.PauliX(w) for w in wires] return qml.counts() circuit() ``` ```pycon {'-000000000000000000000000000000000000000000000000000000000000000000001': tensor(100, requires_grad=True)} ``` With the changes: ```python import pennylane as qml import numpy as np np.random.seed(582) num_wires = 70 wires = list(range(num_wires)) dev = qml.device("default.clifford", wires=wires, shots=100) @qml.qnode(dev) # @qml.defer_measurements def circuit(): [qml.PauliX(w) for w in wires] return qml.counts() circuit() ``` ```pycon {'1111111111111111111111111111111111111111111111111111111111111111111111': tensor(100, requires_grad=True)} ``` **Description of the Change:** * Change `qml.counts` to convert directly from list of samples to binary string without first converting to integers. * Changed `QubitDevice._samples_to_counts` to cast to `int8` instead of `int64`. This is only for casting samples, not converting to ints, as `int8` is more memory efficient. **Benefits:** * `qml.counts` now works with arbitrary wires. This is useful for devices like `default.clifford`, which can simulate hundreds of qubits. **Possible Drawbacks:** **Related GitHub Issues:** #5537 , #5513 --------- Co-authored-by: David Wierichs <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expected behavior
Meaningful strings are created to reference mid-circuit measurement values.
Actual behavior
For a very particular setup, strings are produced that contain a
"-"
character, which is unexpected and not meaningful.Note that the output strings should consist of 4 varying integers (
first_mcms
), 1 integer that is fixed to"1"
(postselected_mcm
) and 3 more varying integers (second_mcms
).Additional information
No response
Source code
Tracebacks
System information
Existing GitHub issues
The text was updated successfully, but these errors were encountered: