34
34
35
35
36
36
class RBAnalysis (BaseAnalysis ):
37
- """RB Analysis class."""
37
+ """RB Analysis class.
38
38
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
40
54
def _run_analysis (
41
55
self ,
42
56
experiment_data ,
@@ -56,21 +70,21 @@ def _run_analysis(
56
70
AnalysisResult objects, and ``figures`` may be
57
71
None, a single figure, or a list of figures.
58
72
"""
59
- self . _num_qubits = len (experiment_data .data [0 ]["metadata" ]["qubits" ])
73
+ num_qubits = len (experiment_data .data [0 ]["metadata" ]["qubits" ])
60
74
xdata , ydata , ydata_sigma = self ._extract_data (experiment_data )
61
75
62
76
def fit_fun (x , a , alpha , b ):
63
77
return a * alpha ** x + b
64
78
65
- p0 = self ._p0 (xdata , ydata )
79
+ p0 = self ._p0 (xdata , ydata , num_qubits )
66
80
analysis_result = curve_fit (
67
81
fit_fun , xdata , ydata , p0 , ydata_sigma , bounds = ([0 , 0 , 0 ], [1 , 1 , 1 ])
68
82
)
69
83
70
84
# Add EPC data
71
85
popt = analysis_result ["popt" ]
72
86
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 )
74
88
analysis_result ["EPC" ] = scale * (1 - popt [1 ])
75
89
analysis_result ["EPC_err" ] = scale * popt_err [1 ] / popt [1 ]
76
90
analysis_result ["plabels" ] = ["A" , "alpha" , "B" ]
@@ -83,9 +97,10 @@ def fit_fun(x, a, alpha, b):
83
97
analysis_result .plt = plt
84
98
return analysis_result , None
85
99
86
- def _p0 (self , xdata , ydata ):
100
+ @staticmethod
101
+ def _p0 (xdata , ydata , num_qubits ):
87
102
"""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 ]
89
104
# Use the first two points to guess the decay param
90
105
dcliff = xdata [1 ] - xdata [0 ]
91
106
dy = (ydata [1 ] - fit_guess [2 ]) / (ydata [0 ] - fit_guess [2 ])
@@ -98,7 +113,8 @@ def _p0(self, xdata, ydata):
98
113
99
114
return fit_guess
100
115
101
- def _extract_data (self , experiment_data , ** filters ):
116
+ @staticmethod
117
+ def _extract_data (experiment_data , ** filters ):
102
118
"""Extract the base data for the fitter from the experiment data.
103
119
Args:
104
120
data: the experiment data to analyze
@@ -122,8 +138,8 @@ def _extract_data(self, experiment_data, **filters):
122
138
xdata , ydata , ydata_sigma = mean_xy_data (xdata , ydata , ydata_sigma )
123
139
return (xdata , ydata , ydata_sigma )
124
140
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 ):
127
143
"""Format curve fit plot"""
128
144
# Formatting
129
145
ax .tick_params (labelsize = 14 )
0 commit comments