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
Given a mutable variable used in a quantum condition block, partial eval can't track that despite value being in a dynamic condition, it is statically constant.
@EntryPoint()
operation Test() : Unit {
mutable value = 0;
use q =Qubit();
let cond = MResetZ(q);
if cond ==Zero {
value -= 1 ;
} else {
value += 1;
}
}
This leads to a variable being used in the CFG for the else block, which is converted into a constant during SSA transformation. This leaves SSA instructions performing mathematical computation on constant values.
This currently causes a panic in the compiler which assumes all constant operations were resolved during partial evaluation.
Which causes the panic. Given that partial evaluation can't fully perform constant folding, we most likely need to implement more SSA passes for constant folding, dead code elimination, at a minimum.
Workaround:
Save off the current mut value and use it on the rhs of the expressions in the conditional blocks:
operation Workaround() : Unit {
mutable value = 0;
use q =Qubit();
let cond = MResetZ(q);
let orig = value;
if cond ==Zero {
value = orig - 1 ;
} else {
value = orig + 1;
}
}
The text was updated successfully, but these errors were encountered:
…n partial evaluation
This fixes the bug by having partial evaluation more explicitly track different variable mappings to literals across branches and recombining those mappings that match (ie: are constant) when all branches are done. This also includes partial eval and RIR SSA pass fixes to correctly support immutable and mutable copies of dynamic variables. New test cases for several combinations of constant folding at partial eval are included, as well as a new test case confirming RIR SSA fix.
Fixes#2087
…n partial evaluation
This fixes the bug by having partial evaluation more explicitly track different variable mappings to literals across branches and recombining those mappings that match (ie: are constant) when all branches are done. This also includes partial eval and RIR SSA pass fixes to correctly support immutable and mutable copies of dynamic variables. New test cases for several combinations of constant folding at partial eval are included, as well as a new test case confirming RIR SSA fix.
Fixes#2087
Given a mutable variable used in a quantum condition block, partial eval can't track that despite
value
being in a dynamic condition, it is statically constant.This leads to a variable being used in the CFG for the else block, which is converted into a constant during SSA transformation. This leaves SSA instructions performing mathematical computation on constant values.
This currently causes a panic in the compiler which assumes all constant operations were resolved during partial evaluation.
Actual:
In SSA processing:
Is turned into:
Which causes the panic. Given that partial evaluation can't fully perform constant folding, we most likely need to implement more SSA passes for constant folding, dead code elimination, at a minimum.
Workaround:
Save off the current
mut
value and use it on the rhs of the expressions in the conditional blocks:The text was updated successfully, but these errors were encountered: