-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into tnguyen/dynamics-mgmn
- Loading branch information
Showing
14 changed files
with
353 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
nvidia-mgpu-repo: cuda-quantum/cuquantum-mgpu.git | ||
nvidia-mgpu-commit: dadce3edc10564e94cd260590344d5840880087a | ||
nvidia-mgpu-commit: 806e7fe5c459f52296ae0d3bd8bc57c3ea806152 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 - 2025 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] | ||
#include <cudaq.h> | ||
|
||
struct xOp { | ||
void operator()(int qubit_count) __qpu__ { | ||
cudaq::qvector q(qubit_count); | ||
x(q); | ||
mz(q); | ||
} | ||
}; | ||
|
||
int main() { | ||
// Add a simple bit-flip noise channel to X gate | ||
const double error_probability = 0.1; | ||
|
||
cudaq::bit_flip_channel bit_flip(error_probability); | ||
// Add noise channels to our noise model. | ||
cudaq::noise_model noise_model; | ||
// Apply the bitflip channel to any X-gate on any qubits | ||
noise_model.add_all_qubit_channel<cudaq::types::x>(bit_flip); | ||
|
||
const int qubit_count = 2; | ||
// Due to the impact of noise, our measurements will no longer be uniformly in | ||
// the |11> state. | ||
auto counts = | ||
cudaq::sample({.shots = 1000, .noise = noise_model}, xOp{}, qubit_count); | ||
|
||
// The probability that we get the perfect result (11) should be ~ 0.9 * 0.9 = | ||
// 0.81 | ||
counts.dump(); | ||
return 0; | ||
} |
45 changes: 45 additions & 0 deletions
45
docs/sphinx/snippets/cpp/using/backends/trajectory_observe.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,45 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 - 2025 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. * | ||
******************************************************************************/ | ||
|
||
#include <iostream> | ||
|
||
// [Begin Documentation] | ||
#include <cudaq.h> | ||
|
||
struct xOp { | ||
void operator()() __qpu__ { | ||
cudaq::qubit q; | ||
x(q); | ||
} | ||
}; | ||
|
||
int main() { | ||
// Add a simple bit-flip noise channel to X gate | ||
const double error_probability = 0.1; | ||
|
||
cudaq::bit_flip_channel bit_flip(error_probability); | ||
// Add noise channels to our noise model. | ||
cudaq::noise_model noise_model; | ||
// Apply the bitflip channel to any X-gate on any qubits | ||
noise_model.add_all_qubit_channel<cudaq::types::x>(bit_flip); | ||
|
||
double noisy_exp_val = | ||
cudaq::observe({.noise = noise_model, .num_trajectories = 1024}, xOp{}, | ||
cudaq::spin::z(0)); | ||
|
||
// True expectation: 0.1 - 0.9 = -0.8 (|1> has <Z> of -1 and |1> has <Z> of | ||
// +1) | ||
std::cout << "Noisy <Z> with 1024 trajectories = " << noisy_exp_val << "\n"; | ||
|
||
// Rerun with a higher number of trajectories | ||
noisy_exp_val = | ||
cudaq::observe({.noise = noise_model, .num_trajectories = 8192}, xOp{}, | ||
cudaq::spin::z(0)); | ||
std::cout << "Noisy <Z> with 8192 trajectories = " << noisy_exp_val << "\n"; | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# ============================================================================ # | ||
# Copyright (c) 2022 - 2024 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 Docs] | ||
import cudaq | ||
|
||
# Use the `nvidia` target | ||
cudaq.set_target("nvidia") | ||
|
||
# Let's define a simple kernel that we will add noise to. | ||
qubit_count = 2 | ||
|
||
|
||
@cudaq.kernel | ||
def kernel(qubit_count: int): | ||
qvector = cudaq.qvector(qubit_count) | ||
x(qvector) | ||
mz(qvector) | ||
|
||
|
||
# Add a simple bit-flip noise channel to X gate | ||
error_probability = 0.1 | ||
bit_flip = cudaq.BitFlipChannel(error_probability) | ||
|
||
# Add noise channels to our noise model. | ||
noise_model = cudaq.NoiseModel() | ||
# Apply the bit-flip channel to any X-gate on any qubits | ||
noise_model.add_all_qubit_channel("x", bit_flip) | ||
|
||
# Due to the impact of noise, our measurements will no longer be uniformly | ||
# in the |11> state. | ||
noisy_counts = cudaq.sample(kernel, | ||
qubit_count, | ||
noise_model=noise_model, | ||
shots_count=1000) | ||
|
||
# The probability that we get the perfect result (11) should be ~ 0.9 * 0.9 = 0.81 | ||
noisy_counts.dump() |
44 changes: 44 additions & 0 deletions
44
docs/sphinx/snippets/python/using/backends/trajectory_observe.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,44 @@ | ||
# ============================================================================ # | ||
# Copyright (c) 2022 - 2024 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 Docs] | ||
import cudaq | ||
from cudaq import spin | ||
|
||
# Use the `nvidia` target | ||
cudaq.set_target("nvidia") | ||
|
||
|
||
@cudaq.kernel | ||
def kernel(): | ||
q = cudaq.qubit() | ||
x(q) | ||
|
||
|
||
# Add a simple bit-flip noise channel to X gate | ||
error_probability = 0.1 | ||
bit_flip = cudaq.BitFlipChannel(error_probability) | ||
|
||
# Add noise channels to our noise model. | ||
noise_model = cudaq.NoiseModel() | ||
# Apply the bit-flip channel to any X-gate on any qubits | ||
noise_model.add_all_qubit_channel("x", bit_flip) | ||
|
||
noisy_exp_val = cudaq.observe(kernel, | ||
spin.z(0), | ||
noise_model=noise_model, | ||
num_trajectories=1024).expectation() | ||
# True expectation: 0.1 - 0.9 = -0.8 (|1> has <Z> of -1 and |1> has <Z> of +1) | ||
print("Noisy <Z> with 1024 trajectories =", noisy_exp_val) | ||
|
||
# Rerun with a higher number of trajectories | ||
noisy_exp_val = cudaq.observe(kernel, | ||
spin.z(0), | ||
noise_model=noise_model, | ||
num_trajectories=8192).expectation() | ||
print("Noisy <Z> with 8192 trajectories =", noisy_exp_val) |
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
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
Oops, something went wrong.