Skip to content

Conversation

@LiranShirizly
Copy link
Contributor

This enable when the circuit metadata contain average_params.

.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.

Comment on lines 1107 to 1111
if (
outer_shape
and not average_params
and not isinstance(joined_data, BitArray)
):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the logic needs to be outer_shape and (not average_params or not isinstance(joined_data, BitArray)) or outer_shape and not (average_params and isinstance(joined_data, BitArray))?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are right. thanks!

Copy link
Collaborator

@wshanks wshanks left a comment

Choose a reason for hiding this comment

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

Looks good!

@wshanks wshanks added this pull request to the merge queue Nov 3, 2025
Merged via the queue into qiskit-community:main with commit ca1cad6 Nov 3, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants