Advanced Features
Branch Optimization
We optimize the conditional branching statements using the following techniques:
- Branch Elimination: We evaluate the outcome of the branch condition, if it is known at compile time and does not contain measurement results of qubits. We remove the branch statement and if it evaluates to a true value, attach the corresponding block of code to the main program.
- Branch Unfolding: If the branch condition contains measurement results of qubits, we unfold the classical registers into individual bits and insert equivalent conditional statements for each bit. This method is particularly useful for systems which do not support multi-bit classical registers in conditional statements.
Switch Case Optimization
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
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.