-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix exp_pauli issues on remote simulators and quantum devices (#2226)
* Made exp_pauli work on quantum devices and remote sim * Add more tests * Address CR comments
- Loading branch information
Showing
12 changed files
with
301 additions
and
14 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# ============================================================================ # | ||
# 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. # | ||
# ============================================================================ # | ||
|
||
import cudaq | ||
|
||
|
||
def test_exp_pauli(): | ||
|
||
@cudaq.kernel | ||
def test(): | ||
q = cudaq.qvector(2) | ||
exp_pauli(1.0, q, "XX") | ||
|
||
counts = cudaq.sample(test) | ||
assert '00' in counts | ||
assert '11' in counts | ||
assert not '01' in counts | ||
assert not '10' in counts | ||
|
||
|
||
def test_exp_pauli_param(): | ||
|
||
@cudaq.kernel | ||
def test_param(w: cudaq.pauli_word): | ||
q = cudaq.qvector(2) | ||
exp_pauli(1.0, q, w) | ||
|
||
counts = cudaq.sample(test_param, cudaq.pauli_word("XX")) | ||
assert '00' in counts | ||
assert '11' in counts | ||
assert not '01' in counts | ||
assert not '10' in counts |
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,62 @@ | ||
/******************************************************************************* | ||
* 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. * | ||
******************************************************************************/ | ||
|
||
// clang-format off | ||
// Simulators | ||
// RUN: nvq++ %cpp_std --enable-mlir %s -o %t && %t | FileCheck %s | ||
// RUN: nvq++ %cpp_std --enable-mlir --target remote-mqpu -fkernel-exec-kind=2 %s -o %t && %t | FileCheck %s | ||
// | ||
// Quantum emulators | ||
// RUN: nvq++ %cpp_std --target quantinuum --emulate -fkernel-exec-kind=2 %s -o %t && %t | FileCheck %s | ||
// RUN: nvq++ %cpp_std --target ionq --emulate -fkernel-exec-kind=2 %s -o %t && %t | FileCheck %s | ||
// 2 different IQM machines for 2 different topologies | ||
// RUN: nvq++ %cpp_std --target iqm --iqm-machine Adonis --emulate -fkernel-exec-kind=2 %s -o %t && %t | FileCheck %s | ||
// RUN: nvq++ %cpp_std --target iqm --iqm-machine Apollo --emulate -fkernel-exec-kind=2 %s -o %t && %t | FileCheck %s | ||
// RUN: nvq++ %cpp_std --target oqc --emulate -fkernel-exec-kind=2 %s -o %t && %t | FileCheck %s | ||
// RUN: nvq++ %cpp_std --target anyon --emulate -fkernel-exec-kind=2 %s -o %t && %t | FileCheck %s | ||
// clang-format on | ||
|
||
#include <cudaq.h> | ||
#include <iostream> | ||
|
||
__qpu__ void test() { | ||
cudaq::qvector q(2); | ||
cudaq::exp_pauli(1.0, q, "XX"); | ||
} | ||
|
||
__qpu__ void test_param(cudaq::pauli_word w) { | ||
cudaq::qvector q(2); | ||
cudaq::exp_pauli(1.0, q, w); | ||
} | ||
|
||
void printCounts(cudaq::sample_result& result) { | ||
std::vector<std::string> values{}; | ||
for (auto &&[bits, counts] : result) { | ||
values.push_back(bits); | ||
} | ||
|
||
std::sort(values.begin(), values.end()); | ||
for (auto &&bits : values) { | ||
std::cout << bits << '\n'; | ||
} | ||
} | ||
|
||
int main() { | ||
auto counts = cudaq::sample(test); | ||
printCounts(counts); | ||
|
||
counts = cudaq::sample(test_param, cudaq::pauli_word{"XY"}); | ||
printCounts(counts); | ||
return 0; | ||
} | ||
|
||
// CHECK: 00 | ||
// CHECK: 11 | ||
|
||
// CHECK: 00 | ||
// CHECK: 11 |
Oops, something went wrong.