Skip to content
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

Better repr representation of Tidy3D Medium when calling print #2307

Open
prashkh opened this issue Mar 12, 2025 · 3 comments
Open

Better repr representation of Tidy3D Medium when calling print #2307

prashkh opened this issue Mar 12, 2025 · 3 comments
Assignees

Comments

@prashkh
Copy link
Contributor

prashkh commented Mar 12, 2025

Currently when I look at the optical or electrical medium this is what I see. It's hard to say by looking at the PoleResidue model what this material is. For example. this is SiO2 from our material library.

{'optical': PoleResidue(attrs={}, name=None, frequency_range=(59958491600000.0, 1998616386666666.8), allow_gain=False, nonlinear_spec=None, modulation_spec=None, viz_spec=None, heat_spec=None, type='PoleResidue', eps_inf=1.5385442336875639, poles=(((-11504139.374277674-1.595196740783775e+16j), (7507685.43042605+4535416182817100j)), ((-249390.3565044153-172280738540723.53j), (46272.506981344035+99704543223121.88j)))), 'electrical': Medium(attrs={}, name='SiO2', frequency_range=None, allow_gain=False, nonlinear_spec=None, modulation_spec=None, viz_spec=None, heat_spec=None, type='Medium', permittivity=3.9, conductivity=0.0)}

@daquinteroflex
Copy link
Collaborator

Yeah agreed! It'd be really cool if we can make our representations more graphical and even in a notebook to be more visually interactive in some form

@tylerflex
Copy link
Collaborator

could try pretty print? https://docs.python.org/3/library/pprint.html

@yaugenst-flex yaugenst-flex self-assigned this Mar 12, 2025
@yaugenst-flex
Copy link
Collaborator

i'm not sure how much we want to do for Medium itself, since most of the information there can be quite useful when you're interested in actually printing the material model, so i'd second tyler's pprint suggestion (rich.print is even prettier and comes with tidy3d too..)

however, i think where we really might want to address this is in the material library. i looked through that a bit today and the data structures in there are not super obvious. ideally i think we would be able to print(material_library), print(material_library["mat"]), print(material_library["mat"]["variant"]), with each of these printing relevant and easily digestible info. or at least have a .summary() method for each of these. however, with how the data structures currently work, this is not really possible. material_library is a dict, and material_library["mat"]["variant"] returns the underlying td.Medium (although this is only part of the datastructure, which is really a VariantItem).
since the material library is used heavily in GUI (and a ton of other places too i assume), i'm a bit hesitant to "overhaul" how these work, but i'm not completely sure what a good solution might look like either without doing that.
we could provide helper functions to do the pretty printing? although i doubt that would solve prash's issue..

essentially the only __str__/__repr__ we can provide right now are for MaterialItem and VariantItem. the material one is fine, but the VariantItem for example does not contain information about which material the model is actually for, so the usefulness of a __repr__ there is also somewhat limited

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants