Why do we have to uncompute rather than simply set registers to zero?












7












$begingroup$


In implementing a quantum subroutine it is important to uncompute temporary registers after use, to ensure the output state of the subroutine is not entangled with them (which would affect its behaviour).



Why is it necessary to perform this through uncomputation rather than simply setting temporary registers to zero afterwards?










share|improve this question









$endgroup$








  • 1




    $begingroup$
    a related question on cstheory
    $endgroup$
    – glS
    Jan 18 at 17:48
















7












$begingroup$


In implementing a quantum subroutine it is important to uncompute temporary registers after use, to ensure the output state of the subroutine is not entangled with them (which would affect its behaviour).



Why is it necessary to perform this through uncomputation rather than simply setting temporary registers to zero afterwards?










share|improve this question









$endgroup$








  • 1




    $begingroup$
    a related question on cstheory
    $endgroup$
    – glS
    Jan 18 at 17:48














7












7








7





$begingroup$


In implementing a quantum subroutine it is important to uncompute temporary registers after use, to ensure the output state of the subroutine is not entangled with them (which would affect its behaviour).



Why is it necessary to perform this through uncomputation rather than simply setting temporary registers to zero afterwards?










share|improve this question









$endgroup$




In implementing a quantum subroutine it is important to uncompute temporary registers after use, to ensure the output state of the subroutine is not entangled with them (which would affect its behaviour).



Why is it necessary to perform this through uncomputation rather than simply setting temporary registers to zero afterwards?







quantum-state entanglement






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 18 at 15:21









Sideshow BobSideshow Bob

1626




1626








  • 1




    $begingroup$
    a related question on cstheory
    $endgroup$
    – glS
    Jan 18 at 17:48














  • 1




    $begingroup$
    a related question on cstheory
    $endgroup$
    – glS
    Jan 18 at 17:48








1




1




$begingroup$
a related question on cstheory
$endgroup$
– glS
Jan 18 at 17:48




$begingroup$
a related question on cstheory
$endgroup$
– glS
Jan 18 at 17:48










3 Answers
3






active

oldest

votes


















2












$begingroup$

Because all operations you carry out (besides measurement) need to be unitary and this one would not.






share|improve this answer









$endgroup$









  • 3




    $begingroup$
    There is one thing you don't address in your answer --- why not use a measurement then, and then flip the bit if the outcome is 1? That would effectively reset the qubit. Not that this is actually a good idea, but could you elaborate your answer to describe why this is not a good idea?
    $endgroup$
    – Niel de Beaudrap
    Jan 18 at 17:28










  • $begingroup$
    @NieldeBeaudrap If you measure you collapse into one possibility. But say you want to continue applying operations on this output state (in the register of interest)... you see why this is not a good idea?
    $endgroup$
    – cnada
    Jan 18 at 18:12






  • 1




    $begingroup$
    My comment was that it is something you don't address, which is conspicuous given that 'resetting' the state is exactly what the OP asked about. While I know why it isn't a good idea, I'm not the one who asked the original question.
    $endgroup$
    – Niel de Beaudrap
    Jan 18 at 19:30



















4












$begingroup$

Uncomputing temporary registers seem to me to be the most efficient way to set temporary registers back to zero.



You can't measure these and classically flip them




  1. because a measurement of $1$ doesn't necessarily mean the state of the temporary register is $|1rangle$


  2. because measuring would cause entangled qubits to collapse into a corresponding state so that would defeat the purpose of uncomputing temporary registers that you mentioned in your question.



And somehow implementing a circuit that detected a temporary register's state moved it back to 0 would be much more difficult than simply uncomputing the temporary register.






share|improve this answer











