bmad-sim / pytao

PyTao is Python interface for Tao, which is based on the Bmad subroutine library for relativistic charged–particle and X-ray simulations in accelerators and storage rings.
https://bmad-sim.github.io/pytao
GNU General Public License v3.0
9 stars 6 forks source link

Add ability to filter certain error messages #85

Open ken-lauer opened 2 months ago

ken-lauer commented 2 months ago

Raising RuntimeError for certain errors is undesirable, depending on what the user is trying to do. This seems to be a recurring theme based on what I've heard and recently reported issues (#84)

If pytao could filter user-defined message classes such as these and redirect them to the logging system, maybe that would be a good solution? (cc @ChristopherMayes )

For example:

[ERROR | 2024-JUL-12 15:57:24] tao_set_invalid:
    UNSTABLE ORBIT AT EVALUATION POINT
    FOR DATUM: abc.x[4] with data_type: bpm_orbit.x

Not sure how it would look, but perhaps some simple string match like this could be fine: tao.ignore_error("tao_set_invalid", "UNSTABLE ORBIT")

ChristopherMayes commented 2 months ago

Yes, there are a few like this that aren't quite "errors" to me.

@DavidSagan what do you consider an "error" vs "warning"?

DavidSagan commented 2 months ago

Essentially, an error occurs when "unexpectedly" the computation cannot be done. The problem is that where you draw the line is somewhat arbitrary.

ken-lauer commented 1 month ago

@DavidSagan I imagine it would be a massive effort to give all such errors a uniquely identifiable code (such as the above might be EVAL001 short for "unstable orbit at evaluation point")?

If we had some way of identifying the errors with unique codes, it'd be much easier for the user to opt out of certain messages or reclassify them as fatal/ignorable/etc.

DavidSagan commented 1 month ago

About 1800 lines give or take. But something someone with only a little training could do. I think better would be to enable the User to opt out using the routine name generating the error which is already something that PyTao knows about.

DavidSagan commented 1 month ago

Another thought is to add more error levels for finer control.