Skip to content

Bypass cyclic emulator state indexing - #1505

Merged
lballerio merged 3 commits into
qiboteam:mainfrom
DennisWayo:fix/emulator-bypass-nondiscriminated
Jun 25, 2026
Merged

Bypass cyclic emulator state indexing#1505
lballerio merged 3 commits into
qiboteam:mainfrom
DennisWayo:fix/emulator-bypass-nondiscriminated

Conversation

@DennisWayo

@DennisWayo DennisWayo commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary

This is a small follow-up to the emulator/Qibocal baseline enabled by qiboteam/qibocal #1551.

It updates cyclic emulator result extraction to marginalize probabilities directly over the measured Hilbert-space component instead of first building the full computational-state index table and masking it.

The behavior is unchanged at the result interface:

  • non-ground states are still classified as population 1;
  • INTEGRATION results still return the expected (I, Q) shape;
  • sweep axes are preserved.

Context

This addresses the marginalization direction described in qiboteam/qibolab#1216: for non-shot/cyclic result processing, there is no need to go through sampled-state machinery or full-state index conversion when probabilities can be reshaped to the system Hilbert-space dimensions and marginalized directly.

I kept this separate from the local #1413 work because #1413 depends on the confusion-matrix path introduced in draft qiboteam/qibolab #1401, which has not landed yet.

Validation

  • pytest tests/instruments/emulator/test_results.py -q
  • pytest tests/instruments/emulator/test_emulator.py tests/instruments/emulator/test_results.py -q
  • pytest tests/instruments/emulator -q
  • ruff check src/qibolab/_core/instruments/emulator/results.py tests/instruments/emulator/test_results.py
  • ruff format --check src/qibolab/_core/instruments/emulator/results.py tests/instruments/emulator/test_results.py
  • Qibocal Rabi smoke on merged Qibocal main platform: qubit acquisition + fit passed
  • Qibocal Rabi smoke on merged Qibocal main platform: qutrit acquisition + fit passed

@DennisWayo
DennisWayo marked this pull request as ready for review June 23, 2026 10:17
@DennisWayo
DennisWayo requested review from a team June 23, 2026 10:17

@lballerio lballerio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi Dennis, thanks for your contribution!
For me is almost fine, I would ask you do the for loop inside the _marginalize_probability, this would be better for modularity and readability.
Also, for even more readability, maybe add some more comments especially in the more convoluted lines.
I'll move this PR to draft, but I think apart for these small suggestions I think it will be soon good to merge for me.

@lballerio
lballerio marked this pull request as draft June 24, 2026 05:54
@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 39.41%. Comparing base (6530bdf) to head (932ae74).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1505      +/-   ##
==========================================
+ Coverage   39.34%   39.41%   +0.06%     
==========================================
  Files         115      115              
  Lines        6145     6152       +7     
==========================================
+ Hits         2418     2425       +7     
  Misses       3727     3727              
Flag Coverage Δ
unittests 39.41% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/qibolab/_core/instruments/emulator/results.py
[
_marginalize_probability(
state_probs[..., measurement, :], hamiltonian.dims, qubit_index
)[..., 1:].sum(axis=-1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess here you are summing all states >=1...I think you can also move this part in the function

@DennisWayo

DennisWayo commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @lballerio, this makes sense. I moved the per-measurement loop into _marginalize_probability(), and the helper now also makes the non-ground-state classification explicit there. I also added the comment around states outside the ground state being classified as 1, so the intent is clearer at the point where the summation happens.

Comment thread src/qibolab/_core/instruments/emulator/results.py
@lballerio
lballerio marked this pull request as ready for review June 24, 2026 09:58
@lballerio
lballerio marked this pull request as draft June 24, 2026 09:58
@DennisWayo

DennisWayo commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @lballerio , I added the comment at that point.

It now states that the non-ground-state sum is intentionally done before stacking because measured subsystems may have different dimensions.

@lballerio
lballerio marked this pull request as ready for review June 25, 2026 11:14
@lballerio

Copy link
Copy Markdown
Contributor

Hi @DennisWayo, I tested your code for a bit and everything seems working, so for me is approved and able to merge.

@lballerio
lballerio added this pull request to the merge queue Jun 25, 2026
Merged via the queue into qiboteam:main with commit 326d9a1 Jun 25, 2026
58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants