Quanlse/QHamiltonian.py
def eigen(self, t: Optional[ndarray] = None):
        """
        Calculate the eigenvalues and eigenvectors of the given Hamiltonian.

        :param t: The time at which the Hamiltonian's eigenvectors and eigenvalues are to compute.
        :return: If t is none, it returns (n, n) Hamiltonian's eigenvalues of shape (n, ) in the
        ascending order and the corresponding eigenvectors matrix of shape (n, n); If t is an (m, ) array,
        it returns list of (m, n) eigenvalues and (m, n, n) eigenvectors.
        """

        # Build cache of the Hamiltonian
        self.buildCache()
        drift = self.driftCache
        ctrl = self.ctrlCache
        wave = self.job.waveCache
        dt = self.dt
        maxDt = self.job.endTimeDt

        def _computeEigen(matrix):
            # Solve eigenvalues problem
            eigenVals, eigenVecs = eig(matrix)
            # Rearrange eigenvalues and eigenvectors in the ascending order
            sortedIndex = eigenVals.argsort()
            eigenVecs = eigenVecs[:, sortedIndex]
            eigenVals = eigenVals[sortedIndex]
            return eigenVals.real, eigenVecs

        if t is None:
            # Solve eigenvalues problem
            vals, vecs = _computeEigen(drift)
        else:
            valsList = []
            vecsList = []
            if len(t) > maxDt:
                raise Error.ArgumentError('The length of time exceeds the number of maximum steps')
            indexDt = floor(t / dt)
            indexDt = indexDt.astype(int)
            for nowDt in indexDt:
                if nowDt >= maxDt:
                    nowDt = nowDt - 1
                ham = drift
                for key in ctrl:
                    ham += ctrl[key] * wave[key][nowDt]
                evals, evecs = _computeEigen(ham)
                valsList.append(evals.tolist())
                vecsList.append(evecs.tolist())
            vals = array(valsList)
            vecs = array(vecsList)

        # Clear cache
        self.clearCache()
        return vals, vecs

        Calculate the eigenvalues and eigenvectors of the given Hamiltonian.

        :param t: The time at which the Hamiltonian's eigenvectors and eigenvalues are to compute.
        :return: If t is none, it returns (n, n) Hamiltonian's eigenvalues of shape (n, ) in the
        ascending order and the corresponding eigenvectors matrix of shape (n, n); If t is an (m, ) array,
        it returns list of (m, n) eigenvalues and (m, n, n) eigenvectors.
        
Calculate the eigenvalues and eigenvectors of the given Hamiltonian.
Calculate the eigenvalues and eigenvectors of the given Hamiltonian .
def eigen(self, t: Optional[ndarray] = None):
        self.buildCache()
        drift = self.driftCache
        ctrl = self.ctrlCache
        wave = self.job.waveCache
        dt = self.dt
        maxDt = self.job.endTimeDt
        def _computeEigen(matrix):
            eigenVals, eigenVecs = eig(matrix)
            sortedIndex = eigenVals.argsort()
            eigenVecs = eigenVecs[:, sortedIndex]
            eigenVals = eigenVals[sortedIndex]
            return eigenVals.real, eigenVecs
        if t is None:
            vals, vecs = _computeEigen(drift)
        else:
            valsList = []
            vecsList = []
            if len(t) > maxDt:
                raise Error.ArgumentError('The length of time exceeds the number of maximum steps')
            indexDt = floor(t / dt)
            indexDt = indexDt.astype(int)
            for nowDt in indexDt:
                if nowDt >= maxDt:
                    nowDt = nowDt - 1
                ham = drift
                for key in ctrl:
                    ham += ctrl[key] * wave[key][nowDt]
                evals, evecs = _computeEigen(ham)
                valsList.append(evals.tolist())
                vecsList.append(evecs.tolist())
            vals = array(valsList)
            vecs = array(vecsList)
        self.clearCache()
        return vals, vecs
def eigen ( self , t : Optional [ ndarray ] = None ) : self . buildCache ( ) drift = self . driftCache ctrl = self . ctrlCache wave = self . job . waveCache dt = self . dt maxDt = self . job . endTimeDt def _computeEigen ( matrix ) : eigenVals , eigenVecs = eig ( matrix ) sortedIndex = eigenVals . argsort ( ) eigenVecs = eigenVecs [ : , sortedIndex ] eigenVals = eigenVals [ sortedIndex ] return eigenVals . real , eigenVecs if t is None : vals , vecs = _computeEigen ( drift ) else : valsList = [ ] vecsList = [ ] if len ( t ) > maxDt : raise Error . ArgumentError ( 'The length of time exceeds the number of maximum steps' ) indexDt = floor ( t / dt ) indexDt = indexDt . astype ( int ) for nowDt in indexDt : if nowDt >= maxDt : nowDt = nowDt - 1 ham = drift for key in ctrl : ham += ctrl [ key ] * wave [ key ] [ nowDt ] evals , evecs = _computeEigen ( ham ) valsList . append ( evals . tolist ( ) ) vecsList . append ( evecs . tolist ( ) ) vals = array ( valsList ) vecs = array ( vecsList ) self . clearCache ( ) return vals , vecs
Calculate the eigenvalues and eigenvectors of the given Hamiltonian.
Calculate the eigenvalues and eigenvectors of the given Hamiltonian .
"""
        Calculate the eigenvalues and eigenvectors of the given Hamiltonian.

        :param t: The time at which the Hamiltonian's eigenvectors and eigenvalues are to compute.
        :return: If t is none, it returns (n, n) Hamiltonian's eigenvalues of shape (n, ) in the
        ascending order and the corresponding eigenvectors matrix of shape (n, n); If t is an (m, ) array,
        it returns list of (m, n) eigenvalues and (m, n, n) eigenvectors.
        """ # Build cache of the Hamiltonian # Solve eigenvalues problem # Rearrange eigenvalues and eigenvectors in the ascending order # Solve eigenvalues problem # Clear cache
If t is none, it returns (n, n) Hamiltonian's eigenvalues of shape (n, ) in the
ascending order and the corresponding eigenvectors matrix of shape (n, n); If t is an (m, ) array,
it returns list of (m, n) eigenvalues and (m, n, n) eigenvectors.
If t is none it returns ( n n ) Hamiltonian ' s eigenvalues of shape ( n ) in the ascending order and the corresponding eigenvectors matrix of shape ( n n ) ; If t is an ( m ) array it returns list of ( m n ) eigenvalues and ( m n n ) eigenvectors .
self
t
Optional[ndarray]
The time at which the Hamiltonian's eigenvectors and eigenvalues are to compute.
The time at which the Hamiltonian ' s eigenvectors and eigenvalues are to compute .