How to use from_state in python cudaq

I am trying to call cuda.from_state but I am getting the error “AttributeError: module ‘cudaq’ has no attribute ‘from_state’”. Even more odd, when I try to search the source code, I see that this method is not yet implemented in this file: cuda-quantum/python/cudaq/kernel/kernel_builder.py at 8174e141fcb6dfc8550cafa78ab405a8a5da413d · NVIDIA/cuda-quantum · GitHub

What is the right way to construct a kernel using a wavefunction as an array?

I am running on ubuntu using the docker image nvcr.io/nvidia/nightly/cuda-quantum:latest (I just updated my container to ensure I have the latest code).

Hi! A reimplementation of from_state() for the new and improved Python API is WIP: [RFC] [Language] Quantum allocation with state initialization · Issue #1086 · NVIDIA/cuda-quantum · GitHub

This forum is primarily for the cuQuantum libraries rather than CUDA-Q. Would you be willing to post this and future questions as a Discussion on the GitHub? That is checked and responded to regularly by the CUDA-Q team: NVIDIA/cuda-quantum · Discussions · GitHub

Excellent, that is very helpful. Thank you! I can post there too but I will catch up to speed on the status of that RFC etc first.

For anyone finding this post in 2026, the feature shipped in 0.8.0 (Aug 2024) with a slightly different form and it’s still the way it’s done in 0.15.0. cudaq.from_state is gone. What you do now is pass the starting state when allocating the qubits.

If you have a list of amplitudes, that would look like this:

import cudaq

c = [0.70710678 + 0j, 0., 0., 0.70710678]

@cudaq.kernel
def k(vec: list[complex]):
    q = cudaq.qvector(vec)

counts = cudaq.sample(k, c, shots_count=1000)

That gets you a 2-qubit Bell state from the amplitudes.

You can provide the state as:

  • a captured Python list
  • a NumPy array
  • a cudaq.amplitudes([...]) object
  • a cudaq.State returned by cudaq.get_state(other_kernel).

These are documented in “Initializing States”, Building Kernels — NVIDIA CUDA-Q documentation