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

DoubleSliceSpan.mask crashes #2184

Closed
yaelbh opened this issue Mar 18, 2025 · 2 comments · Fixed by #2187
Closed

DoubleSliceSpan.mask crashes #2184

yaelbh opened this issue Mar 18, 2025 · 2 comments · Fixed by #2187
Assignees
Labels
bug Something isn't working
Milestone

Comments

@yaelbh
Copy link
Collaborator

yaelbh commented Mar 18, 2025

Describe the bug

It crashes in a real-world case, coming from a real execution result.

Steps to reproduce

from qiskit_ibm_runtime.execution_span.double_slice_span import DoubleSliceSpan

span = DoubleSliceSpan(1, 2, {0: ((7,), slice(0, 1, None), slice(0, 7, None))})
span.mask(0)

Output:

Traceback (most recent call last):
  File "/mnt/wsl/balagan/doubleslicespan_mask_bug.py", line 4, in <module>
    span.mask(0)
  File "/root/miniforge3/envs/env5/lib/python3.11/site-packages/qiskit_ibm_runtime/execution_span/double_slice_span.py", line 73, in mask
    mask.reshape(np.prod(shape[:-1]), shape[-1])[(args_sl, shots_sl)] = True
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'numpy.float64' object cannot be interpreted as an integer

Expected behavior

Suggested solutions

Additional Information

  • qiskit-ibm-runtime version: 0.34.0
  • Python version: 3.11.10
  • Operating system: Linux (Windows + WSL)
@yaelbh yaelbh added the bug Something isn't working label Mar 18, 2025
@kt474
Copy link
Member

kt474 commented Mar 18, 2025

@joshuasn I'm not super familiar with the DoubleSpliceSpan class, does np.prod(shape[:-1]) need to be converted into an int?

def mask(self, pub_idx: int) -> npt.NDArray[np.bool_]:
shape, args_sl, shots_sl = self._data_slices[pub_idx]
mask = np.zeros(shape, dtype=np.bool_)
mask.reshape(np.prod(shape[:-1]), shape[-1])[(args_sl, shots_sl)] = True
return mask

@joshuasn
Copy link
Collaborator

np.prod uses the data type of its argument but in @yaelbh's example shape[:-1] is an empty tuple, so np.prod returns a float rather than an int. Adding dtype=int to the call fixes it, will open a PR.

I suspect the issue is also present in TwirledSliceSpan, will check and fix there as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants