Skip to content

Commit 5dab309

Browse files
Use seeded rng to generate regressor test data (#616)
* Use seeded rng to generate regressor test data * Copyright date --------- Co-authored-by: Anton Dekusar <[email protected]>
1 parent 87aafb9 commit 5dab309

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

test/algorithms/regressors/test_neural_network_regressor.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of Qiskit.
22
#
3-
# (C) Copyright IBM 2018, 2022.
3+
# (C) Copyright IBM 2018, 2023.
44
#
55
# This code is licensed under the Apache License, Version 2.0. You may
66
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -69,8 +69,9 @@ def setUp(self):
6969

7070
# pylint: disable=invalid-name
7171
lb, ub = -np.pi, np.pi
72-
self.X = (ub - lb) * np.random.rand(num_samples, 1) + lb
73-
self.y = np.sin(self.X[:, 0]) + eps * (2 * np.random.rand(num_samples) - 1)
72+
rng = np.random.default_rng(101)
73+
self.X = (ub - lb) * rng.random((num_samples, 1)) + lb
74+
self.y = np.sin(self.X[:, 0]) + eps * (2 * rng.random(num_samples) - 1)
7475

7576
def tearDown(self) -> None:
7677
super().tearDown()

test/algorithms/regressors/test_neural_network_regressor_estimator_qnn.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of Qiskit.
22
#
3-
# (C) Copyright IBM 2022.
3+
# (C) Copyright IBM 2022, 2023.
44
#
55
# This code is licensed under the Apache License, Version 2.0. You may
66
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -53,8 +53,9 @@ def setUp(self):
5353

5454
# pylint: disable=invalid-name
5555
lb, ub = -np.pi, np.pi
56-
self.X = (ub - lb) * np.random.rand(num_samples, 1) + lb
57-
self.y = np.sin(self.X[:, 0]) + eps * (2 * np.random.rand(num_samples) - 1)
56+
rng = np.random.default_rng(101)
57+
self.X = (ub - lb) * rng.random((num_samples, 1)) + lb
58+
self.y = np.sin(self.X[:, 0]) + eps * (2 * rng.random(num_samples) - 1)
5859

5960
def _create_regressor(
6061
self, opt, callback=None

test/algorithms/regressors/test_vqr.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of Qiskit.
22
#
3-
# (C) Copyright IBM 2018, 2022.
3+
# (C) Copyright IBM 2018, 2023.
44
#
55
# This code is licensed under the Apache License, Version 2.0. You may
66
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -59,8 +59,9 @@ def setUp(self):
5959

6060
# pylint: disable=invalid-name
6161
lb, ub = -np.pi, np.pi
62-
self.X = (ub - lb) * np.random.rand(num_samples, 1) + lb
63-
self.y = np.sin(self.X[:, 0]) + eps * (2 * np.random.rand(num_samples) - 1)
62+
rng = np.random.default_rng(101)
63+
self.X = (ub - lb) * rng.random((num_samples, 1)) + lb
64+
self.y = np.sin(self.X[:, 0]) + eps * (2 * rng.random(num_samples) - 1)
6465

6566
def tearDown(self) -> None:
6667
super().tearDown()

test/algorithms/regressors/test_vqr_estimator_qnn.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of Qiskit.
22
#
3-
# (C) Copyright IBM 2022.
3+
# (C) Copyright IBM 2022, 2023.
44
#
55
# This code is licensed under the Apache License, Version 2.0. You may
66
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -43,8 +43,9 @@ def setUp(self):
4343

4444
# pylint: disable=invalid-name
4545
lb, ub = -np.pi, np.pi
46-
self.X = (ub - lb) * np.random.rand(num_samples, 1) + lb
47-
self.y = np.sin(self.X[:, 0]) + eps * (2 * np.random.rand(num_samples) - 1)
46+
rng = np.random.default_rng(101)
47+
self.X = (ub - lb) * rng.random((num_samples, 1)) + lb
48+
self.y = np.sin(self.X[:, 0]) + eps * (2 * rng.random(num_samples) - 1)
4849

4950
@data(
5051
# optimizer, has ansatz

0 commit comments

Comments
 (0)