quickstart.html 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <!DOCTYPE html>
  2. <html >
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width,initial-scale=1">
  6. <title>Getting Started</title>
  7. <link rel="stylesheet" href="_static/pygments.css">
  8. <link rel="stylesheet" href="_static/theme.css">
  9. <script src="_static/theme-vendors.js"></script>
  10. <script src="_static/theme.js" defer></script>
  11. <link rel="index" title="Index" href="genindex.html" />
  12. <link rel="search" title="Search" href="search.html" />
  13. <link rel="prev" title="Installation" href="install.html" />
  14. </head>
  15. <body><div id="app" class="theme-container" :class="pageClasses"><navbar @toggle-sidebar="toggleSidebar">
  16. <router-link to="index.html" class="home-link">
  17. <span class="site-name">QCGPU</span>
  18. </router-link>
  19. <div class="links">
  20. <navlinks class="can-hide">
  21. <div class="nav-item">
  22. <a href="install.html"
  23. class="nav-link router-link-active">
  24. None
  25. </a>
  26. </div>
  27. </navlinks>
  28. </div>
  29. </navbar>
  30. <div class="sidebar-mask" @click="toggleSidebar(false)">
  31. </div>
  32. <sidebar @toggle-sidebar="toggleSidebar">
  33. <navlinks>
  34. <div class="nav-item">
  35. <a href="install.html"
  36. class="nav-link router-link-active">
  37. None
  38. </a>
  39. </div>
  40. </navlinks><div class="sidebar-links" role="navigation" aria-label="main navigation">
  41. <div class="sidebar-group">
  42. <ul class="current">
  43. <li class="toctree-l1"><a class="reference internal" href="install.html">Installation</a></li>
  44. <li class="toctree-l1 current"><a class="current reference internal" href="#">Getting started</a></li>
  45. </ul>
  46. </div>
  47. </div>
  48. </sidebar>
  49. <page>
  50. <div class="content">
  51. <div class="section" id="getting-started">
  52. <h1>Getting Started<a class="headerlink" href="#getting-started" title="Permalink to this headline">¶</a></h1>
  53. <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.
  54. This class represents the state of a quantum register.
  55. Using this class you can apply gates to the register, measure, get the state vector and things like that.</p>
  56. <p>To run a simple quantum circuit, you can use something like this,</p>
  57. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># Import QCGPU</span>
  58. <span class="kn">import</span> <span class="nn">qcgpu</span>
  59. <span class="c1"># Create a new quantum register with 2 qubits</span>
  60. <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>
  61. <span class="c1"># Apply a hadamard (H) gate to the first qubit.</span>
  62. <span class="c1"># You should note that the qubits are zero indexed</span>
  63. <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>
  64. <span class="c1"># Add a controlled not (CNOT/CX) gate, with the control as</span>
  65. <span class="c1"># the first qubit and target as the second.</span>
  66. <span class="c1"># The register will now be in the bell state.</span>
  67. <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>
  68. <span class="c1"># Perform a measurement with 1000 samples</span>
  69. <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>
  70. <span class="c1"># Show the results</span>
  71. <span class="k">print</span><span class="p">(</span><span class="n">results</span><span class="p">)</span>
  72. </pre></div>
  73. </div>
  74. <p>The output of a measurement gives a dictionary of measurement outcomes,
  75. along with how often they occurred.</p>
  76. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="p">{</span><span class="s1">&#39;00&#39;</span><span class="p">:</span> <span class="mi">486</span><span class="p">,</span> <span class="s1">&#39;11&#39;</span><span class="p">:</span> <span class="mi">514</span><span class="p">}</span>
  77. </pre></div>
  78. </div>
  79. </div>
  80. </div>
  81. <div class="page-nav">
  82. <div class="inner">
  83. <span class="prev">
  84. <a href="install.html"
  85. title="previous chapter">← Installation</a>
  86. </span>
  87. <div class="footer" role="contentinfo">
  88. &#169; Copyright 2018, Adam Kelly.
  89. <br>
  90. Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.8.1 with <a href="https://github.com/schettino72/sphinx_press_theme">Press Theme</a>.
  91. </div>
  92. </div>
  93. </div>
  94. </page>
  95. </div></body>
  96. </html>