Skip to content

Commit c68d14f

Browse files
committed
Remove memory_parsimonious option for frequency shifts
Doesn't make much sense since we cannot factor the second order filter function into control matrices as in the first order case. In princinple, one can still loop the integration over one basis axis, but this is a bit tedious and not pretty to implement, so we leave it for now.
1 parent 5ff308c commit c68d14f

File tree

3 files changed

+19
-55
lines changed

3 files changed

+19
-55
lines changed

filter_functions/numeric.py

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,9 +1037,11 @@ def calculate_cumulant_function(
10371037

10381038
if second_order:
10391039
if frequency_shifts is None:
1040+
if memory_parsimonious:
1041+
warn('Memory parsimonious calculation not implemented for frequency shifts.')
1042+
10401043
frequency_shifts = calculate_frequency_shifts(pulse, spectrum, omega,
1041-
n_oper_identifiers, show_progressbar,
1042-
memory_parsimonious)
1044+
n_oper_identifiers, show_progressbar)
10431045

10441046
if frequency_shifts.shape != decay_amplitudes.shape:
10451047
raise ValueError('Frequency shifts not same shape as decay amplitudes')
@@ -1236,8 +1238,7 @@ def calculate_frequency_shifts(
12361238
spectrum: ndarray,
12371239
omega: Coefficients,
12381240
n_oper_identifiers: Optional[Sequence[str]] = None,
1239-
show_progressbar: bool = False,
1240-
memory_parsimonious: bool = False
1241+
show_progressbar: bool = False
12411242
) -> ndarray:
12421243
r"""
12431244
Get the frequency shifts :math:`\Delta_{\alpha\beta, kl}` for noise
@@ -1262,18 +1263,6 @@ def calculate_frequency_shifts(
12621263
the frequency shifts. The default is all.
12631264
show_progressbar: bool, optional
12641265
Show a progress bar for the calculation.
1265-
memory_parsimonious: bool, optional
1266-
For large dimensions, the integrand
1267-
1268-
.. math::
1269-
1270-
F_{\alpha\beta, kl}^{(2)}(\omega)S_{\alpha\beta}(\omega)
1271-
1272-
can consume quite a large amount of memory if set up for all
1273-
:math:`\alpha,\beta,k,l` at once. If ``True``, it is only set up
1274-
and integrated for a single :math:`k` at a time and looped over.
1275-
This is slower but requires much less memory. The default is
1276-
``False``.
12771266
12781267
Raises
12791268
------
@@ -1309,15 +1298,12 @@ def calculate_frequency_shifts(
13091298
calculate_pulse_correlation_filter_function
13101299
"""
13111300
idx = util.get_indices_from_identifiers(pulse, n_oper_identifiers, 'noise')
1312-
if not memory_parsimonious:
1313-
filter_function_2 = pulse.get_filter_function(omega, order=2,
1314-
show_progressbar=show_progressbar)
1315-
integrand = _get_integrand(spectrum, omega, idx, which_pulse='total',
1316-
which_FF='generalized', filter_function=filter_function_2)
1317-
frequency_shifts = util.integrate(integrand, omega)/(2*np.pi)
1318-
return frequency_shifts
1319-
1320-
raise NotImplementedError
1301+
filter_function_2 = pulse.get_filter_function(omega, order=2,
1302+
show_progressbar=show_progressbar)
1303+
integrand = _get_integrand(spectrum, omega, idx, which_pulse='total', which_FF='generalized',
1304+
filter_function=filter_function_2)
1305+
frequency_shifts = util.integrate(integrand, omega)/(2*np.pi)
1306+
return frequency_shifts
13211307

13221308

