コード例 #1
0
    def test_read_benchmark_entry(self):
        """Test reading test_log protobuf contents."""

        # Do temp file setup and queue teardown.
        with tempfile.NamedTemporaryFile(prefix='ReadBenchmarkEntryTest',
                                         dir=self.get_temp_dir(),
                                         delete=False) as temp:
            temp.write(_make_dummy_benchmark_report())
        self.addCleanup(lambda: os.remove(temp.name))

        res = benchmark_util.read_benchmark_entry(temp.name)
        self.assertEqual(res.name, "dummy_report")
        self.assertEqual(res.iters, 1234)
        self.assertEqual(res.wall_time, 5678)
コード例 #2
0
    def testBenchmarkRandomCircuit(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))
        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))
        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(
            res.extras.get("n_moments").double_value, params.n_moments)

        assert hasattr(res, 'iters')
        assert hasattr(res, 'wall_time')
コード例 #3
0
    def testBenchmarkGradient(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))
        self.addCleanup(os.remove, proto_file_path)

        bench = GradientBenchmarks(params=params)
        bench.setup()
        bench._benchmark_tfq_differentiator(diff, params)

        res = benchmark_util.read_benchmark_entry(proto_file_path)
        self.assertEqual(res.name, bench_name)
        self.assertEqual(
            res.extras.get("n_qubits").double_value, params.n_qubits)
        self.assertEqual(
            res.extras.get("n_moments").double_value, params.n_moments)
        self.assertEqual(
            res.extras.get("op_density").double_value, params.op_density)
        assert hasattr(res, 'iters')
        assert hasattr(res, 'wall_time')
コード例 #4
0
    def testBenchmarkCliffordCircuitEager(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))
        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))
        self.assertEqual(
            res.extras.get("n_qubits").double_value, params.n_qubits)
        self.assertEqual(
            res.extras.get("n_moments").double_value, params.n_moments)
        self.assertEqual(
            res.extras.get("op_density").double_value, params.op_density)
        assert hasattr(res, 'iters')
        assert hasattr(res, 'wall_time')