Skip to content

Commit d3b4fef

Browse files
committed
Fix duplicate names in composite components
1 parent 2c07d48 commit d3b4fef

File tree

6 files changed

+35
-3
lines changed

6 files changed

+35
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ The format of this changelog is based on
44
[Keep a Changelog](https://keepachangelog.com/), and this project adheres to
55
[Semantic Versioning](https://semver.org/).
66

7+
## Unreleased
8+
9+
- Fixed issue causing duplicate `Cell` names with paths and composite components, where rendering would use the component's name rather than a unique name
10+
711
## 1.4.2 (2025-07-16)
812

913
- Removed invalid keyword constructor without type parameters for `@compdef`-ed components with type parameters, so it can be overridden without warnings

src/paths/paths.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,14 @@ function DeviceLayout._geometry!(cs::CoordinateSystem, p::Path)
393393
return addref!(cs, p)
394394
end
395395

396+
function DeviceLayout.coordsys_name(p::Path)
397+
# If empty, rendering path directly
398+
isempty(p._geometry) && return name(p._geometry)
399+
# If not empty, p._geometry holds `p` (e.g. `build!` was called)
400+
# and the path coordsys needs its own uniquename
401+
return uniquename(name(p))
402+
end
403+
396404
"""
397405
path_in(h::PointHook)
398406

src/render/render.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ function _render!(
9696
cur_cell = if already_seen
9797
memoized_cells[cur_cs]
9898
else
99-
Cell{S}(name(cur_cs))
99+
Cell{S}(coordsys_name(cur_cs))
100+
end
101+
if name(cur_cell) == "cs_pz"
102+
@show cur_cs
100103
end
101104

102105
# If it's a new CS, render the contents, push refs to the stack, and add to memoized_cells

src/schematics/components/components.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,3 +414,5 @@ function single_component_expr(compname, comptype; params...)
414414
$escname
415415
end
416416
end
417+
418+
DeviceLayout.coordsys_name(comp::AbstractComponent) = name(geometry(comp))

src/structures.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,5 +216,7 @@ function flatten end
216216

217217
# type of coordinate system created by flatten
218218
function coordsys_type end # defined elsewhere, once CoordinateSystem is defined
219+
# name used by CoordinateSystem representation
220+
coordsys_name(geom::GeometryStructure) = name(geom)
219221

220222
Base.isempty(geom::GeometryStructure) = isempty(elements(geom)) && isempty(refs(geom))

test/test_schematicdriven.jl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,10 +617,12 @@ end
617617
g3 = copy(g)
618618
@test length(find_components(TestCompVariant, g3)) == 18
619619
@test length(find_components(TestCompVariant, g3, depth=2)) == 12
620-
@test length(find_components(c -> name(c)[1:1] == "z", g3, depth=2)) == 4
620+
# There are two unique components named "z" appearing a combined 4 times up to depth 2
621+
@test length(find_components(c -> name(c) == "z", g3, depth=2)) == 4
621622
@test length(
622-
unique(component.(g3[find_components(c -> name(c)[1:1] == "z", g3, depth=2)]))
623+
unique(component.(g3[find_components(c -> name(c) == "z", g3, depth=2)]))
623624
) == 2
625+
624626
g3_flat = SchematicDrivenLayout.flatten(g3)
625627
g3 = SchematicDrivenLayout.flatten(g3, depth=1)
626628
@test length(components(g3)) == 14
@@ -633,6 +635,11 @@ end
633635

634636
@test origin(floorplan3, find_components(c -> name(c)[1:1] == "z", g3)[end])
635637
Point(200.2μm, 0.1μm)
638+
# Make sure that cells for unique "z" have unique names when rendering
639+
c = Cell(floorplan3.coordinate_system)
640+
a = []
641+
traverse!(a, c)
642+
@test length(findall(x -> name(last(x)) == DeviceLayout.coordsys_name(zline), a)) == 2
636643

637644
### Full composite component
638645
p = Path(Point(0μm, 0μm), name="pz")
@@ -691,6 +698,12 @@ end
691698

692699
@test hooks(bq2, "bq1", :xy) == hooks(bq2, 1 => :xy) # using subcomp name or index=>hsym
693700
@test keys(SchematicDrivenLayout.subcomponents(bq2)) == (:bq1, :bq2, :pz)
701+
# test creating Cell without build uses path's coordsys_name
702+
c = Cell(geometry(bq2); map_meta=_ -> GDSMeta())
703+
a = []
704+
traverse!(a, c)
705+
@test DeviceLayout.coordsys_name(p) != name(p)
706+
@test isempty(findall(x -> name(last(x)) == name(p), a))
694707

695708
g = SchematicGraph("comp")
696709
bq2_node = add_node!(g, bq2)

0 commit comments

Comments
 (0)