This is inefficient because Python will evaluate the boolean conditions from left to right, so we should start with the cheapest check and end with the most expensive check. What we actually see is that the cheapest check happens at the end and the most expensive check (requiring an eigendecomposition) happens in the middle.
I suspect there are many functions with subtle inefficiencies like this. I'm creating this issue so that I can make sure to sit down and do a proper audit of these functions, rather than identifying inefficiencies and fixing them piecemeal.
The matrixtools.py file is almost 3000 lines long. Some functions in this file are much less efficient than they could be. For example, the check for a valid density matrix is implemented as follows: https://github.com/sandialabs/pyGSTi/blob/ad0c1a5cbcdf081419d8b68ded0ae0da067da66b/pygsti/tools/matrixtools.py#L128
This is inefficient because Python will evaluate the boolean conditions from left to right, so we should start with the cheapest check and end with the most expensive check. What we actually see is that the cheapest check happens at the end and the most expensive check (requiring an eigendecomposition) happens in the middle.
I suspect there are many functions with subtle inefficiencies like this. I'm creating this issue so that I can make sure to sit down and do a proper audit of these functions, rather than identifying inefficiencies and fixing them piecemeal.