From ed5f735503b32f66c2e4e132b166822426ce45a2 Mon Sep 17 00:00:00 2001 From: Toshinari Itoko Date: Tue, 28 Nov 2023 21:15:03 +0900 Subject: [PATCH] compute EPLG --- .../layer_fidelity_analysis.py | 15 ++++-- .../test_layer_fidelity.py | 48 +++++++++---------- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/qiskit_experiments/library/randomized_benchmarking/layer_fidelity_analysis.py b/qiskit_experiments/library/randomized_benchmarking/layer_fidelity_analysis.py index 48432702e8..9e9bab5104 100644 --- a/qiskit_experiments/library/randomized_benchmarking/layer_fidelity_analysis.py +++ b/qiskit_experiments/library/randomized_benchmarking/layer_fidelity_analysis.py @@ -186,8 +186,6 @@ def _run_analysis( extra={}, ) - # TODO: Plot LF by chain length for a full 2q-gate chain - # Return combined results analysis_results = [slf_result] + analysis_results return analysis_results, figures @@ -209,6 +207,7 @@ def __init__(self, layers, analyses=None): super().__init__(analyses, flatten_results=True) self.num_layers = len(layers) + self.num_2q_gates = sum(1 if len(qs) == 2 else 0 for lay in layers for qs in lay) def _run_analysis( self, experiment_data: ExperimentData @@ -233,7 +232,15 @@ def _run_analysis( quality=quality_lf, extra={}, ) - + eplg = 1 - (lf ** (1/self.num_2q_gates)) + eplg_result = AnalysisResultData( + name="EPLG", + value=eplg, + chisq=None, + quality=quality_lf, + extra={}, + ) + # Return combined results - analysis_results = [lf_result] + analysis_results + analysis_results = [lf_result, eplg_result] + analysis_results return analysis_results, figures diff --git a/test/library/randomized_benchmarking/test_layer_fidelity.py b/test/library/randomized_benchmarking/test_layer_fidelity.py index 669b4713f9..a461318f3d 100644 --- a/test/library/randomized_benchmarking/test_layer_fidelity.py +++ b/test/library/randomized_benchmarking/test_layer_fidelity.py @@ -44,28 +44,28 @@ def test_experiment_config(self): self.assertNotEqual(exp, loaded_exp) self.assertEqualExtended(exp, loaded_exp) - # def test_invalid_two_qubit_layers(self): - # """Test raise error when creating experiment with invalid configs.""" - # valid_kwargs = { - # "lengths": [10, 20, 30], - # "two_qubit_gate": "cx", - # "one_qubit_basis_gates": ["rz", "sx", "x"], - # } - # # not disjoit - # with self.assertRaises(QiskitError): - # LayerFidelity( - # physical_qubits=(0, 1, 2, 3), - # two_qubit_layers=[[(0, 1), (1, 2)]], - # **valid_kwargs - # ) - # # no 2q-gate on the qubits (FakeManilaV2 has no cx gate on (0, 3)) - # with self.assertRaises(QiskitError): - # LayerFidelity( - # physical_qubits=(0, 1, 2, 3), - # two_qubit_layers=[[(0, 3)]], - # backend=FakeManilaV2(), - # **valid_kwargs - # ) + def test_invalid_two_qubit_layers(self): + """Test raise error when creating experiment with invalid configs.""" + valid_kwargs = { + "lengths": [10, 20, 30], + "two_qubit_gate": "cx", + "one_qubit_basis_gates": ["rz", "sx", "x"], + } + # not disjoit + with self.assertRaises(QiskitError): + LayerFidelity( + physical_qubits=(0, 1, 2, 3), + two_qubit_layers=[[(0, 1), (1, 2)]], + **valid_kwargs + ) + # no 2q-gate on the qubits (FakeManilaV2 has no cx gate on (0, 3)) + with self.assertRaises(QiskitError): + LayerFidelity( + physical_qubits=(0, 1, 2, 3), + two_qubit_layers=[[(0, 3)]], + backend=FakeManilaV2(), + **valid_kwargs + ) def test_roundtrip_serializable(self): """Test round trip JSON serialization""" @@ -190,8 +190,8 @@ def test_backend_with_directed_basis_gates(self): class TestRunLayerFidelity(QiskitExperimentsTestCase, RBTestMixin): """Test for running LayerFidelity on noisy simulator.""" - def test_three_qubit(self): - """Test two qubit RB. Use default basis gates.""" + def test_run_layer_fidelity(self): + """Test layer fidelity RB. Use default basis gates.""" exp = LayerFidelity( physical_qubits=(0, 1, 2, 3), two_qubit_layers=[[(1, 0), (2, 3)], [(1, 2)]],