Coherent transformations: control, inversion, and power¶
A quantum kernel expression that does not use any preparation or measurement gates is called coherent and corresponds to a unitary transformation. There are several operations that can act on coherent quantum kernel expressions in convenient and powerful ways. If these operations are inappropriately called on non-coherent quantum kernel expressions, the FLEQ compilation stage of IQC will exit with a warning.
Control¶
Coherent qubit control is a unitary transformation that applies an input unitary conditioned on the computation eigenstate of a control qubit. Note the qubit state must be independent of the input unitary for the transformation to be well-defined (enforced by the FLEQ compilation stage of IQC).
FLEQ supports several variations on coherent qubit control:
QExpr qexpr::control(qbit &q, bool b = true, QExpr u)
Returns a quantum kernel expression implementing unitary control of the unitary
ubased on the qubitqbeing in state \(\ket{b}\). That is, ifb == true, the control is on the \(\ket{1}\) state and ifb == false, the control is on the \(\ket{0}\) state. The value ofbcan be dynamic i.e. it does not have to be resolved at compile-time. Its default value istrue.
QExpr qexpr::qIf(qbit &q, QExpr uT, QExpr uF)
Returns a quantum kernel expression that controls the unitary
uTon the condition of \(q=\ket{1}\) anduFon the condition of \(q=\ket{0}\).
QExpr qexpr::control(QList qs, unsigned int ctl_on = -1, QExpr u)
Returns a quantum kernel expression that controls the unitary
uon the state of the qubits inqssuch thatuis applied to the state only if \(\texttt{qs}[i] = \ket{(\texttt{ctl\_on} << i) \% 2}\) for all \(i < \texttt{qs.size()}\). Said differently, the binary representation of the computational state ofqsmatches the binary representation ofctl_onwhere earlier qubits inqscorrespond to the more significant bits (big-endian).ctl_oncan be dynamic i.e. does not have to be resolved at compile time and has a default value of-1which forunsigned inttranslates to \(2^{32}-1 = 1111\ldots\). The size ofqsis limited to8qubits as enforced by the FLEQ compilation stage of IQC. This was done since the function does not add ancilla qubits and as such, the circuit cost grows exponentially with the size ofqs. The recursion limit can be overcome by chainingcontrolcalls using recursion (see Recursion) or with the explicit use of ancilla. See Known limitations.
Inversion¶
Coherent quantum kernel expressions can be inverted using the operation invert.
QExpr qexpr::invert(QExpr u)
Returns a quantum kernel expression implementing the unitary \(U^\dagger\), provided
uis a coherent quantum kernel expression implementing the unitary \(U\).
inverthas three equivalent operator overloads,!u,~uand-u.
Power¶
The power of a quantum kernel expression refers to repeated application of its logic on the quantum backend.
QExpr qexpr::power(unsigned int n, QExpr e)
If \(n > 0\), returns a quantum kernel expression that joins
ewith itselfntimes. If \(n=0\), returns the identity quantum kernel expression. In these two cases,eneed not be coherent.If \(n < 0\),
emust be coherent, in which casepower(e,n)is equivalent topower(invert(e), -n).Currently,
nmust be resolvable at compile-time, though future versions will relax this constraint.
powerhas an operator overloade^nwhich is equivalent toqexpr::power(e, n).