13231309
@util.parse_which_FF_parameter
@@ -1387,7 +1373,6 @@ def calculate_second_order_filter_function(
13871373
n_coeffs: Sequence[Coefficients],
13881374
dt: Coefficients,
13891375
intermediates: Optional[Dict[str, ndarray]] = None,
1390-
memory_parsimonious: bool = False,
13911376
show_progressbar: bool = False
13921377
) -> ndarray:
13931378
r"""Calculate the second order filter function for frequency shifts.
@@ -1423,21 +1408,6 @@ def calculate_second_order_filter_function(
14231408
Intermediate terms of the calculation of the control matrix that
14241409
can be reused here. If None (default), they are computed from
14251410
scratch.
1426-
memory_parsimonious: bool, optional
1427-
1428-
.. warning:: Not implemented.
1429-
1430-
For large dimensions, the integrand
1431-
1432-
.. math::
1433-
1434-
F_{\alpha\beta, kl}^{(2)}(\omega)S_{\alpha\beta}(\omega)
1435-
1436-
can consume quite a large amount of memory if set up for all
1437-
:math:`\alpha,\beta,k,l` at once. If ``True``, it is only set up
1438-
and integrated for a single :math:`k` at a time and looped over.
1439-
This is slower but requires much less memory. The default is
1440-
``False``.
14411411
show_progressbar: bool, optional
14421412
Show a progress bar for the calculation.
14431413

filter_functions/pulse_sequence.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,8 +705,7 @@ def cache_filter_function(
705705
# order == 2
706706
filter_function = numeric.calculate_second_order_filter_function(
707707
self.eigvals, self.eigvecs, self.propagators, omega, self.basis,
708-
self.n_opers, self.n_coeffs, self.dt, memory_parsimonious=False,
709-
show_progressbar=show_progressbar, intermediates=self._intermediates
708+
self.n_opers, self.n_coeffs, self.dt, self._intermediates, show_progressbar
710709
)
711710

712711
self.omega = omega

tests/test_core.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -675,9 +675,8 @@ def test_second_order_filter_function(self):
675675
# Test caching
676676
F_2 = pulse.get_filter_function(omega, order=2)
677677
F_3 = numeric.calculate_second_order_filter_function(
678-
pulse.eigvals, pulse.eigvecs, pulse.propagators, omega, pulse.basis,
679-
pulse.n_opers, pulse.n_coeffs, pulse.dt, memory_parsimonious=False,
680-
show_progressbar=False, intermediates=None
678+
pulse.eigvals, pulse.eigvecs, pulse.propagators, omega, pulse.basis, pulse.n_opers,
679+
pulse.n_coeffs, pulse.dt, show_progressbar=False, intermediates=None
681680
)
682681
# Make sure first and second order are of same order of magnitude
683682
rel = np.linalg.norm(F) / np.linalg.norm(F_1)
@@ -853,15 +852,6 @@ def test_calculate_decay_amplitudes(self):
853852
with self.assertRaises(ValueError):
854853
numeric.calculate_decay_amplitudes(pulse, np.tile(spectrum, [1]*i), omega)
855854

856-
def test_calculate_frequency_shifts(self):
857-
"""Test raises of numeric.calculate_frequency_shifts"""
858-
pulse = testutil.rand_pulse_sequence(2, 1, 1, 1)
859-
omega = rng.standard_normal(43)
860-
spectrum = rng.standard_normal(43)
861-
with self.assertRaises(NotImplementedError):
862-
numeric.calculate_frequency_shifts(pulse, spectrum, omega,
863-
memory_parsimonious=True)
864-
865855
def test_cumulant_function(self):
866856
pulse = testutil.rand_pulse_sequence(2, 1, 1, 1)
867857
omega = rng.standard_normal(43)
@@ -895,6 +885,11 @@ def test_cumulant_function(self):
895885
numeric.calculate_cumulant_function(pulse, spectrum, omega, second_order=True,
896886
decay_amplitudes=Gamma[1:])
897887

888+
with self.assertWarns(UserWarning):
889+
# Memory parsimonious only works for decay amplitudes
890+
numeric.calculate_cumulant_function(pulse, spectrum, omega, second_order=True,
891+
memory_parsimonious=True)
892+
898893
for d in [2, *rng.integers(2, 7, 5)]:
899894
pulse = testutil.rand_pulse_sequence(d, 3, 2, 2)
900895
omega = util.get_sample_frequencies(pulse, n_samples=42)

0 commit comments

Comments
 (0)