Skip to content

Commit cf20129

Browse files
Merge pull request #2 from QuantumJaeYoo/fix_format
Fix format
2 parents 2a15f49 + b44d903 commit cf20129

File tree

3 files changed

+29
-34
lines changed

3 files changed

+29
-34
lines changed

benchmarks/scripts/benchmark_cuquantum_ops.py

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
SRC = os.path.dirname(os.path.realpath(__file__))
1515
os.environ['TEST_REPORT_FILE_PREFIX'] = os.path.join(SRC, 'reports/')
1616

17+
1718
@dataclass(frozen=True)
1819
class BenchmarkParams:
1920
"""Frozen dataclass to store the parameters for the benchmark"""
@@ -22,25 +23,31 @@ class BenchmarkParams:
2223
batch_size: int
2324
n_iters: int = 100
2425

26+
2527
_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)
2834

2935
TEST_PARAMS_EXPECTATION = [
3036
_test_params_1,
31-
_test_params_2, # uncomment for depth params
32-
]
37+
_test_params_2, # uncomment for depth params
38+
]
3339
TEST_PARAMS_SAMPLED_EXPECTATION = [
3440
_test_params_1,
35-
_test_params_2, # uncomment for depth params
36-
]
41+
_test_params_2, # uncomment for depth params
42+
]
3743
TEST_PARAMS_SAMPLES = [
3844
_test_params_1,
39-
_test_params_2, # uncomment for depth params
40-
]
45+
_test_params_2, # uncomment for depth params
46+
]
4147
TEST_PARAMS_STATE = [
4248
_test_params_3,
43-
]
49+
]
50+
4451

