123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <!DOCTYPE html>
- <html >
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width,initial-scale=1">
- <title>Quantum Operations</title>
-
- <link rel="stylesheet" href="_static/pygments.css">
- <link rel="stylesheet" href="_static/theme.css">
-
- <script src="_static/theme-vendors.js"></script>
- <script src="_static/theme.js" defer></script>
-
- <link rel="index" title="Index" href="genindex.html" />
- <link rel="search" title="Search" href="search.html" />
- <link rel="prev" title="Quantum Gates" href="gates.html" />
- </head>
- <body><div id="app" class="theme-container" :class="pageClasses"><navbar @toggle-sidebar="toggleSidebar">
- <router-link to="index.html" class="home-link">
- <span class="site-name">QCGPU</span>
- </router-link>
- <div class="links">
- <navlinks class="can-hide">
- <div class="nav-item">
- <a href="install.html"
- class="nav-link ">
- None
- </a>
- </div>
- </navlinks>
- </div>
- </navbar>
-
- <div class="sidebar-mask" @click="toggleSidebar(false)">
- </div>
- <sidebar @toggle-sidebar="toggleSidebar">
-
- <navlinks>
-
- <div class="nav-item">
- <a href="install.html"
- class="nav-link ">
- None
- </a>
- </div>
-
- </navlinks><div class="sidebar-links" role="navigation" aria-label="main navigation">
-
- <div class="sidebar-group">
- <ul class="current">
- <li class="toctree-l1"><a class="reference internal" href="install.html">Installation</a></li>
- <li class="toctree-l1"><a class="reference internal" href="quickstart.html">Getting Started</a></li>
- <li class="toctree-l1 current"><a class="reference internal" href="guide.html">User Guide</a><ul class="current">
- <li class="toctree-l2"><a class="reference internal" href="registers.html">Quantum Registers</a></li>
- <li class="toctree-l2"><a class="reference internal" href="gates.html">Quantum Gates</a></li>
- <li class="toctree-l2 current"><a class="current reference internal" href="#">Quantum Operations</a></li>
- </ul>
- </li>
- </ul>
- </div>
- </div>
- </sidebar>
- <page>
- <div class="content">
-
- <div class="section" id="quantum-operations">
- <h1>Quantum Operations<a class="headerlink" href="#quantum-operations" title="Permalink to this headline">¶</a></h1>
- <p>There are a number of operations you can perform on quantum registers
- with QCGPU.</p>
- <div class="section" id="measurement">
- <h2>Measurement<a class="headerlink" href="#measurement" title="Permalink to this headline">¶</a></h2>
- <p>Measurement of a register in QCGPU doesn’t collapse the state (although
- this may be added in the future). When you measure the state, you can
- specify the number of times to sample. The output of this <code class="docutils literal notranslate"><span class="pre">measure</span></code>
- function is a dictionary with the bitstrings of the outputs, along with
- the number of times they were measured.</p>
- <p>You can measure a register as follows,</p>
- <div class="code python highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">qcgpu</span>
- <span class="n">register</span> <span class="o">=</span> <span class="n">qcgpu</span><span class="o">.</span><span class="n">State</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
- <span class="n">register</span><span class="o">.</span><span class="n">measure</span><span class="p">(</span><span class="n">samples</span><span class="o">=</span><span class="mi">1000</span><span class="p">)</span>
- <span class="c1"># {'00000': 1000}</span>
- </pre></div>
- </div>
- <p>There is also a convenience method to measure only a single qubit.
- Again, the state is not collapsed</p>
- <div class="code python highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">qcgpu</span>
- <span class="n">register</span> <span class="o">=</span> <span class="n">qcgpu</span><span class="o">.</span><span class="n">State</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
- <span class="n">register</span><span class="o">.</span><span class="n">h</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
- <span class="n">register</span><span class="o">.</span><span class="n">measure_qubit</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">samples</span><span class="o">=</span><span class="mi">1000</span><span class="p">)</span>
- <span class="c1"># {'1': 523, '0': 477}</span>
- </pre></div>
- </div>
- </div>
- <div class="section" id="probability">
- <h2>Probability<a class="headerlink" href="#probability" title="Permalink to this headline">¶</a></h2>
- <p>QCGPU provides another method for getting the probability of each
- outcome.</p>
- <p>The probability of getting an outcome <span class="math notranslate nohighlight">\(j\)</span> from a state
- <span class="math notranslate nohighlight">\(\lvert \psi \rangle = \sum_{j = 0}^{2^n - 1} \alpha_j \lvert j \rangle\)</span>
- is</p>
- <div class="math notranslate nohighlight">
- \[P(j) = \lvert \alpha_j \lvert^2\]</div>
- <p>The method <code class="docutils literal notranslate"><span class="pre">probabilities</span></code> returns a numpy array with each of the
- values corresponding to <span class="math notranslate nohighlight">\(\lvert \alpha_j \lvert ^2\)</span> for each index
- <span class="math notranslate nohighlight">\(j\)</span>.</p>
- <div class="code python highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">qcgpu</span>
- <span class="n">register</span> <span class="o">=</span> <span class="n">qcgpu</span><span class="o">.</span><span class="n">State</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
- <span class="n">register</span><span class="o">.</span><span class="n">h</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
- <span class="n">register</span><span class="o">.</span><span class="n">probabilities</span><span class="p">()</span> <span class="c1"># [0.5, 0.5]</span>
- </pre></div>
- </div>
- <p>This method is particularly useful to plot the probabilities of each
- outcome.</p>
- </div>
- </div>
- </div>
- <div class="page-nav">
- <div class="inner">
- <span class="prev">
- <a href="gates.html"
- title="previous chapter">← Quantum Gates</a>
- </span>
- <script type="text/x-mathjax-config">
- MathJax.Hub.Config({
- tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']], displayMath: [['$$', '$$'], ['\\[', '\\]']]}
- });
- </script>
- <script type="text/javascript"
- src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
- </script>
- </div>
- </div>
- </page>
- </div></body>
- </html>
|