Skip to content

Commit

Permalink
Test calc_cumulant_function for R=None and F=None
Browse files Browse the repository at this point in the history
  • Loading branch information
thangleiter committed Jun 19, 2020
1 parent 9a88506 commit 2a54499
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 7 deletions.
4 changes: 2 additions & 2 deletions tests/test_precision.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ def test_integration(self):
S = spectrum
elif i == 1:
S = spectrum[idx]
elif i == 3:
S = spectrum[idx[None, :], idx]
elif i == 2:
S = spectrum[idx[None, :], idx[:, None]]

R_1 = numeric._get_integrand(S, omega, idx,
which_pulse='total',
Expand Down
72 changes: 67 additions & 5 deletions tests/test_sequencing.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,8 @@ def test_concatenation_periodic(self):

def test_pulse_correlations(self):
"""Test calculating pulse correlation quantities."""
for d, n_dt in zip(testutil.rng.randint(2, 9, 11),
testutil.rng.randint(1, 11, 11)):
for d, n_dt in zip(testutil.rng.randint(2, 7, 11),
testutil.rng.randint(1, 5, 11)):
pulses = [testutil.rand_pulse_sequence(d, n_dt, 1, 2)
for _ in range(testutil.rng.randint(2, 7))]
for pulse in pulses[1:]:
Expand Down Expand Up @@ -548,13 +548,21 @@ def test_pulse_correlations(self):
numeric.calculate_decay_amplitudes,
numeric.calculate_cumulant_function]

R = pulse.get_control_matrix(omega)
R_pc = pulse.get_pulse_correlation_control_matrix()
F = pulse.get_filter_function(omega)
F_kl = pulse.get_filter_function(omega, 'generalized')
F_pc = pulse.get_pulse_correlation_filter_function()
F_pc_kl = pulse.get_pulse_correlation_filter_function(
'generalized')

for i, spectrum in enumerate(spectra):
if i == 0:
S = spectrum
elif i == 1:
S = spectrum[idx]
elif i == 3:
S = spectrum[idx[None, :], idx]
elif i == 2:
S = spectrum[idx[None, :], idx[:, None]]

for func in funcs:
with self.assertRaises(util.CalculationError):
Expand All @@ -564,14 +572,68 @@ def test_pulse_correlations(self):
with self.assertRaises(ValueError):
func(pulse, S, omega + 1, which='correlations')

pulse._R = R
pulse._R_pc = R_pc
correl = func(pulse, S, omega, identifiers,
which='correlations')
total = func(pulse, S, omega, identifiers,
which='total')
pulse._R = None
pulse._R_pc = None

self.assertArrayAlmostEqual(correl.sum((0, 1)), total,
atol=1e-14)

pulse._F = F
pulse._F_kl = F_kl
pulse._F_pc = F_pc
pulse._F_pc_kl = F_pc_kl
correl = func(pulse, S, omega, identifiers,
which='correlations')
total = func(pulse, S, omega, identifiers,
which='total')
which='total')
pulse._F = None
pulse._F_kl = None
pulse._F_pc = None
pulse._F_pc_kl = None

self.assertArrayAlmostEqual(correl.sum((0, 1)), total,
atol=1e-14)

if func != numeric.infidelity:
pulse._R = R
pulse._R_pc = R_pc
correl = func(pulse, S, omega, identifiers,
which='correlations',
memory_parsimonious=True)
total = func(pulse, S, omega, identifiers,
which='total',
memory_parsimonious=True)
pulse._R = None
pulse._R_pc = None

self.assertArrayAlmostEqual(correl.sum((0, 1)), total,
atol=1e-14)

pulse._F = F
pulse._F_kl = F_kl
pulse._F_pc = F_pc
pulse._F_pc_kl = F_pc_kl
correl = func(pulse, S, omega, identifiers,
which='correlations',
memory_parsimonious=True)
total = func(pulse, S, omega, identifiers,
which='total',
memory_parsimonious=True)
pulse._F = None
pulse._F_kl = None
pulse._F_pc = None
pulse._F_pc_kl = None

self.assertArrayAlmostEqual(correl.sum((0, 1)), total,
atol=1e-14)


class ExtensionTest(testutil.TestCase):

def test_extend_with_identity(self):
Expand Down

0 comments on commit 2a54499

Please sign in to comment.