Skip to content

Comments

Implement SimulatorBackend and Statevec#62

Merged
masa10-f merged 81 commits intomasterfrom
statevec
Jul 22, 2025
Merged

Implement SimulatorBackend and Statevec#62
masa10-f merged 81 commits intomasterfrom
statevec

Conversation

@masa10-f
Copy link
Collaborator

Before submitting, please check the following:

  • Make sure you have tests for the new code and that test passes (run pytest)
  • If applicable, add a line to the [unreleased] part of CHANGELOG.md, following keep-a-changelog.
  • Format added code by ruff
  • Type checking by mypy and pyright
  • Make sure the checks (github actions) pass.
  • Check that the docs compile without errors (run make html in ./docs/ - you may need to install dependency for sphinx docs, see docs/requirements.txt.)

Then, please fill in below:

Context (if applicable):

I have implemented simulator_backend and statevec for the basic numerical calculation. Currently, simulator_backend has a minimum set of abstract methods, which will be extended in future PRs.
I added flip and conjugate methods in common.MeasBasis.

Description of the change:

Related issue:

@masa10-f masa10-f requested a review from Copilot June 26, 2025 02:20
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new BaseSimulatorBackend interface and a concrete StateVector simulator backend with core operations (evolution, measurement, tensoring, etc.), extends measurement bases with flip and conjugate methods, and adds corresponding tests and documentation.

  • Implement BaseSimulatorBackend abstract class
  • Add StateVector class with numerical routines (evolve, measure, entangle, ...)
  • Extend MeasBasis with flip/conjugate and update docs/tests

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/test_statevec.py Add unit tests for StateVector; covers init, evolve, measure, etc.
graphix_zx/statevec.py Implement StateVector methods and state-management logic
graphix_zx/simulator_backend.py Introduce BaseSimulatorBackend interface
graphix_zx/matrix.py Add is_hermitian helper
graphix_zx/common.py Add abstract flip/conjugate to MeasBasis and implement in two subclasses
docs/source/statevec.rst Document StateVector module
docs/source/simulator_backend.rst Document simulator_backend module
docs/source/references.rst Register the new modules in the reference guide
Comments suppressed due to low confidence (6)

graphix_zx/statevec.py:119

  • [nitpick] The parameter num_qubits shadows the num_qubits property, which can be confusing. Consider renaming to something like count or new_qubits.
    def add_node(self, num_qubits: int) -> None:

graphix_zx/statevec.py:158

  • [nitpick] The example in the docstring is unclear about the permutation convention. Clarify whether the list represents a mapping from old-to-new or new-to-old axes so users aren't confused.
        if permutation is [2, 0, 1], then

graphix_zx/statevec.py:155

  • The reorder method is new but lacks any unit tests. Consider adding tests to cover common permutations and verify that qubit ordering is handled correctly.
    def reorder(self, permutation: Sequence[int]) -> None:

graphix_zx/statevec.py:130

  • The entangle (and by extension add_node) methods are not exercised by the existing tests. Adding coverage for these operations would help prevent regressions.
    def entangle(self, qubits: tuple[int, int]) -> None:

graphix_zx/matrix.py:39

  • It’s safer to first check that mat is square (shape[0] == shape[1]) before comparing to its conjugate transpose, to avoid unexpected broadcasting.
def is_hermitian(mat: NDArray[T]) -> bool:

graphix_zx/common.py:121

  • The new flip and conjugate methods on measurement bases lack direct unit tests. Consider adding tests to validate their behavior for each basis type.
    def flip(self) -> PlannerMeasBasis:

@masa10-f masa10-f self-assigned this Jun 26, 2025
@masa10-f masa10-f mentioned this pull request Jun 6, 2025
@masa10-f masa10-f marked this pull request as ready for review June 26, 2025 02:31
@masa10-f masa10-f requested review from EarlMilktea and nabe98 June 26, 2025 02:31
@masa10-f masa10-f requested a review from EarlMilktea July 18, 2025 10:23
@masa10-f masa10-f requested a review from EarlMilktea July 19, 2025 01:56
Copy link
Collaborator

@EarlMilktea EarlMilktea left a comment

Choose a reason for hiding this comment

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

Almost there!

@masa10-f masa10-f requested a review from nabe98 July 22, 2025 02:39
@masa10-f masa10-f merged commit 46b8ee3 into master Jul 22, 2025
20 checks passed
@masa10-f masa10-f deleted the statevec branch July 22, 2025 02:45
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