Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 42 additions & 21 deletions src/toast/templates/offset/offset.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,27 +487,48 @@ def _initialize(self, new_data):
# not invert "M" and solve M x = b using the Cholesky
# decomposition of M (*not* M^{-1}).
icenter = noisefilter.size // 2
wband = min(self.precond_width, icenter)
precond_width = max(
wband, min(self.precond_width, n_amp_view)
)
preconditioner = np.zeros(
[precond_width, n_amp_view], dtype=np.float64
)
if detnoise != 0:
preconditioner[0, :] = 1.0 / offsetvar_slice
preconditioner[:wband, :] += np.repeat(
noisefilter[icenter : icenter + wband, np.newaxis],
n_amp_view,
1,
)
lower = True
preconditioner = scipy.linalg.cholesky_banded(
preconditioner,
overwrite_ab=True,
lower=lower,
check_finite=True,
)
try_width = self.precond_width

good_cholesky = False
while not good_cholesky:
wband = min(try_width, icenter)
precond_width = max(
wband, min(try_width, n_amp_view)
)
preconditioner = np.zeros(
[precond_width, n_amp_view], dtype=np.float64
)
if detnoise != 0:
preconditioner[0, :] = 1.0 / offsetvar_slice
preconditioner[:wband, :] += np.repeat(
noisefilter[icenter : icenter + wband, np.newaxis],
n_amp_view,
1,
)
lower = True
try:
preconditioner = scipy.linalg.cholesky_banded(
preconditioner,
overwrite_ab=True,
lower=lower,
check_finite=True,
)
good_cholesky = True
except scipy.linalg.LinAlgError:
if try_width < icenter and try_width < n_amp_view:
# Still room to increase the band width
try_width *= 2
msg = f"obs {ob.name}, det {det}, view {ivw} "
msg += " scipy cholesky_banded fail, increasing"
msg += f" width to {try_width}"
log.debug(msg)
else:
# Width is now the size of the data interval
msg = f"obs {ob.name}, det {det}, view {ivw} "
msg += " scipy cholesky_banded fail with max "
msg += "width of {try_width}"
log.error(msg)
raise RuntimeError(msg)
if self.debug_plots is not None:
axprec.plot(
np.arange(len(preconditioner)),
Expand Down
8 changes: 5 additions & 3 deletions src/toast/tests/ops_mapmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ def test_compare_madam_diagpre(self):
step_time=step_seconds * u.second,
use_noise_prior=True,
precond_width=1,
# debug_plots=testdir,
debug_plots=testdir,
)

tmatrix = ops.TemplateMatrix(templates=[tmpl])
Expand All @@ -613,6 +613,7 @@ def test_compare_madam_diagpre(self):
solve_rcond_threshold=1.0e-4,
map_rcond_threshold=1.0e-4,
iter_max=50,
output_dir=testdir,
write_hits=False,
write_map=False,
write_cov=False,
Expand Down Expand Up @@ -867,8 +868,8 @@ def test_compare_madam_bandpre(self):
noise_model=default_model.noise_model,
step_time=step_seconds * u.second,
use_noise_prior=True,
precond_width=10,
# debug_plots=testdir,
precond_width=2,
debug_plots=testdir,
)

tmatrix = ops.TemplateMatrix(templates=[tmpl])
Expand All @@ -886,6 +887,7 @@ def test_compare_madam_bandpre(self):
solve_rcond_threshold=1.0e-4,
map_rcond_threshold=1.0e-4,
iter_max=50,
output_dir=testdir,
write_hits=False,
write_map=False,
write_cov=False,
Expand Down