@@ -249,24 +249,6 @@ def _second_order_integral(E: ndarray, eigvals: ndarray, dt: float,
249
249
return int_buf
250
250
251
251
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
-
270
252
def _get_integrand (
271
253
spectrum : ndarray ,
272
254
omega : ndarray ,
@@ -330,7 +312,7 @@ def _get_integrand(
330
312
# Everything simpler if noise operators always on 2nd-to-last axes
331
313
filter_function = np .moveaxis (filter_function , source = [- 5 , - 4 ], destination = [- 3 , - 2 ])
332
314
333
- spectrum = _parse_spectrum (spectrum , omega , idx )
315
+ spectrum = util . parse_spectrum (spectrum , omega , idx )
334
316
if spectrum .ndim in (1 , 2 ):
335
317
if filter_function is not None :
336
318
integrand = (filter_function [..., tuple (idx ), tuple (idx ), :]* spectrum )
@@ -342,17 +324,17 @@ def _get_integrand(
342
324
# R is not None
343
325
if which_pulse == 'correlations' :
344
326
if which_FF == 'fidelity' :
345
- einsum_str = 'gako,ao,hako->ghao '
327
+ einsum_str = 'g...ko,...o,h...ko->gh...o '
346
328
else :
347
329
# which_FF == 'generalized'
348
- einsum_str = 'gako,ao,halo->ghaklo '
330
+ einsum_str = 'g...ko,...o,h...lo->gh...klo '
349
331
else :
350
332
# which_pulse == 'total'
351
333
if which_FF == 'fidelity' :
352
- einsum_str = 'ako,ao,ako->ao '
334
+ einsum_str = '...ko,...o,...ko->...o '
353
335
else :
354
336
# which_FF == 'generalized'
355
- einsum_str = 'ako,ao,alo->aklo '
337
+ einsum_str = '...ko,...o,...lo->...klo '
356
338
357
339
integrand = np .einsum (einsum_str ,
358
340
ctrl_left [..., idx , :, :], spectrum , ctrl_right [..., idx , :, :])
@@ -699,7 +681,8 @@ def calculate_control_matrix_from_atomic(
699
681
control_matrix = np .zeros (control_matrix_atomic .shape , dtype = complex )
700
682
for g in util .progressbar_range (n , show_progressbar = show_progressbar ,
701
683
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 ])
703
686
704
687
return control_matrix
705
688
@@ -1077,8 +1060,8 @@ def calculate_cumulant_function(
1077
1060
N , d = pulse .basis .shape [:2 ]
1078
1061
if spectrum is None and omega is None :
1079
1062
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)' )
1082
1065
1083
1066
if which == 'correlations' and second_order :
1084
1067
raise ValueError ('Cannot compute correlation cumulant function for second order terms' )
@@ -1251,8 +1234,8 @@ def calculate_decay_amplitudes(
1251
1234
# which == 'correlations'
1252
1235
if pulse .is_cached ('omega' ):
1253
1236
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.' )
1256
1239
1257
1240
if pulse .is_cached ('filter_function_pc_gen' ):
1258
1241
control_matrix = None
@@ -1819,8 +1802,8 @@ def error_transfer_matrix(
1819
1802
"""
1820
1803
if cumulant_function is None :
1821
1804
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.' )
1824
1807
1825
1808
cumulant_function = calculate_cumulant_function (pulse , spectrum , omega ,
1826
1809
n_oper_identifiers , 'total' , second_order ,
@@ -2020,8 +2003,8 @@ def infidelity(
2020
2003
try :
2021
2004
omega_IR = omega .get ('omega_IR' , 2 * np .pi / pulse .tau * 1e-2 )
2022
2005
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.' )
2025
2008
2026
2009
omega_UV = omega .get ('omega_UV' , 2 * np .pi / pulse .tau * 1e+2 )
2027
2010
spacing = omega .get ('spacing' , 'linear' )
@@ -2058,8 +2041,8 @@ def infidelity(
2058
2041
# but trace tensor plays a role, cf eq. (39). For traceless bases,
2059
2042
# the trace tensor term reduces to delta_ij.
2060
2043
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 ()
2063
2046
2064
2047
control_matrix = pulse .get_control_matrix (omega , show_progressbar , cache_intermediates )
2065
2048
filter_function = np .einsum ('ako,blo,kl->abo' ,
@@ -2070,14 +2053,9 @@ def infidelity(
2070
2053
cache_intermediates = cache_intermediates )
2071
2054
else :
2072
2055
# 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.' )
2081
2059
2082
2060
filter_function = pulse .get_pulse_correlation_filter_function ()
2083
2061
@@ -2087,8 +2065,8 @@ def infidelity(
2087
2065
2088
2066
if return_smallness :
2089
2067
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' )
2092
2070
2093
2071
T1 = util .integrate (spectrum , omega )/ (2 * np .pi )
2094
2072
T2 = (pulse .dt * pulse .n_coeffs [idx ]).sum (axis = - 1 )** 2
0 commit comments