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

Handle confusion matrices in deferred measurements #5851

Merged
merged 27 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
comments
  • Loading branch information
daxfohl committed Sep 2, 2022
commit f8ea3dcbb4f9611a1453764973b52062d155217f
1 change: 1 addition & 0 deletions cirq-core/cirq/transformers/measurement_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ class _ConfusionChannel(ops.Gate):
[sqrt(0.2), 0]],
[[0, 0],
[0, sqrt(0.9)]]]"""

def __init__(self, confusion_map: np.ndarray, shape: Sequence[int]):
kraus = []
R, C = confusion_map.shape
Expand Down
3 changes: 3 additions & 0 deletions cirq-core/cirq/transformers/measurement_transformers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ def test_confusion_map():
# 10K samples would take a long time if we had not deferred the measurements, as we'd have to
# run 10K simulations. Here with DM simulator it's 100ms.
result = sim.sample(deferred, repetitions=10_000)

# This should be 5_000 due to the H, then 1_000 more due to 0's flipping to 1's with p=0.2, and
# then 500 less due to 1's flipping to 0's with p=0.1, so 5_500.
assert 5_100 <= np.sum(result['a']) <= 5_900
assert np.all(result['a'] == result['b'])

Expand Down