Skip to content

Commit

Permalink
Docs preview for PR #741.
Browse files Browse the repository at this point in the history
  • Loading branch information
cuda-quantum-bot committed Oct 16, 2023
1 parent eae2e9c commit 7504655
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 4 deletions.
6 changes: 6 additions & 0 deletions pr-741/api/languages/cpp_api.html
Original file line number Diff line number Diff line change
Expand Up @@ -2335,6 +2335,12 @@ <h2>Algorithms<a class="headerlink" href="#algorithms" title="Permalink to this
<dd><p>The constructor, takes the simulation data. </p>
</dd></dl>

<dl class="cpp function">
<dt class="sig sig-object cpp" id="_CPPv4N5cudaq5state5stateEv">
<span class="target" id="classcudaq_1_1state_1ac4c2617865ad19cc4d449ac559511d6c"></span><span class="k"><span class="pre">inline</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">state</span></span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4N5cudaq5state5stateEv" title="Permalink to this definition"></a><br /></dt>
<dd><p>Default constructor (empty state) </p>
</dd></dl>

<dl class="cpp function">
<dt class="sig sig-object cpp" id="_CPPv4N5cudaq5stateixENSt6size_tE">
<span class="target" id="classcudaq_1_1state_1ade1230f7c5978fbed157f0ba736362b0"></span><span class="n"><span class="pre">std</span></span><span class="p"><span class="pre">::</span></span><span class="n"><span class="pre">complex</span></span><span class="p"><span class="pre">&lt;</span></span><span class="kt"><span class="pre">double</span></span><span class="p"><span class="pre">&gt;</span></span><span class="w"> </span><span class="sig-name descname"><span class="k"><span class="pre">operator</span></span><span class="o"><span class="pre">[]</span></span></span><span class="sig-paren">(</span><span class="n"><span class="pre">std</span></span><span class="p"><span class="pre">::</span></span><span class="n"><span class="pre">size_t</span></span><span class="w"> </span><span class="n sig-param"><span class="pre">idx</span></span><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv4N5cudaq5stateixENSt6size_tE" title="Permalink to this definition"></a><br /></dt>
Expand Down
2 changes: 1 addition & 1 deletion pr-741/api/languages/python_api.html
Original file line number Diff line number Diff line change
Expand Up @@ -3013,7 +3013,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">1654531887</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.SpinOperator"><span class="pre">cudaq.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">3771946794</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.SpinOperator"><span class="pre">cudaq.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
2 changes: 1 addition & 1 deletion pr-741/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ <h2 id="C">C</h2>
</li>
<li><a href="api/languages/cpp_api.html#_CPPv4N5cudaq5state7overlapER5state">cudaq::state::overlap (C++ function)</a>
</li>
<li><a href="api/languages/cpp_api.html#_CPPv4N5cudaq5state5stateE5State">cudaq::state::state (C++ function)</a>
<li><a href="api/languages/cpp_api.html#_CPPv4N5cudaq5state5stateE5State">cudaq::state::state (C++ function)</a>, <a href="api/languages/cpp_api.html#_CPPv4N5cudaq5state5stateEv">[1]</a>
</li>
<li><a href="api/languages/cpp_api.html#_CPPv4N5cudaq11unset_noiseEv">cudaq::unset_noise (C++ function)</a>
</li>
Expand Down
Binary file modified pr-741/objects.inv
Binary file not shown.
2 changes: 1 addition & 1 deletion pr-741/searchindex.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*******************************************************************************
* Copyright (c) 2022 - 2023 NVIDIA Corporation & Affiliates. *
* All rights reserved. *
* *
* This source code and the accompanying materials are made available under *
* the terms of the Apache License 2.0 which accompanies this distribution. *
******************************************************************************/

// Compile and run with:
// ```
// nvq++ get_state_async.cpp -o get_state_async.x -target nvidia-mqpu
// && ./get_state_async.x
// ```
#include <cudaq.h>
#include <cudaq/algorithms/state.h>
int main() {
// [Begin Documentation]
auto kernelToRun = [](int runtimeParam) __qpu__ {
cudaq::qreg q(runtimeParam);
h(q[0]);
for (int i = 0; i < runtimeParam - 1; ++i)
x<cudaq::ctrl>(q[i], q[i + 1]);
};

// Get the quantum_platform singleton
auto &platform = cudaq::get_platform();

// Query the number of QPUs in the system
auto num_qpus = platform.num_qpus();
printf("Number of QPUs: %zu\n", num_qpus);
// We will launch asynchronous tasks
// and will store the results immediately as a future
// we can query at some later point
std::vector<cudaq::async_state_result> stateFutures;
for (std::size_t i = 0; i < num_qpus; i++) {
stateFutures.emplace_back(
cudaq::get_state_async(i, kernelToRun, 5 /*runtimeParam*/));
}

//
// Go do other work, asynchronous execution of tasks on-going
//

// Get the results, note future::get() will kick off a wait
// if the results are not yet available.
for (auto &state : stateFutures) {
state.get().dump();
}
// [End Documentation]
return 0;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Compile and run with:
/*******************************************************************************
* Copyright (c) 2022 - 2023 NVIDIA Corporation & Affiliates. *
* All rights reserved. *
Expand All @@ -7,6 +6,7 @@
* the terms of the Apache License 2.0 which accompanies this distribution. *
******************************************************************************/

// Compile and run with:
// ```
// nvq++ sample_async.cpp -o sample_async.x -target nvidia-mqpu
// && ./sample_async.x
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# ============================================================================ #
# Copyright (c) 2022 - 2023 NVIDIA Corporation & Affiliates. #
# All rights reserved. #
# #
# This source code and the accompanying materials are made available under #
# the terms of the Apache License 2.0 which accompanies this distribution. #
# ============================================================================ #
# [Begin Documentation]
import cudaq

cudaq.set_target("nvidia-mqpu")
target = cudaq.get_target()
num_qpus = target.num_qpus()
print("Number of QPUs:", num_qpus)

kernel = cudaq.make_kernel()
qubits = kernel.qalloc(5)
# Place qubits in GHZ state.
kernel.h(qubits[0])
kernel.for_loop(0, 4, lambda i: kernel.cx(qubits[i], qubits[i + 1]))

state_futures = []
for qpu in range(num_qpus):
state_futures.append(cudaq.get_state_async(kernel, qpu_id=qpu))

for state in state_futures:
print(state.get())

0 comments on commit 7504655

Please sign in to comment.