We optimize the conditional branching statements using the following techniques:
The openqasm reference enforces the switch targets to be of type int and the cases to be unique integer literals or constant integer expressions. This implies that the switch case statements can be optimized at compile time as long as the target variable is not dependent on a measurement result.
Once the target variable is evaluated at compile time, the switch
statement is removed and the
corresponding switch
case code block is attached to the main program.
Subroutine inlining is the process of replacing a subroutine call with the actual code of the subroutine. Since quantum devices do not support subroutines, it is essential to inline the subroutine code against the call to the subroutine. Here, the formal parameters of the subroutine are replaced with the actual parameters used in the subroutine call. Moreover, the subroutine code is inserted at the location of the subroutine call with careful consideration of the scope of the variables used in the subroutine.
Loop unrolling is the process of unfolding a loop with a list of equivalent instructions.
This is particularly important for quantum programs as quantum computers do not support direct execution
of loops. We provide support for unrolling while
and for
loops -
while
Loop
max_loop_iters
parameter. It has a default value of 1e9
and allows
the user to control the max number of loop iterations -while
condition is dependent on a
quantum measurement result. Since the truth value of the condition can only be known at runtime,
an exception is raised while unrolling such loops -Unrolling while
loops which contain quantum measurements is, in fact, an active area of development.
Some researchers have proposed to identify such loops and convert them into a native while
loop instructions which can be executed during runtime. However, this approach has not been
fully implemented yet.
for
Loop
while
loop unrolling process, but the loop counter is
chosen from the range provided by the user. The loop body is executed as many times as
the range value -We optimize the conditional branching statements using the following techniques:
The openqasm reference enforces the switch targets to be of type int and the cases to be unique integer literals or constant integer expressions. This implies that the switch case statements can be optimized at compile time as long as the target variable is not dependent on a measurement result.
Once the target variable is evaluated at compile time, the switch
statement is removed and the
corresponding switch
case code block is attached to the main program.
Subroutine inlining is the process of replacing a subroutine call with the actual code of the subroutine. Since quantum devices do not support subroutines, it is essential to inline the subroutine code against the call to the subroutine. Here, the formal parameters of the subroutine are replaced with the actual parameters used in the subroutine call. Moreover, the subroutine code is inserted at the location of the subroutine call with careful consideration of the scope of the variables used in the subroutine.
Loop unrolling is the process of unfolding a loop with a list of equivalent instructions.
This is particularly important for quantum programs as quantum computers do not support direct execution
of loops. We provide support for unrolling while
and for
loops -
while
Loop
max_loop_iters
parameter. It has a default value of 1e9
and allows
the user to control the max number of loop iterations -while
condition is dependent on a
quantum measurement result. Since the truth value of the condition can only be known at runtime,
an exception is raised while unrolling such loops -Unrolling while
loops which contain quantum measurements is, in fact, an active area of development.
Some researchers have proposed to identify such loops and convert them into a native while
loop instructions which can be executed during runtime. However, this approach has not been
fully implemented yet.
for
Loop
while
loop unrolling process, but the loop counter is
chosen from the range provided by the user. The loop body is executed as many times as
the range value -