Skip to content

redefining OperatorEvolution class and fixing typehints - #1528

Open
lballerio wants to merge 4 commits into
mainfrom
improve_emulator_classes_and_typehint
Open

redefining OperatorEvolution class and fixing typehints#1528
lballerio wants to merge 4 commits into
mainfrom
improve_emulator_classes_and_typehint

Conversation

@lballerio

@lballerio lballerio commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

In this PR, I am redefining the emulator's data handling to make it clearer and more expressive, particularly the way static and time-dependent Hamiltonians are represented before starting the simulation.

Specifically, the static and dynamical contributions of the full Hamiltonian have been split into two separate objects: the static term is now represented by an Operator, while the dynamical terms are represented by an OperatorEvolution.

The main issue with the previous design was that OperatorEvolution.operators is typed as list[Operator | TimeDependentOperator], which introduces some ambiguity. In particular, when loading data from the filesystem, main currently relies on the convention that the first element of this list is the static term. I believe the new design makes the data model much clearer by explicitly separating static and dynamical terms instead of encoding them within a single object.

To better understand the motivation behind these changes, please also refer to the updates to the loading functions in qutip.py.

Finally, I added several type hints throughout the code.

Note that we have decided to focus exclusively on the qutip engine. Therefore, feedback related to the dynamiqs engine is not a priority, as it may already be outdated, partially broken, and not fully tested.

Checklist:

  • Reviewers confirm new code works as expected.
  • Tests are passing.
  • Coverage does not decrease.
  • Documentation is updated.

@lballerio
lballerio requested review from a team July 17, 2026 11:59
@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.75000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 38.96%. Comparing base (dd6f942) to head (339f6dd).

Files with missing lines Patch % Lines
...qibolab/_core/instruments/emulator/engine/qutip.py 66.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1528      +/-   ##
==========================================
+ Coverage   38.90%   38.96%   +0.05%     
==========================================
  Files         120      120              
  Lines        6225     6231       +6     
==========================================
+ Hits         2422     2428       +6     
  Misses       3803     3803              
Flag Coverage Δ
unittests 38.96% <93.75%> (+0.05%) ⬆️

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.

@RoyStegeman RoyStegeman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Different from what the title of this PR suggests, changes go beyond typehints and the interface is also being changed. In particular, OperatorEvolution now separates the static and time-dependent parts into two attributes. This change is propagated and many of the changes in this PR are to accommodate this change.

Before I continue reviewing. What is the reason for this change?

initial_state: Operator,
time: list[float],
collapse_operators: list[Operator] = None,
time: ArrayLike,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

in DynamiqsEngine.evolve time is an Iterable. An iterable can also be a dict which is not an ArrayLike. So this typehint is too restrictive (actually it was already before, but it still is). I'm assuming that Iterable is more general than necessary, so in that case you could change that one instead of here.

def evolve(
self,
hamiltonian: Operator,
hamiltonian: OperatorEvolution,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hamiltonian = 0

This hamiltonian can be 0 or something else, but eventually is also passed to evolve.

@lballerio lballerio changed the title fixing some typechecks in the emulator redefining OperatorEvolution class and fixing typehints Jul 31, 2026
@lballerio
lballerio requested a review from RoyStegeman July 31, 2026 15:43
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.

3 participants