How to compute the inverse of an operation in Q#?How to create an arbitrary state in QISKit for a local_qasm_simulator?How do we code the matrix for a controlled operation knowing the control qubit, the target qubit and the $2times 2$ unitary?How to construct the “Inversion About the Mean” operator?How would one implement a quantum equivalent of a while loop in IBM QISkit?Quantum counting in Q#How many logical qubits are needed to run Shor's algorithm efficiently on large integers ($n > 2^1024$)?How do I produce circuit diagrams from a Q# program?Representing a real valued vector with qubitsHow do I get a list of control qubits from Q# operations when tracing the simulation in C#?How do I do printf debugging in Q# in a convenient way?

Why aren't (poly-)cotton tents more popular?

Cascading Repair Costs following Blown Head Gasket on a 2004 Subaru Outback

What would Earth look like at night in medieval times?

Should my manager be aware of private LinkedIn approaches I receive? How to politely have this happen?

Is it OK to bottle condition using previously contaminated bottles?

Simple object validator with a new API

Content builder HTTPS

How could mana leakage be dangerous to a elf?

How can I convince my reader that I will not use a certain trope?

Does Marvel have an equivalent of the Green Lantern?

Do I recheck baggage at stopovers MCI-SEA-ICN-SGN? Delta and Korean Air

The impact of an intelligent and (mostly) hostile flying race on weapons and armor

Going to get married soon, should I do it on Dec 31 or Jan 1?

Can a US President have someone sent to prison?

Was touching your nose a greeting in second millenium Mesopotamia?

Are there any vegetarian astronauts?

Should I tell my insurance company I'm making payments on my new car?

What is the line crossing the Pacific Ocean that is shown on maps?

Is this one of the engines from the 9/11 aircraft?

What is this particular type of chord progression, common in classical music, called?

Does the UK have a written constitution?

Are Finite Automata Turing Complete?

Why is Madam Hooch not a professor?

How can I repair scratches on a painted French door?



How to compute the inverse of an operation in Q#?


How to create an arbitrary state in QISKit for a local_qasm_simulator?How do we code the matrix for a controlled operation knowing the control qubit, the target qubit and the $2times 2$ unitary?How to construct the “Inversion About the Mean” operator?How would one implement a quantum equivalent of a while loop in IBM QISkit?Quantum counting in Q#How many logical qubits are needed to run Shor's algorithm efficiently on large integers ($n > 2^1024$)?How do I produce circuit diagrams from a Q# program?Representing a real valued vector with qubitsHow do I get a list of control qubits from Q# operations when tracing the simulation in C#?How do I do printf debugging in Q# in a convenient way?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2












$begingroup$


I want to implement amplitude amplification using Q#. I have the operation $A$
that prepares my initial state and I need to compute $ A^-1 $ to implement the algorithm.



Is there an easy way to do that in Q# (a keyword or operation)?










share|improve this question









New contributor



Sorin Bolos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






