Skip to content

Avoid stacking unused emulator coefficients - #1514

Closed
DennisWayo wants to merge 1 commit into
qiboteam:mainfrom
DennisWayo:fix/emulator-swept-duration-coefficients
Closed

Avoid stacking unused emulator coefficients#1514
DennisWayo wants to merge 1 commit into
qiboteam:mainfrom
DennisWayo:fix/emulator-swept-duration-coefficients

Conversation

@DennisWayo

@DennisWayo DennisWayo commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes an emulator execution failure for swept-duration workflows where the pulse sequence length changes between sweep points.

The issue appeared while validating Qibocal T1 workflows on the emulator after the recent result-handling fixes. A T1 delay sweep changes the duration of the sequence, so the pulse-Hamiltonian coefficient arrays can have different lengths for each sweep value. The emulator was stacking those coefficient arrays unconditionally:

return np.stack(state_slices), np.stack(coeff_slices)

That raises:

ValueError: all input arrays must have the same shape

For normal execution, these coefficients are not used. They are only needed when EmulatorController.save_dir is enabled for dumping the simulated evolution. This PR therefore keeps stacking the states as before, but only collects/stacks coefficient arrays when save_dir is set.

Change

The sweep code now treats coefficient stacking as part of the simulation-dump path:

coeff_slices = [] if self.save_dir is not None else None
...
if coeff_slices is not None:
    coeff_slices.append(coeffs)
...
return (
    np.stack(state_slices),
    np.stack(coeff_slices) if coeff_slices is not None else None,
)

This keeps ordinary emulator execution from failing on variable-duration sweeps while preserving the existing behavior for saved simulations.

Test

I added a regression test that sweeps a Delay.duration before measurement. This reproduces the variable sequence-length case that triggered the Qibocal T1 failure.

Validation

Focused checks:

pytest tests/instruments/emulator/test_emulator.py -k variable_sequence_length -q
pytest tests/instruments/emulator/test_emulator.py tests/instruments/emulator/test_results.py -q
ruff check src/qibolab/_core/instruments/emulator/emulator.py tests/instruments/emulator/test_emulator.py
ruff format --check src/qibolab/_core/instruments/emulator/emulator.py tests/instruments/emulator/test_emulator.py

All passed locally.

Qibocal T1 smoke after this patch:

Workflow Engine Status Acquisition time Fitted T1
t1 on qubit QuTiP acquisition + fit passed 5.99 s 982.869 ns
t1 on qubit Dynamiqs acquisition + fit passed 19.25 s 987.984 ns

The Dynamiqs and QuTiP fitted T1 values agree closely for this smoke workflow.

Scope

This is intentionally limited to ordinary emulator execution with swept sequence durations. It does not attempt to redesign the saved-evolution dump format for variable-length coefficient arrays.

@lballerio

lballerio commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Hi @DennisWayo, thanks for pointing this out.
This breaking problem was well known by the team and was consciously introduced because of lack of time in reviewing UnitaryHack2026 PRs.
We've already fixed the issue in #1499 which has been merged this morning.
So I think there is no need to keep this PR open.
However thanks a lot for your effort!

@lballerio lballerio closed this Jul 9, 2026
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