14
14
SRC = os .path .dirname (os .path .realpath (__file__ ))
15
15
os .environ ['TEST_REPORT_FILE_PREFIX' ] = os .path .join (SRC , 'reports/' )
16
16
17
+
17
18
@dataclass (frozen = True )
18
19
class BenchmarkParams :
19
20
"""Frozen dataclass to store the parameters for the benchmark"""
@@ -22,25 +23,31 @@ class BenchmarkParams:
22
23
batch_size : int
23
24
n_iters : int = 100
24
25
26
+
25
27
_test_params_1 = BenchmarkParams (n_qubits = 20 , n_moments = 15 , batch_size = 5 )
26
- _test_params_2 = BenchmarkParams (n_qubits = 21 , n_moments = 25 , batch_size = 5 ) # more depth
27
- _test_params_3 = BenchmarkParams (n_qubits = 22 , n_moments = 15 , batch_size = 5 , n_iters = 10 )
28
+ _test_params_2 = BenchmarkParams (n_qubits = 21 , n_moments = 25 ,
29
+ batch_size = 5 ) # more depth
30
+ _test_params_3 = BenchmarkParams (n_qubits = 22 ,
31
+ n_moments = 15 ,
32
+ batch_size = 5 ,
33
+ n_iters = 10 )
28
34
29
35
TEST_PARAMS_EXPECTATION = [
30
36
_test_params_1 ,
31
- _test_params_2 , # uncomment for depth params
32
- ]
37
+ _test_params_2 , # uncomment for depth params
38
+ ]
33
39
TEST_PARAMS_SAMPLED_EXPECTATION = [
34
40
_test_params_1 ,
35
- _test_params_2 , # uncomment for depth params
36
- ]
41
+ _test_params_2 , # uncomment for depth params
42
+ ]
37
43
TEST_PARAMS_SAMPLES = [
38
44
_test_params_1 ,
39
- _test_params_2 , # uncomment for depth params
40
- ]
45
+ _test_params_2 , # uncomment for depth params
46
+ ]
41
47
TEST_PARAMS_STATE = [
42
48
_test_params_3 ,
43
- ]
49
+ ]
50
+
44
51
45
52
def _measure_median_runtime (
46
53
fn ,
@@ -138,7 +145,6 @@ def benchmark_expectation_cpu(self):
138
145
139
146
return benchmark_values
140
147
141
-
142
148
def benchmark_expectation_cuquantum (self ):
143
149
"""Benchmark expectation simulator on cpu."""
144
150
@@ -192,7 +198,7 @@ def benchmark_expectation_cuquantum(self):
192
198
self .report_benchmark (** benchmark_values )
193
199
194
200
return benchmark_values
195
-
201
+
196
202
def benchmark_sampled_expectation_cpu (self , params = None ):
197
203
params = params if params else self .params
198
204
n_qubits = params .n_qubits
@@ -248,7 +254,7 @@ def benchmark_sampled_expectation_cpu(self, params=None):
248
254
self .report_benchmark (** benchmark_values )
249
255
250
256
return benchmark_values
251
-
257
+
252
258
def benchmark_sampled_expectation_cuquantum (self , params = None ):
253
259
params = params if params else self .params
254
260
n_qubits = params .n_qubits
@@ -424,7 +430,6 @@ def benchmark_state_cpu(self, params=None):
424
430
425
431
circuit_batch_tensor = util .convert_to_tensor (circuit_batch )
426
432
427
-
428
433
symbol_values_array = np .array (
429
434
[[resolver [symbol ]
430
435
for symbol in symbol_names ]
@@ -474,7 +479,6 @@ def benchmark_state_cuquantum(self, params=None):
474
479
475
480
circuit_batch_tensor = util .convert_to_tensor (circuit_batch )
476
481
477
-
478
482
symbol_values_array = np .array (
479
483
[[resolver [symbol ]
480
484
for symbol in symbol_names ]
@@ -512,13 +516,11 @@ def benchmark_state_cuquantum(self, params=None):
512
516
return benchmark_values
513
517
514
518
515
-
516
- class SimulateExpectationCuquantumTest ( tf . test . TestCase , parameterized .TestCase ):
519
+ class SimulateExpectationCuquantumTest ( tf . test . TestCase ,
520
+ parameterized .TestCase ):
517
521
"""Tests tfq_simulate_expectation."""
518
522
519
- @parameterized .parameters (
520
- TEST_PARAMS_EXPECTATION
521
- )
523
+ @parameterized .parameters (TEST_PARAMS_EXPECTATION )
522
524
def test_simulate_expectation_cpu_vs_cuquantum (self , params ):
523
525
"""Make sure that cuquantum version is faster."""
524
526
bench = RandomCircuitBenchmark (params )
@@ -532,9 +534,7 @@ def test_simulate_expectation_cpu_vs_cuquantum(self, params):
532
534
# cuQuantum op should be faster than CPU op.
533
535
self .assertGreater (cpu_median_time , gpu_median_time )
534
536
535
- @parameterized .parameters (
536
- TEST_PARAMS_SAMPLED_EXPECTATION
537
- )
537
+ @parameterized .parameters (TEST_PARAMS_SAMPLED_EXPECTATION )
538
538
def test_simulate_sampled_expectation_cpu_vs_cuquantum (self , params ):
539
539
"""Make sure that cpu & gpu(cuquantum) ops have the same results."""
540
540
bench = RandomCircuitBenchmark (params )
@@ -548,9 +548,7 @@ def test_simulate_sampled_expectation_cpu_vs_cuquantum(self, params):
548
548
# cuQuantum op should be faster than CPU op.
549
549
self .assertGreater (cpu_median_time , gpu_median_time )
550
550
551
- @parameterized .parameters (
552
- TEST_PARAMS_SAMPLES
553
- )
551
+ @parameterized .parameters (TEST_PARAMS_SAMPLES )
554
552
def test_simulate_samples_cpu_vs_cuquantum (self , params ):
555
553
"""Make sure that cpu & gpu(cuquantum) ops have the same results."""
556
554
bench = RandomCircuitBenchmark (params )
@@ -564,9 +562,7 @@ def test_simulate_samples_cpu_vs_cuquantum(self, params):
564
562
# cuQuantum op should be faster than CPU op.
565
563
self .assertGreater (cpu_median_time , gpu_median_time )
566
564
567
- @parameterized .parameters (
568
- TEST_PARAMS_STATE
569
- )
565
+ @parameterized .parameters (TEST_PARAMS_STATE )
570
566
def test_simulate_state_cpu_vs_cuquantum (self , params ):
571
567
"""Make sure that cpu & gpu(cuquantum) ops have the same results."""
572
568
bench = RandomCircuitBenchmark (params )
0 commit comments