Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions qiskit_experiments/curve_analysis/curve_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def curve_fit(
upper = [bounds[key][1] for key in param_keys]
param_bounds = (lower, upper)
else:
param_bounds = None
param_bounds = ([-np.inf] * len(param_keys), [np.inf] * len(param_keys))

# Convert fit function
def fit_func(x, *params):
Expand All @@ -94,7 +94,10 @@ def fit_func(x, *params):
else:
param_keys = None
param_p0 = p0
param_bounds = bounds
if bounds:
param_bounds = bounds
else:
param_bounds = ([-np.inf] * len(p0), [np.inf] * len(p0))
fit_func = func

# Check the degrees of freedom is greater than 0
Expand Down
25 changes: 1 addition & 24 deletions qiskit_experiments/library/characterization/t1_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ class T1Analysis(BaseAnalysis):
- :math:`amplitude\_guess`: Determined by :math:`(y_0 - offset\_guess)`
- :math:`offset\_guess`: Determined by the last :math:`y`
- :math:`t1\_guess`: Determined by the mean of the data points

Bounds
- :math:`amplitude\_bounds`: [0, 1]
- :math:`offset\_bounds`: [0, 1]
- :math:`t1\_bounds`: [0, infinity]
"""

@classmethod
Expand All @@ -60,9 +55,6 @@ def _default_options(cls):
t1_guess=None,
amplitude_guess=None,
offset_guess=None,
t1_bounds=None,
amplitude_bounds=None,
offset_bounds=None,
)

# pylint: disable=arguments-differ
Expand All @@ -72,9 +64,6 @@ def _run_analysis(
t1_guess=None,
amplitude_guess=None,
offset_guess=None,
t1_bounds=None,
amplitude_bounds=None,
offset_bounds=None,
plot=True,
ax=None,
) -> Tuple[List[CurveAnalysisResultData], List["matplotlib.figure.Figure"]]:
Expand All @@ -87,11 +76,6 @@ def _run_analysis(
amplitude_guess (float): Optional, an initial guess of the coefficient
of the exponent
offset_guess (float): Optional, an initial guess of the offset
t1_bounds (list of two floats): Optional, lower bound and upper bound to T1
amplitude_bounds (list of two floats): Optional, lower bound and upper
bound to the amplitude
offset_bounds (list of two floats): Optional, lower bound and upper
bound to the offset
plot (bool): Generator plot of exponential fit.
ax (AxesSubplot): Optional, axes to add figure to.

Expand Down Expand Up @@ -120,20 +104,13 @@ def _run_analysis(
offset_guess = ydata[-1]
if amplitude_guess is None:
amplitude_guess = ydata[0] - offset_guess
if t1_bounds is None:
t1_bounds = [0, np.inf]
if amplitude_bounds is None:
amplitude_bounds = [0, 1]
if offset_bounds is None:
offset_bounds = [0, 1]

# Perform fit
def fit_fun(x, a, tau, c):
return a * np.exp(-x / tau) + c

init = {"a": amplitude_guess, "tau": t1_guess, "c": offset_guess}
bounds = {"a": amplitude_bounds, "tau": t1_bounds, "c": offset_bounds}
fit_result = curve_fit(fit_fun, xdata, ydata, init, sigma=sigma, bounds=bounds)
fit_result = curve_fit(fit_fun, xdata, ydata, init, sigma=sigma)

result_data = {
"value": fit_result["popt"][1],
Expand Down
6 changes: 3 additions & 3 deletions test/test_t1.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ def test_t1_parallel_different_analysis_options(self):
delays = list(range(1, 40, 3))

exp0 = T1(0, delays)
exp0.set_analysis_options(t1_bounds=[10, 30])
exp0.set_analysis_options(t1_guess=30)
exp1 = T1(1, delays)
exp1.set_analysis_options(t1_bounds=[100, 200])
exp1.set_analysis_options(t1_guess=1000000)

par_exp = ParallelExperiment([exp0, exp1])
res = par_exp.run(T1Backend([t1, t1]))
Expand All @@ -101,7 +101,7 @@ def test_t1_parallel_different_analysis_options(self):

self.assertEqual(sub_res[0].quality, "good")
self.assertAlmostEqual(sub_res[0].data()["value"], t1, delta=3)
self.assertFalse(sub_res[1].data()["success"])
self.assertEqual(sub_res[1].quality, "bad")

def test_t1_analysis(self):
"""
Expand Down