Skip to content

Commit a7d211e

Browse files
authored
Merge pull request #96 from amccaugh/dev
1.5.0
2 parents 61c7cc1 + 046a260 commit a7d211e

File tree

13 files changed

+249
-61
lines changed

13 files changed

+249
-61
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,5 @@ target/
8383
*.bat
8484
*.lyp
8585
*.oas
86+
87+
.vscode/

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
# Changelog
22

3+
4+
## 1.5.0 (April 19, 2021)
5+
6+
### New features
7+
- Better interactive windows for `quickplot()`! Now you can use the mousewheel/trackpad scroll to zoom in and out, and right-click or left-click to zoom to a region.
8+
- Added `blocking` option for `quickplot()` (thanks @giumc)
9+
10+
### Changes
11+
- Quickplot options (such as displaying ports, subports, or aliases) are now set using `set_quickplot_options()`
12+
13+
### Bugfixes
14+
- Fix for Path function `smooth()`, which broke when sequential waypoints were co-linear (thanks @giumc)
15+
- Fix for non-C-continguous arrays in `hash_geometry()` (thanks Joaquin Matres @joamatab)
16+
17+
18+
### Bugfixes
19+
320
## 1.4.4 (Feb 23, 2021)
421

522
Bugfix release

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 Adam N. McCaughan
3+
Copyright (c) 2021 Adam N. McCaughan
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ GDS scripting that's intuitive, fast, and powerful. For Python 2 and 3.
66
- [**Installation / requirements**](#installation--requirements)
77
- [**Tutorial + examples**](https://phidl.readthedocs.io/en/latest/tutorials.html) (or [try an interactive notebook](https://mybinder.org/v2/gh/amccaugh/phidl/master?filepath=phidl_tutorial_example.ipynb))
88
- [**Geometry library + function documentation**](https://phidl.readthedocs.io/)
9-
- [Changelog](https://github.com/amccaugh/phidl/blob/master/CHANGELOG.md) (latest update 1.4.4, Feb 23, 2021)
10-
- Allow labels imported through import_gds() to be moved (thanks Joaquin Matres @joamatab)
11-
- Fix to Path.smooth() to prevent right-angle turns from accidentally having an additional +180 degrees applied to them (thanks Jeffrey Holzgrafe @jolzgrafe)
9+
- [Changelog](https://github.com/amccaugh/phidl/blob/master/CHANGELOG.md) (latest update 1.5.0 on April 27, 2021)
10+
- Better interactive windows for `quickplot()`! Now you can use the mousewheel/trackpad scroll to zoom in and out, and right-click or left-click to zoom to a region.
11+
- Quickplot options (such as displaying ports, subports, or aliases) are now set using `set_quickplot_options()`
12+
- A few bugfixes
1213

1314

1415
# Gallery

docs/geometry_reference.ipynb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919
"\n",
2020
"# Configure quickplot to hide subports\n",
2121
"import functools\n",
22-
"from phidl import quickplot as qp\n",
22+
"from phidl import quickplot as qp, set_quickplot_options\n",
2323
"import phidl\n",
24-
"qp = functools.partial(qp, show_subports = False)\n",
25-
"phidl.quickplot = qp"
24+
"set_quickplot_options(show_subports = False)"
2625
]
2726
},
2827
{
@@ -2247,7 +2246,7 @@
22472246
"name": "python",
22482247
"nbconvert_exporter": "python",
22492248
"pygments_lexer": "ipython3",
2250-
"version": "3.7.6"
2249+
"version": "3.9.1"
22512250
}
22522251
},
22532252
"nbformat": 4,

phidl/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from phidl.device_layout import Device, Group, Path, CrossSection, Port, Layer, LayerSet
22
from phidl.device_layout import make_device
3-
from phidl.quickplotter import quickplot, quickplot2
3+
from phidl.quickplotter import quickplot, quickplot2, set_quickplot_options
44
from phidl.device_layout import __version__, reset
55
from phidl.geometry import device_lru_cache

phidl/device_layout.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@
99
#==============================================================================
1010
# Minor TODO
1111
#==============================================================================
12-
# Make pg.vstack() and pg.hstack() -- point to grid()
1312
# Add Group.get_polygons()
1413
# Allow Boolean to use Groups
15-
# Add Paths to quickplot2
1614
# Add pp.delay_sine(distance = 10, length = 20, num_periods = 2)
1715
# add wire_basic to phidl.routing. also add endcap parameter
18-
# check that aliases show up properly in quickplot2
1916
# phidl add autoarray_xy to pg.geometry()
2017
# Allow connect(overlap) to be a tuple (0, 0.7)
2118
# Possibly replace gdspy bezier (font rendering) with
@@ -59,7 +56,7 @@
5956
import gdspy.library
6057
gdspy.library.use_current_library = False
6158

62-
__version__ = '1.4.4'
59+
__version__ = '1.5.0'
6360

6461

6562
#==============================================================================
@@ -1701,7 +1698,7 @@ def hash_geometry(self, precision = 1e-4):
17011698
for layer in sorted_layers:
17021699
layer_hash = hashlib.sha1(layer.astype(np.int64)).digest()
17031700
polygons = polygons_by_spec[tuple(layer)]
1704-
polygons = [((p/precision) + magic_offset).astype(np.int64) for p in polygons]
1701+
polygons = [np.ascontiguousarray((p/precision) + magic_offset, dtype = np.int64) for p in polygons]
17051702
polygon_hashes = np.sort([hashlib.sha1(p).digest() for p in polygons])
17061703
final_hash.update(layer_hash)
17071704
for ph in polygon_hashes:
@@ -2256,7 +2253,7 @@ def add(self, element):
22562253
else:
22572254
raise ValueError('[PHIDL] add() Could not add element to Group, the only ' \
22582255
'allowed element types are ' \
2259-
'(Device, DeviceReference, Port, Polygon, CellArray, Label, Group)')
2256+
'(Device, DeviceReference, Polygon, CellArray, Label, Group)')
22602257
# Remove non-unique entries
22612258
used = set()
22622259
self.elements = [x for x in self.elements if x not in used and (used.add(x) or True)]
@@ -2344,7 +2341,10 @@ def align(self, alignment = 'ymax'):
23442341
_align(elements = self.elements, alignment = alignment)
23452342
return self
23462343

2347-
PHIDL_ELEMENTS = (Device, DeviceReference, Port, Polygon, CellArray, Label, Group)
2344+
2345+
2346+
2347+
PHIDL_ELEMENTS = (Device, DeviceReference, Polygon, CellArray, Label, Group)
23482348

23492349

23502350

phidl/geometry.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4332,13 +4332,12 @@ def optimal_hairpin(width = 0.2, pitch = 0.6, length = 10, turn_ratio = 4,
43324332
return D
43334333

43344334

4335-
# TODO Include parameter which specifies "half" (one edge flat) vs
4336-
# "full" (both edges curved)
43374335
@device_lru_cache
43384336
def optimal_step(start_width = 10, end_width = 22, num_pts = 50,
43394337
width_tol = 1e-3, anticrowding_factor = 1.2,
43404338
symmetric = False, layer = 0):
43414339
""" Creates an optimally-rounded step geometry.
4340+
43424341
Parameters
43434342
----------
43444343
start_width : int or float
@@ -4349,7 +4348,6 @@ def optimal_step(start_width = 10, end_width = 22, num_pts = 50,
43494348
The number of points comprising the entire step geometry.
43504349
width_tol : float
43514350
Point at which to terminate the calculation of the optimal step
4352-
43534351
anticrowding_factor : int or float
43544352
Factor to reduce current crowding by elongating
43554353
the structure and reducing the curvature

phidl/path.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,18 @@ def spiral(num_turns = 5, gap = 1, inner_gap = 2, num_pts = 10000):
284284
# print(P.end_angle)
285285
return P
286286

287+
def _compute_segments(points):
288+
points = np.asfarray(points)
289+
normals = np.diff(points, axis = 0)
290+
normals = (normals.T/np.linalg.norm(normals, axis = 1)).T
291+
dx = np.diff(points[:,0])
292+
dy = np.diff(points[:,1])
293+
ds = np.sqrt(dx**2 + dy**2)
294+
theta = np.degrees(np.arctan2(dy,dx))
295+
dtheta = np.diff(theta)
296+
dtheta = dtheta - 360*np.floor((dtheta + 180)/360)
297+
return points, normals, ds, theta, dtheta
298+
287299

288300
def smooth(
289301
points = [(20,0), (40,0), (80,40), (80,10), (100,10),],
@@ -312,16 +324,16 @@ def smooth(
312324
Path
313325
A Path object with the specified smoothed path.
314326
"""
315-
points = np.asfarray(points)
316-
normals = np.diff(points, axis = 0)
317-
normals = (normals.T/np.linalg.norm(normals, axis = 1)).T
318-
# normals_rev = normals*np.array([1,-1])
319-
dx = np.diff(points[:,0])
320-
dy = np.diff(points[:,1])
321-
ds = np.sqrt(dx**2 + dy**2)
322-
theta = np.degrees(np.arctan2(dy,dx))
323-
dtheta = np.diff(theta)
324-
dtheta = dtheta - 360*np.floor((dtheta + 180)/360)
327+
328+
points, normals, ds, theta, dtheta = _compute_segments(points)
329+
colinear_elements = np.concatenate([[False], np.abs(dtheta) < 1e-6, [False]])
330+
if np.any(colinear_elements):
331+
new_points = points[~colinear_elements,:]
332+
points, normals, ds, theta, dtheta = _compute_segments(new_points)
333+
334+
if np.any(np.abs(np.abs(dtheta)-180) < 1e-6):
335+
raise ValueError('[PHIDL] smooth() received points which double-back on themselves' +
336+
'--turns cannot be computed when going forwards then exactly backwards.')
325337

326338
# FIXME add caching
327339
# Create arcs
@@ -395,6 +407,11 @@ def transition(cross_section1, cross_section2, width_type = 'sine'):
395407
X1 = cross_section1
396408
X2 = cross_section2
397409
Xtrans = CrossSection()
410+
411+
if not X1.aliases or not X2.aliases:
412+
raise ValueError("""[PHIDL] transition() found no named sections in one
413+
or both inputs (cross_section1/cross_section2).""")
414+
398415
for alias in X1.aliases.keys():
399416
if alias in X2.aliases:
400417

phidl/phidl_tutorial_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,8 +777,8 @@ def complicated_waveguide(width = 10, height = 1, x = 10, y = 25, rotation = 15)
777777
D['circle3'].x += 15 # Moving the second circle over by 15
778778
# Note that at this point, D['circle2'] is equivalent to the variable c2
779779
# we made above
780-
qp(D['circle2'], label_aliases = True)
781-
qp(D, label_aliases = True)
780+
qp(D['circle2'])
781+
qp(D)
782782

783783
# You can also access the list of aliases for your Device whenever you want
784784
# to by accessing Device.aliases, which is a Python dictionary. For example:

0 commit comments

Comments
 (0)