Skip to content

Commit 17373a8

Browse files
authored
Fix an overight: mqpu has a side effect of moving the GPU id (#3279)
Signed-off-by: Thien Nguyen <[email protected]>
1 parent 5d265b5 commit 17373a8

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

python/tests/dynamics/system_models.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,6 @@ class TestCompositeSystems(TestSystem):
126126
sm_dag = create(0)
127127
hamiltonian = 2 * np.pi * number(1) + 2 * np.pi * number(
128128
0) + 2 * np.pi * 0.25 * (sm * a_dag + sm_dag * a)
129-
qubit_state = cp.array([[1.0, 0.0], [0.0, 0.0]], dtype=cp.complex128)
130-
cavity_state = cp.zeros((10, 10), dtype=cp.complex128)
131-
cavity_state[5][5] = 1.0
132-
rho0 = cudaq.State.from_data(cp.kron(cavity_state, qubit_state))
133-
qubit_state = cp.array([1.0, 0.0], dtype=cp.complex128)
134-
cavity_state = cp.zeros(10, dtype=cp.complex128)
135-
cavity_state[5] = 1.0
136-
psi0 = cudaq.State.from_data(cp.kron(cavity_state, qubit_state))
137129
steps = np.linspace(0, 10, 201)
138130
tol = 0.1
139131
# Expected results (from qutips)
@@ -239,8 +231,17 @@ def run_test_simple(self, input_state, integrator):
239231
atol=self.tol)
240232

241233
def run_tests(self, integrator):
242-
self.run_test_simple(self.rho0, integrator)
243-
self.run_test_simple(self.psi0, integrator)
234+
qubit_state = cp.array([[1.0, 0.0], [0.0, 0.0]], dtype=cp.complex128)
235+
cavity_state = cp.zeros((10, 10), dtype=cp.complex128)
236+
cavity_state[5][5] = 1.0
237+
rho0 = cudaq.State.from_data(cp.kron(cavity_state, qubit_state))
238+
self.run_test_simple(rho0, integrator)
239+
240+
qubit_state = cp.array([1.0, 0.0], dtype=cp.complex128)
241+
cavity_state = cp.zeros(10, dtype=cp.complex128)
242+
cavity_state[5] = 1.0
243+
psi0 = cudaq.State.from_data(cp.kron(cavity_state, qubit_state))
244+
self.run_test_simple(psi0, integrator)
244245

245246

246247
class TestCrossResonance(TestSystem):

runtime/cudaq/platform/mqpu/custatevec/GPUEmulatedQPU.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ class GPUEmulatedQPU : public cudaq::QPU {
3232
GPUEmulatedQPU(std::size_t id) : QPU(id) {}
3333

3434
void enqueue(cudaq::QuantumTask &task) override {
35+
// Note: enqueue is executed on the main thread, not the QPU execution
36+
// thread. Hence, do not set the CUDA device here.
3537
cudaq::info("Enqueue Task on QPU {}", qpu_id);
36-
cudaSetDevice(qpu_id);
3738
execution_queue->enqueue(task);
3839
}
3940

0 commit comments

Comments
 (0)