`deq.noise.inject_si1000` drops target qubits on `CX[tag] 0 1` and produces invalid `M(p)[tag]` syntax on `M[tag] 0 1`
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 75/100
Research direction
Read deq/deq/noise/common.py at split_two_qubit_gate_targets and deq/deq/noise/injector.py at inject_noise. Reproduce both cases from the issue, then run the deq unit tests. Done means tagged two-qubit gates retain both targets, tagged measurements put the probability after the tag, and the resulting circuit parses cleanly.
Written by the indexing model from the issue text.
Description
Description
Two Stim [tag] bugs in deq.noise:
split_two_qubit_gate_targetschecksif tbefore stripping[...]tags, leaving an empty string""in index 0 forCX[entangle] 0 1. Pair chunking then emits malformedDEPOLARIZE2(0.01) 0and silently drops qubit1.inject_noiseprepends({prob})directly beforeafter_cleanon measurements, rewritingM[ro] 0 1as invalidM(0.01)[ro] 0 1instead ofM[ro](0.01) 0 1.
Steps to Reproduce
Run on main (60dd1134c53d1a7dc792516014fa1a021aa10a61), Python 3.12.14:
# Trigger 1 (2Q [tag] qubit drop):
from deq.noise import inject_si1000
src = "CODE C [[1,1,1]] {\n LOGICAL X0 Z0\n}\nGADGET G {\n R 0 1\n CX[entangle] 0 1\n M 0 1\n}\n"
noisy = inject_si1000(src, p=0.01)
assert "DEPOLARIZE2(0.01) 0 1" in noisy, f"Corrupted 2Q noise:\n{noisy}"
print("OK")
# Trigger 2 (M [tag](prob) ordering):
from deq.circuit.parser import parse
from deq.noise import inject_si1000
src = "CODE C [[1,1,1]] {\n LOGICAL X0 Z0\n}\nGADGET G {\n R 0 1\n M[ro] 0 1\n}\n"
noisy = inject_si1000(src, p=0.01)
assert "M[ro](0.01) 0 1" in noisy, f"Wrong tag/noise order:\n{noisy}"
parse(noisy)
print("OK")
Actual Behavior
On CX[entangle] 0 1:
DEPOLARIZE2(0.01) 0 # qubit 1 dropped
On M[ro] 0 1:
M(0.01)[ro] 0 1 # deq.circuit.parser.parse raises SyntaxError
Expected Behavior
CX[entangle] 0 1 should get DEPOLARIZE2(0.01) 0 1, and M[ro] 0 1 should become M[ro](0.01) 0 1 and parse cleanly via deq.circuit.parser.parse.
Root Cause & Suggested Minimal Fix
- Location:
deq/deq/noise/common.py#L79-L83, deq/deq/noise/injector.py#L158-L167 - Details:
common.pykeeps empty tokens produced by regex tag stripping;injector.pyinserts({prob})before[tag]instead of immediately after].
Suggested minimal diff (verified against `deq` unit tests)
diff --git a/deq/deq/noise/common.py b/deq/deq/noise/common.py
index db910ba..3a49806 100644
--- a/deq/deq/noise/common.py
+++ b/deq/deq/noise/common.py
@@ -79,7 +79,8 @@ def split_two_qubit_gate_targets(
return tok, True
return re.sub(r"\[[^\]]*\]", "", tok), False
- processed = [_process(t) for t in raw_tokens if t]
+ # Drop empty tokens produced when stripping bracketed Stim tags like [tag]
+ processed = [res for t in raw_tokens if (res := _process(t))[0]]
qubit_pairs: list[str] = []
single_qubits: list[str] = []
diff --git a/deq/deq/noise/injector.py b/deq/deq/noise/injector.py
index f54cba5..fc18eb9 100644
--- a/deq/deq/noise/injector.py
+++ b/deq/deq/noise/injector.py
@@ -158,7 +158,13 @@ def inject_noise(text: str, emitter: NoiseEmitter) -> str:
if measure_prob is not None:
after_clean = strip_parens(after) if "(" in after else after
- line = f"{indent}{m.group('name')}({fmt_prob(measure_prob)}){after_clean}{ending}"
+ stripped = after_clean.lstrip()
+ if stripped.startswith("[") and "]" in stripped:
+ ws = after_clean[: len(after_clean) - len(stripped)]
+ tag_end = stripped.index("]") + 1
+ line = f"{indent}{m.group('name')}{ws}{stripped[:tag_end]}({fmt_prob(measure_prob)}){stripped[tag_end:]}{ending}"
+ else:
+ line = f"{indent}{m.group('name')}({fmt_prob(measure_prob)}){after_clean}{ending}"
# --- The (possibly modified) instruction ---
result.append(line)
- Dominant language
- Rust
- Stars
- 69
- Forks
- 25
- Avg merge
- 2d 22h
- Merged PRs (30d)
- 48
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/qdk-ec
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
pauliverse: speed up random-outcome measurements by choosing a cheaper pivotPossibly taken @Mohini204 claimed this 18 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
Maintainers usually reply within 1 day
All issues in microsoft/qdk-ec
Similar issues
-
chat compiler P1
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
HerringtonDarkholme/hd-lang#2793 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
security-advisory
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
MinBZK/regelrecht#2173 ·
-
ci
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
jonathanong/no-mistakes#5804 ·
-
triage: failed
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
oxc-project/tsrs#1277 · 1 comment ·
Maintainers usually reply within 1 day