Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[StateHandling] Implement custatevec state initialization from state vector in device memory #1788

Closed
1tnguyen opened this issue Jun 10, 2024 · 3 comments · Fixed by #2066 · May be fixed by #1982
Closed

[StateHandling] Implement custatevec state initialization from state vector in device memory #1788

1tnguyen opened this issue Jun 10, 2024 · 3 comments · Fixed by #2066 · May be fixed by #1982
Assignees
Labels
TODO Not yet implemented features in the code base
Milestone

Comments

@1tnguyen
Copy link
Collaborator

Implement: FIXME handle case where pointer is a device pointer in CuStateVecCircuitSimulator::addQubitsToState

@schweitzpgi schweitzpgi added the TODO Not yet implemented features in the code base label Jun 10, 2024
@bettinaheim bettinaheim added this to the release 0.8.0 milestone Jul 1, 2024
@sacpis sacpis self-assigned this Jul 21, 2024
@bettinaheim
Copy link
Collaborator

As discussed, the API currently prevents any scenario that would require this support. We hence will just make it a clean error. We'll likely need to come back to it when we expand the API e.g. to integrate with other GPU-accelerated packages.

@amccaskey
Copy link
Collaborator

I might be missing something, but why does the API prevent this scenario? I thought this was possible today, and if so we need an error or an implementation

thrust::host_vector<thrust::complex<double>> hostVector(4);
hostVector[0] = M_SQRT1_2;
hostVector[3] = M_SQRT1_2;
thrust::device_vector<thrust::complex<double>> devState = hostVector;
auto *devPtr = thrust::raw_pointer_cast(&devState[0]);
auto deviceState = cudaq::state::from_data(
      std::make_pair(reinterpret_cast<std::complex<double> *>(devPtr), 4));
auto kernel = [](cudaq::state s) __qpu__ { cudaq::qvector q (s); };
cudaq::get_state(kernel, deviceState).dump()

There's a test for the from_data part in unittests/gpu/get_state_tester.cu.

@1tnguyen
Copy link
Collaborator Author

1tnguyen commented Aug 7, 2024

I might be missing something, but why does the API prevent this scenario? I thought this was possible today, and if so we need an error or an implementation

thrust::host_vector<thrust::complex<double>> hostVector(4);
hostVector[0] = M_SQRT1_2;
hostVector[3] = M_SQRT1_2;
thrust::device_vector<thrust::complex<double>> devState = hostVector;
auto *devPtr = thrust::raw_pointer_cast(&devState[0]);
auto deviceState = cudaq::state::from_data(
      std::make_pair(reinterpret_cast<std::complex<double> *>(devPtr), 4));
auto kernel = [](cudaq::state s) __qpu__ { cudaq::qvector q (s); };
cudaq::get_state(kernel, deviceState).dump()

There's a test for the from_data part in unittests/gpu/get_state_tester.cu.

This is a somewhat 'stale' comment in this addQubitsToState(std::size_t count, const void *stateIn) code path whereby we expect a complex<T>* pointer.

std::complex<ScalarType> *state =
reinterpret_cast<std::complex<ScalarType> *>(

From the current set of qvector constructors, this can only be a host pointer.

The other one below, addQubitsToState(const cudaq::SimulationState &in_state) will handle the above example: handling the qvector(state&) constructor.

Hence, I think we just need to clean up those obsolete comments and add a verification check about this assumption.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TODO Not yet implemented features in the code base
Projects
None yet
5 participants