123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <!DOCTYPE html>
- <html >
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width,initial-scale=1">
- <title>Getting Started</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="next" title="User Guide" href="guide.html" />
- <link rel="prev" title="Installation" href="install.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 router-link-active">
- 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 router-link-active">
- 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 current"><a class="current reference internal" href="#">Getting Started</a></li>
- <li class="toctree-l1"><a class="reference internal" href="guide.html">User Guide</a></li>
- </ul>
- </div>
- </div>
- </sidebar>
- <page>
- <div class="content">
-
- <div class="section" id="getting-started">
- <h1>Getting Started<a class="headerlink" href="#getting-started" title="Permalink to this headline">¶</a></h1>
- <p>When using this library, you will most likely be using the <code class="xref py py-class docutils literal notranslate"><span class="pre">State</span></code> class.
- This class represents the state of a quantum register.
- Using this class you can apply gates to the register, measure, get the state vector and things like that.</p>
- <p>To run a simple quantum circuit, you can use something like this,</p>
- <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># Import QCGPU</span>
- <span class="kn">import</span> <span class="nn">qcgpu</span>
- <span class="c1"># Create a new quantum register with 2 qubits</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">2</span><span class="p">)</span>
- <span class="c1"># Apply a hadamard (H) gate to the first qubit.</span>
- <span class="c1"># You should note that the qubits are zero indexed</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="c1"># Add a controlled not (CNOT/CX) gate, with the control as</span>
- <span class="c1"># the first qubit and target as the second.</span>
- <span class="c1"># The register will now be in the bell state.</span>
- <span class="n">register</span><span class="o">.</span><span class="n">cx</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
- <span class="c1"># Perform a measurement with 1000 samples</span>
- <span class="n">results</span> <span class="o">=</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"># Show the results</span>
- <span class="k">print</span><span class="p">(</span><span class="n">results</span><span class="p">)</span>
- </pre></div>
- </div>
- <p>The output of a measurement gives a dictionary of measurement outcomes,
- along with how often they occurred.</p>
- <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="p">{</span><span class="s1">'00'</span><span class="p">:</span> <span class="mi">486</span><span class="p">,</span> <span class="s1">'11'</span><span class="p">:</span> <span class="mi">514</span><span class="p">}</span>
- </pre></div>
- </div>
- <p>There are a few different ways to do things using QCGPU,
- so you should check out the rest of the documentation too</p>
- </div>
- </div>
- <div class="page-nav">
- <div class="inner">
- <span class="prev">
- <a href="install.html"
- title="previous chapter">← Installation</a>
- </span>
- <span class="next">
- <a href="guide.html"
- title="next chapter">User Guide →</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>
|