From 85d056fcfd9728fbc975b4b38d626f93e0fc0ef4 Mon Sep 17 00:00:00 2001 From: robjmcgibbon Date: Thu, 3 Sep 2026 14:46:20 +0100 Subject: [PATCH] Directly report properties which throw errors --- SOAP/compute_halo_properties.py | 3 +++ SOAP/core/halo_tasks.py | 4 +++- SOAP/particle_selection/SO_properties.py | 9 ++++++++- SOAP/particle_selection/aperture_properties.py | 9 ++++++++- SOAP/particle_selection/projected_aperture_properties.py | 9 ++++++++- SOAP/particle_selection/subhalo_properties.py | 9 ++++++++- SOAP/property_calculation/inertia_tensors.py | 3 +++ 7 files changed, 41 insertions(+), 5 deletions(-) diff --git a/SOAP/compute_halo_properties.py b/SOAP/compute_halo_properties.py index 125bb9e3..9651211a 100644 --- a/SOAP/compute_halo_properties.py +++ b/SOAP/compute_halo_properties.py @@ -12,6 +12,7 @@ import os import os.path +import sys import time import traceback import numpy as np @@ -564,6 +565,8 @@ def compute_halo_properties(): ) except Exception as e: traceback.print_exc() + sys.stdout.flush() + sys.stderr.flush() comm_world.Abort(1) # Can stop the halo request thread now that all chunk tasks have executed diff --git a/SOAP/core/halo_tasks.py b/SOAP/core/halo_tasks.py index 6cb76e52..4da85e23 100644 --- a/SOAP/core/halo_tasks.py +++ b/SOAP/core/halo_tasks.py @@ -141,7 +141,9 @@ def process_single_halo( # Calculation caused an unexpected error. # Output the halo ID so we can debug this. print( - f"Object with HaloCatalogueIndex={input_halo['index']} encountered an error" + f"Object with HaloCatalogueIndex={input_halo['index']} encountered an error " + f"while calculating {halo_prop.name}", + flush=True, ) raise else: diff --git a/SOAP/particle_selection/SO_properties.py b/SOAP/particle_selection/SO_properties.py index 55746315..b5478558 100644 --- a/SOAP/particle_selection/SO_properties.py +++ b/SOAP/particle_selection/SO_properties.py @@ -3674,7 +3674,14 @@ def calculate( unit = unit * unyt.Unit("a", registry=registry) ** a_exponent if do_calculation[filter_name]: t0_calc = time.time() - val = getattr(part_props, name) + try: + val = getattr(part_props, name) + except Exception as e: + e.add_note( + f"Error calculating {prop.name} for subhalo " + f"{input_halo['index']}" + ) + raise if val is not None: assert ( SO[name].shape == val.shape diff --git a/SOAP/particle_selection/aperture_properties.py b/SOAP/particle_selection/aperture_properties.py index a14c9be1..9c4fe74a 100644 --- a/SOAP/particle_selection/aperture_properties.py +++ b/SOAP/particle_selection/aperture_properties.py @@ -4176,7 +4176,14 @@ def calculate( unit = unit * unyt.Unit("a", registry=registry) ** a_exponent if do_calculation[filter_name]: t0_calc = time.time() - val = getattr(part_props, name) + try: + val = getattr(part_props, name) + except Exception as e: + e.add_note( + f"Error calculating {prop.name} for subhalo " + f"{input_halo['index']}" + ) + raise if val is not None: assert ( aperture_sphere[name].shape == val.shape diff --git a/SOAP/particle_selection/projected_aperture_properties.py b/SOAP/particle_selection/projected_aperture_properties.py index c10d35da..58e3d324 100644 --- a/SOAP/particle_selection/projected_aperture_properties.py +++ b/SOAP/particle_selection/projected_aperture_properties.py @@ -1950,7 +1950,14 @@ def calculate( unit = unit * unyt.Unit("a", registry=registry) ** a_exponent if do_calculation[filter_name]: t0_calc = time.time() - val = getattr(proj_part_props, name) + try: + val = getattr(proj_part_props, name) + except Exception as e: + e.add_note( + f"Error calculating {prop.name} ({projname}) " + f"for subhalo {input_halo['index']}" + ) + raise if val is not None: assert ( projected_aperture[projname][name].shape == val.shape diff --git a/SOAP/particle_selection/subhalo_properties.py b/SOAP/particle_selection/subhalo_properties.py index c2294d38..f5bb7e1f 100644 --- a/SOAP/particle_selection/subhalo_properties.py +++ b/SOAP/particle_selection/subhalo_properties.py @@ -2678,7 +2678,14 @@ def calculate(self, input_halo, search_radius, data, halo_result): ) if do_calculation[filter_name]: t0_calc = time.time() - val = getattr(part_props, name) + try: + val = getattr(part_props, name) + except Exception as e: + e.add_note( + f"Error calculating {prop.name} for subhalo " + f"{input_halo['index']}" + ) + raise if val is not None: assert ( subhalo[name].shape == val.shape diff --git a/SOAP/property_calculation/inertia_tensors.py b/SOAP/property_calculation/inertia_tensors.py index 3c11a5fd..c85a6251 100644 --- a/SOAP/property_calculation/inertia_tensors.py +++ b/SOAP/property_calculation/inertia_tensors.py @@ -335,6 +335,9 @@ def get_weighted_projected_inertia_tensor( tensor = tensor.sum(axis=0) eig_val, eig_vec = np.linalg.eigh(tensor.value) + # Handle overflows into negative values of very small eigenvalues + eig_val = np.abs(eig_val) + # Handle cases where there is only one particle after iterating. if q == 0: tensor.fill(0)