$endgroup$





















    2












    $begingroup$

    While it is definitely possible to reset registers after using them (namely, by simply measuring them) the issue is that doing so can potentially destroy interference that one might want to achieve by subsequent computations with the quantum data. Unfortunately, this is the most common case encountered in quantum algorithms, such as e.g. the computation of arithmetic in Shor's factoring and dlog algorithms or the computation of a Boolean predicate in case of Grover's search algorithm.



    Concretely, assume that we have two registers, a data register $A$, an output register $B$, and an ancilla register $C$ and that half-way through the computation we arrived at an entangled state $sum_{x} alpha_{x} |xrangle |f(x)rangle |g(x)rangle$, where the inputs are held in $A$, the function values $f(x)$ are computed into $B$, and the values $g(x)$ are results of some intermediate computations that is stored in the scratch register $C$.



    If we now, instead of uncomputing the register $C$ so that it holds $|0rangle$ (or some other state that is unentangled with registers $A$ and $B$), we decide to reset the register $C$, this will have the following detrimental effect: we will measure (at random) some value $c_0$ and the state will collapse to the superposition of all $x$ that are consistent with this measured value, so that the state will become (up to normalization):



    $$ sum_{x: g(x) = c_0} alpha_x |xrangle |f(x)rangle. $$



    Note that this can be vastly different from the state $sum_x alpha_x |xrangle |f(x)rangle$ that we really wanted (and actually only for constant functions $g$ yields the correct result). Indeed, if $g$ is a permutation, only a single $x$ will survive from the initial superposition! Hence, temporary/scratch registers have to be uncomputed if we want to do subsequent computations with the data in the other registers.






    share|improve this answer









    $endgroup$













    • $begingroup$
      From the perspective of this answer I feel it's not explained why resetting the register necessarily entails a measurement? Can't we just reset it without looking at it? Or would the differing energy required to reset (or not) the register entangle the computation with the power supply or such like?
      $endgroup$
      – Sideshow Bob
      Jan 21 at 13:06










    • $begingroup$
      I think people are referring to measurement because they are trying to guess what you mean when you talk about resetting a qubit. In general though, changing the state of a qubit in any way (that i can think of) other than uncomputing it will cause the states of entangled qubits to change accordingly.
      $endgroup$
      – Malcolm Regan
      Jan 21 at 19:04












    • $begingroup$
      @SideshowBob, the terminology 'setting qubits to zero' required some clarification. If a qubit is part of a register that is entangled across said qubit, then it is physically not possible to reset the qubit to zero (or any other pure quantum state) without destroying the quantum state of the register.
      $endgroup$
      – MartinQuantum
      Jan 22 at 5:08










    • $begingroup$
      @SideshowBob, the terminology 'resetting a qubit' is nonetheless used, e.g., by the quantum programming community, where it means the specific procedure to a) measure the qubit (e.g. in the standard computational basis), followed by b) a flip to bring it to the zero state. See e.g. projectq.readthedocs.io/en/latest/… for ProjectQ and docs.microsoft.com/en-us/qsharp/api/prelude/… for Q#.
      $endgroup$
      – MartinQuantum
      Jan 22 at 5:09












    • $begingroup$
      Would it not be possible to set the qubit to 0 in every component of a mixed state? i.e. leaving the rest of the entanglement unbroken: the entangled bits will behave the same after the qubit of concern has been reset, but the qubit of concern will always be 0 now whatever the other bits are?
      $endgroup$
      – Sideshow Bob
      Jan 22 at 9:56











    Your Answer





    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("mathjaxEditing", function () {
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    });
    });
    }, "mathjax-editing");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "694"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    noCode: true, onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fquantumcomputing.stackexchange.com%2fquestions%2f5222%2fwhy-do-we-have-to-uncompute-rather-than-simply-set-registers-to-zero%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2












    $begingroup$

    Because all operations you carry out (besides measurement) need to be unitary and this one would not.






    share|improve this answer









    $endgroup$









    • 3




      $begingroup$
      There is one thing you don't address in your answer --- why not use a measurement then, and then flip the bit if the outcome is 1? That would effectively reset the qubit. Not that this is actually a good idea, but could you elaborate your answer to describe why this is not a good idea?
      $endgroup$
      – Niel de Beaudrap
      Jan 18 at 17:28










    • $begingroup$
      @NieldeBeaudrap If you measure you collapse into one possibility. But say you want to continue applying operations on this output state (in the register of interest)... you see why this is not a good idea?
      $endgroup$
      – cnada
      Jan 18 at 18:12






    • 1




      $begingroup$
      My comment was that it is something you don't address, which is conspicuous given that 'resetting' the state is exactly what the OP asked about. While I know why it isn't a good idea, I'm not the one who asked the original question.
      $endgroup$
      – Niel de Beaudrap
      Jan 18 at 19:30
















    2












    $begingroup$

    Because all operations you carry out (besides measurement) need to be unitary and this one would not.






    share|improve this answer









    $endgroup$









    • 3




      $begingroup$
      There is one thing you don't address in your answer --- why not use a measurement then, and then flip the bit if the outcome is 1? That would effectively reset the qubit. Not that this is actually a good idea, but could you elaborate your answer to describe why this is not a good idea?
      $endgroup$
      – Niel de Beaudrap
      Jan 18 at 17:28










    • $begingroup$
      @NieldeBeaudrap If you measure you collapse into one possibility. But say you want to continue applying operations on this output state (in the register of interest)... you see why this is not a good idea?
      $endgroup$
      – cnada
      Jan 18 at 18:12






    • 1




      $begingroup$
      My comment was that it is something you don't address, which is conspicuous given that 'resetting' the state is exactly what the OP asked about. While I know why it isn't a good idea, I'm not the one who asked the original question.
      $endgroup$
      – Niel de Beaudrap
      Jan 18 at 19:30














    2












    2








    2





    $begingroup$

    Because all operations you carry out (besides measurement) need to be unitary and this one would not.






    share|improve this answer









    $endgroup$



    Because all operations you carry out (besides measurement) need to be unitary and this one would not.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 18 at 16:05









    cnadacnada

    2,395213




    2,395213








    • 3




      $begingroup$
      There is one thing you don't address in your answer --- why not use a measurement then, and then flip the bit if the outcome is 1? That would effectively reset the qubit. Not that this is actually a good idea, but could you elaborate your answer to describe why this is not a good idea?
      $endgroup$
      – Niel de Beaudrap
      Jan 18 at 17:28










    • $begingroup$
      @NieldeBeaudrap If you measure you collapse into one possibility. But say you want to continue applying operations on this output state (in the register of interest)... you see why this is not a good idea?
      $endgroup$
      – cnada
      Jan 18 at 18:12






    • 1




      $begingroup$
      My comment was that it is something you don't address, which is conspicuous given that 'resetting' the state is exactly what the OP asked about. While I know why it isn't a good idea, I'm not the one who asked the original question.
      $endgroup$
      – Niel de Beaudrap
      Jan 18 at 19:30














    • 3




      $begingroup$
      There is one thing you don't address in your answer --- why not use a measurement then, and then flip the bit if the outcome is 1? That would effectively reset the qubit. Not that this is actually a good idea, but could you elaborate your answer to describe why this is not a good idea?
      $endgroup$
      – Niel de Beaudrap
      Jan 18 at 17:28










    • $begingroup$
      @NieldeBeaudrap If you measure you collapse into one possibility. But say you want to continue applying operations on this output state (in the register of interest)... you see why this is not a good idea?
      $endgroup$
      – cnada
      Jan 18 at 18:12






    • 1




      $begingroup$
      My comment was that it is something you don't address, which is conspicuous given that 'resetting' the state is exactly what the OP asked about. While I know why it isn't a good idea, I'm not the one who asked the original question.
      $endgroup$
      – Niel de Beaudrap
      Jan 18 at 19:30








    3




    3




    $begingroup$
    There is one thing you don't address in your answer --- why not use a measurement then, and then flip the bit if the outcome is 1? That would effectively reset the qubit. Not that this is actually a good idea, but could you elaborate your answer to describe why this is not a good idea?
    $endgroup$
    – Niel de Beaudrap
    Jan 18 at 17:28




    $begingroup$
    There is one thing you don't address in your answer --- why not use a measurement then, and then flip the bit if the outcome is 1? That would effectively reset the qubit. Not that this is actually a good idea, but could you elaborate your answer to describe why this is not a good idea?
    $endgroup$
    – Niel de Beaudrap
    Jan 18 at 17:28












    $begingroup$
    @NieldeBeaudrap If you measure you collapse into one possibility. But say you want to continue applying operations on this output state (in the register of interest)... you see why this is not a good idea?
    $endgroup$
    – cnada
    Jan 18 at 18:12




    $begingroup$
    @NieldeBeaudrap If you measure you collapse into one possibility. But say you want to continue applying operations on this output state (in the register of interest)... you see why this is not a good idea?
    $endgroup$
    – cnada
    Jan 18 at 18:12




    1




    1




    $begingroup$
    My comment was that it is something you don't address, which is conspicuous given that 'resetting' the state is exactly what the OP asked about. While I know why it isn't a good idea, I'm not the one who asked the original question.
    $endgroup$
    – Niel de Beaudrap
    Jan 18 at 19:30




    $begingroup$
    My comment was that it is something you don't address, which is conspicuous given that 'resetting' the state is exactly what the OP asked about. While I know why it isn't a good idea, I'm not the one who asked the original question.
    $endgroup$
    – Niel de Beaudrap
    Jan 18 at 19:30













    4












    $begingroup$

    Uncomputing temporary registers seem to me to be the most efficient way to set temporary registers back to zero.



    You can't measure these and classically flip them




    1. because a measurement of $1$ doesn't necessarily mean the state of the temporary register is $|1rangle$


    2. because measuring would cause entangled qubits to collapse into a corresponding state so that would defeat the purpose of uncomputing temporary registers that you mentioned in your question.



    And somehow implementing a circuit that detected a temporary register's state moved it back to 0 would be much more difficult than simply uncomputing the temporary register.






    share|improve this answer











    $endgroup$


















      4












      $begingroup$

      Uncomputing temporary registers seem to me to be the most efficient way to set temporary registers back to zero.



      You can't measure these and classically flip them




      1. because a measurement of $1$ doesn't necessarily mean the state of the temporary register is $|1rangle$


      2. because measuring would cause entangled qubits to collapse into a corresponding state so that would defeat the purpose of uncomputing temporary registers that you mentioned in your question.



      And somehow implementing a circuit that detected a temporary register's state moved it back to 0 would be much more difficult than simply uncomputing the temporary register.






      share|improve this answer











      $endgroup$
















        4












        4








        4





        $begingroup$

        Uncomputing temporary registers seem to me to be the most efficient way to set temporary registers back to zero.



        You can't measure these and classically flip them




        1. because a measurement of $1$ doesn't necessarily mean the state of the temporary register is $|1rangle$


        2. because measuring would cause entangled qubits to collapse into a corresponding state so that would defeat the purpose of uncomputing temporary registers that you mentioned in your question.



        And somehow implementing a circuit that detected a temporary register's state moved it back to 0 would be much more difficult than simply uncomputing the temporary register.






        share|improve this answer











        $endgroup$



        Uncomputing temporary registers seem to me to be the most efficient way to set temporary registers back to zero.



        You can't measure these and classically flip them




        1. because a measurement of $1$ doesn't necessarily mean the state of the temporary register is $|1rangle$


        2. because measuring would cause entangled qubits to collapse into a corresponding state so that would defeat the purpose of uncomputing temporary registers that you mentioned in your question.



        And somehow implementing a circuit that detected a temporary register's state moved it back to 0 would be much more difficult than simply uncomputing the temporary register.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 18 at 21:36









        Blue

        6,14831354




        6,14831354










        answered Jan 18 at 17:52









        Malcolm ReganMalcolm Regan

        1927




        1927























            2












            $begingroup$

            While it is definitely possible to reset registers after using them (namely, by simply measuring them) the issue is that doing so can potentially destroy interference that one might want to achieve by subsequent computations with the quantum data. Unfortunately, this is the most common case encountered in quantum algorithms, such as e.g. the computation of arithmetic in Shor's factoring and dlog algorithms or the computation of a Boolean predicate in case of Grover's search algorithm.



            Concretely, assume that we have two registers, a data register $A$, an output register $B$, and an ancilla register $C$ and that half-way through the computation we arrived at an entangled state $sum_{x} alpha_{x} |xrangle |f(x)rangle |g(x)rangle$, where the inputs are held in $A$, the function values $f(x)$ are computed into $B$, and the values $g(x)$ are results of some intermediate computations that is stored in the scratch register $C$.



            If we now, instead of uncomputing the register $C$ so that it holds $|0rangle$ (or some other state that is unentangled with registers $A$ and $B$), we decide to reset the register $C$, this will have the following detrimental effect: we will measure (at random) some value $c_0$ and the state will collapse to the superposition of all $x$ that are consistent with this measured value, so that the state will become (up to normalization):



            $$ sum_{x: g(x) = c_0} alpha_x |xrangle |f(x)rangle. $$



            Note that this can be vastly different from the state $sum_x alpha_x |xrangle |f(x)rangle$ that we really wanted (and actually only for constant functions $g$ yields the correct result). Indeed, if $g$ is a permutation, only a single $x$ will survive from the initial superposition! Hence, temporary/scratch registers have to be uncomputed if we want to do subsequent computations with the data in the other registers.






            share|improve this answer









            $endgroup$













            • $begingroup$
              From the perspective of this answer I feel it's not explained why resetting the register necessarily entails a measurement? Can't we just reset it without looking at it? Or would the differing energy required to reset (or not) the register entangle the computation with the power supply or such like?
              $endgroup$
              – Sideshow Bob
              Jan 21 at 13:06










            • $begingroup$
              I think people are referring to measurement because they are trying to guess what you mean when you talk about resetting a qubit. In general though, changing the state of a qubit in any way (that i can think of) other than uncomputing it will cause the states of entangled qubits to change accordingly.
              $endgroup$
              – Malcolm Regan
              Jan 21 at 19:04












            • $begingroup$
              @SideshowBob, the terminology 'setting qubits to zero' required some clarification. If a qubit is part of a register that is entangled across said qubit, then it is physically not possible to reset the qubit to zero (or any other pure quantum state) without destroying the quantum state of the register.
              $endgroup$
              – MartinQuantum
              Jan 22 at 5:08










            • $begingroup$
              @SideshowBob, the terminology 'resetting a qubit' is nonetheless used, e.g., by the quantum programming community, where it means the specific procedure to a) measure the qubit (e.g. in the standard computational basis), followed by b) a flip to bring it to the zero state. See e.g. projectq.readthedocs.io/en/latest/… for ProjectQ and docs.microsoft.com/en-us/qsharp/api/prelude/… for Q#.
              $endgroup$
              – MartinQuantum
              Jan 22 at 5:09












            • $begingroup$
              Would it not be possible to set the qubit to 0 in every component of a mixed state? i.e. leaving the rest of the entanglement unbroken: the entangled bits will behave the same after the qubit of concern has been reset, but the qubit of concern will always be 0 now whatever the other bits are?
              $endgroup$
              – Sideshow Bob
              Jan 22 at 9:56
















            2












            $begingroup$

            While it is definitely possible to reset registers after using them (namely, by simply measuring them) the issue is that doing so can potentially destroy interference that one might want to achieve by subsequent computations with the quantum data. Unfortunately, this is the most common case encountered in quantum algorithms, such as e.g. the computation of arithmetic in Shor's factoring and dlog algorithms or the computation of a Boolean predicate in case of Grover's search algorithm.



            Concretely, assume that we have two registers, a data register $A$, an output register $B$, and an ancilla register $C$ and that half-way through the computation we arrived at an entangled state $sum_{x} alpha_{x} |xrangle |f(x)rangle |g(x)rangle$, where the inputs are held in $A$, the function values $f(x)$ are computed into $B$, and the values $g(x)$ are results of some intermediate computations that is stored in the scratch register $C$.



            If we now, instead of uncomputing the register $C$ so that it holds $|0rangle$ (or some other state that is unentangled with registers $A$ and $B$), we decide to reset the register $C$, this will have the following detrimental effect: we will measure (at random) some value $c_0$ and the state will collapse to the superposition of all $x$ that are consistent with this measured value, so that the state will become (up to normalization):



            $$ sum_{x: g(x) = c_0} alpha_x |xrangle |f(x)rangle. $$



            Note that this can be vastly different from the state $sum_x alpha_x |xrangle |f(x)rangle$ that we really wanted (and actually only for constant functions $g$ yields the correct result). Indeed, if $g$ is a permutation, only a single $x$ will survive from the initial superposition! Hence, temporary/scratch registers have to be uncomputed if we want to do subsequent computations with the data in the other registers.






            share|improve this answer









            $endgroup$













            • $begingroup$
              From the perspective of this answer I feel it's not explained why resetting the register necessarily entails a measurement? Can't we just reset it without looking at it? Or would the differing energy required to reset (or not) the register entangle the computation with the power supply or such like?
              $endgroup$
              – Sideshow Bob
              Jan 21 at 13:06










            • $begingroup$
              I think people are referring to measurement because they are trying to guess what you mean when you talk about resetting a qubit. In general though, changing the state of a qubit in any way (that i can think of) other than uncomputing it will cause the states of entangled qubits to change accordingly.
              $endgroup$
              – Malcolm Regan
              Jan 21 at 19:04












            • $begingroup$
              @SideshowBob, the terminology 'setting qubits to zero' required some clarification. If a qubit is part of a register that is entangled across said qubit, then it is physically not possible to reset the qubit to zero (or any other pure quantum state) without destroying the quantum state of the register.
              $endgroup$
              – MartinQuantum
              Jan 22 at 5:08










            • $begingroup$
              @SideshowBob, the terminology 'resetting a qubit' is nonetheless used, e.g., by the quantum programming community, where it means the specific procedure to a) measure the qubit (e.g. in the standard computational basis), followed by b) a flip to bring it to the zero state. See e.g. projectq.readthedocs.io/en/latest/… for ProjectQ and docs.microsoft.com/en-us/qsharp/api/prelude/… for Q#.
              $endgroup$
              – MartinQuantum
              Jan 22 at 5:09












            • $begingroup$
              Would it not be possible to set the qubit to 0 in every component of a mixed state? i.e. leaving the rest of the entanglement unbroken: the entangled bits will behave the same after the qubit of concern has been reset, but the qubit of concern will always be 0 now whatever the other bits are?
              $endgroup$
              – Sideshow Bob
              Jan 22 at 9:56














            2












            2








            2





            $begingroup$

            While it is definitely possible to reset registers after using them (namely, by simply measuring them) the issue is that doing so can potentially destroy interference that one might want to achieve by subsequent computations with the quantum data. Unfortunately, this is the most common case encountered in quantum algorithms, such as e.g. the computation of arithmetic in Shor's factoring and dlog algorithms or the computation of a Boolean predicate in case of Grover's search algorithm.



            Concretely, assume that we have two registers, a data register $A$, an output register $B$, and an ancilla register $C$ and that half-way through the computation we arrived at an entangled state $sum_{x} alpha_{x} |xrangle |f(x)rangle |g(x)rangle$, where the inputs are held in $A$, the function values $f(x)$ are computed into $B$, and the values $g(x)$ are results of some intermediate computations that is stored in the scratch register $C$.



            If we now, instead of uncomputing the register $C$ so that it holds $|0rangle$ (or some other state that is unentangled with registers $A$ and $B$), we decide to reset the register $C$, this will have the following detrimental effect: we will measure (at random) some value $c_0$ and the state will collapse to the superposition of all $x$ that are consistent with this measured value, so that the state will become (up to normalization):



            $$ sum_{x: g(x) = c_0} alpha_x |xrangle |f(x)rangle. $$



            Note that this can be vastly different from the state $sum_x alpha_x |xrangle |f(x)rangle$ that we really wanted (and actually only for constant functions $g$ yields the correct result). Indeed, if $g$ is a permutation, only a single $x$ will survive from the initial superposition! Hence, temporary/scratch registers have to be uncomputed if we want to do subsequent computations with the data in the other registers.






            share|improve this answer









            $endgroup$



            While it is definitely possible to reset registers after using them (namely, by simply measuring them) the issue is that doing so can potentially destroy interference that one might want to achieve by subsequent computations with the quantum data. Unfortunately, this is the most common case encountered in quantum algorithms, such as e.g. the computation of arithmetic in Shor's factoring and dlog algorithms or the computation of a Boolean predicate in case of Grover's search algorithm.



            Concretely, assume that we have two registers, a data register $A$, an output register $B$, and an ancilla register $C$ and that half-way through the computation we arrived at an entangled state $sum_{x} alpha_{x} |xrangle |f(x)rangle |g(x)rangle$, where the inputs are held in $A$, the function values $f(x)$ are computed into $B$, and the values $g(x)$ are results of some intermediate computations that is stored in the scratch register $C$.



            If we now, instead of uncomputing the register $C$ so that it holds $|0rangle$ (or some other state that is unentangled with registers $A$ and $B$), we decide to reset the register $C$, this will have the following detrimental effect: we will measure (at random) some value $c_0$ and the state will collapse to the superposition of all $x$ that are consistent with this measured value, so that the state will become (up to normalization):



            $$ sum_{x: g(x) = c_0} alpha_x |xrangle |f(x)rangle. $$



            Note that this can be vastly different from the state $sum_x alpha_x |xrangle |f(x)rangle$ that we really wanted (and actually only for constant functions $g$ yields the correct result). Indeed, if $g$ is a permutation, only a single $x$ will survive from the initial superposition! Hence, temporary/scratch registers have to be uncomputed if we want to do subsequent computations with the data in the other registers.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 19 at 23:38









            MartinQuantumMartinQuantum

            30019




            30019












            • $begingroup$
              From the perspective of this answer I feel it's not explained why resetting the register necessarily entails a measurement? Can't we just reset it without looking at it? Or would the differing energy required to reset (or not) the register entangle the computation with the power supply or such like?
              $endgroup$
              – Sideshow Bob
              Jan 21 at 13:06










            • $begingroup$
              I think people are referring to measurement because they are trying to guess what you mean when you talk about resetting a qubit. In general though, changing the state of a qubit in any way (that i can think of) other than uncomputing it will cause the states of entangled qubits to change accordingly.
              $endgroup$
              – Malcolm Regan
              Jan 21 at 19:04












            • $begingroup$
              @SideshowBob, the terminology 'setting qubits to zero' required some clarification. If a qubit is part of a register that is entangled across said qubit, then it is physically not possible to reset the qubit to zero (or any other pure quantum state) without destroying the quantum state of the register.
              $endgroup$
              – MartinQuantum
              Jan 22 at 5:08










            • $begingroup$
              @SideshowBob, the terminology 'resetting a qubit' is nonetheless used, e.g., by the quantum programming community, where it means the specific procedure to a) measure the qubit (e.g. in the standard computational basis), followed by b) a flip to bring it to the zero state. See e.g. projectq.readthedocs.io/en/latest/… for ProjectQ and docs.microsoft.com/en-us/qsharp/api/prelude/… for Q#.
              $endgroup$
              – MartinQuantum
              Jan 22 at 5:09












            • $begingroup$
              Would it not be possible to set the qubit to 0 in every component of a mixed state? i.e. leaving the rest of the entanglement unbroken: the entangled bits will behave the same after the qubit of concern has been reset, but the qubit of concern will always be 0 now whatever the other bits are?
              $endgroup$
              – Sideshow Bob
              Jan 22 at 9:56


















            • $begingroup$
              From the perspective of this answer I feel it's not explained why resetting the register necessarily entails a measurement? Can't we just reset it without looking at it? Or would the differing energy required to reset (or not) the register entangle the computation with the power supply or such like?
              $endgroup$
              – Sideshow Bob
              Jan 21 at 13:06










            • $begingroup$
              I think people are referring to measurement because they are trying to guess what you mean when you talk about resetting a qubit. In general though, changing the state of a qubit in any way (that i can think of) other than uncomputing it will cause the states of entangled qubits to change accordingly.
              $endgroup$
              – Malcolm Regan
              Jan 21 at 19:04












            • $begingroup$
              @SideshowBob, the terminology 'setting qubits to zero' required some clarification. If a qubit is part of a register that is entangled across said qubit, then it is physically not possible to reset the qubit to zero (or any other pure quantum state) without destroying the quantum state of the register.
              $endgroup$
              – MartinQuantum
              Jan 22 at 5:08










            • $begingroup$
              @SideshowBob, the terminology 'resetting a qubit' is nonetheless used, e.g., by the quantum programming community, where it means the specific procedure to a) measure the qubit (e.g. in the standard computational basis), followed by b) a flip to bring it to the zero state. See e.g. projectq.readthedocs.io/en/latest/… for ProjectQ and docs.microsoft.com/en-us/qsharp/api/prelude/… for Q#.
              $endgroup$
              – MartinQuantum
              Jan 22 at 5:09












            • $begingroup$
              Would it not be possible to set the qubit to 0 in every component of a mixed state? i.e. leaving the rest of the entanglement unbroken: the entangled bits will behave the same after the qubit of concern has been reset, but the qubit of concern will always be 0 now whatever the other bits are?
              $endgroup$
              – Sideshow Bob
              Jan 22 at 9:56
















            $begingroup$
            From the perspective of this answer I feel it's not explained why resetting the register necessarily entails a measurement? Can't we just reset it without looking at it? Or would the differing energy required to reset (or not) the register entangle the computation with the power supply or such like?
            $endgroup$
            – Sideshow Bob
            Jan 21 at 13:06




            $begingroup$
            From the perspective of this answer I feel it's not explained why resetting the register necessarily entails a measurement? Can't we just reset it without looking at it? Or would the differing energy required to reset (or not) the register entangle the computation with the power supply or such like?
            $endgroup$
            – Sideshow Bob
            Jan 21 at 13:06












            $begingroup$
            I think people are referring to measurement because they are trying to guess what you mean when you talk about resetting a qubit. In general though, changing the state of a qubit in any way (that i can think of) other than uncomputing it will cause the states of entangled qubits to change accordingly.
            $endgroup$
            – Malcolm Regan
            Jan 21 at 19:04






            $begingroup$
            I think people are referring to measurement because they are trying to guess what you mean when you talk about resetting a qubit. In general though, changing the state of a qubit in any way (that i can think of) other than uncomputing it will cause the states of entangled qubits to change accordingly.
            $endgroup$
            – Malcolm Regan
            Jan 21 at 19:04














            $begingroup$
            @SideshowBob, the terminology 'setting qubits to zero' required some clarification. If a qubit is part of a register that is entangled across said qubit, then it is physically not possible to reset the qubit to zero (or any other pure quantum state) without destroying the quantum state of the register.
            $endgroup$
            – MartinQuantum
            Jan 22 at 5:08




            $begingroup$
            @SideshowBob, the terminology 'setting qubits to zero' required some clarification. If a qubit is part of a register that is entangled across said qubit, then it is physically not possible to reset the qubit to zero (or any other pure quantum state) without destroying the quantum state of the register.
            $endgroup$
            – MartinQuantum
            Jan 22 at 5:08












            $begingroup$
            @SideshowBob, the terminology 'resetting a qubit' is nonetheless used, e.g., by the quantum programming community, where it means the specific procedure to a) measure the qubit (e.g. in the standard computational basis), followed by b) a flip to bring it to the zero state. See e.g. projectq.readthedocs.io/en/latest/… for ProjectQ and docs.microsoft.com/en-us/qsharp/api/prelude/… for Q#.
            $endgroup$
            – MartinQuantum
            Jan 22 at 5:09






            $begingroup$
            @SideshowBob, the terminology 'resetting a qubit' is nonetheless used, e.g., by the quantum programming community, where it means the specific procedure to a) measure the qubit (e.g. in the standard computational basis), followed by b) a flip to bring it to the zero state. See e.g. projectq.readthedocs.io/en/latest/… for ProjectQ and docs.microsoft.com/en-us/qsharp/api/prelude/… for Q#.
            $endgroup$
            – MartinQuantum
            Jan 22 at 5:09














            $begingroup$
            Would it not be possible to set the qubit to 0 in every component of a mixed state? i.e. leaving the rest of the entanglement unbroken: the entangled bits will behave the same after the qubit of concern has been reset, but the qubit of concern will always be 0 now whatever the other bits are?
            $endgroup$
            – Sideshow Bob
            Jan 22 at 9:56




            $begingroup$
            Would it not be possible to set the qubit to 0 in every component of a mixed state? i.e. leaving the rest of the entanglement unbroken: the entangled bits will behave the same after the qubit of concern has been reset, but the qubit of concern will always be 0 now whatever the other bits are?
            $endgroup$
            – Sideshow Bob
            Jan 22 at 9:56


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Quantum Computing Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fquantumcomputing.stackexchange.com%2fquestions%2f5222%2fwhy-do-we-have-to-uncompute-rather-than-simply-set-registers-to-zero%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Mario Kart Wii

            What does “Dominus providebit” mean?

            Antonio Litta Visconti Arese