Skip to content

Commit 1e0fb2f

Browse files
authored
Merge pull request #63 from amccaugh/dev
1.2.2
2 parents 74756f5 + 488dbaf commit 1e0fb2f

File tree

4 files changed

+48
-19
lines changed

4 files changed

+48
-19
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ PHotonic and Integrated Device Layout - GDS CAD layout and geometry creation for
77
- [**Tutorial + examples**](https://github.com/amccaugh/phidl/blob/master/phidl/phidl_tutorial_example.py#L35) (or [Try now in an interactive notebook](https://mybinder.org/v2/gh/amccaugh/phidl/master?filepath=phidl_tutorial_example.ipynb))
88
- [**Geometry + function documentation**](https://phidl.readthedocs.io/)
99
- [About PHIDL](#about-phidl)
10-
- [Changelog](#changelog) (latest update 1.2.1 (January 13, 2020))
10+
- [Changelog](#changelog) (latest update 1.2.2 (January 17, 2020))
1111

1212
# Installation / requirements
1313
- Install or upgrade with `pip install -U phidl`
@@ -79,6 +79,12 @@ You can also do things like create a backing fill to make sure the resist develo
7979

8080
# Changelog
8181

82+
## 1.2.2 (January 17, 2020)
83+
84+
### Bugfixes
85+
- Fixed rare bug with `pg.import_gds()` causing cell name collisions
86+
- `pg.boolean()` no longer errors when passed empty geometries
87+
8288
## 1.2.1 (January 13, 2020)
8389

8490
- Maintenance update to work with `gdspy` 1.5

phidl/device_layout.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import gdspy.library
3535
gdspy.library.use_current_library = False
3636

37-
__version__ = '1.2.1'
37+
__version__ = '1.2.2'
3838

3939

4040

@@ -634,22 +634,30 @@ def write_gds(self, filename, unit = 1e-6, precision = 1e-9,
634634
# Autofix names so there are no duplicates
635635
if auto_rename == True:
636636
all_cells_sorted = sorted(all_cells, key=lambda x: x.uid)
637-
used_names = {'toplevel':1}
637+
all_cells_names = [c._internal_name for c in all_cells_sorted]
638+
all_cells_original_names = [c.name for c in all_cells_sorted]
639+
used_names = {'toplevel'}
640+
n = 1
638641
for c in all_cells_sorted:
639642
if max_cellname_length is not None:
640643
new_name = c._internal_name[:max_cellname_length]
641644
else:
642645
new_name = c._internal_name
643-
if new_name not in used_names:
644-
used_names[new_name] = 1
645-
c.name = new_name
646-
else:
647-
c.name = new_name + ('%0.3i' % used_names[new_name])
648-
used_names[new_name] += 1
646+
temp_name = new_name
647+
while temp_name in used_names:
648+
n += 1
649+
temp_name = new_name + ('%0.3i' % n)
650+
new_name = temp_name
651+
used_names.add(new_name)
652+
c.name = new_name
649653
self.name = 'toplevel'
654+
# Write the gds
650655
gdspy.write_gds(filename, cells=all_cells, name='library',
651656
unit=unit, precision=precision)
652-
self.name = tempname
657+
# Return cells to their original names if they were auto-renamed
658+
if auto_rename == True:
659+
for n,c in enumerate(all_cells_sorted):
660+
c.name = all_cells_original_names[n]
653661
return filename
654662

655663

phidl/geometry.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,8 @@ def boolean(A, B, operation, precision = 1e-4, num_divisions = [1,1],
403403
Note that 'A+B' is equivalent to 'or', 'A-B' is equivalent to 'not', and
404404
'B-A' is equivalent to 'not' with the operands switched
405405
"""
406+
D = Device('boolean')
407+
406408
A_polys = []
407409
B_polys = []
408410
if type(A) is not list: A = [A]
@@ -427,16 +429,27 @@ def boolean(A, B, operation, precision = 1e-4, num_divisions = [1,1],
427429
elif operation not in ['not', 'and', 'or', 'xor', 'a-b', 'b-a', 'a+b']:
428430
raise ValueError("[PHIDL] phidl.geometry.boolean() `operation` parameter not recognized, must be one of the following: 'not', 'and', 'or', 'xor', 'A-B', 'B-A', 'A+B'")
429431

430-
if all(np.array(num_divisions) == np.array([1,1])):
431-
p = gdspy.boolean(operand1 = A_polys, operand2 = B_polys, operation = operation, precision=precision,
432-
max_points=max_points, layer=gds_layer, datatype=gds_datatype)
432+
# Check for trivial solutions
433+
if (len(A_polys) == 0) or (len(B_polys) == 0):
434+
if (operation == 'not'):
435+
if len(A_polys) == 0: p = None
436+
elif len(B_polys) == 0: p = A_polys
437+
elif (operation == 'and'):
438+
p = None
439+
elif (operation == 'or') or (operation == 'xor'):
440+
if (len(A_polys) == 0) and (len(B_polys) == 0): p = None
441+
elif len(A_polys) == 0: p = B_polys
442+
elif len(B_polys) == 0: p = A_polys
433443
else:
434-
p = _boolean_polygons_parallel(polygons_A = A_polys, polygons_B = B_polys,
435-
num_divisions = num_divisions, operation = operation,
436-
precision = precision)
437-
444+
# If no trivial solutions, run boolean operation either in parallel or straight
445+
if all(np.array(num_divisions) == np.array([1,1])):
446+
p = gdspy.boolean(operand1 = A_polys, operand2 = B_polys, operation = operation, precision=precision,
447+
max_points=max_points, layer=gds_layer, datatype=gds_datatype)
448+
else:
449+
p = _boolean_polygons_parallel(polygons_A = A_polys, polygons_B = B_polys,
450+
num_divisions = num_divisions, operation = operation,
451+
precision = precision)
438452

439-
D = Device('boolean')
440453
if p is not None:
441454
polygons = D.add_polygon(p, layer = layer)
442455
[polygon.fracture(max_points = max_points, precision = precision) for polygon in polygons]
@@ -937,6 +950,7 @@ def import_gds(filename, cellname = None, flatten = False):
937950
magnification = e.magnification,
938951
x_reflection = e.x_reflection,
939952
)
953+
dr.owner = D
940954
converted_references.append(dr)
941955
elif isinstance(e, gdspy.CellArray):
942956
dr = CellArray(
@@ -949,6 +963,7 @@ def import_gds(filename, cellname = None, flatten = False):
949963
magnification = e.magnification,
950964
x_reflection = e.x_reflection,
951965
)
966+
dr.owner = D
952967
converted_references.append(dr)
953968
D.references = converted_references
954969
# Next convert each Polygon

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
]
1111

1212
setup(name='phidl',
13-
version='1.2.1',
13+
version='1.2.2',
1414
description='PHIDL',
1515
install_requires=install_requires,
1616
author='Adam McCaughan',

0 commit comments

Comments
 (0)