deq.noise.inject_noise (inject_si1000 / inject_biased) silently skips all instructions inside single-line REPEAT blocks
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 72/100
Research direction
Start by reading deq/deq/noise/injector.py around lines 107–109, where lines containing braces are skipped. Reproduce the issue with the single-line and multi-line REPEAT examples using deq.circuit.parser.parse and inject_si1000; check the same path for inject_biased. Done means both forms inject noise inside the loop and the resulting source still parses.
Written by the indexing model from the issue text.
Description
Describe the bug
deq.noise.inject_noise (and therefore inject_si1000 and inject_biased) silently skips noise injection for every instruction inside a single-line REPEAT N { ... } block, even though single-line REPEAT blocks are valid .deq syntax accepted by deq.circuit.parser.parse.
By contrast, writing the exact same REPEAT block across multiple lines injects the expected noise inside the loop body.
To Reproduce
- Install or import
deqfrommain(19a8853b7611d147d49d8ab46f817d7d9efc76ce,deq 0.7.0). - Run the following script:
from deq.circuit.parser import parse
from deq.noise import inject_si1000
single_line = "GADGET G {\n REPEAT 2 { X 0 }\n M 0\n}\n"
multi_line = "GADGET G {\n REPEAT 2 {\n X 0\n }\n M 0\n}\n"
# Both are valid .deq circuits accepted by the parser:
parse(single_line)
parse(multi_line)
print("=== single-line REPEAT ===")
print(inject_si1000(single_line, p=0.01))
print("=== multi-line REPEAT ===")
print(inject_si1000(multi_line, p=0.01))
Observed output:
=== single-line REPEAT ===
GADGET G {
REPEAT 2 { X 0 }
M(0.01) 0
}
=== multi-line REPEAT ===
GADGET G {
REPEAT 2 {
X 0
DEPOLARIZE1(0.01) 0
}
M(0.01) 0
}
No DEPOLARIZE1(0.01) 0 is emitted for X 0 inside REPEAT 2 { X 0 }.
Expected behavior
Single-line REPEAT N { ... } blocks inside a GADGET should receive the same noise injection as their multi-line equivalent (e.g., expanding the block and emitting DEPOLARIZE1(0.01) 0 after X 0 inside REPEAT 2 { ... }), and the resulting .deq source should continue to parse via deq.circuit.parser.parse.
System environment (please complete the following information):
- OS: Windows 11
- Architecture: x86_64
- Python or Rust versions, as appropriate: Python 3.12.14 (
deq0.7.0, commit19a8853b7611d147d49d8ab46f817d7d9efc76ce; pure-Pythondeq.noisemodule, no Rust toolchain required to reproduce)
Additional context
In deq/deq/noise/injector.py (lines 107–109), any line containing an opening or closing brace is appended unchanged and skipped immediately:
if opens or closes:
result.append(line)
continue
For REPEAT 2 { X 0 }, opens == 1 and closes == 1, so inject_noise appends the raw line verbatim without inspecting the inner body. The same code path affects all NoiseEmitter callers (inject_si1000, inject_biased).
Suggested minimal fix (expanding single-line brace blocks inside GADGETs)
diff --git a/deq/deq/noise/injector.py b/deq/deq/noise/injector.py
--- a/deq/deq/noise/injector.py
+++ b/deq/deq/noise/injector.py
@@ -105,6 +105,24 @@ def inject_noise(text: str, emitter: NoiseEmitter) -> str:
block_stack.pop()
if opens or closes:
+ if in_gadget and opens == 1 and closes == 1:
+ code_part = strip_comment(line)
+ open_idx = code_part.find("{")
+ close_idx = code_part.rfind("}")
+ inner = code_part[open_idx + 1 : close_idx].strip()
+ if inner:
+ orig_indent = line[: len(line) - len(line.lstrip(" \t"))]
+ ending = line[len(line.rstrip("\n\r")) :] or "\n"
+ head = line[:open_idx].rstrip()
+ tail = line[close_idx + 1 :]
+ inner_noisy = inject_noise(
+ f"GADGET _ {{\n{orig_indent} {inner}\n}}\n", emitter
+ ).splitlines(keepends=True)[1:-1]
+ result.append(f"{head} {{\n")
+ result.extend(inner_noisy)
+ result.append(f"{orig_indent}}}{tail if tail else ending}")
+ continue
result.append(line)
continue
- 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 75/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/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