-
Notifications
You must be signed in to change notification settings - Fork 40
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
Add metadata to Tidy3D components #1493
Conversation
15e42eb
to
d8cabc8
Compare
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.
Just one question: it is possible to get an error if the user adds non-serializable data to the dictionary, because it will be included in the json representation of the model, right?
I think that's the correct behavior here, but we might also want to add a note about that in the description (and maybe try to catch it early and warn the user when creating the json string).
Yea it should be, good point. I'll add a test and also see what I can do about catching it. |
03beca1
to
d33fcd2
Compare
728ec83
to
f5601aa
Compare
This point sounds like going against the idea of using these for the One more question to bring up (@xin-flex) if two simulations only differ in their |
I think we could consider setting |
Hm, but then how do we upload this information? maybe that doesn't work after all. |
@momchil-flex could you take a look into this PR and let me know if you need any other changes? I think I'll be doing the jax refactor stuff we discussed without attrs, although I'm still working that out. |
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.
The way this is currently, identical simulations with different attrs
will not go through the caching mechanism, right? I think this may be fine, but I do remember maybe at some point discussing having the opposite behavior? It's probably harder to implement though. Any thoughts?
tidy3d/components/base.py
Outdated
"operation of Tidy3D as it is not used internally. " | ||
"Note that, unlike regular Tidy3D fields, ``attrs`` are mutable. " | ||
"For example, the following is allowed for setting an ``attr`` ``obj.attrs['foo'] = bar``. " | ||
"Also note that if objects that are not serializable (eg types) are added to " |
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.
what do you mean by "eg types"? Like if I have something like [Callable]
in my attrs?
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.
I mean that you can't put int
in your attrs, e.g. attrs = {'test': int}
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.
I just removed this eg types
comment because it might just be confusing
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.
Also note that `Tidy3D`` will raise a ``TypeError`` if ``attrs`` contain objects that can not be serialized.
I'm not excactly sure how the caching functions. Do you know what it compares based of? In my mind, it probably makes most sense to ignore attrs when deciding whether to load a cached dataset but I don't know |
3cb3266
to
a99f294
Compare
I believe it compares the hdf5 file byte by byte, so it will take some engineering to modify this to exclude attrs. But, in some use cases, that's probably safer. For example, the |
k, I feel comfortable taking the most conservative route and just caching based on attrs for now.. or until someone complains :) |
acd82f2
to
c44de29
Compare
Addresses #1352
How do you all feel about this?
.attrs
, because it follows the same convention asxarray
,pandas
, maybe others.attrs
are dictionaries (mutable) so they can be set on the fly,sim.attrs['foo'] = bar
.sim.attrs = {}
doesn't work.xarray
, attrs remain when the objects are copied and updated. but are removed when the objects are modified. We only need to handle the copy part since we can't modify tidy3d objects. therefore ifsim.copy()
, then the new object's attrs are the same.attrs
are mutable, we want to ensure our internal code doesn't depend on attrs in any way. Otherwise we introduce state. So as a rule, we don't useattrs
for any calculation? That being said, maybe we can set attrs internally if it makes sense to, but never code likeif obj.attrs["something"] == something: ...
All of the logic is spelled out in the test.
Also please check the description and see if it is clear.
Thanks