quickstart.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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="next" title="User Guide" href="guide.html" />
  14. <link rel="prev" title="Installation" href="install.html" />
  15. </head>
  16. <body><div id="app" class="theme-container" :class="pageClasses"><navbar @toggle-sidebar="toggleSidebar">
  17. <router-link to="index.html" class="home-link">
  18. <span class="site-name">QCGPU</span>
  19. </router-link>
  20. <div class="links">
  21. <navlinks class="can-hide">
  22. <div class="nav-item">
  23. <a href="install.html"
  24. class="nav-link router-link-active">
  25. None
  26. </a>
  27. </div>
  28. </navlinks>
  29. </div>
  30. </navbar>
  31. <div class="sidebar-mask" @click="toggleSidebar(false)">
  32. </div>
  33. <sidebar @toggle-sidebar="toggleSidebar">
  34. <navlinks>
  35. <div class="nav-item">
  36. <a href="install.html"
  37. class="nav-link router-link-active">
  38. None
  39. </a>
  40. </div>
  41. </navlinks><div class="sidebar-links" role="navigation" aria-label="main navigation">
  42. <div class="sidebar-group">
  43. <ul class="current">
  44. <li class="toctree-l1"><a class="reference internal" href="install.html">Installation</a></li>
  45. <li class="toctree-l1 current"><a class="current reference internal" href="#">Getting Started</a></li>
  46. <li class="toctree-l1"><a class="reference internal" href="guide.html">User Guide</a></li>
  47. </ul>
  48. </div>
  49. </div>
  50. </sidebar>
  51. <page>
  52. <div class="content">
  53. <div class="section" id="getting-started">
  54. <h1>Getting Started<a class="headerlink" href="#getting-started" title="Permalink to this headline">¶</a></h1>
  55. <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.
  56. This class represents the state of a quantum register.
  57. Using this class you can apply gates to the register, measure, get the state vector and things like that.</p>
  58. <p>To run a simple quantum circuit, you can use something like this,</p>
  59. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># Import QCGPU</span>
  60. <span class="kn">import</span> <span class="nn">qcgpu</span>
  61. <span class="c1"># Create a new quantum register with 2 qubits</span>
  62. <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>
  63. <span class="c1"># Apply a hadamard (H) gate to the first qubit.</span>
  64. <span class="c1"># You should note that the qubits are zero indexed</span>
  65. <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>
  66. <span class="c1"># Add a controlled not (CNOT/CX) gate, with the control as</span>
  67. <span class="c1"># the first qubit and target as the second.</span>
  68. <span class="c1"># The register will now be in the bell state.</span>
  69. <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>
  70. <span class="c1"># Perform a measurement with 1000 samples</span>
  71. <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>
  72. <span class="c1"># Show the results</span>
  73. <span class="k">print</span><span class="p">(</span><span class="n">results</span><span class="p">)</span>
  74. </pre></div>
  75. </div>
  76. <p>The output of a measurement gives a dictionary of measurement outcomes,
  77. along with how often they occurred.</p>
  78. <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>
  79. </pre></div>
  80. </div>
  81. <p>There are a few different ways to do things using QCGPU,
  82. so you should check out the rest of the documentation too</p>
  83. </div>
  84. </div>
  85. <div class="page-nav">
  86. <div class="inner">
  87. <span class="prev">
  88. <a href="install.html"
  89. title="previous chapter">← Installation</a>
  90. </span>
  91. <span class="next">
  92. <a href="guide.html"
  93. title="next chapter">User Guide →</a>
  94. </span>
  95. <script type="text/x-mathjax-config">
  96. MathJax.Hub.Config({
  97. tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']], displayMath: [['$$', '$$'], ['\\[', '\\]']]}
  98. });
  99. </script>
  100. <script type="text/javascript"
  101. src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
  102. </script>
  103. </div>
  104. </div>
  105. </page>
  106. </div></body>
  107. </html>