Fix single-qubit depolarizing noise channel#352
Merged
hayekr merged 5 commits intoMay 27, 2026
Merged
Conversation
Noise.apply_depolarizing_noise hardcoded the Pauli index combinations as 2-qubit tuples ([(i, j) for i in range(4) for j in range(4)]). For the documented single-qubit case (k=1) this had two effects: - spurious full-identity operators were included in the Pauli sum (the tuples (0, 1), (0, 2), (0, 3) map every qubit to I), and - the normalization used 15 operators instead of 3. The result was a mathematically incorrect channel: applying p=0.3 to |0><0| returned diag(0.84, 0.16) instead of the correct diag(0.8, 0.2). Generate the index tuples from the actual number of target qubits with itertools.product(range(4), repeat=k). The two-qubit path is unchanged (15 operators); the single-qubit path now matches the standard depolarizing channel. Adds a regression test for k=1. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes Noise.apply_depolarizing_noise so the single-qubit (k=1) depolarizing channel uses the correct set of Pauli operators and normalization, matching the standard definition while keeping the two-qubit (k=2) behavior unchanged.
Changes:
- Generate Pauli index tuples based on the actual number of target qubits via
itertools.product(..., repeat=k)(instead of hardcoding 2-qubit tuples). - Add a regression test verifying the k=1 depolarizing channel matches the standard
(1-p)ρ + (p/3)(XρX + YρY + ZρZ)behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
sequence/utils/noise.py |
Fixes Pauli operator enumeration/normalization for k=1 by generating index tuples with repeat=k. |
tests/utils/test_noise.py |
Adds a single-qubit depolarizing regression test comparing against a manual reference implementation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…eys in testing the depolarizing noise
hayekr
approved these changes
May 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Noise.apply_depolarizing_noise(insequence/utils/noise.py) is documented to support 1 or 2 target qubits, but it hardcodes the Pauli index combinations as 2-qubit tuples:For the single-qubit case (
k = 1) onlyidx_tuple[0]is used, which produces two problems:(0, 1),(0, 2),(0, 3)map the target qubit (and every other qubit) toI, so the full identity operator is added to the Pauli sum three times.len(pauli_ops) = 15instead of4^1 - 1 = 3.As a result the single-qubit depolarizing channel is mathematically incorrect. For example, applying
p = 0.3to|0><0|:diag(0.84, 0.16)(1-p)ρ + (p/3)(XρX + YρY + ZρZ)diag(0.8, 0.2)Fix
Generate the Pauli index tuples from the actual number of target qubits:
X,Y,Z) and matches the standard depolarizing channel.Test plan
test_apply_depolarizing_noise_single_qubitcomparing thek=1output against the standard single-qubit depolarizing channel.test_apply_depolarizing_noise(two-qubit) still passes — the two-qubit path is unaffected.🤖 Generated with Claude Code