NVIDIA / cuda-quantum

C++ and Python support for the CUDA Quantum programming model for heterogeneous quantum-classical workflows
https://nvidia.github.io/cuda-quantum/
Other
497 stars 181 forks source link

Add more tests for control vs. broadcast #913

Open schweitzpgi opened 11 months ago

schweitzpgi commented 11 months ago

I think we should add more tests to see how the compiler is behaving with a wide variety of combinations. Some that I could think of (likely not comprehensive):

__qpu__ void example() {
  cudaq::qreg q(4);
  cudaq::qreg w(2);
  cudaq::qubit t;

  x(q[0], q[1], q[2]); // Broadcast
  x(q); // Broadcast
  x(q, t, w); // Broadcast?
  x<cudaq::ctrl>(q); // Error? Or controls: q[0], q[1], q[2], target: q[3]?
  x<cudaq::ctrl>(q, t); // controls: q[0], q[1], q[2], q[3] target: t
  x<cudaq::ctrl>(t, q); // Error?

  swap(w); // Ok
  swap(q[0], q[1]); // Ok
  swap(q[0], q[1], q[2]); // Error
  swap(q); // Error ? Broadcast (swap(q[0], q[1]) swap(q[2],q[3])?
  swap<cudaq::ctrl>(w); // Error?
  swap<cudaq::ctrl>(q[0], q[1], q[2]); // Error? Or control: q[0], targets: q[1], q[2]
  swap<cudaq::ctrl>(q, w); // controls: q, targets: w[0], w[1]
  swap<cudaq::ctrl>(w, q); // Error?
}

Originally posted by @boschmitt in https://github.com/NVIDIA/cuda-quantum/pull/898#pullrequestreview-1727528562

schweitzpgi commented 11 months ago

See #875 as well.