sandialabs / pyGSTi

A python implementation of Gate Set Tomography
http://www.pygsti.info
Apache License 2.0
134 stars 56 forks source link

Audit implementations of functions in ``matrixtools.py``. #429

Closed rileyjmurray closed 1 week ago

rileyjmurray commented 5 months ago

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.

rileyjmurray commented 4 months ago

This is handled in PR #442.

sserita commented 1 week ago

Fixed with #442