Table of Contents

Pauli gates (CUDA-Q)

Pauli gates implementation using CUDA-Q.

// Compile: nvq++ main.cpp -o main
// Run:     ./main
 
#include <cudaq.h>
 
struct apply_i { __qpu__ void operator()() { cudaq::qubit q;           mz(q); } };
struct apply_x { __qpu__ void operator()() { cudaq::qubit q; x(q);     mz(q); } };
struct apply_y { __qpu__ void operator()() { cudaq::qubit q; y(q);     mz(q); } };
struct apply_z { __qpu__ void operator()() { cudaq::qubit q; h(q); z(q); h(q); mz(q); } };
 
int main() {
    cudaq::sample(apply_i{}).dump();  // ~100% |0>
    cudaq::sample(apply_x{}).dump();  // 100%  |1>
    cudaq::sample(apply_y{}).dump();  // 100%  |1>
    cudaq::sample(apply_z{}).dump();  // 100%  |1>  (Z|+> = |-> -> H -> |1>)
}