Repository navigation
Bug in slicot TB05AD #11
Description
Activity
@rabraker Do we need to fix before doing the next release of
slycotor is this a minor issue that can wait for later? I'm assuming the latter.I'm not terribly familiar with how the releases work...
The TB05AD function should return correct results if one uses the 'NG' and 'NH' flags (which are the flags used in the the recent PR 177 on python-control).
The bug is "documented" with a known failure in the unit tests. But perhaps a comment about this bug using the balancing option 'AG' could be added to the doc-string?
Copy & paste issues?
I grep'd DGEBAL in the Fortran sources. The results
TB01TDfound the same presumed erroneous structure.TB05ADreported above. I think, from reading the docs, that you are correct. These are permutations that need to be carried over to the B and C matrices, and thus in the same order as those on the A.MB04MDis an alternative version for the DGEBAL routine. It is used internally in SLICOT, in the routineMB05OD.MB05OYis to reverse the effects of DGEBAL, and it should thus work in the reverse order, which it does. It also is only used internally byMB05ODAB13DDhas the correct order, down from N and then up from 1.AB13FD,MB03SDandMB04DYonly use scaling or don't do back transformation, thus no issues here.
The curious thing is that variable names are different on all the pieces where permutation is applied or reversed, whether (assumed) correct or wrong. This may be due to the habit of re-using integer variables with Fortran.
I guess the
TB01TDandTB05ADneed to be corrected. Now trying to find some test cases.Reacted by PedroRegisPOARThis was probably due to the bug that caused some issues present all the way to LAPACK version 3.4.2 and fixed in LAPACK 3.5. It might not be an issue anymore.
Closing as stale, feel free to reopen, if you encounter it with a more recent version.
I recently submitted a pull request for a wrapper for TB05AD. The TB05AD routine is used to efficiently compute the frequency response of a state space system at many frequencies. The first time you call TB05AD.f, the routine will transform the system matrices such that the A matrix is in upper Hessenberg form. These transformed system matrices are returned and should then be used in subsequent calls to TB05AD.f.
One of the job options for TB05AD.f is BALEIG='N' or 'C' or 'B' or 'A'. My wrapper currently only uses options 'N' and 'A'.
When using option 'A', TB05AD.f will balance the A matrix before transforming A to upper Hessenberg form. For certain A matrices, this results in an incorrect frequency response calculation. For example:
I believe this is a bug in TB05AD.f circa line 354. When doing the balancing, TB05AD calls the lapack routine DGEBAL. From what I can tell, TB05AD misinterprets the permutation information provided by DGEBAL. This is similar to the scipy matrix_balance bug which I reported here. Before that bug was fixed, linalg.matrix_balance + linalg.hessenberg and TB05AD would yield the same transformed set of (Abar, Bbar, Cbar), but both would yield the wrong frequency response.
The documentation for DGEBAL says that rows/cols are permuted going from N to IGH+1, then from 1 to LO-1. I think TB05AD does the backwards. In some preliminary tests, replacing line 349 with
JJ = N + 1 - Jseems to fix the issue, but this needs further testing.