Skip to content

Commit 643c20a

Browse files
authored
Work around lmfit limiting RBAnalysis to 10,000 Cliffords (#1595)
lmfit (through its asteval dependnecy) limits exponentiation in its expression models to 10,000. The limit is there to avoid denial of service attacks where user input could be substituted into a model and Python integers which are unbounded and could take up exponential amounts of memory. In qiskit-experiments, this case is not a concern. The workaround implemented here is to divide the exponential in the curve by 10 and then exponentiate the result by 10. This change allows up to 100,000 Cliffords which should be enough. The alternative workaround is to change `asteval.astutils.MAX_EXPONENT` to a sufficiently large value. Closes #1594
1 parent 109e317 commit 643c20a

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

qiskit_experiments/library/randomized_benchmarking/rb_analysis.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ class RBAnalysis(curve.CurveAnalysis):
5050
5151
F(x) = a \alpha^x + b
5252
53+
.. note::
54+
55+
The string expression model used by the class is implemented using
56+
:math:`(\alpha^{(x / 10)})^{10}` in order to allow :math:`x` to vary up
57+
to 100,000 without hitting an exponentiation limit of 10,000
58+
imposed by the `LMFIT
59+
<https://lmfit.github.io/lmfit-py/intro.html>`__ fitting framework.
60+
5361
# section: fit_parameters
5462
defpar a:
5563
desc: Height of decay curve.
@@ -73,7 +81,14 @@ def __init__(self):
7381
super().__init__(
7482
models=[
7583
lmfit.models.ExpressionModel(
76-
expr="a * alpha ** x + b",
84+
# NOTE: the `/10` and then `** 10` are done because asteval
85+
# (used by lmfit to evaluate the model expression) limits
86+
# exponents to 10,000 as a security precaution. For gates
87+
# with errors around 1e-4, it is desirable to go beyond
88+
# 10,000 Cliffords. By splitting out the factors of 10 like
89+
# this, we can have `x` go up to 100,000 Cliffords without
90+
# hitting the asteval limit.
91+
expr="a * (alpha ** (x/10)) ** 10 + b",
7792
name="rb_decay",
7893
)
7994
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
fixes:
3+
- |
4+
A workaround was added for a limit on exponentiation imposed by `LMFIT
5+
<https://lmfit.github.io/lmfit-py/intro.html>`__ which prevented
6+
:class:`.RBAnalysis` from working on experiments with Clifford lengths
7+
longer than 10,000. See `#1594
8+
<https://github.com/qiskit-community/qiskit-experiments/issues/1594>`__.

0 commit comments

Comments
 (0)