-
Notifications
You must be signed in to change notification settings - Fork 58
XY transposable sim.plot() plots (issue1072) VERSION 2 #2544
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
base: develop
Are you sure you want to change the base?
Conversation
I don't want to add complexity to your code where it's not needed, @tylerflex ! The
|
This code has not yet been tested. It probably won't even run. I am beginning the (manual) testing process now. |
tidy3d/components/geometry/base.py
Outdated
@@ -1315,6 +1345,7 @@ def to_gdstk( | |||
z: Optional[float] = None, |
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.
we probably dont need to pass transpose to these gds functions, these are used to export the polygons to file.
hey @jewettaijfc , this is an interesting approach. I think it looks promising! I would have a few pieces of advice at this stage:
Thanks for the effort on this! good luck on the testing. |
For sure. Regarding my work-flow, I don't put PRs up for review until I have some unit tests. It takes a little extra time to write them, but unit tests have saved my butt so many times.
Thanks! I'll fix that now.
I will let you decide. But I suggest we use the same name for all functions. (I like both
I was wondering about this too. I will look into that.
Thank you! |
Currently:
Here are some things fixed in this PR (which weren't working before in PR2537):
Here are some things that are currently broken in this PR (which were working in PN2537):
|
NOTE: I left some print() statements in the code that I'm still using for (manual) debugging. I'll remove these soon. |
|
I'm done with manual testing. I started writing unit tests. |
Oops. I guess I wasn't done with manual testing.
|
|
|
@@ -89,7 +89,6 @@ class PolySlab(base.Planar): | |||
@staticmethod | |||
def make_shapely_polygon(vertices: ArrayLike) -> shapely.Polygon: | |||
"""Make a shapely polygon from some vertices, first ensures they are untraced.""" | |||
vertices = get_static(vertices) |
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 think this is causing the error, this line should be put back
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.
yup! just verified that it works after adding it back
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.
Wow. Thank you! This would have taken me hours to figure out.
return [self.make_shapely_polygon(vertices_z)] | ||
vertices = vertices_z | ||
if swap_axes: | ||
vertices = vertices[:, (1, 0)] # swap column 0 (x coords) with column 1 (y coords) |
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'm worried this code will not work with autograd (the package I mentioned that handles our automatic differentiation).
I would suggest replacing with
vertices = vertices[:, ::-1] # reverse the second axis
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!
Other than pop_axis_and_swap()
and unpop_axis_and_swap()
, this is the only other place in the code (that I am aware of) containing non-trivial modifications. I need to write a unit-test for it.
max_bounds = list(field_data_bounds[1]) | ||
min_bounds.pop(axis) | ||
max_bounds.pop(axis) | ||
_, min_bounds = self.pop_axis_and_swap(field_data_bounds[0], axis, swap_axes=swap_axes) |
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.
good catch, this is probably more robust than what we had before.
…ry/base.py, geometry/primitives.py
…n `geometry/base.py`
…at was an accident.)
… transposed correctly. It looks like I need to modify the "polyslab.py" file. (I haven't touched this file yet.)
…inally. I tested the plot capability with the slice plane aligned with the polyslab plane, and perpendicular to it (which invokes and , respectively).
…hem back when I was trying to debug `Simulation.plot_eps()`)
…ose" (a.k.a. "swap_axes") argument. I removed that argument
…he other plot functions
…"swap_axis" is used
… with swap_axes=True and False)
…ut crashing with the default argument (`swap_axes=False`). But it does not produce the correct graphical result when `swap_axes=True`.
… tcad/data/sim_data.py. I don't know how to test this function yet.
2f38175
to
de2d14d
Compare
…unit tests that Tyler suggested (and add a new unit test for PolySlab._intersections_normal())
…s it depends on. WARNING: This effort is not complete. The code is now in a completely broken state. But I had to backup my changes before I changed branches.
This PR addresses he feature request from issue #1072 (adding the ability to swap the horizontal and vertical axes of a simulation plot).
This PR is an alternative to PR#2537
I don't know which approach will work better in the long run. I will test both.
Motivation
I can think of 2 different strategies to transpose XY axes:
Simulation.plot()
to work.Simulation.plot()
.Specifically:
transpose
argument to all plot-related functions that previously acceptedaxis
orx
,y
,z
arguments. (Conceptually, these arguments all go together: they specify how to display a plane from a 3D space on the screen.)pop_axis()
andunpop_axis()
, and the (plot-related) functions that invoke them ...all the way up to the top-levelplot()
functions.transpose=False
everywhere. So unless someone overrides this by settingtranspose=True
, the code should behave as it did before.It seems like I made a lot of complicated changes in this PR, but I really didn't. The only non-trivial changes to the code happen inside
pop_axis()
andunpop_axis()
(see below). All of the higher-level functions merely propagate thetranspose
argument downwards until it is finally processed by eitherpop_axis()
orunpop_axis()
. This reduces the cognitive burden on the programmer: In each function, I no longer have to think hard about how to deal with the newtranspose
argument. I just forward thetranspose
argument downwards to any functions that ultimately invoke eitherpop_axis()
orunpop_axis()
. If we do this consistently, we hopefully shouldn't see surprising behavior later.(UPDATE: These functions are now called
pop_axis_and_swap()
andunpop_axis_and_swap()
.)For completeness, here are the new definitions of
pop_axis_and_swap()
andunpop_axis_and_swap()
:That's all this PR does.