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
489 stars 181 forks source link

Error not thrown in `from_state` on wrong backends #1023

Closed anthony-santana closed 3 months ago

anthony-santana commented 9 months ago

Required prerequisites

Describe the bug

The following should produce a "not yet implemented" style error instead of successfully running. Circuit synthesis from a density matrix is not yet supported, but this code inserts a rotation gate into the kernel set to the parameter value of 0.0. This is confusing if you don't inspect the kernel closely to see that the kernel still remains identity.

Steps to reproduce the bug

import cudaq
cudaq.set_target("density-matrix-cpu")

initial_state = np.array([[0,0],[0,1]], dtype=np.complex128)

qubit_count = 1
kernel = cudaq.make_kernel()
qubits = kernel.qalloc(qubit_count)

cudaq.from_state(kernel, qubits, initial_state)
print(kernel)

Produces the kernel

module {
  func.func @__nvqpp__mlirgen____nvqppBuilderKernel_367535629127() attributes {"cudaq-entrypoint"} {
    %cst = arith.constant 0.000000e+00 : f64
    %0 = quake.alloca !quake.veq<1>
    %1 = quake.extract_ref %0[0] : (!quake.veq<1>) -> !quake.ref
    quake.ry (%cst) %1 : (f64, !quake.ref) -> ()
    return
  }
}

Expected behavior

Need a runtime error.

Is this a regression? If it is, put the last known working version (or commit) here.

Not a regression

Environment

Suggestions

No response

bettinaheim commented 3 months ago

Obsolete after the general revision of the state handling.