Git Product home page Git Product logo

Comments (3)

tcNickolas avatar tcNickolas commented on May 18, 2024

Your solution doesn't actually prepare the superposition of the two given bit strings, it prepares one of the bit strings at random with 50-50 chance.

Consider the simplest example possible: prepare superposition of |0⟩ and |1⟩ basis states (bits1 = [true], bits2 = [false]). After the two loops, right before Reset, the state of the qubits is |00⟩ + |11⟩ (with appropriate normalization). Reset measures the qubit q and applies X if necessary to convert it to |0⟩ state. If you measure one of the qubits in the superposition |00⟩ + |11⟩, the second one will be left either in |0⟩ state or in |1⟩ state, depending on the measurement result, but not in a superposition.

It is possible to make this approach work, but you'll need to convert the additional qubit to |0⟩ state by uncomputing it, not by measuring it - for example, you can find a position in which the bitstrings differ and do a CNOT with the corresponding qubit the as control and the additional qubit as the target - but then it stops being conceptually simpler :-)

from quantumkatas.

wsgac avatar wsgac commented on May 18, 2024

Thanks for the great explanation! So my means of zeroing the additional qubit (i.e. Reset) simply collapses the superposition I've built and by the time I was measuring my qubits proper, there was no more superposition to collapse, is that right?

I also want to clear one detail about your suggestion of 'uncomputing'. So, the configuration of superpositions between the additional qubit and the one corresponding to the first mismatch in bitstrings can be either 'straight' or 'diagonal' (meaning (q0 = |0⟩+|1⟩, qi = |0⟩+|1⟩) or (q0 = |0⟩+|1⟩, qi = |1⟩+|0⟩), respectively), and so the CNOT results in q0 becoming |0⟩ or |1⟩, respectively, after which measuring it no longer collapses our desired superposition. So the crux here is going with a unitary transformation (CNOT) instead of a measurement. Do I get this right?

from quantumkatas.

wsgac avatar wsgac commented on May 18, 2024

I've implemented your suggestion and it worked fine. Perhaps it did in fact lose some conceptual clarity, but somehow it feels more natural to me :). Here's the code:

operation TwoBitstringSuperposition (qs : Qubit[], bits1 : Bool[], bits2 : Bool[]) : Unit {
    // Find first index where bit strings differ
    mutable mismatch = -1;
    for (i in 0..Length(qs)-1) {
        if (bits1[i] != bits2[i] && mismatch == -1) {
            set mismatch = i;
        }
    }
    // Allocate one additional qubit
    using (q = Qubit()) {
        H(q); // Produce superposition
        // Set one half of the superpositon...
        for (i in 0..Length(qs)-1) {
            if (bits2[i]) {
                CNOT(q, qs[i]);
            }
        }
        // ...then another
        X(q);
        for (i in 0..Length(qs)-1) {
            if (bits1[i]) {
                CNOT(q, qs[i]);
            }
        }
        // Uncompute the additional qubit
        CNOT(qs[mismatch], q);
        // Cleanup
        Reset(q);
    }        
}

Thanks for a very enlightening discussion and keep up the great work :).

from quantumkatas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.