Allow None in simulator's input_state type#458
Allow None in simulator's input_state type#458thierry-martinez wants to merge 5 commits intoTeamGraphix:masterfrom
None in simulator's input_state type#458Conversation
The `run` method handles `None` and doesn't add input nodes to the
backend in this case, assuming that the backend has already been
prepared by the caller. However, the type annotation prevented using
`None` as an `input_state` value.
```python
if input_state is not None:
self.backend.add_nodes(self.pattern.input_nodes, input_state)
```
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #458 +/- ##
==========================================
+ Coverage 88.29% 88.91% +0.62%
==========================================
Files 44 44
Lines 6533 6533
==========================================
+ Hits 5768 5809 +41
+ Misses 765 724 -41 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
matulni
left a comment
There was a problem hiding this comment.
Thanks for the PR, just one small comment
graphix/sim/statevec.py
Outdated
| Parameters | ||
| ---------- | ||
| other : :class:`Statevec` | ||
| other : :class:`Matrix` | :class:`Statevec` |
There was a problem hiding this comment.
Could it be a problem that with the enlarged type of other it becomes easier to mistakenly compare two vectors in different basis ?
Before this was to some extent guaranteed by the type-checker (in the sense that we could only compare Statevec objects), and the responsibility of having an np.array in the correct basis was delegated to the initialisation step.
But maybe I'm being overly cautious...
There was a problem hiding this comment.
I don't have a strong opinion either way, but worth noting Matrix input is similarly not supported in DensityMatrix fidelity either.
graphix/sim/statevec.py
Outdated
| Parameters | ||
| ---------- | ||
| other : :class:`Statevec` | ||
| other : :class:`Matrix` | :class:`Statevec` |
There was a problem hiding this comment.
I don't have a strong opinion either way, but worth noting Matrix input is similarly not supported in DensityMatrix fidelity either.
This partially reverts commit 4addf27.
This partially reverts commit 4addf27.
The
runmethod handlesNoneand doesn't add input nodes to the backend in this case, assuming that the backend has already been prepared by the caller. However, the type annotation prevented usingNoneas aninput_statevalue.Update [2026-03-06T13:16:30]: Allow
NoneinPattern.simulate_patternandMatrixinStatevec.isclose.