CNOT gate implementation using CUDA-Q. The example prepares the Bell state $\lvert\Phi^+\rangle = \frac{1}{\sqrt{2}}(\lvert 00\rangle + \lvert 11\rangle)$.
// Compile: nvq++ main.cpp -o main // Run: ./main #include <cudaq.h> struct kernel { __qpu__ void operator()() { cudaq::qvector<2> q; h(q[0]); // |00> -> |+0> cx(q[0], q[1]); // CNOT -> Bell state |Phi+> mz(q); } }; int main() { auto counts = cudaq::sample(kernel{}); counts.dump(); // ~50% |00>, ~50% |11> }