4552
def _measure_median_runtime(
4653
fn,
@@ -138,7 +145,6 @@ def benchmark_expectation_cpu(self):
138145

139146
return benchmark_values
140147

141-
142148
def benchmark_expectation_cuquantum(self):
143149
"""Benchmark expectation simulator on cpu."""
144150

@@ -192,7 +198,7 @@ def benchmark_expectation_cuquantum(self):
192198
self.report_benchmark(**benchmark_values)
193199

194200
return benchmark_values
195-
201+
196202
def benchmark_sampled_expectation_cpu(self, params=None):
197203
params = params if params else self.params
198204
n_qubits = params.n_qubits
@@ -248,7 +254,7 @@ def benchmark_sampled_expectation_cpu(self, params=None):
248254
self.report_benchmark(**benchmark_values)
249255

250256
return benchmark_values
251-
257+
252258
def benchmark_sampled_expectation_cuquantum(self, params=None):
253259
params = params if params else self.params
254260
n_qubits = params.n_qubits
@@ -424,7 +430,6 @@ def benchmark_state_cpu(self, params=None):
424430

425431
circuit_batch_tensor = util.convert_to_tensor(circuit_batch)
426432

427-
428433
symbol_values_array = np.array(
429434
[[resolver[symbol]
430435
for symbol in symbol_names]
@@ -474,7 +479,6 @@ def benchmark_state_cuquantum(self, params=None):
474479

475480
circuit_batch_tensor = util.convert_to_tensor(circuit_batch)
476481

477-
478482
symbol_values_array = np.array(
479483
[[resolver[symbol]
480484
for symbol in symbol_names]
@@ -512,13 +516,11 @@ def benchmark_state_cuquantum(self, params=None):
512516
return benchmark_values
513517

514518

515-
516-
class SimulateExpectationCuquantumTest(tf.test.TestCase, parameterized.TestCase):
519+
class SimulateExpectationCuquantumTest(tf.test.TestCase,
520+
parameterized.TestCase):
517521
"""Tests tfq_simulate_expectation."""
518522

519-
@parameterized.parameters(
520-
TEST_PARAMS_EXPECTATION
521-
)
523+
@parameterized.parameters(TEST_PARAMS_EXPECTATION)
522524
def test_simulate_expectation_cpu_vs_cuquantum(self, params):
523525
"""Make sure that cuquantum version is faster."""
524526
bench = RandomCircuitBenchmark(params)
@@ -532,9 +534,7 @@ def test_simulate_expectation_cpu_vs_cuquantum(self, params):
532534
# cuQuantum op should be faster than CPU op.
533535
self.assertGreater(cpu_median_time, gpu_median_time)
534536

535-
@parameterized.parameters(
536-
TEST_PARAMS_SAMPLED_EXPECTATION
537-
)
537+
@parameterized.parameters(TEST_PARAMS_SAMPLED_EXPECTATION)
538538
def test_simulate_sampled_expectation_cpu_vs_cuquantum(self, params):
539539
"""Make sure that cpu & gpu(cuquantum) ops have the same results."""
540540
bench = RandomCircuitBenchmark(params)
@@ -548,9 +548,7 @@ def test_simulate_sampled_expectation_cpu_vs_cuquantum(self, params):
548548
# cuQuantum op should be faster than CPU op.
549549
self.assertGreater(cpu_median_time, gpu_median_time)
550550

551-
@parameterized.parameters(
552-
TEST_PARAMS_SAMPLES
553-
)
551+
@parameterized.parameters(TEST_PARAMS_SAMPLES)
554552
def test_simulate_samples_cpu_vs_cuquantum(self, params):
555553
"""Make sure that cpu & gpu(cuquantum) ops have the same results."""
556554
bench = RandomCircuitBenchmark(params)
@@ -564,9 +562,7 @@ def test_simulate_samples_cpu_vs_cuquantum(self, params):
564562
# cuQuantum op should be faster than CPU op.
565563
self.assertGreater(cpu_median_time, gpu_median_time)
566564

567-
@parameterized.parameters(
568-
TEST_PARAMS_STATE
569-
)
565+
@parameterized.parameters(TEST_PARAMS_STATE)
570566
def test_simulate_state_cpu_vs_cuquantum(self, params):
571567
"""Make sure that cpu & gpu(cuquantum) ops have the same results."""
572568
bench = RandomCircuitBenchmark(params)

release/setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ def has_ext_modules(self):
9292
project_name = 'tfq-nightly'
9393
build_version = build_version + '.dev' + str(date.today()).replace('-', '')
9494

95-
9695
setup(
9796
name=project_name,
9897
version=build_version,

tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ def test_sampled_expectation_simple_tf_train(self, use_cuquantum):
404404
# GPU is not set. Ignores this sub-test.
405405
self.skipTest("GPU is not set. Ignoring gpu tests...")
406406
tf.random.set_seed(RANDOM_SEED)
407-
initializer = tf.keras.initializers.RandomUniform(0, 2*np.pi)
407+
initializer = tf.keras.initializers.RandomUniform(0, 2 * np.pi)
408408
bit = cirq.GridQubit(0, 0)
409409
circuit = cirq.Circuit(cirq.rx(sympy.Symbol('theta'))(bit))
410410
layer = sampled_expectation.SampledExpectation(
@@ -447,7 +447,7 @@ def test_simple_param_value_input(self, backend, use_cuquantum):
447447
# GPU is not set. Ignores this sub-test.
448448
self.skipTest("GPU is not set. Ignoring gpu tests...")
449449
tf.random.set_seed(RANDOM_SEED)
450-
initializer = tf.keras.initializers.RandomUniform(0, 2*np.pi)
450+
initializer = tf.keras.initializers.RandomUniform(0, 2 * np.pi)
451451
bit = cirq.GridQubit(0, 0)
452452
symbols = sympy.symbols('x y z')
453453
circuit = _gen_single_bit_rotation_problem(
@@ -498,7 +498,7 @@ def test_simple_op_input(self, backend, use_cuquantum):
498498
# GPU is not set. Ignores this sub-test.
499499
self.skipTest("GPU is not set. Ignoring gpu tests...")
500500
tf.random.set_seed(RANDOM_SEED)
501-
initializer = tf.keras.initializers.RandomUniform(0, 2*np.pi)
501+
initializer = tf.keras.initializers.RandomUniform(0, 2 * np.pi)
502502
bit = cirq.GridQubit(0, 0)
503503
symbols = sympy.symbols('x y z')
504504
ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.Z(bit)]])
@@ -555,7 +555,7 @@ def test_simple_op_and_param_input(self, backend, use_cuquantum):
555555
# GPU is not set. Ignores this sub-test.
556556
self.skipTest("GPU is not set. Ignoring gpu tests...")
557557
tf.random.set_seed(RANDOM_SEED)
558-
initializer = tf.keras.initializers.RandomUniform(0, 2*np.pi)
558+
initializer = tf.keras.initializers.RandomUniform(0, 2 * np.pi)
559559
bit = cirq.GridQubit(0, 0)
560560
symbols = sympy.symbols('x y z')
561561
ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.Z(bit)]])
@@ -616,7 +616,7 @@ def test_dnn_qnn_dnn(self, backend, use_cuquantum):
616616
# GPU is not set. Ignores this sub-test.
617617
self.skipTest("GPU is not set. Ignoring gpu tests...")
618618
tf.random.set_seed(RANDOM_SEED)
619-
initializer = tf.keras.initializers.RandomUniform(0, 2*np.pi)
619+
initializer = tf.keras.initializers.RandomUniform(0, 2 * np.pi)
620620
bit = cirq.GridQubit(0, 0)
621621
symbols = sympy.symbols('x, y, z')
622622
circuits = util.convert_to_tensor([

0 commit comments

Comments
 (0)