silq-lang / silq

Boost Software License 1.0
609 stars 52 forks source link

Method for resetting Quantum State #29

Open marco-lewis opened 3 years ago

marco-lewis commented 3 years ago

Is there a method for resetting the global state if there are no quantum variables? I am considering some code that requires a repeat until success loop and the quantum state needs to be reset at the start of the loop.

Example with a minimal program:

def main(){
    loop := true:!B;
    while (loop){
        q := 0:B;
        q := rotY(1,q);
        q := rotZ(0.5,q);
        loop = measure(q);
    }
    return loop;
}

On the first iteration, the quantum state is (1+0i)·|⟩ or (1+0i)·|0⟩ up to the rotation statements. Once the rotations are done the quantum state is (0.850301-0.217117i)·|0⟩₂+(0.464521+0.118612i)·|1⟩₂. Now if the measurement is 1 the quantum state becomes (0.968912+0.247404i)·|⟩, which leaks into the redefinition of q in the next iteration. The state is therefore (0.968912+0.247404i)·|0⟩ rather than (1+0i)·|0⟩.

Basically, I would be looking for something like:

def main(){
    loop := true:!B;
    while (loop){
        q := 0:B;
        q := rotY(1,q);
        q := rotZ(0.5,q);
        loop = measure(q);
        reset();
    }
    return loop;
}

where reset() changes an empty quantum state back to (1+0i)·|⟩.

tgehr commented 3 years ago

In terms of the physical interpretation, there is no difference between the two states as global phases are irrelevant, but I see why picking up global phases can be annoying when trying to interpret the output.

I think one way to resolve this to some extent might be to reset the global phase to 1 whenever there is only one component in the superposition after a measurement. (But in general, it's hard to know what global phase the user wanted.)