-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Measurement confusion maps #5480
Measurement confusion maps #5480
Conversation
Can you add a note in DeferredMeasurementsTransformer docstring that measurement confusion maps are not accounted for, and create a github task for fixing that? |
It now raises an error on confused measurements. Opened #5482 (marked after-1.0) for the eventual fix. |
Latest commit fixes an issue I ran into while documenting this: |
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.
LGTM
def measure( | ||
self, | ||
qubits: Sequence['cirq.Qid'], | ||
key: str, | ||
invert_mask: Sequence[bool], | ||
confusion_map: Dict[Tuple[int, ...], np.ndarray], | ||
): |
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.
Without a default value for confusion_map argument, wouldn't this break all user code that uses this public API ?
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.
Good point. The only Cirq code that calls this is MeasurementGate._act_on_
, but there's still some risk:
- External measurement gates don't pass this argument, and would break
- External simulators which reimplement this method won't expect this argument, and would break
(2) actually seems more likely to me than (1), but we can guard against both. I'll put up another PR and mark this one as breaking.
confusion_map: Dict[Tuple[int, ...], np.ndarray], | ||
): | ||
"""Applies confusion matrices to measured results.""" | ||
confused = list(bits) |
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.
bits
is already a List[int]
so this looks redundant. Should bits be a Sequence[int]
instead?
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.
The purpose of this is not to convert to list but to copy bits
.
Fixes the breakage created by #5480.
* Measurement confusion maps * format * mypy+format * Error on deferred confused measure * Also change SimulatesSamples behavior. * Test SimulatesSamples * docstring zero note
Fixes the breakage created by quantumlib#5480.
* Measurement confusion maps * format * mypy+format * Error on deferred confused measure * Also change SimulatesSamples behavior. * Test SimulatesSamples * docstring zero note
Fixes the breakage created by quantumlib#5480.
Fixes #4348.
This adds an optional
confusion_map
field toMeasurementGate
which probabilistically changes the results of that measurement without changing the state of the targeted qubits.Compare with
TensoredConfusionMatrices
introduced in #4854. I opted to provide a conversion to that type instead of using it directly as it differs too greatly from what is needed here:EDIT: It was pointed out that this potentially breaks external measurement and simulator behavior by requiring the
confusion_map
parameter. PR #5534 resolves this.