Skip to content

Commit

Permalink
Fix guess.rb_decay not to raise an error against bad output
Browse files Browse the repository at this point in the history
  • Loading branch information
itoko committed Dec 4, 2023
1 parent e65e1c6 commit 227896b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion qiskit_experiments/curve_analysis/guess.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,9 @@ def rb_decay(
y = y[valid_inds]
x = x[valid_inds]

if len(x) < 2:
if len(x) == 0:
return 0
if len(x) == 1:
# If number of element is 1, assume y(0) = 1.0 and directly compute alpha.
a = 1.0 - b
return ((y[0] - b) / a) ** (1 / x[0])
Expand Down
6 changes: 6 additions & 0 deletions test/curve_analysis/test_guess.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,9 @@ def test_rb_decay(self, a, b, alpha):
alpha_guess = guess.rb_decay(x, y, b=b)

self.assertAlmostEqual(alpha, alpha_guess, delta=alpha * 0.1)

def test_rb_decay_with_very_bad_output(self):
"""Test if rb decay guess does not raise an error even for very bad outputs."""
x = np.array([1, 2, 3])
y = np.array([0.24, 0.22, 0.23]) # all are below b
guess.rb_decay(x=x, y=y, b=0.25)

0 comments on commit 227896b

Please sign in to comment.