You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Courtesy of copilot. Confirmed via QIR generation in VS Code
"""`Choose(true)` should return `H`, so the QIR should apply `h` to qubit 0. Thedefunctionalized branch tree remaps both `b` guards to the same caller expressionand keeps the last inner default, so the QIR applies `x` instead. There's no panic.Exits 0 while the miscompile reproduces. Found by opus-b17 in the panic hunt(qsc_fir_transforms/src/defunctionalize/rewrite.rs, build_branch_tree)."""importreimportsysfromqdkimportqsharpSOURCE="""namespace Demo { function Choose(b : Bool) : (Qubit => Unit) { if b { H } else { if b { X } else { Z } } } operation Main() : Result { use q = Qubit(); let arr = [1, 2, 3]; let x = Length(arr) > 1; let f = Choose(x); f(q); MResetZ(q) }}"""qsharp.init(target_profile=qsharp.TargetProfile.Adaptive_RIF)
qsharp.eval(SOURCE)
qir=str(qsharp.compile("Demo.Main()"))
gates=re.findall(r"@__quantum__qis__(\w+)__body\(%Qubit\* (?:null|inttoptr \(i64 0 to %Qubit\*\))", qir)
print("gates on qubit 0:", gates)
if"x"ingatesand"h"notingates:
print("REPRODUCED: QIR applies X where Choose(true) should give H")
sys.exit(0)
print("NOT REPRODUCED")
sys.exit(1)
Activity
[-]Miscompile in defunctionalization[/-][+][Miscompile] Incorrect defunctionalization[/+]