Skip to content

Allow None in simulator's input_state type#458

Open
thierry-martinez wants to merge 5 commits intoTeamGraphix:masterfrom
thierry-martinez:input_state_none
Open

Allow None in simulator's input_state type#458
thierry-martinez wants to merge 5 commits intoTeamGraphix:masterfrom
thierry-martinez:input_state_none

Conversation

@thierry-martinez
Copy link
Collaborator

@thierry-martinez thierry-martinez commented Mar 5, 2026

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.

        if input_state is not None:
            self.backend.add_nodes(self.pattern.input_nodes, input_state)

Update [2026-03-06T13:16:30]: Allow None in Pattern.simulate_pattern and Matrix in Statevec.isclose.

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
Copy link

codecov bot commented Mar 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.91%. Comparing base (b70ffeb) to head (bae79d0).
⚠️ Report is 2 commits behind head on master.

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.
📢 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.

Copy link
Contributor

@matulni matulni left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, just one small comment

Parameters
----------
other : :class:`Statevec`
other : :class:`Matrix` | :class:`Statevec`
Copy link
Contributor

Choose a reason for hiding this comment

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

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...

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have a strong opinion either way, but worth noting Matrix input is similarly not supported in DensityMatrix fidelity either.

Parameters
----------
other : :class:`Statevec`
other : :class:`Matrix` | :class:`Statevec`
Copy link
Contributor

Choose a reason for hiding this comment

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

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.
@thierry-martinez
Copy link
Collaborator Author

@emlynsg @matulni, thanks for your comments. I agree that relaxing the type annotation for is_close is not ideal, so I've reverted that change in 19840a1, retaining only the update to input_state's type.

This partially reverts commit 4addf27.
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