Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions benchmarks/scripts/benchmark_clifford_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,17 @@ class CliffordBenchmarksTest(tf.test.TestCase, parameterized.TestCase):
def test_benchmark_clifford_circuit_eager(self, params):
"""Test that Op constructs and runs correctly."""
proto_file_path = os.path.join(
SRC, "reports/",
"CliffordBenchmarks.benchmark_clifford_circuit_{}_{}_{}".format(
params.n_qubits, params.n_moments, params.batch_size))
SRC, "reports/", "CliffordBenchmarks.benchmark_clifford_circuit_"
f"{params.n_qubits}_{params.n_moments}_{params.batch_size}")
self.addCleanup(os.remove, proto_file_path)

bench = CliffordBenchmarks(params=params)
bench.benchmark_clifford_circuit_eager()

res = benchmark_util.read_benchmark_entry(proto_file_path)
self.assertEqual(
res.name,
"CliffordBenchmarks.benchmark_clifford_circuit_{}_{}_{}".format(
params.n_qubits, params.n_moments, params.batch_size))
res.name, "CliffordBenchmarks.benchmark_clifford_circuit_"
f"{params.n_qubits}_{params.n_moments}_{params.batch_size}")
self.assertEqual(
res.extras.get("n_qubits").double_value, params.n_qubits)
self.assertEqual(
Expand Down Expand Up @@ -115,11 +113,11 @@ def benchmark_clifford_circuit_eager(self):
'batch_size': self.params.batch_size,
"min_time": min(deltas),
}
name = "benchmark_clifford_circuit_{}_{}_{}".format(
self.params.n_qubits, self.params.n_moments, self.params.batch_size)
name = (f"benchmark_clifford_circuit_{self.params.n_qubits}_"
f"{self.params.n_moments}_{self.params.batch_size}")

full_path = os.path.join(os.environ['TEST_REPORT_FILE_PREFIX'],
"{}.{}".format(self.__class__.__name__, name))
f"{self.__class__.__name__}.{name}")
if os.path.exists(full_path):
os.remove(full_path)

Expand Down
16 changes: 8 additions & 8 deletions benchmarks/scripts/benchmark_op_gradients.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ class GradientBenchmarksTest(tf.test.TestCase, parameterized.TestCase):
def test_benchmark_gradient(self, diff, params):
"""Test that op constructs and runs correctly."""

bench_name = "GradientBenchmarks.{}_{}_{}_{}_{}".format(
diff.__class__.__name__, params.n_qubits, params.n_moments,
params.batch_size, params.n_symbols)
proto_file_path = os.path.join(SRC, "reports/", "{}".format(bench_name))
bench_name = (
f"GradientBenchmarks.{diff.__class__.__name__}_"
f"{params.n_qubits}_{params.n_moments}_{params.batch_size}_"
f"{params.n_symbols}")
proto_file_path = os.path.join(SRC, "reports/", bench_name)
self.addCleanup(os.remove, proto_file_path)

bench = GradientBenchmarks(params=params)
Expand Down Expand Up @@ -153,12 +154,11 @@ def _benchmark_tfq_differentiator(self, differentiator, params):
deltas[i] = time.perf_counter() - start

# Name benchmark logs by differentiator classname.
name = "{}_{}_{}_{}_{}".format(differentiator.__class__.__name__,
params.n_qubits, params.n_moments,
params.batch_size, params.n_symbols)
name = (f"{differentiator.__class__.__name__}_{params.n_qubits}_"
f"{params.n_moments}_{params.batch_size}_{params.n_symbols}")

full_path = os.path.join(os.environ['TEST_REPORT_FILE_PREFIX'],
"{}.{}".format(self.__class__.__name__, name))
f"{self.__class__.__name__}.{name}")
if os.path.exists(full_path):
os.remove(full_path)

Expand Down
16 changes: 7 additions & 9 deletions benchmarks/scripts/benchmark_random_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,17 @@ class RandomCircuitBenchmarksTest(tf.test.TestCase, parameterized.TestCase):
def test_benchmark_random_circuit(self, params):
"""Test that Op constructs and runs correctly."""
proto_file_path = os.path.join(
SRC, "reports/",
"RandomCircuitBenchmarks.benchmark_random_circuit_{}_{}_{}".format(
params.n_rows, params.n_cols, params.n_moments))
SRC, "reports/", "RandomCircuitBenchmarks.benchmark_random_circuit_"
f"{params.n_rows}_{params.n_cols}_{params.n_moments}")
self.addCleanup(os.remove, proto_file_path)

bench = RandomCircuitBenchmarks(params=params)
bench.benchmark_random_circuit()

res = benchmark_util.read_benchmark_entry(proto_file_path)
self.assertEqual(
res.name,
"RandomCircuitBenchmarks.benchmark_random_circuit_{}_{}_{}".format(
params.n_rows, params.n_cols, params.n_moments))
res.name, "RandomCircuitBenchmarks.benchmark_random_circuit_"
f"{params.n_rows}_{params.n_cols}_{params.n_moments}")
self.assertEqual(res.extras.get("n_rows").double_value, params.n_rows)
self.assertEqual(res.extras.get("n_cols").double_value, params.n_cols)
self.assertEqual(
Expand Down Expand Up @@ -129,10 +127,10 @@ def benchmark_random_circuit(self):
"min_time": min(deltas),
}

name = "benchmark_random_circuit_{}_{}_{}".format(
self.params.n_rows, self.params.n_cols, self.params.n_moments)
name = (f"benchmark_random_circuit_{self.params.n_rows}_"
f"{self.params.n_cols}_{self.params.n_moments}")
full_path = os.path.join(os.environ['TEST_REPORT_FILE_PREFIX'],
"{}.{}".format(self.__class__.__name__, name))
f"{self.__class__.__name__}.{name}")
if os.path.exists(full_path):
os.remove(full_path)

Expand Down
Loading
Loading