$endgroup$


















    2












    $begingroup$


    I want to implement amplitude amplification using Q#. I have the operation $A$
    that prepares my initial state and I need to compute $ A^-1 $ to implement the algorithm.



    Is there an easy way to do that in Q# (a keyword or operation)?










    share|improve this question









    New contributor



    Sorin Bolos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






    $endgroup$














      2












      2








      2





      $begingroup$


      I want to implement amplitude amplification using Q#. I have the operation $A$
      that prepares my initial state and I need to compute $ A^-1 $ to implement the algorithm.



      Is there an easy way to do that in Q# (a keyword or operation)?










      share|improve this question









      New contributor



      Sorin Bolos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      $endgroup$




      I want to implement amplitude amplification using Q#. I have the operation $A$
      that prepares my initial state and I need to compute $ A^-1 $ to implement the algorithm.



      Is there an easy way to do that in Q# (a keyword or operation)?







      programming q#






      share|improve this question









      New contributor



      Sorin Bolos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share|improve this question









      New contributor



      Sorin Bolos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share|improve this question




      share|improve this question








      edited Jun 16 at 17:11









      Sanchayan Dutta

      7,8764 gold badges16 silver badges62 bronze badges




      7,8764 gold badges16 silver badges62 bronze badges






      New contributor



      Sorin Bolos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      asked Jun 16 at 17:06









      Sorin BolosSorin Bolos

      233 bronze badges




      233 bronze badges




      New contributor



      Sorin Bolos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      New contributor




      Sorin Bolos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          2 Answers
          2






          active

          oldest

          votes


















          4












          $begingroup$

          As given in the documentation, if your operation is unitary, you can add the statement adjoint auto; within the operation after the body block. This will generate the adjoint (which is the inverse for unitary).



          Then, to use the inverse call Adjoint A(parameters)






          share|improve this answer









          $endgroup$








          • 1




            $begingroup$
            Thank you. I didn't know that the adjoint is also the inverse for unitary matrices.
            $endgroup$
            – Sorin Bolos
            Jun 16 at 17:44


















          4












          $begingroup$

          In the case that your operation can be represented by a unitary operator $U$ (this is typically the case if your operation doesn't use any measurements), you can indicate that by adding is Adj to your operation's signature, letting the Q# compiler know that your operation is adjointable:



          open Microsoft.Quantum.Math as Math;

          /// # Summary
          /// Prepares a qubit in a state representing a classical probability
          /// distribution p, 1 - p.
          /// # Description
          /// Given a qubit in the |0⟩, prepares √p |0⟩ + √(1 - p) |1⟩
          /// for a given probability p.
          operation PrepareDistribution(probability : Double, target : Qubit) : Unit
          is Adj
          let rotationAngle = 2.0 * Math.ArcCos(Math.Sqrt(1.0 - probability));
          Ry(rotationAngle, target);



          You can then call Adjoint PrepareDistribution to "undo" the PrepareDistribution operation. The Adjoint keyword is an example of a Q# functor, and tells Q# that you want the inverse operation. In this case, the Q# compiler will apply Ry(-rotationAngle, target).



          For more information:



          • Functors


          • Learn Quantum Computing with Python and Q# (chapter 6 covers the example above, future chapters will talk more about functors)





          share|improve this answer









          $endgroup$















            Your Answer








            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
            );



            );






            Sorin Bolos is a new contributor. Be nice, and check out our Code of Conduct.









            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fquantumcomputing.stackexchange.com%2fquestions%2f6477%2fhow-to-compute-the-inverse-of-an-operation-in-q%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            4












            $begingroup$

            As given in the documentation, if your operation is unitary, you can add the statement adjoint auto; within the operation after the body block. This will generate the adjoint (which is the inverse for unitary).



            Then, to use the inverse call Adjoint A(parameters)






            share|improve this answer









            $endgroup$








            • 1




              $begingroup$
              Thank you. I didn't know that the adjoint is also the inverse for unitary matrices.
              $endgroup$
              – Sorin Bolos
              Jun 16 at 17:44















            4












            $begingroup$

            As given in the documentation, if your operation is unitary, you can add the statement adjoint auto; within the operation after the body block. This will generate the adjoint (which is the inverse for unitary).



            Then, to use the inverse call Adjoint A(parameters)






            share|improve this answer









            $endgroup$








            • 1




              $begingroup$
              Thank you. I didn't know that the adjoint is also the inverse for unitary matrices.
              $endgroup$
              – Sorin Bolos
              Jun 16 at 17:44













            4












            4








            4





            $begingroup$

            As given in the documentation, if your operation is unitary, you can add the statement adjoint auto; within the operation after the body block. This will generate the adjoint (which is the inverse for unitary).



            Then, to use the inverse call Adjoint A(parameters)






            share|improve this answer









            $endgroup$



            As given in the documentation, if your operation is unitary, you can add the statement adjoint auto; within the operation after the body block. This will generate the adjoint (which is the inverse for unitary).



            Then, to use the inverse call Adjoint A(parameters)







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jun 16 at 17:33









            Mahathi VempatiMahathi Vempati

            82410 bronze badges




            82410 bronze badges







            • 1




              $begingroup$
              Thank you. I didn't know that the adjoint is also the inverse for unitary matrices.
              $endgroup$
              – Sorin Bolos
              Jun 16 at 17:44












            • 1




              $begingroup$
              Thank you. I didn't know that the adjoint is also the inverse for unitary matrices.
              $endgroup$
              – Sorin Bolos
              Jun 16 at 17:44







            1




            1




            $begingroup$
            Thank you. I didn't know that the adjoint is also the inverse for unitary matrices.
            $endgroup$
            – Sorin Bolos
            Jun 16 at 17:44




            $begingroup$
            Thank you. I didn't know that the adjoint is also the inverse for unitary matrices.
            $endgroup$
            – Sorin Bolos
            Jun 16 at 17:44













            4












            $begingroup$

            In the case that your operation can be represented by a unitary operator $U$ (this is typically the case if your operation doesn't use any measurements), you can indicate that by adding is Adj to your operation's signature, letting the Q# compiler know that your operation is adjointable:



            open Microsoft.Quantum.Math as Math;

            /// # Summary
            /// Prepares a qubit in a state representing a classical probability
            /// distribution p, 1 - p.
            /// # Description
            /// Given a qubit in the |0⟩, prepares √p |0⟩ + √(1 - p) |1⟩
            /// for a given probability p.
            operation PrepareDistribution(probability : Double, target : Qubit) : Unit
            is Adj
            let rotationAngle = 2.0 * Math.ArcCos(Math.Sqrt(1.0 - probability));
            Ry(rotationAngle, target);



            You can then call Adjoint PrepareDistribution to "undo" the PrepareDistribution operation. The Adjoint keyword is an example of a Q# functor, and tells Q# that you want the inverse operation. In this case, the Q# compiler will apply Ry(-rotationAngle, target).



            For more information:



            • Functors


            • Learn Quantum Computing with Python and Q# (chapter 6 covers the example above, future chapters will talk more about functors)





            share|improve this answer









            $endgroup$

















              4












              $begingroup$

              In the case that your operation can be represented by a unitary operator $U$ (this is typically the case if your operation doesn't use any measurements), you can indicate that by adding is Adj to your operation's signature, letting the Q# compiler know that your operation is adjointable:



              open Microsoft.Quantum.Math as Math;

              /// # Summary
              /// Prepares a qubit in a state representing a classical probability
              /// distribution p, 1 - p.
              /// # Description
              /// Given a qubit in the |0⟩, prepares √p |0⟩ + √(1 - p) |1⟩
              /// for a given probability p.
              operation PrepareDistribution(probability : Double, target : Qubit) : Unit
              is Adj
              let rotationAngle = 2.0 * Math.ArcCos(Math.Sqrt(1.0 - probability));
              Ry(rotationAngle, target);



              You can then call Adjoint PrepareDistribution to "undo" the PrepareDistribution operation. The Adjoint keyword is an example of a Q# functor, and tells Q# that you want the inverse operation. In this case, the Q# compiler will apply Ry(-rotationAngle, target).



              For more information:



              • Functors


              • Learn Quantum Computing with Python and Q# (chapter 6 covers the example above, future chapters will talk more about functors)





              share|improve this answer









              $endgroup$















                4












                4








                4





                $begingroup$

                In the case that your operation can be represented by a unitary operator $U$ (this is typically the case if your operation doesn't use any measurements), you can indicate that by adding is Adj to your operation's signature, letting the Q# compiler know that your operation is adjointable:



                open Microsoft.Quantum.Math as Math;

                /// # Summary
                /// Prepares a qubit in a state representing a classical probability
                /// distribution p, 1 - p.
                /// # Description
                /// Given a qubit in the |0⟩, prepares √p |0⟩ + √(1 - p) |1⟩
                /// for a given probability p.
                operation PrepareDistribution(probability : Double, target : Qubit) : Unit
                is Adj
                let rotationAngle = 2.0 * Math.ArcCos(Math.Sqrt(1.0 - probability));
                Ry(rotationAngle, target);



                You can then call Adjoint PrepareDistribution to "undo" the PrepareDistribution operation. The Adjoint keyword is an example of a Q# functor, and tells Q# that you want the inverse operation. In this case, the Q# compiler will apply Ry(-rotationAngle, target).



                For more information:



                • Functors


                • Learn Quantum Computing with Python and Q# (chapter 6 covers the example above, future chapters will talk more about functors)





                share|improve this answer









                $endgroup$



                In the case that your operation can be represented by a unitary operator $U$ (this is typically the case if your operation doesn't use any measurements), you can indicate that by adding is Adj to your operation's signature, letting the Q# compiler know that your operation is adjointable:



                open Microsoft.Quantum.Math as Math;

                /// # Summary
                /// Prepares a qubit in a state representing a classical probability
                /// distribution p, 1 - p.
                /// # Description
                /// Given a qubit in the |0⟩, prepares √p |0⟩ + √(1 - p) |1⟩
                /// for a given probability p.
                operation PrepareDistribution(probability : Double, target : Qubit) : Unit
                is Adj
                let rotationAngle = 2.0 * Math.ArcCos(Math.Sqrt(1.0 - probability));
                Ry(rotationAngle, target);



                You can then call Adjoint PrepareDistribution to "undo" the PrepareDistribution operation. The Adjoint keyword is an example of a Q# functor, and tells Q# that you want the inverse operation. In this case, the Q# compiler will apply Ry(-rotationAngle, target).



                For more information:



                • Functors


                • Learn Quantum Computing with Python and Q# (chapter 6 covers the example above, future chapters will talk more about functors)






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jun 16 at 17:44









                Chris GranadeChris Granade

                2032 silver badges6 bronze badges




                2032 silver badges6 bronze badges




















                    Sorin Bolos is a new contributor. Be nice, and check out our Code of Conduct.









                    draft saved

                    draft discarded


















                    Sorin Bolos is a new contributor. Be nice, and check out our Code of Conduct.












                    Sorin Bolos is a new contributor. Be nice, and check out our Code of Conduct.











                    Sorin Bolos is a new contributor. Be nice, and check out our Code of Conduct.














                    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%2f6477%2fhow-to-compute-the-inverse-of-an-operation-in-q%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

                    Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

                    Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                    Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form