<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Harshit Gupta on Medium]]></title>
        <description><![CDATA[Stories by Harshit Gupta on Medium]]></description>
        <link>https://medium.com/@harshit.11235?source=rss-b9061b9da9d9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*bBvFMaXyCgwSg0WkMZqVDg.jpeg</url>
            <title>Stories by Harshit Gupta on Medium</title>
            <link>https://medium.com/@harshit.11235?source=rss-b9061b9da9d9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 12 Apr 2026 19:55:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@harshit.11235/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[A Glimpse of Technology in Middle School : GirlsGrow’s Workshop in Gurugram, Delhi NCR]]></title>
            <link>https://medium.com/@harshit.11235/a-glimpse-of-technology-in-middle-school-girlsgrows-workshop-in-gurugram-delhi-ncr-3ecb423d045e?source=rss-b9061b9da9d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ecb423d045e</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[ngos-in-india]]></category>
            <category><![CDATA[career-development]]></category>
            <dc:creator><![CDATA[Harshit Gupta]]></dc:creator>
            <pubDate>Tue, 26 Nov 2024 14:03:09 GMT</pubDate>
            <atom:updated>2024-11-26T14:05:16.018Z</atom:updated>
            <content:encoded><![CDATA[<h3>A Glimpse of Technology in Middle School : GirlsGrow’s Workshop in Gurugram, Delhi NCR</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jyhpV9YAD9LjWPnWLVlayw.jpeg" /><figcaption>The students and faculty of Sankalp School</figcaption></figure><p>We are proud to announce the successful completion of our <em>Careers in Technology</em> Workshop at Gurugram’s Sankalp School! With the main focus of this workshop on software engineering, we gave a brief introduction of the field, its worldwide impact and potential careers to middle school children. Our goal was to ignite curiosity, establish analogies and help children see software’s role in their everyday lives, perhaps the next time they pick up their parents’ phones!</p><p>Since software is rarely introduced at this stage in a child’s education, we carefully adapted our presentation to suit young learners. Starting with light introductions and aspirations, we were amazed by their diverse responses — ranging from doctor to astronaut, scientist to army officer. Building upon their interests, we highlighted software’s pervasiveness in daily life, from mobile phones and laptops to hospitals and even superhero tech! To explain software’s career opportunities, we used a simple yet effective analogy of a pen to break down career roles into <em>design</em>, <em>development</em>, and <em>management</em>. This was followed by an engaging game where children classified phone components into these roles — a fun and insightful way to reinforce learning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GyXjrn1ONbYmPv-Leo1qWg.jpeg" /><figcaption>Interacting with the students — 1</figcaption></figure><p>It was great to see the receptiveness of the children, their immense sense of curiosity and an infectious desire to learn the “why” of things. We also saw a wave of interest as we started diving into things like computer games, social media and other present day technologies. One thing which caught our attention was interest in the field of hacking. While their view was restricted, it was surprising to see a couple of 10 year olds talking about a possible career in computer security! Other than their obvious enthusiasm, it was exciting to see the sheer breadth of interests, related questions and a fluid mindset this early in their educational journey.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9ODIqul6IlgrIbxIh1ATeg.jpeg" /><figcaption>Interacting with students — 2</figcaption></figure><p>After conducting numerous such workshops, we have come to realize that each of them is as much of a learning experience for us as it might be for the children. We observed that a great way to mitigate children’s smaller attention span is by introducing games in discussions. Children are naturally attracted towards play and adding a touch of fun always makes the conversation more interactive and well received. Moreover, simplicity and zero jargon goes a long way when talking with young learners. Lastly, having a less rigid presentation structure and active audience participation makes things a lot more interesting.</p><p>These experiences have equipped us to better empower children to explore technology on their terms. With more workshops in the pipeline, we look forward to continuing this journey of inspiring future leaders, one classroom at a time.</p><blockquote>Learn more about <a href="https://www.linkedin.com/company/girls-grow/posts/?feedView=all">GirlsGrow on Linkedin</a>!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ecb423d045e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Byte Sized Python — 1]]></title>
            <link>https://medium.com/@harshit.11235/byte-sized-python-1-f95d53311860?source=rss-b9061b9da9d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/f95d53311860</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[programming-languages]]></category>
            <dc:creator><![CDATA[Harshit Gupta]]></dc:creator>
            <pubDate>Thu, 19 Sep 2024 10:56:44 GMT</pubDate>
            <atom:updated>2024-09-19T10:56:44.838Z</atom:updated>
            <content:encoded><![CDATA[<h3>Byte Sized Python — 1</h3><h4>Python is a versatile language consisting of a vibrant feature set. This is a catalogue of new features which I’m discovering as I go about it and the details are pretty interesting!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u8QOpzgwbZ4zbaRdJ265xA.png" /><figcaption>Byte Sized Python</figcaption></figure><h4>1. Interfaces in Python</h4><p>I came across this while developing theqbraid-qir project. The pyi extension for Python files means a file where ALL method/function definitions are empty.</p><p>The i in pyi stands for <em>interface. </em>Taking the analogy from other languages like Java which have a concept of interface, a pyi file would contain only the structure of what a function or a class method would look like but not its implementation. I encountered this extension while going into the details of the <a href="https://github.com/qir-alliance/pyqir/blob/main/pyqir/pyqir/_native.pyi">pyqir</a>repository.</p><p>Another name for this is a stub . It is just a specification of what an interface is going to look like or the structure of some function. Again, no implementation details are present in it.</p><p>It can also be thought of as something like the C header files, eg-</p><pre># my_file.py<br>def my_method(name):<br>    return &quot;hello&quot;+name</pre><pre># my_file.pyi<br>def my_method(name : str) -&gt; str ...</pre><p>First is the implementation, and the second is the header/interface/stub / pyi file.</p><h4>2. Ellipsis in Python</h4><p>Ellipsis or ... is a keyword in python. It has multiple uses such as —</p><p><strong>As a placeholder</strong></p><p>When we are unsure of what we would be writing in our code, we can easily use ... to denote the same. Eg —</p><pre># py_script.py<br>def do_something(name):<br>  ...<br>do_something(&quot;hi&quot;)</pre><p>When we execute py_script.py it will correctly be interpreted and we won’t see any errors.</p><p>Another place where ... can be used in <em>stubs.</em> Stubs are used when we only want to define the skeleton of a particular method / function but do not want anything to be executed. This might be a requirement while building an application not yet handling external user requests. Eg —</p><pre># example file <br>from some_package import external_request_counter <br><br><br>if debug_mode:<br>  def external_request_counter(): ...<br><br>... # rest of the code </pre><p>The ... helps in making testing easier by overriding definitions and just ensuring that the structure is as expected.</p><p><a href="https://realpython.com/python-ellipsis/#what-does-the-ellipsis-mean-in-type-hints">https://realpython.com/python-ellipsis/#what-does-the-ellipsis-mean-in-type-hints</a></p><h4>3. Caching arbitrary functions in Python</h4><p>During the development of qBraid-sdk, I found a method which was making a GET request for retrieving the quantum devices from our rest API, and doing so every single time. This was kind of slow and we needed to do something about it.</p><p>The nature of the method was to get the devices supported by a quantum provider and it made sense for it to make a call to the API. But the device distribution does not change very much over the course of minutes, right? If this is the case, we can safely “cache” the returned devices in memory and return them if the cache has not yet expired. Seems simple enough and a straightforward implementation is to keep a last_accessed variable and time_to_live (TTL) attribute for our quantum devices.</p><p>But, what if we could cache the whole “function signature”? This is what I did finally! (courtesy of the OP Ryan Hill). Turns out we can decorate a function with anything that we want and make it “cachable”. How exactly? Let’s take a simple example —</p><pre>class Multiply:<br>  def __init__(self):<br>     pass <br>  def get_value(self, n):<br>      return n * 10<br></pre><p>We have a very simple class Multiply whose get_value method multiplies the argument by 10. Now, we can easily instantiate and call this as —</p><pre>a_obj = A()<br>print(a_obj.get_value(1)) # 10</pre><p>This prints 10, good enough. But now, we don’t want to do this computation but want to just retrieve the return value. The idea is to store the results in a cache to be retrieved later. But its boring to just store the name of the argument as our key, as it can lead to cache collisions. Let’s store the hash of the function signature! Define a hashing function like —</p><pre>import hashlib<br>import json<br><br>def _generate_cache_key(func_name: str, args: tuple, kwargs: dict) -&gt; str:<br>    &quot;&quot;&quot;Generate a cache key based on function name, args, and kwargs.&quot;&quot;&quot;<br>    key_data = {&quot;func_name&quot;: func_name, &quot;args&quot;: args, &quot;kwargs&quot;: kwargs}<br>    key_str = json.dumps(key_data, sort_keys=True)# Ensure consistent key order<br>    return hashlib.sha256(key_str.encode()).hexdigest()</pre><p>The _generate_cache_key function would spit out a hash value for a function signature, example —</p><pre>def my_function(n):<br>  return n * 10 <br><br>print(_generate_cache_key(my_function.__name__, (&#39;n&#39;, 3), {}))<br><br># output : 8a2c747f9adc491c838e593179c3bbca8eae018f88f4bd434729cced25492ebd</pre><p>Now, we can identify a function call “uniquely” with this cache key. Here comes the interesting part! To make a method “cachable” we use the built in decorator functionality of python. How exactly? The following example would make things clear —</p><pre>import functools <br>import time <br><br>def cache_results(ttl: int = 120):<br>    &quot;&quot;&quot;<br>    A decorator to cache the results of get_device or get_devices methods.<br>    Args:<br>        ttl (int): Time-to-live for the cache in seconds.<br>    &quot;&quot;&quot;<br><br>    def decorator(func):<br>        cache = {}<br>        @functools.wraps(func)<br>        def wrapper(*args, **kwargs):<br><br>            # Generate a unique cache key based on method name, args, and kwargs<br>            key = _generate_cache_key(func.__name__, args, kwargs)<br><br>            # Check if the result is in cache and still valid<br>            if key in cache:<br>                cached_result, timestamp = cache[key]<br>                if (time.time() - timestamp) &lt; ttl:<br>                    return cached_result<br><br>            # Call the actual method and cache the result<br>            result = func(*args, **kwargs)<br>            cache[key] = (result, time.time())<br>            return result<br><br>        return wrapper<br><br>    return decorator</pre><p>This cache_results method is a python decorator i.e. it be can be wrapped around any function that we want. We have the name of the decorator — cache_results. Post that we have the decorator method i.e. what will happen to a function which is decorated with the @cache_results(). this will have the argument as the callable or the function which is wrapped. Then, wrapper defines what happens during the invocation of this decorator. In wrapper, we first calculate the hash value of the function signature, then check if the cache entry is present AND valid. If yes, we return from there. Otherwise, we call the function and update the cache with the return value and current time. Now, if we do something like —</p><pre>@cache_results(ttl = 10)<br>def my_function(n)<br>  time.sleep(5)<br>  return 10 * n <br><br>init_time = time.time()<br>_ = my_function(1)<br>print(&quot;time taken:&quot;, time.time() - init_time) <br># output : 5.0021278858184814<br><br>init_time = time.time()<br>_ = my_function(1)<br>print(&quot;time taken with cache:&quot;, time.time() - init_time) <br># output : 0.0001590251922607422</pre><p>We can clearly see that the second function call has come from the cache as the time taken is &lt; 0.001 seconds whereas the original time is ~ 5 seconds (atrributed to the time.sleep()).</p><p>Why this is powerful is because of the nature of this decorator. It does not matter what kind of function we have or its return value. As long as the function call signature is hashable, we are good to go!</p><p>Some nuances which I had in my PR can be found here — <a href="https://github.com/qBraid/qBraid/pull/755">https://github.com/qBraid/qBraid/pull/755</a>. Essentially I used a different access scope for the cache due to some specific constraints but the primary idea was the same.</p><p>Hope this helps out someone else too!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f95d53311860" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[qbraid-qir]]></title>
            <link>https://medium.com/@harshit.11235/qbraid-qir-086442e73e35?source=rss-b9061b9da9d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/086442e73e35</guid>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[quantum-computing]]></category>
            <category><![CDATA[quantum]]></category>
            <category><![CDATA[openqasm]]></category>
            <category><![CDATA[parser]]></category>
            <dc:creator><![CDATA[Harshit Gupta]]></dc:creator>
            <pubDate>Wed, 11 Sep 2024 10:24:59 GMT</pubDate>
            <atom:updated>2024-09-16T17:43:25.707Z</atom:updated>
            <content:encoded><![CDATA[<h4>Enabling access to the Quantum Intermediate Representation (QIR) through qBraid</h4><h4><strong>Background</strong></h4><p>Quantum computers are evolving at a rapid pace in today’s post-NISQ era with a plethora of techniques to develop <em>qubits. </em>From superconducting circuits and photonics to neutral atoms and ion traps, each quantum computer employs a unique approach to realizing qubits. Along with different qubit architectures, a lot of packages, like Qiskit, Braket, Cirq, Pennylane and languages such as Q# have been developed that allow users to interact with these systems. These varied architectures and input formats are not a new concept in the field of computing. Different architectures exist for classical computers as well like the x86, ARM or AMD and languages such as Python, C, C++, Java and the likes. Just as in classical computing, users in quantum seek to write code that is agnostic of the underlying architecture, allowing their programs to run seamlessly across different systems.</p><p>Well, we do not write an if statement thinking whether it will be executed on x86 or ARM. Similar constructs are available in quantum like the <a href="https://en.wikipedia.org/wiki/Quantum_logic_gate">gate based model </a>of quantum computing. This is an abstraction which defines the behavior of a particular gate irrespective of <em>how</em> it is implemented; just that <em>it is. </em>The users are not, and need not be, aware of the hardware even though they can use quantum gates and execute circuits. It is the job of the developers writing a <em>converter</em> who cater to these aspects of circuit execution thus bringing us to an interesting problem of converting a high level program to executable code.</p><p>How do we achieve this architecture agnostic execution of quantum programs and is there any <em>one way</em> to do it? Lets find out!</p><p>Let’s first talk about how this is done in the classical systems. If we want to convert the programs written in a particular language say Python to the x86 or the arm architecture, we would need 2 <a href="https://en.wikipedia.org/wiki/Compiler">compilers</a> — Python to x86 and Python to arm. Each one would take our high level Python code, and convert its constructs according to the target architecture. The users need not be aware of these transformations because these tools would automatically detect the target system in their backend.</p><p>This is all well and good but what about when we have an arbitrary number of language formats coupled with a different number of architectures?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PsqMg-7Z5oCQ1kJzUKvw5w.png" /><figcaption>Fig. 1 — Language to Architecture Conversion Graph</figcaption></figure><p>The number of compilers would scale as the <em>product</em> of these formats and architectures. Each new format would require 1 converter for each architecture it targets. Since writing a compiler is not a trivial task, it is hard to keep up with the development of packages and architectures. A possible solution to this problem is using a <a href="https://en.wikipedia.org/wiki/Intermediate_representation">common intermediate representation (IR)</a>. Languages can be compiled down to this common IR before compiling it further to architecture specific representations. Why does this help? It is because adding a new format or architecture entails a “single” tool to be built. A new language would only need a single converter to the target IR and a new architecture target would require only 1 compiler.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZPKuX6wrOv0xCmMtiF4jOg.png" /><figcaption>Fig. 2 — Introduction of Intermediate Representation (IR)</figcaption></figure><p>While this problem has been solved for classical computers with IRs such as <a href="https://en.wikipedia.org/wiki/LLVM">LLVM</a>, the efforts for standardizing a common IR for quantum computers are still underway. One project which aims to realize this for quantum computers is Quantum Intermediate Representation (QIR) backed by the <a href="https://www.qir-alliance.org/">QIR alliance</a>. Composed of members from various organizations such as Microsoft, NVIDIA, Quantinuum and others, their primary aim is to design and implement compiler technologies for advancing quantum programming language design and development.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eMkJ3U8CX6wQ6Taf.png" /><figcaption>Fig. 3 — Steering committee for QIR Alliance</figcaption></figure><h4>What is QIR?</h4><p><a href="https://github.com/qir-alliance/qir-spec">Quantum Intermediate Representation</a> or QIR is a type of IR which uses the <a href="https://en.wikipedia.org/wiki/LLVM">Low Level Virtual Machine(LLVM)</a> IR. QIR is defined by something called a <a href="https://github.com/qir-alliance/qir-spec">QIR spec</a> which defines how to represent quantum programs within the LLVM IR. This form can utilize the existing LLVM toolchain and be converted to the executables targeting different qubit implementations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uw2IxO0Sk2evTeN5khzxVw.png" /><figcaption>Fig. 4 — Lifecycle of a quantum program with QIR</figcaption></figure><p>As evident from Fig. 4, QIR exists in the middle of the user code and the backend target. It enables different quantum computing packages to lower their programs into a single IR which can eventually be compiled down to the qubit level.</p><h4>How is it different from openqasm?</h4><p>There are several levels in which QIR is different from the existing <a href="https://openqasm.com/intro.html">openqasm specification</a> —</p><p><strong>Focus</strong>:</p><ul><li><strong>openqasm</strong>: Specializes in representing quantum circuits with a primary focus on quantum gate operations and limited classical control.</li><li><strong>QIR</strong>: Provides a unified representation of both quantum and classical operations, enabling integrated optimization and management of hybrid quantum-classical programs.</li></ul><p><strong>Optimization</strong>:</p><ul><li><strong>openqasm</strong>: Supports circuit-level optimizations, mainly targeting quantum gate reductions and qubit mapping.</li><li><strong>QIR</strong>: Leverages the LLVM framework for advanced optimizations across <em>both quantum and classical code</em>, offering broader and more sophisticated optimization capabilities.</li></ul><p><strong>Hardware Abstraction</strong>:</p><ul><li><strong>openqasm</strong>: Closer to hardware-specific quantum circuit representation, requiring backend compilation for specific QPU architectures.</li><li><strong>QIR</strong>: Hardware-agnostic intermediate representation that is further compiled into hardware-specific instructions, offering greater portability across different quantum platforms.</li></ul><h4><strong>Come in qbraid-qir</strong></h4><p>At <a href="https://www.qbraid.com/">qBraid</a>, we aim to develop platform agnostic resources for quantum computers. Whether it be our quantum software development kit i.e. the <a href="https://github.com/qBraid/qBraid">qbraid-sdk</a> or a unified platform providing access to a variety of quantum computers all within the <a href="https://lab.qbraid.com/hub/spawn">qbraid lab</a>, our goal is to enable a seamless access to users without having to worry about dependencies, multiple software packages or how to access different quantum computers. So when an IR was being developed to standardize quantum program translation, we couldn’t help but pitch in!</p><p>We are rapidly developing a python package called <a href="https://github.com/qBraid/qbraid-qir">qbraid-qir</a> which enables people to convert quantum programs directly to QIR. It currently supports conversions between cirq and openqasm to QIR programs. Users can supply quantum circuits or code, written in either of the packages, and the converter takes care of generating a semantically valid QIR program. Here’s a simple example to convert a bell state circuit into QIR —</p><pre># Run: pip install qbraid-qir <br>from qbraid_qir.qasm3 import qasm3_to_qir<br><br>program = &quot;&quot;&quot;<br>OPENQASM 3;<br>include &quot;stdgates.inc&quot;;<br><br>qubit[2] q;<br>bit[2] c;<br><br>h q[0];<br>cx q[0], q[1];<br><br>measure q[0] -&gt; c[0];<br>measure q[1] -&gt; c[1];<br>&quot;&quot;&quot;<br><br>module = qasm3_to_qir(program, name=&quot;my-program&quot;)<br><br>ir = str(module)</pre><p>Besides direct conversions, we can also utilise qbraid-sdk’s abilities to extend this conversion to other packages. Although qbraid-sdk supports conversions between popular packages such as braket, cirqand qiskit out of the box, it can perform arbitrary conversions given that we specify a conversion method for the source and target packages. For example, we can add the conversion function for cirq to QIR into qbraid-sdk’s package conversion graph and convert a braket circuit to QIR. Here’s an <a href="https://github.com/qBraid/qbraid-qir/blob/main/examples/qbraid_transpiler_braket_to_qir.ipynb">example notebook for converting braket circuits to QIR</a> that uses the qbraid-sdk and qbraid-qir packages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h3wZ3lbrjiWv1dCKac7bHQ.png" /><figcaption>Fig. 5 — Conversion Graph for qbraid-sdk with QIR support</figcaption></figure><h4>Current State</h4><p>The development for qbraid-qir was started in Dec 2023 with the cirq to QIR converter. Since then, we have expanded to openqasm conversions and are currently at v0.2.2, after our first release back in Jan 2024. Housing a semantic analyser for openqasm, our converter <a href="https://github.com/qBraid/qbraid-qir/blob/main/qbraid_qir/qasm3/README.md">supports a wide range</a> of semantic checks based on the OpenQASM3 specification and we aim to target the full breadth of those operations.</p><p>qbraid-qir can be easily installed using pip, allowing users to quickly start local development. Moreover, the qbraid-lab provides built-in support for qbraid-qir package in our default environments. Users can access the package in cloud and even submit jobs to the <a href="https://docs.qbraid.com/home/pricing#quantum-circuit-simulators">remote QIR simulator</a> available at qBraid.</p><h4>Future Scope</h4><p>We aim to release the first stable version of the openqasm to QIR converter sometime around Oct 2024. This version will provide complete support for openqasm constructs which can be converted down to QIR and enable complex openqasm programs to be transformed and executed in equivalent QIR code. Subsequently, we also want to expand the capabilities of the cirq to QIR converter. While we support many native cirq gates, the converter would benefit from tackling more complex gate conversions and supporting a larger number of cirq constructs.</p><p>During the development of the converter, we also identified that the semantic analyser for openqasm could potentially be de-coupled from the qbraid-qir package. Although the current implementation has some coupling with the <a href="https://github.com/qir-alliance/pyqir">QIR python bindings</a>, our eventual goal is to split the semantic analyser into a separate package. This will enable independent usage of the openqasm checker and allow it to be used either as an independent analyser or as a dependency in other packages which require semantic analysis for QASM programs.</p><p>We believe that standardization in quantum program representation is the way forward for a scalable and platform independent development of the field. QIR is an initiative which does exactly that and thus at qBraid we want to enable a seamless integration with existing quantum computing packages and pave the way for future tools looking for an established IR for their quantum programs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=086442e73e35" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[New features of the Qiskit Trebugger]]></title>
            <link>https://medium.com/qiskit/new-features-of-the-qiskit-trebugger-2c790dd6709d?source=rss-b9061b9da9d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c790dd6709d</guid>
            <category><![CDATA[quantum-computing]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[qiskit]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[qiskit-advocate]]></category>
            <dc:creator><![CDATA[Harshit Gupta]]></dc:creator>
            <pubDate>Sat, 12 Aug 2023 14:25:56 GMT</pubDate>
            <atom:updated>2023-08-30T13:58:00.459Z</atom:updated>
            <content:encoded><![CDATA[<p><em>By Harshit Gupta, Qiskit Advocate</em></p><p>The Qiskit Transpiler is an essential tool that allows us to map any arbitrary quantum circuit into a circuit that is both physically runnable and compatible with the properties of its target quantum backend. Qiskit’s transpiler has built-in logging and callback mechanisms to help users understand transpilation, but, many users don’t know about these methods, nor do they have sufficient knowledge about using them. That’s where we come in.</p><p>The process we use Qiskit’s transpiler for is called <strong>quantum circuit<br>transpilation</strong>. It includes important tasks like expanding a circuit to the backend’s qubit count, breaking down higher-level quantum operations in terms of the supported basis set, routing qubits according to the chip connectivity, and optimizing the final circuit. Users often find it difficult to visualize these tasks, however. That’s why we decided to build <strong>Qiskit Trebugger (transpiler-debugger)</strong>, a tool that provides a visual representation of the transpilation process. <a href="https://medium.com/qiskit/qiskit-trebugger-f7242066d368">Originally debuting on the Qiskit blog in early 2022</a> in the form of a Jupyter widget, we’re pleased to share that Qiskit Trebugger is now also available as a lightweight command-line interface (CLI) as well.</p><p><strong>Qiskit Trebugger </strong>was developed as an interactive tool with multiple views catering to the needs of different users. Available as a <a href="https://pypi.org/project/qiskit-trebugger/">Python package on PyPI</a>, it can be used as a <em>Jupyter widget</em> or a lightweight <em>CLI tool </em>to understand how a circuit goes through the Qiskit transpiler. Below, we’ll take a closer look at this new CLI functionality and its key features.</p><h3>Command Line View</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IRMADCHueHCFMpakFf8lVQ.gif" /></figure><p>The command line view for the debugger is a recent development. Built using the <a href="https://docs.python.org/3/howto/curses.html">ncurses</a> and <a href="https://pypi.org/project/tabulate/">tabulate</a> packages, it is a lightweight alternative to the Jupyter view. It has minimal overhead for loading and gives users the ability to debug circuits in a familiar terminal environment.</p><p>The CLI view is also interactive, with action keys for navigation and a status bar. Users can index into the pass list to see the details of each pass and toggle through different views. The CLI supports most features that are provided by the Jupyter view. However, users should note that they can only render the CLI view in the terminal, not a Jupyter notebook.</p><p>Installing the package is as simple as running the following command —</p><pre>pip install qiskit-trebugger</pre><p>To test the package, users can run a Python file with the given code —</p><pre>from qiskit.providers.fake_provider import FakeCasablanca<br>from qiskit.circuit.random import random_circuit <br>from qiskit_trebugger import Debugger<br>import warnings<br><br>warnings.simplefilter(&#39;ignore&#39;)<br>debugger = Debugger(view_type = &quot;cli&quot;)<br>backend = FakeCasablanca()<br>circuit = random_circuit(num_qubits = 4, depth = 5 , seed = 44)<br><br># replace qiskit&#39;s transpile call <br>debugger.debug(circuit, optimization_level = 2, backend = backend)</pre><p>This will render a view describing the transpilation process of the Qiskit transpiler.</p><h4>Components</h4><ul><li><strong>Overview Panel: </strong>The overview consists of the header and the transpilation overview panels. The transpilation overview panel highlights crucial information about the workings of the transpiler. It consists of the total number of transpiler passes executed, the total runtime of the transpiler, and a comparison of the different statistics for the original and final circuits.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/1*67wJ_kqyNjNXnryBW0Yb9A.png" /><figcaption>Overview</figcaption></figure><ul><li><strong>Global Transpilation Panel: </strong>Provides the details about which passes were executed during transpilation and in which order. Key details such as pass type, runtime for the pass, and circuit statistics post-execution of each pass are highlighted in a tabular format. Passes that change at least one property of the circuit are highlighted as well.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wO5CHAbmrZcvuNyI4YU2Sg.png" /><figcaption>Global Transpilation Table</figcaption></figure><ul><li><strong>Interaction Bar: </strong>The CLI tool is interactive and can take in user input to modify its state. This input is taken through ‘hot keys’ listed in the interaction bar at the bottom of the terminal. The commands are listed below :</li></ul><ol><li><strong>Arrow Keys</strong>: Scroll horizontally or vertically</li><li><strong>U: </strong>Page Up</li><li><strong>D: </strong>Page Down</li><li><strong>H: </strong>Toggle the overview panel</li><li><strong>I: </strong>Index into any transpiler pass</li><li><strong>N: </strong>Move to Next</li><li><strong>P: </strong>Previous pass while viewing pass details</li><li><strong>B: </strong>Move back to the initial view</li><li><strong>Q: </strong>Quit</li></ol><p>Note: After pressing <strong>I</strong>, the user can enter the index of any transpiler pass and the pass level details will be rendered for the same.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4VwiFqX_35MjW3TAg3tpBA.png" /><figcaption>Initial View</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UYFshDBXDVAgaYaYjyrCng.png" /><figcaption>Input from User</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*khC_XDvF19slCk0mbi76gA.png" /><figcaption>Indexed View</figcaption></figure><ul><li><strong>Pass Level Panels: </strong>These panels display a more granular level of detail. The user indexes into a particular pass by pressing <strong>‘I’</strong> followed by the index of the transpiler pass. This renders a new panel where users can see the state and properties of the circuit after this pass is executed. Trebugger highlights circuit statistics and property set for the given pass. Moreover, it also expands properties like the <em>layout</em> and <em>original qubit indices, </em>providing an insight into the detailed mapping of the circuit’s virtual to the physical qubits of the quantum backend. Lastly, circuit diagrams, documentation, and logs are displayed for an easier lookup.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*G0jMr_TaLSvMeFo0EhmLcw.png" /><figcaption>Circuit Statistics and Pass Information</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*ahtk5CckC7JF4jLRIkbHNw.png" /><figcaption>Property Set</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1014/1*MnPWFIc4Hhpjmy2cn4yn-Q.png" /><figcaption>Qubit Layout</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*kPvOKZvDG08QTauyRvUT1A.png" /><figcaption>Circuit Diagram</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*Kl7F7H6iqkG-w4DRhnW6rQ.png" /><figcaption>Documentation and Logs</figcaption></figure><h4>Future Work</h4><p>The project&#39;s development is ongoing with more upcoming features in both the CLI and the Jupyter view on the way. These include expanding different elements in the property set in the CLI view and introducing new elements in the jupyter widget such as the backend coupling maps, timeline drawer for the qiskit pulse schedule, and routing maps for the qubits. We encourage anyone interested in contributing to the project to do so via the GitHub repository linked below.</p><p>Sincere thanks to <a href="https://unitary.fund/">Unitary Fund</a> for supporting this project through their Microgrant Program and facilitating the opportunity to work on it. Thanks as well to the Qiskit team for their support in the <a href="https://file+.vscode-resource.vscode-cdn.net/home/harshit/Desktop/college/quantum/Unitary%20Fund/unitary.fund/posts/_markdown">Qiskit Advocate Mentorship Program</a>, and to mentors <a href="https://github.com/kdk">Kevin Krsulich</a> and <a href="https://github.com/mtreinish">Matthew Treinish</a> for their constant guidance and feedback.</p><p><em>Reference Links :</em></p><p><a href="https://medium.com/qiskit/qiskit-trebugger-f7242066d368">Qiskit Blog Post</a> | <a href="https://github.com/TheGupta2012/qiskit-timeline-debugger/tree/main">GitHub Repository</a> | <a href="https://pypi.org/project/qiskit-trebugger/">Python Package</a> | <a href="https://drive.google.com/file/d/1XXXOYcwehxFYAaAE0PUUfOCR4kEp8auv/view?usp=sharing">Demo Video</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c790dd6709d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/qiskit/new-features-of-the-qiskit-trebugger-2c790dd6709d">New features of the Qiskit Trebugger</a> was originally published in <a href="https://medium.com/qiskit">Qiskit</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[On Quantum Entanglement]]></title>
            <link>https://medium.com/@harshit.11235/on-quantum-entanglement-df66b4f3141?source=rss-b9061b9da9d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/df66b4f3141</guid>
            <category><![CDATA[quantum-mechanics]]></category>
            <category><![CDATA[entanglement]]></category>
            <category><![CDATA[quantum-physics]]></category>
            <category><![CDATA[einstein]]></category>
            <category><![CDATA[quantum-computing]]></category>
            <dc:creator><![CDATA[Harshit Gupta]]></dc:creator>
            <pubDate>Fri, 13 Jan 2023 16:31:28 GMT</pubDate>
            <atom:updated>2023-01-13T16:31:28.741Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>This blog post is intended to provide on overview of a fundamental concept which laid the foundation of quantum computing. With the 2022 Nobel Prize being awarded to the pioneers who proved Quantum Entanglement, understanding it becomes essential for anyone seriously interested in the field. Some familiarity with Quantum Mechanics and the Copenhagen Interpretation would help the reader appreciate the post a lot more. If not, or looking to brush up your knowledge, check out the blogs by <a href="https://medium.com/quantum-untangled">Quantum Untangled</a>!</blockquote><p>Quantum computing is a paradigm which utilises quantum objects and their properties to carry out computational tasks which may be very time consuming or even impractical for classical computers. Quantum superposition, interference and entanglement are the 3 major properties which are used to achieve the same. Here, in this blog, we talk about quantum entanglement in more detail.</p><h4>Quantum Entanglement</h4><p>I’m sure a lot of you reading this blog post have a broad idea about quantum entanglement, which goes something like the following —</p><blockquote>Any two quantum objects <em>may </em>become entangled and any change in the state of one particle <em>instantaneously </em>changes the state of its entangled counterpart.</blockquote><p>Let us dissect it and understand what does this <em>really </em>mean?</p><p>In simplest of forms, entanglement means some kind of<em> correlation</em>.</p><p>For a simple example, consider any pair of particles, say A and B. We assume that these are sufficiently small, like electrons, and their lives are directly governed by quantum mechanical properties. If particles A and B are <em>entangled </em>with each other, it means that any change in the <em>state</em> of A or any <em>action </em>on A will <em>affect </em>the state of B. That’s all fine, we observe this in our daily lives. For instance, hitting a billiard ball affects the state of the ball in comes in contact with. But can it happen <em>instantaneously</em>? Without any communication or information transfer? Without contact of the balls? <em>Quantum Entanglement </em>does.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uyn54pXu84g8V9fD0kvh_w.jpeg" /><figcaption>Image depicting classical and quantum effects</figcaption></figure><p>Irrespective of the magnitude of the distance present between the entangled particles, the change is instantaneous or <em>non — local. </em>This is what is puzzling. How can it happen? Does the pair actually contain some hidden information which gets transferred? All this was pondered upon by Einstein and his colleagues.</p><h4>Einstein, Podolsky and Rosen on Entanglement</h4><p>Come in Einstein.</p><p>He was a realist and believed that the world was governed by <em>local realism —</em></p><ul><li><em>local </em>means that any event or action or effect or any change in our vicinity (at arm’s length/in the room/near the building) <em>does not</em> affect something (body/reaction/process) which is far away or sufficiently separated from the former event. By far away we mean that any effect <em>can not be felt</em> in a time lesser than that required by light to travel between the cause and the effect.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n0lu8iRY4byD4NCvPT261g.jpeg" /><figcaption>Locality — any information transfer is bounded by the speed of light</figcaption></figure><ul><li><em>realism</em> means that the world exists even if there is no observer. Means that even if no one is looking at a tree, it must exist. Similarly for quantum particles it means that even though we have not observed the particle, its <em>definite state must exist</em>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pe_Hj38ZJqGI1vT9NcgQtw.jpeg" /><figcaption>Realism — the world keeps on existing independent of observations</figcaption></figure><p>Coming back to entanglement.</p><p>According to Einstein, entanglement was something like <em>correlation at origination. </em>Building upon the ideas of <em>local realism</em>, his explanation was that the entangled particles must have emerged as the states which we are observing them right now, instead of any kind of <em>instantaneous change</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oHetQUWVRfVG_oxI_ArLiQ.jpeg" /><figcaption>Einstein’s Interpretation of Quantum States</figcaption></figure><p>According to him the entangled particles must have started off in the same set of states as measured and that no collapse of the state vector had occurred.</p><p>Moreover, using these two principles as universal truths, Einstein along with Podolsky and Rosen (EPR), claimed that quantum mechanics might not be complete, even though it was correct. To understand this, we can take an analogy. Think of an <em>apple</em>. A theory says that an apple is a red looking object. While this theory is correct, but it is not complete. An apple is characterised by many properties such as weight, size, sweetness, etc. which are indeed relevant to any human interacting with it. So while saying an apple is red, may be correct, but not complete.</p><p>As some of you may know, a very crucial aspect of quantum mechanics is the concept of measurement. Following the <a href="https://en.wikipedia.org/wiki/Copenhagen_interpretation"><em>Copenhagen Interpretation of Quantum Mechanics</em></a><em>, </em>it is widely accepted that the state of a quantum particle is not well defined until it is measured. Measurement itself forces the particle(s) to choose one of the several possible states in which they can collapse. These pioneers conjectured that even though quantum mechanics gave correct results and agreed with experiments, it was not in line with <em>realism.</em> So what were indeed their explanations and what was the quantum mechanical view of particles? Let us see —</p><h4>An Experimental Setup</h4><p>Take a pair of particles which are entangled. While not going into the experimental details of creating such entangled pairs, we are assuming we have something like a <em>generator</em>. This device would produce entangled pairs of particles for us to play around with. The physical property which this device deals with is the spin and what is actually <em>entangled</em> is the <a href="https://en.wikipedia.org/wiki/Spin_(physics)#Quantum_number">spin of the pair of particles.</a></p><p>Say that the particles are entangled such that we have perfect anti-correlation. This means that if one of the particle has an <em>up</em> spin (↑) along an axis, the other would necessarily have <em>down</em> spin(↓) across that same axis of measurement. Also assume that we have 2 detectors situated at some distance from the generator, with one on the left and the other on right. Note that the generator and the detectors are located in a straight line. The last assumption we make is that the detectors are synchronised — whenever one detector measures a particle, the other detector <em>simultaneously</em> measures another.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ka8awTqlZdJIVs_kGmwvDw.jpeg" /><figcaption>Experimental Setup for Generating and Detecting Entangled Particles</figcaption></figure><blockquote>Einstein’s View</blockquote><p>Einstein could not accept randomness which is associated with quantum mechanics. Whenever a wave function of a quantum object is measured, he conjectured, randomness isn’t associated with it. According to him, what we had measured was exactly how the state of the particle existed before measuring.</p><p>With respect to our experiment it means that the although particles are correlated, the result we obtained at measurement was <em>always present </em>since the time of origination of the particle pair. During the generation of the entangled pair it may have been randomly assigned, but once set <em>it does not fluctuate.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WWFY-VMaxbX6y0gR7CfPbw.jpeg" /><figcaption>Einstein’s View of Reality</figcaption></figure><p>This means a pair with spins ↑↓ remained as ↑↓ after getting generated. Moreover, when we measure the particles we measure a property as it was <em>already set</em>. There is no ‘spookiness’ here (to quote Einstein!).</p><blockquote>Quantum Mechanical View</blockquote><p>Here things are a bit different. Quantum Mechanics says that we do have anti-correlation, but during the time when the particle pair is <em>not measured</em>, its states are <em>not definite.</em></p><p>Whenever we measure one or both the particles, not only do we get a definite answer, but the answer is defined by the <em>act of measurement</em> itself. Measurement forces the system to choose from one of the possible states. For our simple experimental setup, this means that if we measure one particle as ↑ along an axis, the other one is bound to be measured as ↓ along the same axis. This was the thing which bothered Einstein.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4XHktOO8CjEYBmyY-AneIQ.jpeg" /><figcaption>Quantum Mechanical View of Reality</figcaption></figure><p>For instance, in the above measurement setup, we did measure particle 1 as ↑. Now, we also <em>simultaneously </em>measured particle 2, and detected it as ↓. Einstein could not get to terms with the fact that measurement of one particle affects the quantum state of the other particle <em>instantaneously. </em>To say in terms of a concept which we just went over in the above post, the interaction is <em>non-local. </em>This problem or rather the mystery about the real nature of entanglement or <em>reality</em> remained a mystery for a long time, as it was really hard to test.</p><p>Why was it like this? Well, because it was difficult to test something when testing itself breaks the thing we want to test. Let’s take an analogy to clear that up.</p><p>If you measure a particle you get a certain definite value or a result, here ↓ or ↑. But doing so, you have lost the information about the nature of what you’re measuring, what was it like before measuring. Its like saying — Hey! I actually have 3 hands when you’re not looking, but as soon as you look, I only have 2. One of the hand vanishes and you see me as a normal human being. The other person will not have any way to test this. This is because the act of seeing or looking at your hands changes the number of hands itself!</p><p>This was all about entanglement where we talked about what it means for particles to be entangled and about two very popular yet contradicting views about the real nature of entanglement. Which one of them was correct? This seemingly difficult question was answered by John Stewart Bell in 1964.</p><p>Bell said that it is indeed possible to test the Einstein’s view of entanglement and that is what led to the formulation of the <em>Bell’s Inequality</em> and the experiments trying to prove them. What were the ideas behind these inequalities and experiments which settled the dispute about the nature of reality, once and for all? That’s the story of another blog post!</p><p>Till then, keep thinking :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df66b4f3141" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Errors in Quantum Computing— Introduction]]></title>
            <link>https://medium.com/@harshit.11235/errors-in-quantum-computing-introduction-af64ca74d3e5?source=rss-b9061b9da9d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/af64ca74d3e5</guid>
            <category><![CDATA[quantum-mechanics]]></category>
            <category><![CDATA[qiskit]]></category>
            <category><![CDATA[qubit]]></category>
            <category><![CDATA[quantum-error-correction]]></category>
            <category><![CDATA[quantum-computing]]></category>
            <dc:creator><![CDATA[Harshit Gupta]]></dc:creator>
            <pubDate>Sat, 06 Aug 2022 12:28:03 GMT</pubDate>
            <atom:updated>2022-08-06T12:28:03.829Z</atom:updated>
            <content:encoded><![CDATA[<h4>Why are we in the <em>Noisy Intermediate Scale (NISQ) Era</em> of Quantum Computers? What are the characteristics of this Noise? Keep reading to explore my views about these questions.</h4><p>Quantum computers are devices developed with a fundamentally different set of building blocks than classical computers. Properties such as <em>superposition, entanglement </em>and <em>interference, </em>and the ways to manipulate and combine a quantum computer’s individual components are what make these systems more powerful than classical ones. But before going deeper into our topic of errors, let’s have some high-level understanding of quantum computers and compare them with their counterparts.</p><p><em>The article assumes that the readers have a basic knowledge about some concepts and notations used in quantum computing such as state vectors, quantum gates and measurement. If you would like to brush up on these topics, feel free to go through some awesome content by </em><a href="https://medium.com/quantum-untangled"><em>Quantum Untangled</em></a>!</p><h4>Introduction</h4><p>Let us discuss the components of our 2 systems on the physical level.</p><p>Classical computers employ <em>bits</em> as their unit of computation. At any point of time, these <em>bits </em>are in a state of 0 or 1. But their quantum cousins behave a bit differently. Quantum computers use <em>qubits</em> as their units of computation which can exist as 0, 1 or in a <em>superposition </em>of the states 0 and 1 simultaneously, until observed. Let us see how these units are processed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*nHVccwG7xcCkI1QJZfwqNQ.png" /><figcaption>Comparison of a bit with qubit</figcaption></figure><p>Classical computers use a set of gates such as NAND and NOR for the basic computing operations. While these gates can implement any boolean logic at the processor level, they are utilised primarily for <em>classical bits. </em>The case for <em>qubits </em>is a bit different (pun intended!). Since <em>qubits </em>follow the laws of quantum mechanics, their transformation has to be done via a specific type of quantum operation. These operations try to act on both of the states of a <em>qubit simultaneously </em>and can be modelled as <a href="https://en.wikipedia.org/wiki/Quantum_logic_gate"><em>unitary matrices</em></a><em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/1*1Cm4d6Dd1bCgx6mmtAhxQg.png" /><figcaption>Classical and Quantum operations</figcaption></figure><p>Finally, we have measurements. In classical systems, if there is a voltage representing 1 state of a bit, it would still be at 1 if we try to <em>read </em>this state. This is not always true for <em>qubits. </em>According to the <a href="https://en.wikipedia.org/wiki/Copenhagen_interpretation">most widely accepted interpretation of quantum mechanics,</a> a 2-level quantum system (<em>qubit) </em>would collapse to one of its 2 basis states when observed. An analogy would go something like this — you take a coin, toss it and then look at it in mid-air. As soon as you look at the coin, it would produce a head or tail in your hand. But you’ll not be able to look at it spinning!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*vzWA1hz-NOF9R6GedXQ3iQ.png" /><figcaption>Measurement — Classical vs Quantum</figcaption></figure><p>With these fundamental elements of quantum computers described, let us look at how they are realised in an actual device.</p><h4>Realisation of Components</h4><p>Qubits are generally modelled with a <a href="https://en.wikipedia.org/wiki/Qubit#Physical_implementations">physical system</a> which follows the laws of quantum mechanics and has 2 distinct energy levels. This can be anything ranging from <a href="https://en.wikipedia.org/wiki/Superconducting_quantum_computing">artificial atoms</a>, <a href="https://en.wikipedia.org/wiki/Linear_optical_quantum_computing">photons</a>, <a href="https://en.wikipedia.org/wiki/Nuclear_magnetic_resonance_quantum_computer">real atoms</a> and even <a href="https://en.wikipedia.org/wiki/Trapped_ion_quantum_computer">ions</a>. Each of these systems coupled with a <em>property, </em>act as the qubit. For example photons can be a <em>system</em> and their polarisation the <em>property. </em>Along with this, the two <em>states </em>of this property act as the 2 computational states 0 and 1. Extending the above example we may have <em>vertical</em> polarisation of photons as the 1 state and <em>horizontal</em> polarisation as 0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*TbsY1wbfAuhhVFYs0O5N7Q.png" /><figcaption>How an atom can act as a qubit</figcaption></figure><p>Besides the qubits, there also exist control electronics which try to manipulate the quantum states of these physical systems and introduce entanglement between different qubits. For an example, consider the<a href="https://en.wikipedia.org/wiki/Superconducting_quantum_computing"> superconducting qubits</a>. They employ microwave pulses to change the state of the qubits and thus perform 1 and 2 qubit operations.</p><p>Lastly coming on to the measurements. To obtain useful results from any quantum operation or algorithm, they are followed by measurements. These can be done in various ways depending upon the implementation of our qubit and are again made by keeping in mind the property which was used to model the qubit. For example in the <a href="https://en.wikipedia.org/wiki/Superconducting_quantum_computing#Qubit_readout">superconducting qubits</a>, measurements are done via microwave resonators whose resonant frequency depends on the qubit state being measured.</p><p>Even though the above knowledge gives us a glimpse of how quantum computers are realised in practice, we should still keep in mind that we are trying to model quantum mechanical systems. Systems such as individual atoms or photons are extremely fragile objects. To have any kind of useful information processing, they have to be isolated from the external environment. This isolation may not be perfect and from here, arise errors.</p><h4>Source of Errors</h4><p>A famous quote by <em>Asher Peres</em> states that —</p><blockquote>Quantum phenomena do not occur in the Hilbert Space, they occur in a laboratory</blockquote><p>Building on the above statement let us look at how errors creep into quantum computers on the physical level.</p><blockquote><strong><em>Qubits</em></strong></blockquote><p>We noted that quantum mechanical systems are used to model a qubit and the fact that they have to be isolated from the external environment. If this does not happen correctly, the qubits may exchange unwanted energy and their states may get disturbed. In can also happen that due to this noise, the preparation of qubits in some initial state may not be exact. Moreover, the superposition states may deviate from the targeted superposition, or even completely change to basis states.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*jU4jlzg7NSBCLJyCvbQX7g.png" /><figcaption>Errors in qubits</figcaption></figure><blockquote><strong><em>Gates</em></strong></blockquote><p>It can happen that the operations which we are trying to perform may not be exact. This may be because that the amount of change which the operation was supposed to perform was not exact. Taking the example of superconducting qubits, it may be so that the microwave pulse provides some extra <strong>x</strong> amount of energy while during a quantum operation. For a more concrete example, suppose that a quantum gate is supposed to put a 0 state into the equal superposition of 0 and 1 state, but instead it transforms the state as —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/589/1*BhVW2P7SYN7gRuRgHK51LA.png" /><figcaption>Errors in quantum gates</figcaption></figure><p>This can lead to imperfections in the quantum operations and the source of these errors could be due to errors in the classical control equipment. This is one of the major reasons that quantum gates need to be calibrated for errors.</p><blockquote><strong><em>Measurements</em></strong></blockquote><p>Lastly, measurement operations may be faulty. Suppose that we are trying to read a qubit in an array of qubits. We may report the value of the readout as 1 when in fact the qubit was in a state of 0. This is true not just for the 0–1 measurement basis, but for any basis across which we try to measure our system. This would result in errors in identifying probability distribution of the final results and <a href="https://qiskit.org/textbook/ch-quantum-hardware/measurement-error-mitigation.html">measurement error mitigation</a> would be required to deal with such errors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*J7LJQHuaevKLptOXLh3olg.png" /><figcaption>Errors in measurements</figcaption></figure><p>In this blog, we talked about the basics of realising a quantum system, looked into how different components are modelled in practice and delved into the sources of errors in this modelling. I hope that with the above knowledge you are able to appreciate the complexity behind developing quantum computers and the need for error correction in today’s NISQ era.</p><blockquote>Stay tuned for the the next entry where we will introduce different categories of quantum errors and look into the <em>State Preparation and Measurement </em>(SPAM) error in quantum systems. Till then, keep exploring!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af64ca74d3e5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[New Debugger Takes You Under The Hood of Qiskit’s Transpiler]]></title>
            <link>https://medium.com/qiskit/qiskit-trebugger-f7242066d368?source=rss-b9061b9da9d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7242066d368</guid>
            <category><![CDATA[quantum-computing]]></category>
            <category><![CDATA[transpilation]]></category>
            <category><![CDATA[ibm-quantum]]></category>
            <category><![CDATA[qiskit-advocate]]></category>
            <category><![CDATA[qiskit]]></category>
            <dc:creator><![CDATA[Harshit Gupta]]></dc:creator>
            <pubDate>Thu, 03 Feb 2022 15:58:22 GMT</pubDate>
            <atom:updated>2022-02-03T15:58:22.807Z</atom:updated>
            <content:encoded><![CDATA[<p><em>By Aboulkhair Foda (Qiskit Advocate) and Harshit Gupta (Qiskit Advocate)</em></p><p>Quantum circuit transpilation is the process of rewriting high-level quantum circuits into equivalent circuits which are compatible with a specific quantum backend. Qiskit uses a tool called the <a href="https://medium.com/qiskit/how-does-the-qiskit-transpiler-work-6710863beaac">qiskit transpiler</a> for achieving this transformation. Though important for realizing physically runnable circuits, its methods remain hidden from the general user. We developed TreBugger, a Qiskit Timeline Debugger, to address this underlying issue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dv6E_uWZB-wqyskRNbn2kQ.png" /><figcaption>Layout of Qiskit Transpiler Debugger</figcaption></figure><p>We developed the Qiskit Timeline Debugger as a mentorship project during the <a href="https://github.com/qiskit-advocate/qamp-fall-21">Qiskit Advocate Mentorship Program Fall ’21</a>, under the guidance of Kevin Krsulich. Built as a jupyter widget, it tries to make the transpilation process more transparent and accessible, regardless of a user’s background.</p><p>How? Let us find out!</p><h3>Why the need?</h3><ul><li>The ability to play around with a concept can be an important way to learn about it. But, the transpiler currently stands almost as a <em>black box </em>tool. While there are some methods to see its inner workings, they are accessible to the users more proficient in programming.</li><li>A quantum computer can only run a discrete set of quantum gates. This decomposition of arbitrary quantum gates to the basic gate set can sometimes be expensive in the terms of the final number of operations required to model them. Identifying and optimizing such operations can allow us to better adapt our circuits for today’s noisy, intermediate-scale quantum backends.</li><li>Finally, there exists a need for better error handling in the transpilation process. Trace backs in code may bewilder a user when a transpiler runs into an error. A structured way to understand these problems is necessary.</li></ul><h3>The Debugger</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NKBj_Ng-baB2a3OB.gif" /><figcaption>Working of Qiskit Transpiler Debugger</figcaption></figure><p>We present a lightweight Jupyter widget in the form of a debugger. It is built with the python <a href="https://ipywidgets.readthedocs.io/en/latest/">ipywidgets</a>module and aims to address all the issues we hope to resolve. With an in-depth analysis of different transpilation stages and a simple, easy to use user interface, any user can quickly set up a debugger instance with as little as 4 lines of code. In the remainder of this section, it is assumed that the reader is familiar with python environments and using Qiskit. If not — <a href="https://qiskit.org/">get started with Qiskit here!</a></p><p>You can download the debugger via pip using —</p><pre>pip install -i <a href="https://test.pypi.org/simple/">https://test.pypi.org/simple/</a> --extra-index <a href="https://pypi.org/simple/">https://pypi.org/simple/</a> qiskit-trebugger</pre><p>The following code fires up the debugger in the python environment where it was installed. Simply replacing the call to the transpile method with the debug method of Debugger —</p><pre>from qiskit import QuantumCircuit<br>from qiskit.test.mock import FakeCasablanca<br><strong>from qiskit_trebugger import Debugger</strong></pre><pre><strong>debugger = Debugger()</strong><br>backend = FakeCasablanca()</pre><pre>circuit = QuantumCircuit(3)<br>circuit.h(0)<br>circuit.cx(0,1)<br>circuit.cx(1,2)<br>circuit.measure_all()</pre><pre># replace transpile call <br># circ = transpile(circuit, backend = backend)<br># with debug method</pre><pre><strong>debugger.debug(circuit, backend = backend)</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AXSYLXAAHr3v3OWLGRIprA.gif" /><figcaption>Quick loading of the widget in jupyter</figcaption></figure><p>Taking a small overhead of visual rendering, it quickly loads up the transpilation sequence of the circuit as it goes through different passes of the transpiler. As you can see, the widget is divided into three broad components which are —</p><ul><li><strong>Description</strong> of the circuit, backend and transpiler arguments provided during transpilation.</li><li><strong>Transpilation Overview</strong> for the final circuit which provides a quick summary of the complete process.</li><li><strong>Main Passes</strong> of the transpiler, where each component contains a description of circuit state (depth &lt; 300), properties, logs of pass and documentation.</li></ul><p>Let us unwrap its features and design.</p><h3>Features</h3><h4>1. Visual diff for quantum circuits</h4><ul><li>Inspired by the git diff command for highlighting changes in two versions of a file, we built a custom feature called<em> visual diffs </em>which highlights the changes made to quantum circuits.</li><li>We built the <em>visual diff </em>feature using the <a href="https://en.wikipedia.org/wiki/Directed_acyclic_graph">DAG representation </a>of circuits and the <a href="https://qiskit.org/documentation/tutorials/circuits_advanced/03_advanced_circuit_visualization.html#Alternative-Renderers-for-Circuits">qiskit matplotlib drawer</a>, allowing users to visually see what changed between two quantum circuits during transpilation. Realizing what exactly changed after each transpiler pass will allow users to get more familiar with the transpiler.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/507/0*EJTSpiOODDEk3MNa.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*oL_R9XtbWXPq31AC.png" /><figcaption>Circuit diff of above two circuits being highlighted in orange.</figcaption></figure><ul><li>For the more curious readers, <em>visual diff</em> uses something called the <a href="https://en.wikipedia.org/wiki/Longest_common_subsequence_problem">Longest Common Subsequences</a> (LCS) over the DAG of quantum circuits. Treating DAG as a string of <em>one-depth</em> circuits, the LCS contains what is common in two circuits. Everything else is just the <em>diff </em>!</li><li>Currently, our debugger supports this functionality for ≤2000 depth circuits and for easy exporting, circuits are available in different formats such as png , qasm and qpy.</li></ul><h4>2. Log based analysis and documentation</h4><ul><li>The qiskit transpiler is not a perfect black box after all, it just takes a lot of work to fully understand. It does have a built-in <em>logging </em>functionality which allows anyone to see the steps it takes while processing circuits.</li><li>Logs are just text-based messages or records that define what a particular software is doing. The transpiler publishes these messages at each stage, allowing us to look under its hood. TreBugger publishes this information as a separate panel in the pass tabs.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/0*XexgzcfaHrT3MloO.png" /><figcaption>Logs being displayed according to level of severity</figcaption></figure><ul><li>Each log record has a level of <em>severity</em>, which defines the kind of information it contains. In our debugger, we color code each log according to this severity level thus, adding a greater level of granularity for the whole process.</li><li>Each pass panel is further coupled with a Help tab which contains the docstring of the transpiler pass. This allows the user to easily see what the aim of a particular pass was and the target return value.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sAGpg896VWNBeXdr-H7KDw.png" /><figcaption>Documentation tab for a transpiler pass</figcaption></figure><h4>3. Circuit statistics and Property set</h4><ul><li>The debugger presents a lot of important information at the first glance, such as circuit size, depth, number of operations and time taken to run the particular transpiler pass.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gJEPPcJIpFhSCdwI.png" /><figcaption>Collapsed view of the transpiler passes</figcaption></figure><ul><li>The debugger lets a user easily identify the passes which highly affect the final gate count or are particularly time-consuming. Isolation of such passes would help in targeted research towards specific transpiler optimizations.</li></ul><h3>Contributions and future work</h3><p>We have built the debugger using jupyter widgets along with some basic web development tools (HTML and CSS). Anyone comfortable with python, web development and having a working knowledge of quantum computing concepts is more than welcome to contribute to our project.</p><p>Since our project uses the <a href="https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller">MVC architecture</a>, we would love to also see a command line version of the debugger. This view would purely be based upon python and use text-based logs and properties to allow users see how a circuit evolves.</p><p>Another need for the Trebugger is <em>UI testing</em>. Frameworks like <a href="https://www.cypress.io/"><em>Cypress</em></a><em> </em>and <a href="https://seleniumbase.io/"><em>SeleniumBase</em> </a>were decided but the tests are yet to be formulated. Once completed, the project would directly be available to be installed from the actual python packaging index, PyPi.</p><p>If you would like to contribute or be up to date with the progress of our project be sure to check out the<a href="https://github.com/TheGupta2012/qiskit-timeline-debugger"> Qiskit Timeline Debugger GitHub repo</a>. We hope that this project opens up the workings of qiskit transpiler to the general public and makes it a more accessible tool for qiskit users.</p><blockquote>This project is part of the <a href="https://github.com/qiskit-advocate/qamp-fall-21">Qiskit Advocate Mentorship Program Fall 21 cohort</a>. If you are interested in joining the Qiskit Advocate program, please check out <a href="http://qisk.it/advocate-application-guide">the application guide</a>. You can also fill <a href="https://airtable.com/shrt7lqrHDWO56W9x">this form</a> to get an email update when the new application round opens later this year.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7242066d368" width="1" height="1" alt=""><hr><p><a href="https://medium.com/qiskit/qiskit-trebugger-f7242066d368">New Debugger Takes You Under The Hood of Qiskit’s Transpiler</a> was originally published in <a href="https://medium.com/qiskit">Qiskit</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kitaev’s Phase Estimation — QPE algorithms]]></title>
            <link>https://medium.com/quantum-untangled/kitaevs-phase-estimation-qpe-algorithms-b1cc6a1c9cab?source=rss-b9061b9da9d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/b1cc6a1c9cab</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[quantum-algorithms]]></category>
            <category><![CDATA[quantum-computing]]></category>
            <category><![CDATA[physics]]></category>
            <dc:creator><![CDATA[Harshit Gupta]]></dc:creator>
            <pubDate>Wed, 11 Aug 2021 16:41:09 GMT</pubDate>
            <atom:updated>2021-08-12T05:19:22.336Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kitaev’s Phase Estimation — QPE algorithms</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0MFabsK0OjgTLzPN.jpg" /><figcaption>Alexei Kitaev, source —Google</figcaption></figure><p>In the last few posts of the series, we touched upon the relevant tools required for QPE, some mathematics, and two of the most widely used QPE algorithms. This post is dedicated to the original phase estimation algorithm proposed by <em>Alexei Kitaev </em>and delves into the workings, advantages, and some limitations of the original phase estimation approach. It is assumed that the reader is familiar with the basic concepts of quantum phase estimation and linear algebra. Also, if you have been following the series up until now, you shall be good to go! Let’s get started then.</p><h4>Ideas and Mathematics</h4><p>To remind you of our original problem, what we have is an unknown unitary matrix <strong>U</strong> and we want to find the eigenvalues of our matrix. Since any eigenvalue of a unitary matrix has <em>unit </em>modulus, it can be represented as follows</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*ilu3-BpCYgW-feL7L1qKYw.png" /><figcaption>The unitary eigenvalue equation —(1)</figcaption></figure><p>If we are somehow able to determine <strong>θ, </strong>we would be able to find the eigenvalue of the unitary matrix <strong>U.</strong></p><p>Although the basic and iterative QPE algorithms build up our phase either bit by bit or encoding it into multiple qubits, Kitaev’s QPE (KQPE) algorithm relies on some classical processing to obtain a <em>decimal representation </em>of the phase. The readers familiar with QPE would appreciate the nature of the processing involved in KQPE as it is the inspiration for the previous two approaches. Let us go ahead and start from the basics.</p><p>Given below is the simple quantum circuit used for the <a href="https://medium.com/quantum-untangled/a-clever-quantum-trick-54f27e2518a4">phase kickback</a> procedure:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bn2BPLqk0yBCZP2CyxV6eQ.png" /><figcaption>Phase Kickback circuit — (2)</figcaption></figure><p>Going through the gates in our circuit mathematically we get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X2V62a5rmcJb02B9gkCoMQ.png" /><figcaption>Mathematics for phase kickback —( 3)</figcaption></figure><p>You can clearly see that the first qubit has some kind of information <em>encoded</em> into the relative phase of its state. But if we look closely, it is not enough. Why? This is because this relative phase has no<em> observable effect </em>when we try to measure <em>only </em>the <em>first qubit:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*gyam6Sh1HVCWbT_oOfS-Eg.png" /><figcaption>Initial probabilities of qubit 1–(4)</figcaption></figure><p>Can we do something to make the factor containing <strong>θ </strong>appear in <em>observable quantities</em> i.e. probabilities of measuring 0 or 1? Try adding a Hadamard gate on the first qubit just after the controlled unitary gate. What do you see? Work on the math a bit before seeing the result below! In the following image, we see the effect of the Hadamard gate on the first qubit:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*PT2XrO7ytGUcRKbzctgMhA.png" /><figcaption>The first proposed circuit — (5)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8_dszpOJZuR41D8gbSF1hA.png" /><figcaption>Continued mathematics of the first circuit — (6)</figcaption></figure><p>Now we do have something! If we see carefully see the measurement probabilities we have:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/1*DYH4KWu_BfEOsm_qqr61hQ.png" /><figcaption>Probabilities of qubit 1 after H gate is applied — (7)</figcaption></figure><p>How does this help? Let us digress a little bit to brush up on some mathematics to fully understand and thus make use of these equations to evaluate our phase, <strong>θ.</strong></p><h4><strong>Euler’s Identity and Trigonometry</strong></h4><p>Leonard Euler, one of the greatest mathematicians of all time, had devised a beautiful equation, now known as<a href="https://en.wikipedia.org/wiki/Euler%27s_formula"> Euler’s formula</a>. It is a very simple formula that relates the exponential of a real quantity with its corresponding cosine and sine values:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*U1zgzg8v6Icr6G6Dum3HYw.png" /><figcaption>Euler’s Formula — (8)</figcaption></figure><p>If we try to do some twists and turns, we arrive at:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*1vItOEwTrUki_m94QtVCbw.png" /><figcaption>Finding a relation for cosine θ — (9)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*VHU5RQb7_0TCcSdRa17HZw.png" /><figcaption>Finding a relation for cosine <strong>θ — </strong>(10)</figcaption></figure><p>Doesn’t this look strangely familiar? It does and is exactly the probability of measuring the first qubit in our circuit as 0! This is pretty great as we have expressed the phase in a well-defined function for which <em>an inverse</em> exists. We shall get into the details of the above relation in a bit but first, let us state some useful trigonometric identities which will be used for further calculations in the KQPE algorithm:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*aK0uUJcgamCCdLHqKP3W9g.png" /><figcaption>Some trigonometric identities — (11)</figcaption></figure><h4>Initial Results</h4><p>Now that we have the tools, let’s see the final measurement probabilities in terms of trigonometric functions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*udKm9RPvdm0XJwJR0OigQw.png" /><figcaption>Probabilities of the first qubit in terms of cosine <strong>θ </strong>— (12)</figcaption></figure><p>Using the above two equations we arrive at the result that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*uBUaSzpwo6bUAf_MlJOlhg.png" /><figcaption>The phase in terms of inverse cosine function — (13)</figcaption></figure><p>Although we have the probabilities expressed as a function of cosθ<strong>, </strong>there is a bit of a problem here. Since cosθ is equal to cos(-θ), even if we evaluate arccos(2P(0)-1) or arccos(1–2P(1)), we won’t be able to distinguish whether the value pertains to +<strong>θ or -θ. </strong>This is because cosine has a positive value when the argument lies in the first or the fourth quadrants.</p><p>This limitation brings us to think about an alternative approach. If we could somehow encode the phase information in some other function that allows us to distinguish between +θ and -θ, we would be able to recover θ from the probabilities. Given that we are fairly deep in trigonometric functions, thinking of sine and tangent would be wise. Let us try for sine!</p><h4>Building a modified circuit</h4><p>The thought that would lead us to a different circuit for encoding phase as the sine is that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*vzDo1FeoKRg557Jzc8v9IA.png" /><figcaption>Initial probabilities of the first qubit — (14)</figcaption></figure><p>Well, if we had a factor of <strong>i</strong> (iota) associated with exp(iθ), it could very well be written as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*iEIUH5dtAtbUnlrBb4AI9A.png" /><figcaption>Desired probabilities to achieve distinguishability in phase — (15)</figcaption></figure><p>to obtain the desired function of ‘sin(θ)’ in our results. (this is because of the fact that cos(θ + π/2) = -sin(θ) ). Follow along to see how!</p><p>Let us try to work backward and see this idea in action. We know that for trying to uniquely identify the phase of the unitary matrix, we want the following expression:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/1*w1ag_N6p4qcA90I_fkPulQ.png" /><figcaption>Desired probability expression for the first qubit — (16)</figcaption></figure><p>which means that the system should have been in the state:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*t-F7ASHv1arJevrv3M0N-g.png" /><figcaption>Desired final state for the first qubit — (17)</figcaption></figure><p>just before measurement. How would that be possible? If we regroup the terms a little bit we shall see that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s6jPlcR0Hz48vagK5q1a-Q.png" /><figcaption>The regrouped final state in the X basis — (18)</figcaption></figure><p>The above equation means that if we had applied an <strong>H</strong> gate to the state:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*SFXJITg1Oas5X33M8obifg.png" /><figcaption>Desired state of the system just before the last H gate — (19)</figcaption></figure><p>we would get the state that we desire. Comparing the state of qubit 1 in the above image to the state of qubit 1 in the image (3), we can observe that <em>only</em> the |1⟩ state is affected by a factor of <strong>‘i’. </strong>This transformation can be modeled as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*epITrxFTLmOwI5FXI_etLg.png" /><figcaption>Required transformation matrix — (20)</figcaption></figure><p>For the readers familiar with the Clifford Gates, the above representation exactly matches with the <strong>S </strong>or the Rz(π/2) gate, up to a global phase. This is exciting as applying this <strong>S</strong> gate to qubit 1, just before the controlled unitary matrix, transforms the state as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*spy9Mql-SqkTz2o9Bz_hqQ.png" /><figcaption>Desired transformation of the original superposition state — (21)</figcaption></figure><p>Now that we have arrived at the change that we would require in our circuit, let us look at the final result and the math to solidify our understanding:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*UvZfWOr6YVkICuTH6_aX3g.png" /><figcaption>Final modified circuit — (22)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GvJszVUHma7-ghfbu3RcGg.png" /><figcaption>The final state of the system — (23)</figcaption></figure><p>Finally, we have the probabilities of obtaining a 0 and 1 for the first qubit as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VlQgyWXQxextKfsx6myxTw.png" /><figcaption>The final desired probabilities of the first qubit — (24)</figcaption></figure><p>This lets us distinguish between the values of +θ and -θ as positive θ would correspond to a positive value ( in the domain 0,π) and negative theta would correspond to negative values ( again in domain 0,π). Going forward with our last stage of calculation and using something called the inverse trigonometric functions, we see that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/344/1*RfG175b6ifqcvxHOW9gc4g.png" /><figcaption>The phase in terms of inverse sine function — (25)</figcaption></figure><p>There is also a small caveat to using the inverse trigonometric functions. They are only defined for a certain domain of the input values. For those of you who aren’t familiar with inverse trigonometric functions, they are just like an <a href="https://en.wikipedia.org/wiki/Inverse_function">inverse mapping</a> of the outputs of the trigonometric functions to their respective inputs. For instance, since sin(x) is bound by [-1,1] in the output, the <em>inverse</em> of sin(x) (<em>arcsin(x)</em>) has its <em>input</em> bound by the output of sin(x). These domain conditions are always going to be satisfied for our inputs as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*9GtP-Pfzgqefg43oMJ7o0A.png" /><figcaption>Domain verification for inverse cosine and sine — (26)</figcaption></figure><p>We may also employ the inverse tangent or the <em>arctan(x) </em>function to evaluate theta values in the following way:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*DsA9fzpX19HnmhE-697Gew.png" /><figcaption>Obtaining phase in terms of the inverse tangent function — (27)</figcaption></figure><p>The reason for trying to use <em>arctan </em>is that the <em>arctan </em>function is more robust to errors than the <em>arcsin </em>function. If we have an error of, let’s say, <em>s</em> in our measured fractions and we plot the difference between the <em>arctan a</em>nd <em>arcsin</em> values for the actual and measured results, we would see something like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZQm0TVeJik4mDTzyMVsLng.gif" /><figcaption>A clip showing that the absolute error in arcsin(x) is always greater than arctan(x) where s is the measurement error in the input — (28)</figcaption></figure><p>This clearly shows that if we have an error in our measurements, the <em>arctan </em>function is a more robust function to use for the evaluation of our results. This leads us to the end of our KQPE algorithm with the final phase presented as :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*8JHfXmrPCRApinIL7rxYMw.png" /><figcaption>The final phase in terms of an inverse tangent function — (29)</figcaption></figure><p>where the symbols have the relevant meanings as mentioned in previous images. Note that these probabilities are experimentally determined and thus we can indeed find out the phase of the unitary matrix using the simple equation above. This is Kitaev’s original approach for quantum phase estimation.</p><p>I hope this approach to solve the QPE problem made you ponder about how simple classical processing may sometimes pose an equivalent way to approach quantum computing problems and reduce the complexity of our operations by reducing the size of our quantum circuits.</p><p>During all our discussions with QPE algorithms, one thing which we skipped was the accuracy of our approach. How many measurements do we really need to make to get a good accuracy of the phase that we are trying to measure? How erroneous is our algorithm in measuring the phase that it <em>is trying to evaluate? </em>These are just the questions to be answered in our next post on the error and accuracy of QPE algorithms.</p><p>As always, stay tuned for more by Quantum Untangled.</p><blockquote>For those of you who are curious, please follow this <a href="https://nbviewer.jupyter.org/github/TheGupta2012/QPE-Algorithms/blob/master/QPE/Kitaev%27s%20Algorithm/Kitaev%20QPE.ipynb">link</a> to see the algorithm realized with IBM’s qiskit. Click<a href="https://github.com/TheGupta2012/QPE-Algorithms/blob/master/QPE/Modules/kitaev_qpe.py"> here </a>to go to the repository with the full code.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b1cc6a1c9cab" width="1" height="1" alt=""><hr><p><a href="https://medium.com/quantum-untangled/kitaevs-phase-estimation-qpe-algorithms-b1cc6a1c9cab">Kitaev’s Phase Estimation — QPE algorithms</a> was originally published in <a href="https://medium.com/quantum-untangled">Quantum Untangled</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Iterative Quantum Phase Estimation — QPE algorithms]]></title>
            <link>https://medium.com/quantum-untangled/iterative-quantum-phase-estimation-qpe-algorithms-ced794341487?source=rss-b9061b9da9d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/ced794341487</guid>
            <category><![CDATA[quantum-computing]]></category>
            <category><![CDATA[quantum-physics]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[quantum-algorithms]]></category>
            <dc:creator><![CDATA[Harshit Gupta]]></dc:creator>
            <pubDate>Sat, 03 Jul 2021 15:35:06 GMT</pubDate>
            <atom:updated>2021-08-08T16:34:29.702Z</atom:updated>
            <content:encoded><![CDATA[<h3>Iterative Quantum Phase Estimation — QPE algorithms</h3><p>This is the third installment in our QPE series and revolves around a very interesting approach towards phase estimation. Some prerequisites for this article are <a href="https://medium.com/quantum-untangled/intro-to-qpe-and-phase-encoding-qpe-algorithms-15638a8554b9">phase kickback</a> and basic phase estimation algorithm. Also, if the reader has followed the series up until now, they should be able to understand and appreciate the Iterative Quantum Phase Estimation (IQPE) Algorithm. Let’s get started then.</p><h4>Motivation behind IQPE</h4><p>Let us backtrack a little bit and see our basic QPE circuit, which we talked about in our last post.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*w6jrSM2eUhjDBjPqSQDGcw.png" /><figcaption>QFT⁻¹ for three qubits. Since q2 contains the least significant bit of the phase, a swap gate is applied at the end for a better visual interpretation.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*F76QWa0PCheE2wKBGDIelA.png" /><figcaption>The complete phase estimation circuit — 1</figcaption></figure><p>The above circuit is used to estimate the phase of a single-qubit unitary matrix up to 3-bit precision. What this means is that <strong>n </strong>qubits are required to measure the phase up to <strong>n-bit </strong>precision. Although the basic QPE algorithm is a very important procedure, it is a bit troublesome to implement for today’s quantum computers.</p><p>We are currently dealing with quantum computers of the NISQ (Noisy Intermediate Scale Quantum) era. The qubits that we have are, still, <em>not </em>perfect and prone to many errors, either due to noise or due to the system not behaving quantum mechanically after a certain amount of time. Since these errors are an inescapable fact for our present systems, having a <em>larger number of qubits </em>interacting with each other increases the error probability to a great extent.</p><p>Anyone familiar with the experimental realisations of gates would know the fact that <em>multi-qubit</em> gates are the hardest to implement. Since they are hard to fabricate, multi-qubit gates are the ones with the largest errors. Moreover, since any multi-qubit gate can be <a href="https://en.wikipedia.org/wiki/Quantum_logic_gate#Universal_quantum_gates">broken down</a> into CX gates (2-qubit) and single-qubit gates, we mainly characterise the errors of a system using the largest amongst them, i.e., the CX errors. Now, imagine if we have <strong>n</strong> extra qubits in our algorithm. Since a CX gate is applied between two qubits, each pair of qubits would have a <em>different CX</em> error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*d-JBaqpsiZ0OQAc41U35uA.png" /><figcaption>IBMQ Casablanca configuration — An actual quantum computer — 2</figcaption></figure><p>Since our QPE algorithm employs <strong>n</strong> extra qubits, we would be getting varied results at the end due to fact that different qubit pairs have <em>different CX errors. </em>What if we could constrain the number of qubits we use? This motivation leads us to the IQPE algorithm.</p><h4>Idea behind IQPE</h4><p>Let’s trace back our steps to the basic QPE algorithm and remember what the circuit meant in a general QPE setting; the image below may help you remember this. Let’s say we had the qubit <strong>Qj </strong>representing the <strong>jth</strong> bit of our phase<strong>.</strong> The circuit would be like the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aIP7drEM0dYzaVZPzVAK3g.png" /><figcaption>General phase estimation circuit — 3</figcaption></figure><p>The 4 steps that are highlighted in our algorithm, i.e., state preparation, phase encoding, controlled inverse rotation, and measurement in H-basis, are what make <em>one bit-identification</em> step. To reduce the errors, we want to somehow constrain the use of the extra qubits. If we watch closely, steps 1 and 4 are performed on a single qubit, and can not be reduced further.</p><p>Step 2 deals with encoding the phase into a control qubit and, without question, requires the presence of the eigenvector and the controlled unitary to apply phase kickback. We are only left with step 3. Can we somehow reduce the number of qubits required in our algorithm modifying step 3? Let us take a closer look at what happens in step 3, i.e., the <em>controlled inverse rotation </em>step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*iXpnHgUJYAF4SwjxcfJUpQ.png" /><figcaption>Inverse rotation step — 4</figcaption></figure><p>If you remember the definition of these CROT<em>k</em> gates, you would understand that these inverse rotations are dependent on the <em>previous bits</em> that we have determined before the <strong>jth bit — </strong>(j+1), (j+2), …, (n). Also, note that these controlled rotations just apply a rotation of</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*jFSyWH-Hx82PxoBZWT6c2w.png" /><figcaption>Inverse Rotation — 5</figcaption></figure><p>in a number of steps</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*RUR6ddVn84CnbqEAmnfefQ.png" /><figcaption>Successive rotations — 6</figcaption></figure><p>Okay, here is something we could optimise in these applications. If you think, instead of applying <em>(n-j-1) controlled rotation</em> gates conditioned on (n-j-1) <strong>qubits</strong>, why not apply these gates conditioned on <strong>classical bits?</strong> What we could do is instead of using the qubits to condition our gates, we measure a qubit, store its bit value in a classical register and use <em>that to condition </em>the rotation gate. We will see how in a moment, but we can see that the modified circuit would look something like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*k1qol3kFKv10HIScc557kw.png" /><figcaption>Modified circuit identifying jth bit of the phase — 7</figcaption></figure><p>Let us explore a simple example to bring into perspective all the ideas that we have discussed till now. Let us say we want to find the phase</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*RwaKpeZ4epqK0w_bhUggsA.png" /><figcaption>The target phase — 8</figcaption></figure><p>and we are determining the <em>least significant bit</em> in our phase. This is going to be the first step in our estimation procedure. The phase that is encoded up to the single bit is just</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*2GWxK-lGkD8lpJpOdxyP6w.png" /><figcaption>Single bit encoding — 9</figcaption></figure><p>and as we saw in the basic QPE, this does not require any kind of inverse rotation gate. To recapitulate, the circuit looks something like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*xoe3Idoh4np2h3PEoLWc_g.png" /><figcaption>The first-bit identification circuit — 10</figcaption></figure><p>Coming to the next bit, we have our phase encoding as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/310/1*ztdiTT8TYeEvOMbmZ2xn5g.png" /><figcaption>Two-bit phase encoding — 11</figcaption></figure><p>Now, since this is not a single bit, we need an inverse rotation of</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*wyVIMmMJQUFBdUGgPRFXSw.png" /><figcaption>Inverse rotation needed — 12</figcaption></figure><p>to determine our second last bit in the phase. But, instead of using a rotation gate controlled by the ‘<strong>state’</strong> of the previous bits, we use a gate controlled by the ‘<strong>result’ </strong>of the previous bits. What I mean by that is we use a <em>classically controlled rotation </em>gate instead of a <em>quantum controlled rotation</em> gate. Why does it help? This helps because errors do not creep up <em>as often</em> in classical computation as they do in quantum computing. After changing our gate to a classical controlled rotation, this is what our circuit looks like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*GRxhw3nTqOE6lKF77GoStg.png" /><figcaption>Second-bit identification circuit — 13</figcaption></figure><p>As you will notice, this idea of using classically controlled rotation gates helps us in reducing the number of qubits to just<strong> 1</strong> for determining our phase, <em>bit-by-bit</em>. The following image represents the circuit for the third last bit in our phase and if you have understood the workings till now, it should be easily comprehensible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QqeLpLWTUSW-CtPzJq7_fQ.png" /><figcaption>Third-bit identification circuit — 14</figcaption></figure><p>Now that we are familiar with the circuit quite a bit, let’s look at the mathematics for a general <strong>jth </strong>step to solidify our understanding.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0MJcw3oP2CBqv5UpO1xpeA.png" /><figcaption>Mathematics for the general state — 15</figcaption></figure><p>Each of the <em>bit-identification </em>steps that we saw above comprises <em>one iteration</em> in the algorithm. Each iteration result gives us 1 bit of the original phase and that is why this procedure is called <em>Iterative Quantum Phase Estimation</em>. Before seeing the differences in the basic QPE and iterative QPE, I would advise you to make yourself comfortable with the idea of a classically controlled rotation gate which is surely going to help in understanding the details a lot more.</p><h4>Differences and Details</h4><p>The ideas behind our Iterative Phase Estimation scheme are quite similar to the basic QPE algorithm but some of the major differences lie in the implementation parts. Majorly:</p><ul><li>If we say that the unitary matrix is <em>m-qubit </em>in size, then the total number of qubits required in the IQPE algorithm is <em>(1+m)</em> whereas the same requirement of qubits for the same matrix goes up to<em> (n+m)</em> in basic QPE for <strong>n</strong>-bit precision.</li><li>Unlike basic QPE, IQPE relies on <em>classically controlled rotation</em> gates instead of the original <em>quantum controlled rotation gates</em></li><li>The phase of the unitary matrix <strong>U</strong> is determined one bit at a time in IQPE and the <em>results </em>of measurement are required to proceed with the algorithm further whereas, in traditional QPE, the <em>ancillary </em>qubits are measured only once at the end of our algorithm, providing us the complete phase.</li></ul><p>Going past the differences between IQPE and basic QPE, let us flesh out some details which are important to be dealt with before moving on to the implementation of our circuit.</p><ul><li>Since the same qubit is needed for the subsequent <em>bit-identification</em> steps, a ‘<strong>reset to|0⟩</strong>’ operation is mandatory. This helps us utilise the same qubit for the determination of the remaining bits in our phase.</li><li>The last thing which we need to look at is the <em>classically controlled rotation</em> gates. Although we may use classically controlled rotation gates pertaining to each previously identified bit, there can be <em>one more optimisation</em>. When we are at the <strong>j</strong>th qubit and need an inverse rotation of</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*jFSyWH-Hx82PxoBZWT6c2w.png" /><figcaption>Inverse Rotation — 16</figcaption></figure><p>what we do is apply these rotations <em>‘sequentially’ (as shown in image 6). </em>But, since we <em>do have the values </em>of the previous bits with us, we may construct the complete rotation and replace it with <strong>one single </strong>rotation gate. This gate would apply the equivalent rotation in the jth qubit to give us the desired single-bit phase.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*IWdlgVwqDAufqsfiXvUnkg.png" /><figcaption>Equivalent rotation gate for the jth qubit — 17</figcaption></figure><p>In my opinion, this is a pretty cool algorithm since we just use 1 extra qubit for the determination of our phase! With all of the intuitions, mathematics, and optimisations up our sleeve let’s head over to the implementation part with IBM’s Qiskit.</p><h4>IQPE Implementation</h4><blockquote><strong>Unitary matrix</strong></blockquote><p>The unitary for our implementation is going to be a 2-qubit matrix made up of the <strong>X </strong>and <strong>Z</strong> gates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*qQ9icANWPbimqRdziPHxkw.png" /><figcaption>Unitary matrix — 18</figcaption></figure><blockquote><strong>State preparation and desired phase</strong></blockquote><p>Since the gate is a 2-qubit matrix, there are 4 eigenvectors, namely |1⟩|+⟩, |0⟩|+⟩, |1⟩|-⟩, |0⟩|-⟩. This implementation looks to identify the phase for the eigenvector |1⟩|+⟩. Since the unitary applied to this eigenvector generates -1 as an eigenvalue, we should expect the algorithm to identify the phase as 1/2 (work out the mathematics and you’ll be able to figure out why it is 1/2).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/332/1*g3sc5iDnONcHQL6tBBu-xQ.png" /><figcaption>Eigenvector preparation — 19</figcaption></figure><blockquote><strong>Optimised IQPE circuit</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zul5PnG9N1T6UW8PihaJPQ.jpeg" /><figcaption>Optimised circuit for IQPE. The classically controlled rotation gates are replaced by a single inverse controlled rotation gate i.e. the P gate(phase gate) — 20</figcaption></figure><blockquote><strong>Results for estimation</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*5wo1ZdkoJVqpo3yC1Go7pQ.png" /><figcaption>Phase in binary and decimal, as returned by the algorithm — 21</figcaption></figure><blockquote><strong>Plot for estimation of single-qubit unitary</strong></blockquote><p>Let us see the performance of our algorithm for a one-qubit phase unitary with phase = 1/6. This plot shows us the behavior of the algorithm as the number of iterations increases and we can clearly see that the algorithm is convergent to the actual phase as the number of iterations increases beyond 4.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J74xYkYTKZlJJFRXQ3N9tw.jpeg" /><figcaption>Plot for phase estimates vs increasing iterations — 22</figcaption></figure><p>That’s it, that’s IQPE folks!</p><p>Coming to the end of this post, I would like you to again first remember the <em>intuitions</em> and the <em>ideas</em> which led to the optimisation of the basic QPE algorithm, and once you are familiar with what the algorithm <em>means, </em>have a look at the mathematics<em>. </em>Hope you learned some new concepts here and enjoyed reading it as much as I did writing it. As always, stay tuned for more by Quantum Untangled!</p><blockquote>Code used in the above article can be found in <a href="https://github.com/TheGupta2012/QPE-Algorithms/blob/master/QPE/Iterative%20QPE/Iterative%20QPE.ipynb">this </a>repository.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ced794341487" width="1" height="1" alt=""><hr><p><a href="https://medium.com/quantum-untangled/iterative-quantum-phase-estimation-qpe-algorithms-ced794341487">Iterative Quantum Phase Estimation — QPE algorithms</a> was originally published in <a href="https://medium.com/quantum-untangled">Quantum Untangled</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quantum Fourier Transform and Basic QPE — QPE algorithms]]></title>
            <link>https://medium.com/quantum-untangled/quantum-fourier-transform-and-basic-qpe-qpe-algorithms-1af4d08b661c?source=rss-b9061b9da9d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/1af4d08b661c</guid>
            <category><![CDATA[fourier-transform]]></category>
            <category><![CDATA[quantum-algorithms]]></category>
            <category><![CDATA[quantum-computing]]></category>
            <category><![CDATA[mathematics]]></category>
            <dc:creator><![CDATA[Harshit Gupta]]></dc:creator>
            <pubDate>Wed, 30 Jun 2021 05:52:00 GMT</pubDate>
            <atom:updated>2021-06-30T05:52:00.001Z</atom:updated>
            <content:encoded><![CDATA[<h3>Quantum Fourier Transform and Basic QPE — QPE algorithms</h3><p>In the <a href="https://medium.com/quantum-untangled/intro-to-qpe-and-phase-encoding-qpe-algorithms-15638a8554b9">last post</a> of our series, we explored some of the required mathematics to tackle phase estimation. We learned phase kickbacks and phase encodings. This post revolves around the last piece of our puzzle (QPE), i.e., the Quantum Fourier Transform followed by the combination of all the mathematics into the QPE algorithm and why do we even care about it in the first place. Let’s get started then.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*5ooY5ol0OVwiKa8D" /><figcaption>Classical Fourier transform, similar to its quantum counterpart. Image by <a href="https://aavos.eu/glossary/fourier-transform/">AAVOS International</a>.</figcaption></figure><h4>Quantum Fourier Transform</h4><p>Sounds a bit scary.</p><p>Anyway, let’s remember where we left off in the previous post. This image would help you in recalling the final quantum states that we had in the qubits:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*4fbZ1YvLJwh4l2Yoi-xt3A.png" /><figcaption>Final qubit states after phase encoding- (1)</figcaption></figure><p>We concluded with the remark that phase was being encoded up to different bits in our ancilla register but we still needed a <em>‘way’</em> to extract those bits out. Quantum Fourier Transform(QFT) is how we do it.</p><p>Although many people teach QFT in a conventional way, saying that it is a change of basis(which it is) and then write the resultant state for a given binary state. We are not going to do that. Here, we are going to first build up the <em>inverse circuit</em> (QFT⁻¹) from scratch, look at its use case in the QPE algorithm and when we are comfortable with it, we just take the complex conjugate of the circuit that we have built.</p><p>Let us start from the simplest of cases. By <em>simple,</em> what I mean to say is that let us take the qubit which only has <em>1 bit </em>of information encoded in its phase. Which bit is that? If we see closely, Q(n-1) contains only a single bit, θₙ encoded in its phase:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*Q8uRtMYqA3XOmSv-TfxJsQ.png" /><figcaption>One-bit phase encoding-(2)</figcaption></figure><p>This is the last bit in our ancilla register. How do we extract it? Let’s try out some mathematics. Expanding our state when θₙ = 0 and θₙ = 1 gives us:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*E81aZcJgDNl1lPywKzRq1Q.png" /><figcaption>Final control state depending on last bit — (3)</figcaption></figure><p>This is a very important representation of our state. This means that whenever the value of θₙ is 0 or 1, our final state is going to be|+⟩ and |-⟩ respectively. This is exciting because |+⟩ corresponds to |0⟩ and |-⟩ corresponds to |1⟩ if we measure in the X-basis! Thus, if we apply an H-gate on this ancilla qubit, we are going to measure the qubit either as 0 with probability 1 or 1 with probability 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*Oh1K-kVR-afMswSOvyPnLw.png" /><figcaption>Circuit for measuring the control — (4)</figcaption></figure><p>Now think of this — if we have some means to transform each of the states <strong>Qi</strong> to the states |+⟩ or |-⟩(the <em>X </em>basis), we could measure them in the X basis and <em>extract </em>the information stored inside their phases, <em>one bit at a time</em>. Let us look at the math to drive home this simple discovery —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*xAMbipZeJjAuaYdiSUeu3Q.png" /><figcaption>State of the control qubit before and after measurement -(5)</figcaption></figure><p>This is the basic idea behind QFT⁻¹ that we are trying to build — somehow extract the bit information from our qubits by changing the <em>basis</em>. Note that we are still building upon intuition and thus, we don’t have any concrete formula for it, yet.</p><p>If you understood the workings till now, let’s move on to the next qubit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*FPuuWbu1GEEvWFZRrbkh8A.png" /><figcaption>Two-bit phase encoding-(6)</figcaption></figure><p>Well, there isn’t just 1 bit in our phase encoding — there are 2. What if there was just 1? Could it be somehow reduced to that simpler case? You should remember one thing though — we have the final state of θₙ with us. Since we proved in image 5 that θₙ either collapses deterministically to 0 or 1, this also means that the previous bit was either in the state |0⟩ or in the state |1⟩ just before the collapse.</p><p>Let us have a closer look at the phase of the second last qubit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/569/1*eJHCaMjPHU4onI6ZEg4RhA.png" /><figcaption>Phase structure in two-bit encoding — (7)</figcaption></figure><p>Well, you see that if θₙ is 0, there shouldn’t be any trouble — we just measure in the X basis again and get the answer for the next bit. But if θₙ is 1, the phase needs to be <em>reduced </em>to a simpler version through which we can extract the next bit. If you think about it, doesn’t this sound like a <em>conditional gate</em>? If we have θₙ as 0, don’t do anything, if θₙ is 1 do <em>something</em> to simplify the phase. What is this <em>something?</em></p><p>As we saw in image 7, the phase consists of contributions from both the current and the last bit. The phase contributed by the last bit θₙ can be <em>turned off</em> using a <em>controlled rotation gate</em> conditioned on the state of θₙ bit. This means if θₙ = 0, no gate is applied to the target qubit. If θₙ was 1, apply a rotation to cancel out the θₙ/2² term from our phase. What should the rotation be? It is exactly equal to —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*sSJ-HppnQN96I0zIFg2hQQ.png" /><figcaption>Inverse rotation needed — (8)</figcaption></figure><p>Let us see the simple circuit which is used to accomplish this and what is the final state —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*J8EsDLJXhNwLskiYmTkbAQ.png" /><figcaption>Final state for the 2-bit encoded phase-(9)</figcaption></figure><p>This is the heart of this transformation — we want to cancel out all the bits other than the one we want to find and then collapse the qubit to determine the bit information. Given that we have understood intuition till now, let’s look at the general case.</p><p>Let us say we have a phase, encoded as —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*8plep2YlQY8C3Qsr95vhcA.png" /><figcaption>Phase encoded up to the bit j-(10)</figcaption></figure><p>and we want to determine θⱼ. If we are able to cancel out the bits —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*VgL4OgNmz98pBB1i2HTKBQ.png" /><figcaption>The bits to be canceled-(11)</figcaption></figure><p>with the inverse rotation —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*jFSyWH-Hx82PxoBZWT6c2w.png" /><figcaption>Inverse Rotation needed-(12)</figcaption></figure><p>we would be left with phase 0.θⱼ which allows us to determine θⱼ with very high certainty. This brings us to our controlled inverse rotation gate — a gate that is conditioned on a single control qubit and applies the needed inverse rotations in our current qubit:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*TlEvR-RI0iCTwSUZXwJhuw.png" /><figcaption>Controlled rotation gate-(13)</figcaption></figure><p>Since the trailing bits, i.e.,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*VgL4OgNmz98pBB1i2HTKBQ.png" /><figcaption>The bits to be canceled-(14)</figcaption></figure><p>would be identified by us as either |0⟩ or |1⟩ in earlier trials, we have the ability to apply the correct C-ROTₖ gates to turn off the kᵗʰ bit of our representation. To be clear, <strong>k</strong> is the <em>position of the bit</em>, from the decimal point, that we want to cancel out. For example, if the phase encoding is 0.001 and we want to cancel out the last bit(3rd from the decimal point), the C-ROT₃ gate, conditioned on the last bit state, would be applied.</p><p>Taking another example, let us say we wanted to determine the <em>second last bit</em> in our phase. Let us assume the phase encoding is something like 0.01. Now, to cancel out the θₙ(last bit) we would apply the C-ROT₂ gate conditioned on θₙ (as θₙ is the <em>second bit to the right </em>from the decimal point). The circuit we would be getting would be is exactly the same as we saw in image 9 with the change that the controlled gate, now, has a name —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*e6ZzRlsKccRGa0TS8IyEUQ.png" /><figcaption>Final circuit for 2-bit encoded phase — (15)</figcaption></figure><p>We have come a long way but I am sure that you have now understood what actually happens in the QFT⁻¹ circuit and are able to make sense of and thus appreciate the final circuit. Again, we have built QFT⁻¹ without any kind of pre-defined formula and maybe you could even build the formula by yourself!</p><h4>Basic QPE with qiskit</h4><p>OKAY. With all the math under our belt now, let us see the complete Phase Estimation circuit with all our components. We’ll be doing some hands-on phase estimation using IBM’s qiskit package and constructing our circuit piece by piece. The phase we are trying to estimate is 1/8 and we have a 1-qubit unitary. Since phase 1/8 is represented as 0.001 in binary, we will be using 3 extra qubits for phase encoding, one for each bit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*x-3VfrVjD6bzZ-FftdqiaA.png" /><figcaption>Phase and the unitary matrix</figcaption></figure><ul><li>Preparation of Eigenvector</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/241/1*yc74vxLf9XI_PTeF5_FuZA.png" /><figcaption>The |1⟩ state acts as an eigenvector with eigenvalue 1/8.</figcaption></figure><ul><li>Phase Encoding</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/815/1*g8BzPt_23hdniVuVA3KH3Q.png" /><figcaption>Phase being encoded into the extra qubits using the controlled U gates</figcaption></figure><ul><li>QFT⁻¹ circuit</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*w6jrSM2eUhjDBjPqSQDGcw.png" /><figcaption>QFT⁻¹ for three qubits. Since q2 contains the least significant bit of the phase, hence a swap gate is applied at the end for a better visual interpretation.</figcaption></figure><ul><li>Final Circuit in Qiskit</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/919/1*F76QWa0PCheE2wKBGDIelA.png" /><figcaption>The complete phase estimation circuit</figcaption></figure><ul><li>Results for estimation using a single qubit phase gate with θ = 1/8</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*5-MCQB-lhzQEBPqTjv0JCw.png" /><figcaption>The final phase estimation result</figcaption></figure><h4><strong>Applications of QPE</strong></h4><p>The Quantum Phase Estimation algorithm is used as a sub-routine in many other quantum algorithms like <a href="https://qiskit.org/textbook/ch-algorithms/shor.html"><em>Shor’s </em></a>factoring algorithm (the most famous) and <a href="https://arxiv.org/pdf/2008.02102.pdf"><em>Quantum Amplitude Estimation </em></a>algorithms. Another major application for QPE is eigenvalue estimation for quantum systems. Since atoms and molecules follow unitary evolution, the observable values of their hamiltonians are their eigenvalues, and using QPE, we could also estimate the <em>energy eigenvalues </em>of a molecule.</p><p>Coming to the end of this article, I would like you to take a step back from all the math and first intuitively think of the phase estimation algorithm, what it does, how can it be implemented, what are its limitations. Then when you are comfortable, the math should be worked out completely to get the final grasp. While we haven’t discussed what happens when the phase does <strong>not</strong> have an exact binary representation, we shall in the upcoming posts. I hope you liked the ideas and concepts behind Phase Estimation Algorithm and learned some new things here and there.</p><p><em>Stick around for more by Quantum Untangled.</em></p><blockquote>You may find the code in <a href="https://github.com/TheGupta2012/QPE-Algorithms/blob/master/QPE/Basic%20QPE/Basic%20QPE.ipynb">this</a> repository.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1af4d08b661c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/quantum-untangled/quantum-fourier-transform-and-basic-qpe-qpe-algorithms-1af4d08b661c">Quantum Fourier Transform and Basic QPE — QPE algorithms</a> was originally published in <a href="https://medium.com/quantum-untangled">Quantum Untangled</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>