|
37 | 37 | from cirq.experiments.xeb_sampling import sample_2q_xeb_circuits
|
38 | 38 |
|
39 | 39 |
|
40 |
| -def test_benchmark_2q_xeb_fidelities(): |
| 40 | +@pytest.fixture(scope='module') |
| 41 | +def circuits_cycle_depths_sampled_df(): |
41 | 42 | q0, q1 = cirq.LineQubit.range(2)
|
42 | 43 | circuits = [
|
43 | 44 | rqcg.random_rotations_between_two_qubit_circuit(
|
44 | 45 | q0, q1, depth=50, two_qubit_op_factory=lambda a, b, _: SQRT_ISWAP(a, b), seed=52
|
45 | 46 | )
|
46 | 47 | for _ in range(2)
|
47 | 48 | ]
|
48 |
| - cycle_depths = np.arange(3, 50, 9) |
| 49 | + cycle_depths = np.arange(10, 40 + 1, 10) |
49 | 50 |
|
50 | 51 | sampled_df = sample_2q_xeb_circuits(
|
51 | 52 | sampler=cirq.Simulator(seed=53), circuits=circuits, cycle_depths=cycle_depths
|
52 | 53 | )
|
53 |
| - fid_df = benchmark_2q_xeb_fidelities(sampled_df, circuits, cycle_depths) |
| 54 | + return circuits, cycle_depths, sampled_df |
| 55 | + |
| 56 | + |
| 57 | +@pytest.mark.parametrize('pass_cycle_depths', (True, False)) |
| 58 | +def test_benchmark_2q_xeb_fidelities(circuits_cycle_depths_sampled_df, pass_cycle_depths): |
| 59 | + circuits, cycle_depths, sampled_df = circuits_cycle_depths_sampled_df |
| 60 | + |
| 61 | + if pass_cycle_depths: |
| 62 | + fid_df = benchmark_2q_xeb_fidelities(sampled_df, circuits, cycle_depths) |
| 63 | + else: |
| 64 | + fid_df = benchmark_2q_xeb_fidelities(sampled_df, circuits) |
54 | 65 | assert len(fid_df) == len(cycle_depths)
|
55 |
| - for _, row in fid_df.iterrows(): |
56 |
| - assert row['cycle_depth'] in cycle_depths |
57 |
| - assert row['fidelity'] > 0.98 |
| 66 | + assert sorted(fid_df['cycle_depth'].unique()) == cycle_depths.tolist() |
| 67 | + assert np.all(fid_df['fidelity'] > 0.98) |
58 | 68 |
|
59 | 69 | fit_df = fit_exponential_decays(fid_df)
|
60 | 70 | for _, row in fit_df.iterrows():
|
61 | 71 | assert list(row['cycle_depths']) == list(cycle_depths)
|
62 | 72 | assert len(row['fidelities']) == len(cycle_depths)
|
63 | 73 |
|
64 | 74 |
|
| 75 | +def test_benchmark_2q_xeb_subsample_depths(circuits_cycle_depths_sampled_df): |
| 76 | + circuits, _, sampled_df = circuits_cycle_depths_sampled_df |
| 77 | + cycle_depths = [10, 20] |
| 78 | + fid_df = benchmark_2q_xeb_fidelities(sampled_df, circuits, cycle_depths) |
| 79 | + assert len(fid_df) == len(cycle_depths) |
| 80 | + assert sorted(fid_df['cycle_depth'].unique()) == cycle_depths |
| 81 | + |
| 82 | + cycle_depths = [11, 21] |
| 83 | + with pytest.raises(ValueError): |
| 84 | + _ = benchmark_2q_xeb_fidelities(sampled_df, circuits, cycle_depths) |
| 85 | + |
| 86 | + cycle_depths = [10, 100_000] |
| 87 | + with pytest.raises(ValueError): |
| 88 | + _ = benchmark_2q_xeb_fidelities(sampled_df, circuits, cycle_depths) |
| 89 | + |
| 90 | + cycle_depths = [] |
| 91 | + with pytest.raises(ValueError): |
| 92 | + _ = benchmark_2q_xeb_fidelities(sampled_df, circuits, cycle_depths) |
| 93 | + |
| 94 | + |
65 | 95 | def _gridqubits_to_graph_device(qubits: Iterable[cirq.GridQubit]):
|
66 | 96 | # cirq contrib: routing.gridqubits_to_graph_device
|
67 | 97 | def _manhattan_distance(qubit1: cirq.GridQubit, qubit2: cirq.GridQubit) -> int:
|
|
0 commit comments