Skip to content

Commit

Permalink
Docs preview for PR #1932.
Browse files Browse the repository at this point in the history
  • Loading branch information
cuda-quantum-bot committed Jul 15, 2024
1 parent 2b76e97 commit 430af7b
Show file tree
Hide file tree
Showing 71 changed files with 135 additions and 6 deletions.
3 changes: 2 additions & 1 deletion pr-1932/_sources/api/languages/python_api.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ Kernel Execution
.. autofunction:: cudaq::get_state
.. autofunction:: cudaq::get_state_async
.. autofunction:: cudaq::vqe
.. autofunction:: cudaq::draw
.. autofunction:: cudaq::draw
.. autofunction:: cudaq::translate

Backend Configuration
=============================
Expand Down
1 change: 1 addition & 0 deletions pr-1932/api/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@
<li class="toctree-l4"><a class="reference internal" href="languages/python_api.html#cudaq.get_state_async"><code class="docutils literal notranslate"><span class="pre">get_state_async()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="languages/python_api.html#cudaq.vqe"><code class="docutils literal notranslate"><span class="pre">vqe()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="languages/python_api.html#cudaq.draw"><code class="docutils literal notranslate"><span class="pre">draw()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="languages/python_api.html#cudaq.translate"><code class="docutils literal notranslate"><span class="pre">translate()</span></code></a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="languages/python_api.html#backend-configuration">Backend Configuration</a><ul>
Expand Down
1 change: 1 addition & 0 deletions pr-1932/api/default_ops.html
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@
<li class="toctree-l4"><a class="reference internal" href="languages/python_api.html#cudaq.get_state_async"><code class="docutils literal notranslate"><span class="pre">get_state_async()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="languages/python_api.html#cudaq.vqe"><code class="docutils literal notranslate"><span class="pre">vqe()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="languages/python_api.html#cudaq.draw"><code class="docutils literal notranslate"><span class="pre">draw()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="languages/python_api.html#cudaq.translate"><code class="docutils literal notranslate"><span class="pre">translate()</span></code></a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="languages/python_api.html#backend-configuration">Backend Configuration</a><ul>
Expand Down
1 change: 1 addition & 0 deletions pr-1932/api/languages/cpp_api.html
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@
<li class="toctree-l4"><a class="reference internal" href="python_api.html#cudaq.get_state_async"><code class="docutils literal notranslate"><span class="pre">get_state_async()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="python_api.html#cudaq.vqe"><code class="docutils literal notranslate"><span class="pre">vqe()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="python_api.html#cudaq.draw"><code class="docutils literal notranslate"><span class="pre">draw()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="python_api.html#cudaq.translate"><code class="docutils literal notranslate"><span class="pre">translate()</span></code></a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="python_api.html#backend-configuration">Backend Configuration</a><ul>
Expand Down
61 changes: 60 additions & 1 deletion pr-1932/api/languages/python_api.html
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@
<li class="toctree-l4"><a class="reference internal" href="#cudaq.get_state_async"><code class="docutils literal notranslate"><span class="pre">get_state_async()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#cudaq.vqe"><code class="docutils literal notranslate"><span class="pre">vqe()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#cudaq.draw"><code class="docutils literal notranslate"><span class="pre">draw()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#cudaq.translate"><code class="docutils literal notranslate"><span class="pre">translate()</span></code></a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#backend-configuration">Backend Configuration</a><ul>
Expand Down Expand Up @@ -991,6 +992,64 @@ <h2>Kernel Execution<a class="headerlink" href="#kernel-execution" title="Permal
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="cudaq.translate">
<span class="sig-prename descclassname"><span class="pre">cudaq.</span></span><span class="sig-name descname"><span class="pre">translate</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#cudaq.translate" title="Permalink to this definition"></a></dt>
<dd><dl class="py function">
<dt class="sig sig-object py">
<span class="sig-prename descclassname"><span class="pre">cudaq.</span></span><span class="sig-name descname"><span class="pre">translate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">kernel:</span> <span class="pre">object</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">\*args</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">format:</span> <span class="pre">str</span> <span class="pre">=</span> <span class="pre">'qir'</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><span class="pre">str</span></a></span></span></dt>
<dd></dd></dl>

