-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eae2e9c
commit 7504655
Showing
8 changed files
with
88 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
pr-741/sphinx/snippets/cpp/using/cudaq/platform/get_state_async.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
pr-741/sphinx/snippets/python/using/cudaq/platform/get_state_async.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |