-
Notifications
You must be signed in to change notification settings - Fork 131
Description
Summary
Both models of T1 and RB are exponential decays, however their default guesses for parameter values are different. They will benefit from sharing the code that generates default guesses. This is the idea behind what I call in this issue "the guess library", which is the recent file guess.py, consisting of methods for guess generation for various fit functions. The guess library already contains a method for exponential decays (with one parameter, which is the exponent; without amplitude and offset).
For simplicity, from now on I'll assume that RB is a 1-qubit RB.
Default guess for the offset
When there are no SPAM errors, the T1 curve converges to 0 when x tends to infinity, and the RB curve converges to 0.5. This is why the default guess for the offset of RB is currently 0.5.
https://github.com/Qiskit/qiskit-experiments/blob/c3458fbb5e994e7152d27c092b4459b00ddeef00/qiskit_experiments/library/randomized_benchmarking/rb_analysis.py#L48
https://github.com/Qiskit/qiskit-experiments/blob/c3458fbb5e994e7152d27c092b4459b00ddeef00/qiskit_experiments/library/randomized_benchmarking/rb_analysis.py#L116
For T1, on the other hand, the current guess for the offset takes into account SPAM errors by setting the offset guess to y[-1].
https://github.com/Qiskit/qiskit-experiments/blob/c3458fbb5e994e7152d27c092b4459b00ddeef00/qiskit_experiments/library/characterization/t1_analysis.py#L48
https://github.com/Qiskit/qiskit-experiments/blob/c3458fbb5e994e7152d27c092b4459b00ddeef00/qiskit_experiments/library/characterization/t1_analysis.py#L103-L104
The T1 approach makes more sense. In the shared code, I suggest to set the offset guess to y[-1] (unless specified otherwise by the user).
Default guess for the exponent
Here the parameter is alpha for RB and T1 for T1, with the relation alpha = e^(-1/T1). We can still guess one of them, say alpha, in a shared location, and this implies a guess for T1.
The current guess of T1 is just the mean of the delays.
https://github.com/Qiskit/qiskit-experiments/blob/c3458fbb5e994e7152d27c092b4459b00ddeef00/qiskit_experiments/library/characterization/t1_analysis.py#L49
https://github.com/Qiskit/qiskit-experiments/blob/c3458fbb5e994e7152d27c092b4459b00ddeef00/qiskit_experiments/library/characterization/t1_analysis.py#L99-L100
RB extracts the guess for alpha from the two first data points, using the already existing guess of the offset.
https://github.com/Qiskit/qiskit-experiments/blob/c3458fbb5e994e7152d27c092b4459b00ddeef00/qiskit_experiments/library/randomized_benchmarking/rb_analysis.py#L49-L50
https://github.com/Qiskit/qiskit-experiments/blob/c3458fbb5e994e7152d27c092b4459b00ddeef00/qiskit_experiments/library/randomized_benchmarking/rb_analysis.py#L118-L121
By the way we could do this trick with any pair of data points, not necessarily the first two. So in fact this RB approach consists of many sub-options, because it requires to choose the pair of data points to be used.
There is a third approach, which is to use the guess method from the guess library.
https://github.com/Qiskit/qiskit-experiments/blob/c3458fbb5e994e7152d27c092b4459b00ddeef00/qiskit_experiments/curve_analysis/guess.py#L131-L141
https://github.com/Qiskit/qiskit-experiments/blob/c3458fbb5e994e7152d27c092b4459b00ddeef00/qiskit_experiments/curve_analysis/guess.py#L152-L154
We can do it if we take new_y = (y-B)/A, where B is the guess of the offset, which we already have, and A is the guess of the amplitude, which we don't have yet. In the next section we'll see two ways to guess the amplitude. In one of them the guess does not depend on the guess for the exponent; in this case, we can first guess the amplitude, and then use this approach to guess the exponent. Similarly, this approach is applicable if the user provides a guess for the amplitude.
Yet a fourth option to guess the exponent: this option, like the previous one, assumes that we already have a guess for the amplitude. Then we can choose a data point x[i], y[i] for some i and extract alpha from the fit function.
Overall, out of the four options described here, I'm not in favor of the first option. The T1 approach is too heuristic.
Default guess for the amplitude
When x is equal to 0, y is equal to the sum of the amplitude and the offset. This is why, for T1, the guess of the amplitude is y[0] minus the guess of the offset.
https://github.com/Qiskit/qiskit-experiments/blob/c3458fbb5e994e7152d27c092b4459b00ddeef00/qiskit_experiments/library/characterization/t1_analysis.py#L47
https://github.com/Qiskit/qiskit-experiments/blob/c3458fbb5e994e7152d27c092b4459b00ddeef00/qiskit_experiments/library/characterization/t1_analysis.py#L105-L106
RB doesn't assume that the first x is 0. Actually, since we have x[0], and if we already have a guess for the exponent (either because the user provides a guess for the exponent, or because we've applied one of the first two options in the previous section), we can use any data point to extract the amplitude, similarly to the fourth option in the previous section. RB chooses to do it with the first data point.
https://github.com/Qiskit/qiskit-experiments/blob/c3458fbb5e994e7152d27c092b4459b00ddeef00/qiskit_experiments/library/randomized_benchmarking/rb_analysis.py#L46-L47
https://github.com/Qiskit/qiskit-experiments/blob/c3458fbb5e994e7152d27c092b4459b00ddeef00/qiskit_experiments/library/randomized_benchmarking/rb_analysis.py#L126-L127
Here I think the RB approach is what we should adapt in the shared code.
Refactor the guess handling in CurveAnalysis
In RB, the generation of default guesses is done in the method _initial_guess. It is called by _setup_fitting, which overrides these default guesses if the user provides her own guesses. There is a problem here, when the default guess of one parameter depends on the guess of another parameter. Suppose that the user provides a guess for the offset, but not for the exponent. Then, when calculating the default guess of the exponent, we use the default guess of the offset, instead of the user's guess.
Following the same logic, every method in the guess library should receive the user's guess as an input parameter. In general, we have to reconsider the relations between these three: _setup_fitting, _initial_guess, and the guess library. Do we still need _initial_guess, now that we have the guess library, or can we remove it from the CurveAnalysis class?
Sanity checks
RB ensures that the generated guesses are reasonable. For example, it verifies that the guess of the exponent is smaller than 1. If not then it overrides it with 0.99. It does so only for guesses not coming from the user; if the user provides a guess for the exponent which is greater than 1, it is not overridden.
So, in our shared code, we'll have to make the following decisions:
- Do we want to override unphysical guesses?
- If yes, do we want to do it also for user guesses?
Does it really matter?
As far as I know, fitting exponential decays is not sensitive to the initial point.