7
$\begingroup$

Is it possible to obtain amplitude information (in lexicographic ordering) for a particular qubit register in Q#?

For example, in the following code:

operation GetProbabilityAmplitude() : Double[]
{
    body
    {
        mutable result = new Double[4];
        using (register = Qubit[2])
        {
            H(register[0]);
            CNOT(register[0], register[1]);
            // ...put the amplitude doubles in the result array
        }
        return result;
    }
}

The doubles in result should be {0.5,0.0,0.0,0.5}. I looked quite a bit for it in the documentation but couldn't find anything about getting the amplitudes.

$\endgroup$
9
$\begingroup$

Yes, it is possible to obtain this information, but only for troubleshooting purposes, not for using it in the code.


Dump functions dump the status of the target machine into a file or to the console output. If the program is executed on the full-state simulator, this status will include the wave function of the whole system (for DumpMachine) or of the register (for DumpRegister).

So you could do the following:

using (register = Qubit[2]) {
    H(register[0]);
    CNOT(register[0], register[1]);
    DumpMachine("");
    // to avoid ReleasedQubitsAreNotInZeroState exception
    ResetAll(register);
}

and get the following amplitudes (each one is a complex number):

Ids:    [1;0;]
Wavefunction:
0:      0.707107        0
1:      0       0
2:      0       0
3:      0.707107        0

Note that this does not allow you to implement the GetProbabilityAmplitude() function which you requested. If you are running a Q# program on a simulator, it will let you see the wave function but it will not let you make any decisions in the program based on that information. The intent is twofold: to facilitate debugging on a simulator while not allowing to implement any logic which would be impossible to execute on a quantum computer. Since the execution on a quantum computer won't give the program direct access to the quantum state, it's better not to rely on this feature in the code.

$\endgroup$
2
$\begingroup$

I never looked at Q# but it looks like by using Dump functions you can output it. Hope this helps.

$\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.