Skip to content


The power statement applies the unitary operation raised to some integer power, where the unitary is specified as a nested statement block.


power ( exponent ) { statements }

def power(power: CInt, operand: QCallable) -> None:


  • If the statement block specifies the unitary operation \(U\) on some quantum object, power applies \(U^{exponent}\).
  • In the general case, the statement block is iterated over exponent times, but in some important special cases the operation is implemented more efficiently.
  • Quantum variables declared outside the power statement and used inside its nested block must be initialized prior to it and remain initialized subsequently.


In the following example power is applied 3 times - to gate-level functions H and RX, and to a user-defined function foo. It demonstrates both special and general treatment of the power operation.

qfunc foo<p: int>(q: qbit) {
  power (p) {
  power (p) {
    PHASE<pi / 8>(q);

qfunc main() {
  q: qbit[];
  power (2) {
from classiq import PHASE, CInt, H, QArray, QBit, allocate, power, qfunc

def foo(p: CInt, q: QBit) -> None:
    power(p, lambda: H(q))
    power(p, lambda: PHASE(pi / 8, q))

def main() -> None:
    q = QArray("q")
    allocate(1, q)
    power(2, lambda: foo(5, q))

Synthesizing this model creates the quantum program shown below. Because two consecutive applications of H cancel each other out, raising H to the power of 5 is equivalent to applying H once. Raising RX with rotation angle \(\pi / 8\) to the power 5 is equivalent to applying RX with rotation angle \(5 \times \pi / 8\). However, raising foo to the power 2 requires 2 consecutive applications of foo.