@@ -249,24 +249,6 @@ def _second_order_integral(E: ndarray, eigvals: ndarray, dt: float,
249249 return int_buf
250250
251251
252- def _parse_spectrum (spectrum : Sequence , omega : Sequence , idx : Sequence ) -> ndarray :
253- spectrum = np .asanyarray (spectrum )
254- error = 'Spectrum should be of shape {}, not {}.'
255- shape = (len (idx ),)* (spectrum .ndim - 1 ) + (len (omega ),)
256- if spectrum .shape != shape and spectrum .ndim <= 3 :
257- raise ValueError (error .format (shape , spectrum .shape ))
258-
259- if spectrum .ndim == 1 :
260- # As we broadcast over the noise operators
261- spectrum = spectrum [None , ...]
262- if spectrum .ndim == 3 and not np .allclose (spectrum , spectrum .conj ().swapaxes (0 , 1 )):
263- raise ValueError ('Cross-spectra given but not Hermitian along first two axes' )
264- elif spectrum .ndim > 3 :
265- raise ValueError (f'Expected spectrum to have < 4 dimensions, not { spectrum .ndim } ' )
266-
267- return spectrum
268-
269-
270252def _get_integrand (
271253 spectrum : ndarray ,
272254 omega : ndarray ,
@@ -330,7 +312,7 @@ def _get_integrand(
330312 # Everything simpler if noise operators always on 2nd-to-last axes
331313 filter_function = np .moveaxis (filter_function , source = [- 5 , - 4 ], destination = [- 3 , - 2 ])
332314
333- spectrum = _parse_spectrum (spectrum , omega , idx )
315+ spectrum = util . parse_spectrum (spectrum , omega , idx )
334316 if spectrum .ndim in (1 , 2 ):
335317 if filter_function is not None :
336318 integrand = (filter_function [..., tuple (idx ), tuple (idx ), :]* spectrum )
@@ -342,17 +324,17 @@ def _get_integrand(
342324 # R is not None
343325 if which_pulse == 'correlations' :
344326 if which_FF == 'fidelity' :
345- einsum_str = 'gako,ao,hako->ghao '
327+ einsum_str = 'g...ko,...o,h...ko->gh...o '
346328 else :
347329 # which_FF == 'generalized'
348- einsum_str = 'gako,ao,halo->ghaklo '
330+ einsum_str = 'g...ko,...o,h...lo->gh...klo '
349331 else :
350332 # which_pulse == 'total'
351333 if which_FF == 'fidelity' :
352- einsum_str = 'ako,ao,ako->ao '
334+ einsum_str = '...ko,...o,...ko->...o '
353335 else :
354336 # which_FF == 'generalized'
355- einsum_str = 'ako,ao,alo->aklo '
337+ einsum_str = '...ko,...o,...lo->...klo '
356338
357339 integrand = np .einsum (einsum_str ,
358340 ctrl_left [..., idx , :, :], spectrum , ctrl_right [..., idx , :, :])
@@ -699,7 +681,8 @@ def calculate_control_matrix_from_atomic(
699681 control_matrix = np .zeros (control_matrix_atomic .shape , dtype = complex )
700682 for g in util .progressbar_range (n , show_progressbar = show_progressbar ,
701683 desc = 'Calculating control matrix' ):
702- control_matrix [g ] = expr (phases [g ]* control_matrix_atomic [g ], propagators_liouville [g ])
684+ control_matrix [g ] = expr (phases [g ]* control_matrix_atomic [g ], propagators_liouville [g ],
685+ out = control_matrix [g ])
703686
704687 return control_matrix
705688
@@ -1077,8 +1060,8 @@ def calculate_cumulant_function(
10771060 N , d = pulse .basis .shape [:2 ]
10781061 if spectrum is None and omega is None :
10791062 if decay_amplitudes is None or (frequency_shifts is None and second_order ):
1080- raise ValueError ('Require either spectrum and frequencies or precomputed ' +
1081- 'decay amplitudes (frequency shifts)' )
1063+ raise ValueError ('Require either spectrum and frequencies or precomputed '
1064+ + 'decay amplitudes (frequency shifts)' )
10821065
10831066 if which == 'correlations' and second_order :
10841067 raise ValueError ('Cannot compute correlation cumulant function for second order terms' )
@@ -1251,8 +1234,8 @@ def calculate_decay_amplitudes(
12511234 # which == 'correlations'
12521235 if pulse .is_cached ('omega' ):
12531236 if not np .array_equal (pulse .omega , omega ):
1254- raise ValueError ('Pulse correlation decay amplitudes requested but omega not ' +
1255- 'equal to cached frequencies.' )
1237+ raise ValueError ('Pulse correlation decay amplitudes requested but omega not '
1238+ + 'equal to cached frequencies.' )
12561239
12571240 if pulse .is_cached ('filter_function_pc_gen' ):
12581241 control_matrix = None
@@ -1819,8 +1802,8 @@ def error_transfer_matrix(
18191802 """
18201803 if cumulant_function is None :
18211804 if pulse is None or spectrum is None or omega is None :
1822- raise ValueError ('Require either precomputed cumulant function ' +
1823- 'or pulse, spectrum, and omega as arguments.' )
1805+ raise ValueError ('Require either precomputed cumulant function '
1806+ + 'or pulse, spectrum, and omega as arguments.' )
18241807
18251808 cumulant_function = calculate_cumulant_function (pulse , spectrum , omega ,
18261809 n_oper_identifiers , 'total' , second_order ,
@@ -2020,8 +2003,8 @@ def infidelity(
20202003 try :
20212004 omega_IR = omega .get ('omega_IR' , 2 * np .pi / pulse .tau * 1e-2 )
20222005 except AttributeError :
2023- raise TypeError ('omega should be dictionary with parameters ' +
2024- 'when test_convergence == True.' )
2006+ raise TypeError ('omega should be dictionary with parameters '
2007+ + 'when test_convergence == True.' )
20252008
20262009 omega_UV = omega .get ('omega_UV' , 2 * np .pi / pulse .tau * 1e+2 )
20272010 spacing = omega .get ('spacing' , 'linear' )
@@ -2058,8 +2041,8 @@ def infidelity(
20582041 # but trace tensor plays a role, cf eq. (39). For traceless bases,
20592042 # the trace tensor term reduces to delta_ij.
20602043 traces = pulse .basis .four_element_traces
2061- traces_diag = (sparse .diagonal (traces , axis1 = 2 , axis2 = 3 ).sum (- 1 ) -
2062- sparse .diagonal (traces , axis1 = 1 , axis2 = 3 ).sum (- 1 )).todense ()
2044+ traces_diag = (sparse .diagonal (traces , axis1 = 2 , axis2 = 3 ).sum (- 1 )
2045+ - sparse .diagonal (traces , axis1 = 1 , axis2 = 3 ).sum (- 1 )).todense ()
20632046
20642047 control_matrix = pulse .get_control_matrix (omega , show_progressbar , cache_intermediates )
20652048 filter_function = np .einsum ('ako,blo,kl->abo' ,
@@ -2070,14 +2053,9 @@ def infidelity(
20702053 cache_intermediates = cache_intermediates )
20712054 else :
20722055 # which == 'correlations'
2073- if not pulse .basis .istraceless :
2074- warn ('Calculating pulse correlation fidelities with non-' +
2075- 'traceless basis. The results will be off.' )
2076-
2077- if pulse .is_cached ('omega' ):
2078- if not np .array_equal (pulse .omega , omega ):
2079- raise ValueError ('Pulse correlation infidelities requested ' +
2080- 'but omega not equal to cached frequencies.' )
2056+ if pulse .is_cached ('omega' ) and not np .array_equal (pulse .omega , omega ):
2057+ raise ValueError ('Pulse correlation infidelities requested '
2058+ + 'but omega not equal to cached frequencies.' )
20812059
20822060 filter_function = pulse .get_pulse_correlation_filter_function ()
20832061
@@ -2087,8 +2065,8 @@ def infidelity(
20872065
20882066 if return_smallness :
20892067 if spectrum .ndim > 2 :
2090- raise NotImplementedError ('Smallness parameter only implemented ' +
2091- 'for uncorrelated noise sources' )
2068+ raise NotImplementedError ('Smallness parameter only implemented '
2069+ + 'for uncorrelated noise sources' )
20922070
20932071 T1 = util .integrate (spectrum , omega )/ (2 * np .pi )
20942072 T2 = (pulse .dt * pulse .n_coeffs [idx ]).sum (axis = - 1 )** 2
0 commit comments