POSYDON-code / POSYDON

POSYDON is a next-generation single and binary-star population synthesis code incorporating full stellar structure and evolution modeling with the use of MESA.
BSD 3-Clause "New" or "Revised" License
25 stars 19 forks source link

Add POSYDON Warnings #300

Open mkruckow opened 1 month ago

mkruckow commented 1 month ago
celiotine commented 1 month ago

In my most recent commit #70e05fc, I've adjusted the warning filter settings in binarypopulation. To ensure that the warnings filters are applied consistently at runtime, I think we should set the filter settings in the sections of code where we want to control the filtering to standard output/error. If we set these filters in the warnings class, the application of the filters is inconsistent, and I found it was not working in general.

In my changes, I added a BinaryPopulation kwarg "warnings_verbose." Similar to the error checking, if "warnings_verbose=True", all POSYDON warnings will be printed to standard output at runtime with the "default" filter setting (using the "always" filter sometimes prints many copies of the exact same warning for one binary depending on its evolution). If "warnings_verbose=False", all POSYDON warnings are ignored and not written to standard output/error. This is the default setting.

Now, previously, all warnings that occurred when evolving a binary population were suppressed from being written to output/error in this section of the code. Instead, they were caught and added to a list, which was then added as an attribute of the binary (binary.warning_message). It could still be useful to keep this feature, but I will need to think about a way to do this and also be able to print warnings to standard output. If you record the warnings when you catch them, it suppresses them being written to output/error, which is why no warnings were showing-up previously when running a binary population.

The remaining changes I made in this commit catch the occurrence of a few python divide-by-zero RunTime Warnings. I added a check for this behavior and a corresponding POSYDON Warning that I think is more informative, and now these warnings will be included in the general POSYDON Warning filtering. I think code could be re-written in general so that these divide-by-zero warnings do not happen (it seems avoidable to me), but that is outside the scope of this PR. Monica and I are planning to go through and change any python warnings to POSYDON warnings, if appropriate, similar to what we did for the error checking. This will ensure that when developers add new code, they can see if new python warnings arise from their changes.