From fd1ed94e84561e1ecb78dcbfe8828bfda6214c2c Mon Sep 17 00:00:00 2001 From: Abe Coull <85974725+AbeCoull@users.noreply.github.com> Date: Fri, 22 Nov 2024 08:46:09 -0800 Subject: [PATCH] fix: update numpy random function to use a generator (#274) --- src/braket/default_simulator/density_matrix_simulation.py | 3 ++- src/braket/default_simulator/state_vector_simulation.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/braket/default_simulator/density_matrix_simulation.py b/src/braket/default_simulator/density_matrix_simulation.py index c5cc248d..651beb22 100644 --- a/src/braket/default_simulator/density_matrix_simulation.py +++ b/src/braket/default_simulator/density_matrix_simulation.py @@ -108,7 +108,8 @@ def _apply_operations( return np.reshape(dm_tensor, (2**qubit_count, 2**qubit_count)) def retrieve_samples(self) -> list[int]: - return np.random.choice( + rng_generator = np.random.default_rng() + return rng_generator.choice( self._density_matrix.shape[0], p=self.probabilities, size=self._shots ) diff --git a/src/braket/default_simulator/state_vector_simulation.py b/src/braket/default_simulator/state_vector_simulation.py index ef13604e..1f9f7a01 100644 --- a/src/braket/default_simulator/state_vector_simulation.py +++ b/src/braket/default_simulator/state_vector_simulation.py @@ -107,7 +107,8 @@ def _apply_operations( return np.reshape(final, 2**qubit_count) def retrieve_samples(self) -> list[int]: - return np.random.choice(len(self._state_vector), p=self.probabilities, size=self._shots) + rng_generator = np.random.default_rng() + return rng_generator.choice(len(self._state_vector), p=self.probabilities, size=self._shots) @property def state_vector(self) -> np.ndarray: