Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
10 changes: 8 additions & 2 deletions qiskit_experiments/framework/experiment_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1099,11 +1099,17 @@ def _add_result_data(
if testres.data:
joined_data = testres.join_data()
outer_shape = testres.data.shape
if outer_shape:
average_params = (
result[i]
.metadata.get("circuit_metadata", {})
.get("average_params", False)
)
if outer_shape and not average_params:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you call join_data(), the BitArray for level 2 or ndarray for level 1 gets concatenated on the last axis. The next to last dimension is the shot index. When there are parameters, the earlier dimensions are the parameter indices. Allowing the data to pass this error for the BitArray case leads to get_counts() and get_bitstrings() getting called and that leads to averaging over parameters because those methods produce one combined counts dict and a one dimensional list of bitstrings (unraveling the parameter dimensions into the shots dimension effectively).

I have a few thoughts on this:

  1. Maybe we should not let level 1 ndarray case get past the error here. I think the pub dimensions will make the arrays not match and lead to an exception on the data["memory"] assignment lines below.
  2. Maybe we should change data["shots"] below to be len(data["memory"])? Otherwise, it will be the single parameter value shot number instead of the combined shot total. I think most of our analysis does len(bitstrings) or sum(counts.value()) any way rather than relying on the separate shots number.
  3. If you wanted, you could add a simple test with an outer parameter dimension and check that the data() has the right shape. The risk is if we ever try to support parameterized pubs more fully we might break this option. Maybe that risk is pretty low.

raise QiskitError(
f"Outer PUB dimensions {outer_shape} found in result. "
"Only unparameterized PUBs are currently supported by "
"qiskit-experiments."
"qiskit-experiments unless the circuit metadata "
"indicates to average them."
)
else:
joined_data = None
Expand Down
6 changes: 6 additions & 0 deletions releasenotes/notes/average-pub-params-f24fd73f817051ac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---

features:
- |
Enable averaging PUB parameters in :class:`~.ExperimentData` when
the circuit metadata contain "average_params".