3434
3535
3636class RBAnalysis (BaseAnalysis ):
37- """RB Analysis class."""
37+ """RB Analysis class.
3838
39- # pylint: disable = arguments-differ, invalid-name, attribute-defined-outside-init
39+ Analysis Options:
40+ p0: Optional, initial parameter values for curve_fit.
41+ plot: If True generate a plot of fitted data.
42+ ax: Optional, matplotlib axis to add plot to.
43+ """
44+
45+ @classmethod
46+ def _default_options (cls ):
47+ return Options (
48+ p0 = None ,
49+ plot = True ,
50+ ax = None ,
51+ )
52+
53+ # pylint: disable = arguments-differ, invalid-name
4054 def _run_analysis (
4155 self ,
4256 experiment_data ,
@@ -56,21 +70,21 @@ def _run_analysis(
5670 AnalysisResult objects, and ``figures`` may be
5771 None, a single figure, or a list of figures.
5872 """
59- self . _num_qubits = len (experiment_data .data [0 ]["metadata" ]["qubits" ])
73+ num_qubits = len (experiment_data .data [0 ]["metadata" ]["qubits" ])
6074 xdata , ydata , ydata_sigma = self ._extract_data (experiment_data )
6175
6276 def fit_fun (x , a , alpha , b ):
6377 return a * alpha ** x + b
6478
65- p0 = self ._p0 (xdata , ydata )
79+ p0 = self ._p0 (xdata , ydata , num_qubits )
6680 analysis_result = curve_fit (
6781 fit_fun , xdata , ydata , p0 , ydata_sigma , bounds = ([0 , 0 , 0 ], [1 , 1 , 1 ])
6882 )
6983
7084 # Add EPC data
7185 popt = analysis_result ["popt" ]
7286 popt_err = analysis_result ["popt_err" ]
73- scale = (2 ** self . _num_qubits - 1 ) / (2 ** self . _num_qubits )
87+ scale = (2 ** num_qubits - 1 ) / (2 ** num_qubits )
7488 analysis_result ["EPC" ] = scale * (1 - popt [1 ])
7589 analysis_result ["EPC_err" ] = scale * popt_err [1 ] / popt [1 ]
7690 analysis_result ["plabels" ] = ["A" , "alpha" , "B" ]
@@ -83,9 +97,10 @@ def fit_fun(x, a, alpha, b):
8397 analysis_result .plt = plt
8498 return analysis_result , None
8599
86- def _p0 (self , xdata , ydata ):
100+ @staticmethod
101+ def _p0 (xdata , ydata , num_qubits ):
87102 """Initial guess for the fitting function"""
88- fit_guess = [0.95 , 0.99 , 1 / 2 ** self . _num_qubits ]
103+ fit_guess = [0.95 , 0.99 , 1 / 2 ** num_qubits ]
89104 # Use the first two points to guess the decay param
90105 dcliff = xdata [1 ] - xdata [0 ]
91106 dy = (ydata [1 ] - fit_guess [2 ]) / (ydata [0 ] - fit_guess [2 ])
@@ -98,7 +113,8 @@ def _p0(self, xdata, ydata):
98113
99114 return fit_guess
100115
101- def _extract_data (self , experiment_data , ** filters ):
116+ @staticmethod
117+ def _extract_data (experiment_data , ** filters ):
102118 """Extract the base data for the fitter from the experiment data.
103119 Args:
104120 data: the experiment data to analyze
@@ -122,8 +138,8 @@ def _extract_data(self, experiment_data, **filters):
122138 xdata , ydata , ydata_sigma = mean_xy_data (xdata , ydata , ydata_sigma )
123139 return (xdata , ydata , ydata_sigma )
124140
125- @classmethod
126- def _format_plot (cls , ax , analysis_result , add_label = True ):
141+ @staticmethod
142+ def _format_plot (ax , analysis_result , add_label = True ):
127143 """Format curve fit plot"""
128144 # Formatting
129145 ax .tick_params (labelsize = 14 )
0 commit comments