# How to use from\_state in python cudaq

**URL:** <https://forums.developer.nvidia.com/t/how-to-use-from-state-in-python-cudaq/288478>\
**Category:** CUDA-Q\
**Created:** [April 3, 2024, 10:08pm UTC](https://forums.developer.nvidia.com/t/how-to-use-from-state-in-python-cudaq/288478 "2024-04-03T22:08:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![skordono](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@skordono](https://forums.developer.nvidia.com/u/skordono)\
**Post date:** [April 3, 2024, 10:08pm UTC](https://forums.developer.nvidia.com/t/how-to-use-from-state-in-python-cudaq/288478/1 "2024-04-03T22:08:28Z")

</div>

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](https://github.com/NVIDIA/cuda-quantum/blob/8174e141fcb6dfc8550cafa78ab405a8a5da413d/python/cudaq/kernel/kernel_builder.py#L619)

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).

---

<div class="post-metadata">

**Author:** ![sstanwyck](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@sstanwyck](https://forums.developer.nvidia.com/u/sstanwyck)\
**Post date:** [April 4, 2024, 8:44pm UTC](https://forums.developer.nvidia.com/t/how-to-use-from-state-in-python-cudaq/288478/2 "2024-04-04T20:44:20Z")

</div>

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](https://github.com/NVIDIA/cuda-quantum/issues/1086)

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](https://github.com/NVIDIA/cuda-quantum/discussions)

---

<div class="post-metadata">

**Author:** ![skordono](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@skordono](https://forums.developer.nvidia.com/u/skordono)\
**Post date:** [April 4, 2024, 9:47pm UTC](https://forums.developer.nvidia.com/t/how-to-use-from-state-in-python-cudaq/288478/3 "2024-04-04T21:47:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rogerawong](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/rogerawong/32/531464_2.png) [@rogerawong](https://forums.developer.nvidia.com/u/rogerawong)\
**Post date:** [September 10, 2026, 1:57pm UTC](https://forums.developer.nvidia.com/t/how-to-use-from-state-in-python-cudaq/288478/4 "2026-09-10T13:57:54Z")

</div>

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:

```python
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](https://nvidia.github.io/cuda-quantum/0.15.0/using/examples/building_kernels.html#initializing-states)
