-
Notifications
You must be signed in to change notification settings - Fork 1
Combine counters #103
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
base: main
Are you sure you want to change the base?
Combine counters #103
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
from __future__ import annotations | ||
|
||
import logging | ||
from collections import Counter | ||
from typing import Any, cast | ||
|
||
import numpy as np | ||
|
@@ -60,6 +61,8 @@ def __init__( | |
self, | ||
povm_sample: POVMPubResult, | ||
dual: BaseDual | None = None, | ||
*, | ||
combine_counts: bool = False, | ||
) -> None: | ||
"""Initialize the POVM post-processor. | ||
|
||
|
@@ -70,6 +73,9 @@ def __init__( | |
:meth:`get_decomposition_weights`. When this is ``None``, the standard | ||
"state-average" Dual frame will be constructed from the POVM stored in the | ||
``povm_sample``'s :attr:`.POVMPubResult.metadata`. | ||
combine_counts: indicates, when applicable, whether to combine the counts associated | ||
with different parameter values that were submitted for a single parametrized | ||
circuit. | ||
Comment on lines
+76
to
+78
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this explanation has to be extended further:
We can either do that in the docs here, or in a how-to guide and link to that from here (which may be better as it gives us more space for explanations). |
||
|
||
Raises: | ||
ValueError: If the provided ``dual`` is not a dual frame to the POVM stored in the | ||
|
@@ -78,6 +84,11 @@ def __init__( | |
self._povm = povm_sample.metadata.povm_implementation.definition() | ||
|
||
self._counts = cast(np.ndarray, povm_sample.get_counts()) | ||
if combine_counts: | ||
combined_counter: Counter = Counter() | ||
for count in self._counts.flatten(): | ||
combined_counter.update(count) | ||
mrossinek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self._counts = np.array([combined_counter], dtype=object) | ||
|
||
if (dual is not None) and (not dual.is_dual_to(self._povm)): | ||
raise ValueError( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
features: | ||
- | | ||
Add an option for the post-processors to combine the counts associated with different parameter | ||
values that were submitted in the same POVM sampler PUB. | ||
Comment on lines
+4
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we do end up with a new how-to guide, we should link to that from here. |
||
|
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 needs to be aligned with whatever updates we apply based on the previous comment.