@@ -528,7 +528,7 @@ def set_elementary_errorgens(self, elementary_errorgens, on_missing='ignore', tr
528
528
raise ValueError ("Missing entry for %s in dictionary of elementary errorgens." % str (eeg_lbl ))
529
529
flat_data [i ] = val
530
530
531
- self .block_data [( slice ( None , None ),) * self . block_data . ndim ] = flat_data .reshape (self .block_data .shape )
531
+ self .block_data [: ] = flat_data .reshape (self .block_data .shape )
532
532
self ._truncate_block_data (truncate )
533
533
534
534
#set a flag to indicate that the coefficients (as returned by elementary_errorgens)
@@ -652,7 +652,7 @@ def _block_data_to_params(self, truncate=False):
652
652
in the case of `'other'` blocks.
653
653
"""
654
654
if truncate is False :
655
- ttol = - 1e-15 # (was -1e-12) # truncation tolerance
655
+ ttol = - 1e-14 # (was -1e-12) # truncation tolerance
656
656
elif truncate is True :
657
657
ttol = - _np .inf
658
658
else :
@@ -725,25 +725,24 @@ def _block_data_to_params(self, truncate=False):
725
725
nonzero_block_data = perm_block_data [0 :num_nonzero , 0 :num_nonzero ]
726
726
assert (_np .isclose (_np .linalg .norm (self .block_data ), _np .linalg .norm (nonzero_block_data )))
727
727
728
- #evals, U = _np.linalg.eigh(nonzero_block_data) # works too (assert hermiticity above)
729
- evals , U = _np .linalg .eig (nonzero_block_data )
728
+ evals , U = _np .linalg .eigh (nonzero_block_data )
730
729
731
730
assert (all ([ev > ttol for ev in evals ])), \
732
731
("Lindblad coefficients are not CPTP (truncate == %s)! (largest neg = %g)"
733
- % (str (truncate ), min (evals . real )))
732
+ % (str (truncate ), min (evals )))
734
733
735
734
if ttol < 0 : # if we're truncating and assert above allows *negative* eigenvalues
736
735
#push any slightly negative evals of other_projs positive so that
737
736
# the Cholesky decomp will work.
738
- Ui = _np . linalg . inv ( U )
737
+ Ui = U . T . conj ( )
739
738
pos_evals = evals .clip (1e-16 , None )
740
- nonzero_block_data = _np . dot ( U , _np . dot ( _np . diag ( pos_evals ), Ui ) )
739
+ nonzero_block_data = U @ ( pos_evals [:, None ] * Ui )
741
740
try :
742
741
nonzero_Lmx = _np .linalg .cholesky (nonzero_block_data )
743
742
# if Lmx not postitive definite, try again with 1e-12 (same lines as above)
744
- except _np .linalg .LinAlgError : # pragma: no cover
743
+ except _np .linalg .LinAlgError : # pragma: no cover
745
744
pos_evals = evals .clip (1e-12 , 1e100 ) # pragma: no cover
746
- nonzero_block_data = _np . dot ( U , _np . dot ( _np . diag ( pos_evals ), Ui ) ) # pragma: no cover
745
+ nonzero_block_data = U @ ( pos_evals [:, None ] * Ui ) # pragma: no cover
747
746
nonzero_Lmx = _np .linalg .cholesky (nonzero_block_data )
748
747
else : # truncate == False or == 0 case
749
748
nonzero_Lmx = _np .linalg .cholesky (nonzero_block_data )
@@ -753,15 +752,15 @@ def _block_data_to_params(self, truncate=False):
753
752
Lmx = perm .T @ perm_Lmx @ perm
754
753
755
754
for i in range (num_bels ):
756
- assert (_np .linalg . norm ( _np . imag ( Lmx [i , i ]) ) < IMAG_TOL )
755
+ assert (_np .abs ( Lmx [i , i ]. imag ) < IMAG_TOL )
757
756
params [i , i ] = Lmx [i , i ].real
758
757
for j in range (i ):
759
758
params [i , j ] = Lmx [i , j ].real
760
759
params [j , i ] = Lmx [i , j ].imag
761
760
762
761
elif self ._param_mode == "elements" : # params mx stores block_data (hermitian) directly
763
762
for i in range (num_bels ):
764
- assert (_np .linalg . norm ( _np . imag ( self .block_data [i , i ]) ) < IMAG_TOL )
763
+ assert (_np .abs ( self .block_data [i , i ]. imag ) < IMAG_TOL )
765
764
params [i , i ] = self .block_data [i , i ].real
766
765
for j in range (i ):
767
766
params [i , j ] = self .block_data [i , j ].real
0 commit comments