-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix warning capture #1136
Fix warning capture #1136
Conversation
f27f045
to
ae141c4
Compare
ae141c4
to
f434a1f
Compare
Having issues with having this PR pass github tests. Everything seems fine on linux and macos, but failing on windows https://github.com/flexcompute/tidy3d/actions/runs/6086188923. There two issues:
@momchil-flex @tylerflex let me know if you have any suggestions |
Hm, not sure about the monitor size thing, but in the meantime it could be possible to just change the test to relax the monitor sizes a bit until we figure it out. Regarding the jax part. So the JVPTracer is what jax uses to store the gradient information. It can't be serialized to json unfortuantely. Does this come up when trying to serialize a warning or error due to the changes in this PR? I'm having trouble pinpointing where this is happening in the code. I also have no idea why this would occur in windows and not the other OS :/ |
for some reason I couldn't see the error but now I do, so yea I guess
I wonder if we need to instead wrap whatever block this is in a |
0357117
to
c709f5c
Compare
Actually, after looking more carefully, We still need to figure out why calculated monitor size is different on different OS's, and make warning capture work with adjoint related objects. The latter would be needed when GUI start integrating the adjoint feature. For now, this PR passes tests and ready to be reviewed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @dbochkov-flexcompute . it looks good to me, I dont 100% follow all of the details so feel free to get another review if you are unsure, but given the tests are passing and the issue seems cleared up, I approve. The improvements are also quite nice , thanks 👍
@@ -89,49 +93,166 @@ def test_logging_warning_capture(): | |||
monitor_flux = td.FluxMonitor( | |||
center=(0, 0, 0), | |||
size=(8, 8, 8), | |||
freqs=freqs, | |||
freqs=list(freqs), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did this not work with freqs
passed as a numpy array? I would have thought ArrayLike would handle this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, I was just playing around with adding frequencies outside of source range (something like freqs=list(freqs) + [1]
), and this remained like that accidentally
While trying to incorporate warnings capture into GUI, MC team noticed that when we have validation errors, setting
td.log.set_capture(True)
changes returned validation errors to something not very informative. This happens because during initialization of models we usetry-finally
inTidy3dBaseModel.__init__()
https://github.com/flexcompute/tidy3d/pull/1136/files#diff-d331aef8c3290adc3733d4ce375c5a4b139ad41bd5634113ca404cc827e3d949L76-R82 to try to finish warning capture no matter what. But our warning capture parsing assumes the models are well-built. So, when there are validation errors the instances are incomplete and parsing produces its own errors that are not related to simulation validation.A seemingly straightforward way to fix this is to just remove
try-finally
construction, so that we don't attempt to built warning capture tree if there are any errors. Initially, it wouldn't work as intended, but after I added missingdiscriminator=TYPE_TAG_STR
everything is fine. I believe this is because when there is nodiscriminator
pydantic tries to initialize with every model possible and those that fail, exit before reachinglog.end_capture(self)
inTidy3dBaseModel.__init__()
. Previouslyfinally:
would ensure we still execure that.Additional improvements:
log.start_capture()
/log.end_capture(self)
intoSimulation.validate_pre_upload()
to capture those warnings toocustom_loc: List = None
tolog.warning()
so that additional information can be provided about warning location. This is useful forSimulation
validators, which otherwise would just point at the simulation itself.capture: bool = True
tolog.warning()
to avoid capturing not very informative and somewhat arbitraryfrequency passed to 'Medium.eps_model()' is outside of 'Medium.frequency_range' = ...
,td.log.set_capture(True)
doesn't screw anything if there are validation errors.Note that all these changes doesn't affect python client warning behavior. This only matters for output of
td.log.captured_warnings()
whentd.log.set_capture(True)