@@ -308,6 +308,20 @@ def _get_instruments(inputVisitSummaries):
308308 return instruments , instrumentIndices
309309
310310
311+ class CholeskyError (pipeBase .AlgorithmError ):
312+ """Raised if the Cholesky decomposition in the model fit fails."""
313+
314+ def __init__ (self ) -> None :
315+ super ().__init__ (
316+ "Cholesky decomposition failed, likely because data is not sufficient to constrain the model."
317+ )
318+
319+ @property
320+ def metadata (self ) -> dict :
321+ """There is no metadata associated with this error."""
322+ return {}
323+
324+
311325class GbdesAstrometricFitConnections (
312326 pipeBase .PipelineTaskConnections ,
313327 dimensions = ("skymap" , "tract" , "instrument" , "physical_filter" ),
@@ -743,14 +757,18 @@ def runQuantum(self, butlerQC, inputRefs, outputRefs):
743757 colorCatalog = inputs .pop ("colorCatalog" )
744758 else :
745759 colorCatalog = None
746-
747- output = self .run (
748- ** inputs ,
749- instrumentName = instrumentName ,
750- refObjectLoader = refObjectLoader ,
751- colorCatalog = colorCatalog ,
752- nCores = nCores ,
753- )
760+ try :
761+ output = self .run (
762+ ** inputs ,
763+ instrumentName = instrumentName ,
764+ refObjectLoader = refObjectLoader ,
765+ colorCatalog = colorCatalog ,
766+ nCores = nCores ,
767+ )
768+ except pipeBase .AlgorithmError as e :
769+ error = pipeBase .AnnotatedPartialOutputsError .annotate (e , self , log = self .log )
770+ # No partial outputs for butler to put
771+ raise error from e
754772
755773 wcsOutputRefDict = {outWcsRef .dataId ["visit" ]: outWcsRef for outWcsRef in outputRefs .outputWcs }
756774 for visit , outputWcs in output .outputWcss .items ():
@@ -924,13 +942,20 @@ def run(
924942 nCoeffVisitModel = _nCoeffsFromDegree (self .config .exposurePolyOrder )
925943 minFitExposures = int (np .ceil (nCoeffVisitModel / (1 - self .config .fitReserveFraction )))
926944 # Do the WCS fit
927- wcsf .fit (
928- reserveFraction = self .config .fitReserveFraction ,
929- randomNumberSeed = self .config .fitReserveRandomSeed ,
930- minFitExposures = minFitExposures ,
931- clipThresh = self .config .clipThresh ,
932- clipFraction = self .config .clipFraction ,
933- )
945+ try :
946+ wcsf .fit (
947+ reserveFraction = self .config .fitReserveFraction ,
948+ randomNumberSeed = self .config .fitReserveRandomSeed ,
949+ minFitExposures = minFitExposures ,
950+ clipThresh = self .config .clipThresh ,
951+ clipFraction = self .config .clipFraction ,
952+ )
953+ except RuntimeError as e :
954+ if "Cholesky decomposition failed" in str (e ):
955+ raise CholeskyError () from e
956+ else :
957+ raise
958+
934959 self .log .info ("WCS fitting done" )
935960
936961 outputWcss , cameraParams , colorParams , camera , partialOutputs = self ._make_outputs (
@@ -2388,12 +2413,17 @@ def runQuantum(self, butlerQC, inputRefs, outputRefs):
23882413 else :
23892414 colorCatalog = None
23902415
2391- output = self .run (
2392- ** inputs ,
2393- instrumentName = instrumentName ,
2394- refObjectLoader = refObjectLoader ,
2395- colorCatalog = colorCatalog ,
2396- )
2416+ try :
2417+ output = self .run (
2418+ ** inputs ,
2419+ instrumentName = instrumentName ,
2420+ refObjectLoader = refObjectLoader ,
2421+ colorCatalog = colorCatalog ,
2422+ )
2423+ except pipeBase .AlgorithmError as e :
2424+ error = pipeBase .AnnotatedPartialOutputsError .annotate (e , self , log = self .log )
2425+ # No partial outputs for butler to put
2426+ raise error from e
23972427
23982428 for outputRef in outputRefs .outputWcs :
23992429 visit = outputRef .dataId ["visit" ]
@@ -2544,12 +2574,19 @@ def run(
25442574 self ._add_color_objects (wcsf , colorCatalog )
25452575
25462576 # Do the WCS fit
2547- wcsf .fit (
2548- reserveFraction = self .config .fitReserveFraction ,
2549- randomNumberSeed = self .config .fitReserveRandomSeed ,
2550- clipThresh = self .config .clipThresh ,
2551- clipFraction = self .config .clipFraction ,
2552- )
2577+ try :
2578+ wcsf .fit (
2579+ reserveFraction = self .config .fitReserveFraction ,
2580+ randomNumberSeed = self .config .fitReserveRandomSeed ,
2581+ clipThresh = self .config .clipThresh ,
2582+ clipFraction = self .config .clipFraction ,
2583+ )
2584+ except RuntimeError as e :
2585+ if "Cholesky decomposition failed" in str (e ):
2586+ raise CholeskyError () from e
2587+ else :
2588+ raise
2589+
25532590 self .log .info ("WCS fitting done" )
25542591
25552592 outputWcss , cameraParams , colorParams , camera , partialOutputs = self ._make_outputs (
0 commit comments