<p>Return a UTF-8 encoded string representing drawing of the execution
path, i.e., the trace, of the provided <code class="code docutils literal notranslate"><span class="pre">kernel</span></code>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>format</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.12)"><em>str</em></a>) – format to translate to. Available formats: <code class="code docutils literal notranslate"><span class="pre">qir</span></code>, <code class="code docutils literal notranslate"><span class="pre">qir-base</span></code>,
<code class="code docutils literal notranslate"><span class="pre">qir-adaptive</span></code>, <code class="code docutils literal notranslate"><span class="pre">openqasm2</span></code>.</p></li>
<li><p><strong>kernel</strong> (<a class="reference internal" href="#cudaq.Kernel" title="cudaq.Kernel"><code class="xref py py-class docutils literal notranslate"><span class="pre">Kernel</span></code></a>) – The <a class="reference internal" href="#cudaq.Kernel" title="cudaq.Kernel"><code class="xref py py-class docutils literal notranslate"><span class="pre">Kernel</span></code></a> to translate.</p></li>
<li><p><strong>*arguments</strong> (<em>Optional</em><em>[</em><em>Any</em><em>]</em>) – The concrete values to evaluate the kernel
function at. Leave empty if the kernel doesn’t accept any arguments.</p></li>
<li><p><strong>Note</strong> – Translating functions with arguments to OpenQASM 2.0 is not supported.</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>The UTF-8 encoded string of the circuit, without measurement operations.</p>
</dd>
</dl>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># Example</span>
<span class="kn">import</span> <span class="nn">cudaq</span>
<span class="nd">@cudaq</span><span class="o">.</span><span class="n">kernel</span>
<span class="k">def</span> <span class="nf">bell_pair</span><span class="p">():</span>
<span class="n">q</span> <span class="o">=</span> <span class="n">cudaq</span><span class="o">.</span><span class="n">qvector</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="n">h</span><span class="p">(</span><span class="n">q</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">cx</span><span class="p">(</span><span class="n">q</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">q</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="n">mz</span><span class="p">(</span><span class="n">q</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">cudaq</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="n">bell_pair</span><span class="p">,</span> <span class="nb">format</span><span class="o">=</span><span class="s2">&quot;qir&quot;</span><span class="p">))</span>

<span class="c1"># Output</span>
<span class="p">;</span> <span class="n">ModuleID</span> <span class="o">=</span> <span class="s1">&#39;LLVMDialectModule&#39;</span>
<span class="n">source_filename</span> <span class="o">=</span> <span class="s1">&#39;LLVMDialectModule&#39;</span>

<span class="o">%</span><span class="n">Array</span> <span class="o">=</span> <span class="nb">type</span> <span class="n">opaque</span>
<span class="o">%</span><span class="n">Result</span> <span class="o">=</span> <span class="nb">type</span> <span class="n">opaque</span>
<span class="o">%</span><span class="n">Qubit</span> <span class="o">=</span> <span class="nb">type</span> <span class="n">opaque</span>

<span class="o">...</span>
<span class="o">...</span>

<span class="n">define</span> <span class="n">void</span> <span class="nd">@__nvqpp__mlirgen__function_variable_qreg</span><span class="o">.</span><span class="n">_Z13variable_qregv</span><span class="p">()</span> <span class="n">local_unnamed_addr</span> <span class="p">{</span>
<span class="o">%</span><span class="mi">1</span> <span class="o">=</span> <span class="n">tail</span> <span class="n">call</span> <span class="o">%</span><span class="n">Array</span><span class="o">*</span> <span class="nd">@__quantum__rt__qubit_allocate_array</span><span class="p">(</span><span class="n">i64</span> <span class="mi">2</span><span class="p">)</span>
<span class="o">...</span>
<span class="o">%</span><span class="mi">8</span> <span class="o">=</span> <span class="n">tail</span> <span class="n">call</span> <span class="o">%</span><span class="n">Result</span><span class="o">*</span> <span class="nd">@__quantum__qis__mz</span><span class="p">(</span><span class="o">%</span><span class="n">Qubit</span><span class="o">*</span> <span class="o">%</span><span class="mi">4</span><span class="p">)</span>
<span class="o">%</span><span class="mi">9</span> <span class="o">=</span> <span class="n">tail</span> <span class="n">call</span> <span class="o">%</span><span class="n">Result</span><span class="o">*</span> <span class="nd">@__quantum__qis__mz</span><span class="p">(</span><span class="o">%</span><span class="n">Qubit</span><span class="o">*</span> <span class="o">%</span><span class="mi">7</span><span class="p">)</span>
<span class="n">tail</span> <span class="n">call</span> <span class="n">void</span> <span class="nd">@__quantum__rt__qubit_release_array</span><span class="p">(</span><span class="o">%</span><span class="n">Array</span><span class="o">*</span> <span class="o">%</span><span class="mi">1</span><span class="p">)</span>
<span class="n">ret</span> <span class="n">void</span>
<span class="p">}</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="backend-configuration">
<h2>Backend Configuration<a class="headerlink" href="#backend-configuration" title="Permalink to this heading"></a></h2>
Expand Down Expand Up @@ -1990,7 +2049,7 @@ <h2>Data Types<a class="headerlink" href="#data-types" title="Permalink to this
<em class="property"><span class="pre">static</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">random</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#cudaq.SpinOperator.random" title="Permalink to this definition"></a></dt>
<dd><dl class="py function">
<dt class="sig sig-object py">
<span class="sig-name descname"><span class="pre">random</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">qubit_count</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">term_count</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">seed</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">2377850447</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference internal" href="#cudaq.SpinOperator" title="cudaq.mlir._mlir_libs._quakeDialects.cudaq_runtime.SpinOperator"><span class="pre">cudaq.mlir._mlir_libs._quakeDialects.cudaq_runtime.SpinOperator</span></a></span></span></dt>
<span class="sig-name descname"><span class="pre">random</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">qubit_count</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">term_count</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span></em>, <em class="sig-param"><span class="n"><span class="pre">seed</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.12)"><span class="pre">int</span></a></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">3685079100</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference internal" href="#cudaq.SpinOperator" title="cudaq.mlir._mlir_libs._quakeDialects.cudaq_runtime.SpinOperator"><span class="pre">cudaq.mlir._mlir_libs._quakeDialects.cudaq_runtime.SpinOperator</span></a></span></span></dt>
<dd></dd></dl>

<p>Return a random <a class="reference internal" href="#cudaq.SpinOperator" title="cudaq.SpinOperator"><code class="xref py py-class docutils literal notranslate"><span class="pre">SpinOperator</span></code></a> on the given number of qubits (<code class="code docutils literal notranslate"><span class="pre">qubit_count</span></code>) and composed of the given number of terms (<code class="code docutils literal notranslate"><span class="pre">term_count</span></code>). An optional seed value may also be provided.</p>
Expand Down
1 change: 1 addition & 0 deletions pr-1932/examples/python/tutorials/cost_minimization.html
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@
<li class="toctree-l4"><a class="reference internal" href="../../../api/languages/python_api.html#cudaq.get_state_async"><code class="docutils literal notranslate"><span class="pre">get_state_async()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../api/languages/python_api.html#cudaq.vqe"><code class="docutils literal notranslate"><span class="pre">vqe()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../api/languages/python_api.html#cudaq.draw"><code class="docutils literal notranslate"><span class="pre">draw()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../api/languages/python_api.html#cudaq.translate"><code class="docutils literal notranslate"><span class="pre">translate()</span></code></a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../../../api/languages/python_api.html#backend-configuration">Backend Configuration</a><ul>
Expand Down
5 changes: 3 additions & 2 deletions pr-1932/examples/python/tutorials/deutschs_algorithm.html
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@
<li class="toctree-l4"><a class="reference internal" href="../../../api/languages/python_api.html#cudaq.get_state_async"><code class="docutils literal notranslate"><span class="pre">get_state_async()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../api/languages/python_api.html#cudaq.vqe"><code class="docutils literal notranslate"><span class="pre">vqe()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../api/languages/python_api.html#cudaq.draw"><code class="docutils literal notranslate"><span class="pre">draw()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../api/languages/python_api.html#cudaq.translate"><code class="docutils literal notranslate"><span class="pre">translate()</span></code></a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../../../api/languages/python_api.html#backend-configuration">Backend Configuration</a><ul>
Expand Down Expand Up @@ -602,7 +603,7 @@ <h2>XOR <span class="math notranslate nohighlight">\(\oplus\)</span><a class="he
</section>
<section id="Quantum-oracles">
<h2>Quantum oracles<a class="headerlink" href="#Quantum-oracles" title="Permalink to this heading"></a></h2>
<p><img alt="0956369faab54fa9b922a0365244da7f" class="no-scaled-link" src="../../../_images/oracle.png" style="width: 300px; height: 150px;" /></p>
<p><img alt="38c5d37de0b64f75983adc0fe9d69a38" class="no-scaled-link" src="../../../_images/oracle.png" style="width: 300px; height: 150px;" /></p>
<p>Suppose we have <span class="math notranslate nohighlight">\(f(x): \{0,1\} \longrightarrow \{0,1\}\)</span>. We can compute this function on a quantum computer using oracles which we treat as black box functions that yield the output with an appropriate sequence of logic gates.</p>
<p>Above you see an oracle represented as <span class="math notranslate nohighlight">\(U_f\)</span> which allows us to transform the state <span class="math notranslate nohighlight">\(\ket{x}\ket{y}\)</span> into:</p>
<div class="math notranslate nohighlight">
Expand Down Expand Up @@ -650,7 +651,7 @@ <h2>Quantum parallelism<a class="headerlink" href="#Quantum-parallelism" title="
<h2>Deutschs’ Algorithm:<a class="headerlink" href="#Deutschs'-Algorithm:" title="Permalink to this heading"></a></h2>
<p>Our aim is to find out if <span class="math notranslate nohighlight">\(f: \{0,1\} \longrightarrow \{0,1\}\)</span> is a constant or a balanced function? If constant, <span class="math notranslate nohighlight">\(f(0) = f(1)\)</span>, and if balanced, <span class="math notranslate nohighlight">\(f(0) \neq f(1)\)</span>.</p>
<p>We step through the circuit diagram below and follow the math after the application of each gate.</p>
<p><img alt="f328a37d30174d5a8707f69ced4ddd7d" class="no-scaled-link" src="../../../_images/deutsch.png" style="width: 500px; height: 210px;" /></p>
<p><img alt="eb8f62d66d674681937df691e364332c" class="no-scaled-link" src="../../../_images/deutsch.png" style="width: 500px; height: 210px;" /></p>
<div class="math notranslate nohighlight">
\[\ket{\psi_0} = \ket{01}
\tag{1}\]</div>
Expand Down
Loading

0 comments on commit 430af7b

Please sign in to comment.