Skip to content

Commit f81e537

Browse files
committed
modify test to num_samples=100 and atol=1e-4
1 parent 46aa1f0 commit f81e537

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

tensorflow_quantum/core/ops/tfq_simulate_ops_gpu_test.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,21 @@ def test_simulate_expectation_cpu_vs_cuda(self):
6565
circuit_batch_tensor,
6666
symbol_names, symbol_values_array.astype(np.float64),
6767
pauli_sums_tensor),
68-
"CPU"
68+
"CPU",
69+
num_samples=100,
6970
)
7071

7172
cuda_avg_time, res_cuda = measure_average_runtime(
7273
lambda: tfq_simulate_ops_cuda.tfq_simulate_expectation(
7374
circuit_batch_tensor,
7475
symbol_names, symbol_values_array.astype(np.float64),
7576
pauli_sums_tensor),
76-
"CUDA"
77+
"CUDA",
78+
num_samples=100,
7779
)
7880

7981
# The result should be the similar within a tolerance.
80-
np.testing.assert_allclose(res_cpu, res_cuda, atol=1e-5)
82+
np.testing.assert_allclose(res_cpu, res_cuda, atol=1e-4)
8183

8284
# CUDA op should be faster than CPU op.
8385
self.assertGreater(cpu_avg_time, cuda_avg_time)
@@ -107,19 +109,22 @@ def test_simulate_expectation_cpu_vs_cuquantum(self):
107109
circuit_batch_tensor,
108110
symbol_names, symbol_values_array.astype(np.float64),
109111
pauli_sums_tensor),
110-
"CPU"
111-
)
112+
"CPU",
113+
num_samples=100,
112114

115+
)
116+
113117
cuda_avg_time, res_cuda = measure_average_runtime(
114118
lambda: tfq_simulate_ops_cuquantum.tfq_simulate_expectation(
115119
circuit_batch_tensor,
116120
symbol_names, symbol_values_array.astype(np.float64),
117121
pauli_sums_tensor),
118-
"cuQuantum"
122+
"cuQuantum",
123+
num_samples=100,
119124
)
120125

121126
# The result should be the similar within a tolerance.
122-
np.testing.assert_allclose(res_cpu, res_cuda, atol=1e-5)
127+
np.testing.assert_allclose(res_cpu, res_cuda, atol=1e-4)
123128

124129
# cuQuantum op should be faster than CPU op.
125130
self.assertGreater(cpu_avg_time, cuda_avg_time)

0 commit comments

Comments
 (0)