Skip to content

Make tests in test_noisy_density_matrix.py use the BranchSelector feature#425

Open
tibisabau wants to merge 9 commits intoTeamGraphix:masterfrom
tibisabau:416-makes-backend-tests-deterministic
Open

Make tests in test_noisy_density_matrix.py use the BranchSelector feature#425
tibisabau wants to merge 9 commits intoTeamGraphix:masterfrom
tibisabau:416-makes-backend-tests-deterministic

Conversation

@tibisabau
Copy link
Contributor

Before submitting, please check the following:

  • Make sure you have tests for the new code and that test passes (run nox)
  • If applicable, add a line to the [unreleased] part of CHANGELOG.md, following keep-a-changelog.
  • Format added code by ruff
    • See CONTRIBUTING.md for more details
  • Make sure the checks (github actions) pass.

Then, please fill in below:

Context (if applicable):

The noisy density matrix backend tests in test_noisy_density_matrix.py were non-deterministic because they relied on random measurement outcomes. These tests used or conditions to check multiple possible outcomes, making them fail intermittently. The BranchSelector feature (introduced in PR #300) allows fixing measurement outcomes deterministically.

Description of the change:

Modified all affected tests in test_noisy_density_matrix.py to use BranchSelector (ConstBranchSelector and FixedBranchSelector) to fix measurement outcomes, making the tests fully deterministic. Updated test logic based on understanding that noise channels are applied unconditionally after correction commands in the depolarising noise model.

Related issue:

Fixes #416

@codecov
Copy link

codecov bot commented Feb 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.76%. Comparing base (03a89c9) to head (fff9592).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #425   +/-   ##
=======================================
  Coverage   88.76%   88.76%           
=======================================
  Files          44       44           
  Lines        6308     6308           
=======================================
  Hits         5599     5599           
  Misses        709      709           

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

@thierry-martinez
Copy link
Collaborator

@tibisabau Thank you for your last commits. I pointed just the first occurrences of each problem, but you need to solve all the other occurrences for ruff and mypy to be happy. You can run ruff and mypy (and even nox) locally to check that all CI checks will pass before pushing.

Comment on lines 366 to 375
Copy link
Collaborator

Choose a reason for hiding this comment

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

My previous comment (#425 (comment)) applies here and lines 410 and below as well: in particular, we don't need to use cast here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

For homogeneity, I would prefer if we do the same here as for line 324 (and this applies to line 398 and 442 too).

@mgarnier59
Copy link
Contributor

@tibisabau thanks for your PR! While checking it, we realised that the behaviour in the test was the one we wanted but not the one taht was implemented. Son instead of making the tests fit the implementation, we'll modify the implementation see #428 for more details.

Thanks again and keep an eye on further developments!

@mgarnier59
Copy link
Contributor

mgarnier59 commented Feb 17, 2026

Thanks @tibisabau for updating the PR. It looks good! However I still see previous history in your PR. Do you know why that is? If you can't fix it, it will disappear when squashing and merging anyways.

Graphix requires 2 approvals before merging so another colleague will take a look soon. Thanks again for conributing!

tibisabau and others added 8 commits February 19, 2026 10:51
Co-authored-by: thierry-martinez <thierry.martinez@inria.fr>
Co-authored-by: thierry-martinez <thierry.martinez@inria.fr>
Co-authored-by: thierry-martinez <thierry.martinez@inria.fr>
Co-authored-by: thierry-martinez <thierry.martinez@inria.fr>
@tibisabau tibisabau force-pushed the 416-makes-backend-tests-deterministic branch from b8c62a7 to 737d36d Compare February 19, 2026 09:59
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.

Make the noisy density matrix backend tests deterministic with the BranchSelector feature

3 participants

Comments