1
$\begingroup$

I am interested in implementing a operation in Q#. The operation should follow the algorithm below: Taken from a paper on quantum algorithms

When $A=0$ it is quite easy to see that the algorithm states if the qubitt is in nullspace apply a transformation to flip the sign of the qubit.

I am not sure how to use the algorithm for the 'i is in A' case.

$\endgroup$
2
$\begingroup$

The trick here is to define a new operation whose unitary representation is \begin{align} S_a|i\rangle = \begin{cases} -|i\rangle \text{ if } i = a \\ |i\rangle \text{ otherwise } \end{cases}. \end{align}

At that point, $S_A = \prod_{a \in A} S_a$. In Q#, you can implement $S_a$ easily using the ControlledOnInt operation, an auxillary qubit in the $|-\rangle$ state, and an X operation:

operation ApplyConditionalPhase(subset : Int[], register : LittleEndian)
: Unit is Adj + Ctl {
    using (aux = Qubit()) {
        within {
            // prepare aux in the |−⟩ state. 
            H(aux);
            Z(aux);
        } apply {
            for (element in subset) {
                (ControlledOnInt(element, X))(register!, aux);
            }
        }
    }
}

This works using the same phase kickback principle as in the Deutsch−Jozsa algorithm; for more details on how phase kickback works, check out Chapters 6 and 7 of my book.

| improve this answer | |
$\endgroup$
  • $\begingroup$ What does setting our data type to LittleEndian for our register input do? $\endgroup$ – Mridul Jun 3 at 3:26
  • $\begingroup$ Also, why do we specify the output is Adj + Ctl? $\endgroup$ – Mridul Jun 3 at 3:27
  • $\begingroup$ The LittleEndian user-defined type (UDT)_is used to specify that a register of qubits is to be interpreted as encoding an unsigned integer; in this case, that ensures that the user passes in the control register in a format consistent with the ordering expected by ControlledOnInt. For your other question, is Adj + Ctl specifies that the operation is adjointable and controllable, so that you can implement $S_A^{\dagger}$ and controlled applications of $S_A$ automatically. $\endgroup$ – Chris Granade Jun 3 at 3:30
  • $\begingroup$ last question: what does apply do? can we replace that line by using ApplytoAll or ApplytoEach and containing it into the for loop? $\endgroup$ – Mridul Jun 3 at 3:30
  • 1
    $\begingroup$ Speaking of qsharp.community, we are always looking for posts and content from folks so if you are interested in writing something about what you learned here or anything else you think other community members might find useful, let use know! qsharp.community/blog/call-for-contributions You can see an example of a post we just got today on the Q# + Python install process for Linux: qsharp.community/blog/qsharp-python-linux $\endgroup$ – Dr. Sarah Kaiser Jun 3 at 4:13
0
$\begingroup$
operation ApplyConditionalPhase_0(register: LittleEndian) : Unit is Adj + Ctl
{
    using (aux = Qubit()) 
    {
        (ControlledOnInt(0,X))(register!,aux);
    }
}
operation ApplyConditionalPhase(register : LittleEndian) : Unit is Adj + Ctl 
{
    using (aux = Qubit()) 
    {
        (ControlledOnInt(1,X))(register!,aux);
    }
}

I realized this paper treats A as all positive integers, that means not including zero. I am understanding this gate to simply flip the qubit when it is 0 for the first. Since 0 is not in the set of positive integers, we flip all qubits that are 1 to satisfy i = a.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.