luceda ipkiss教程 20:线路设计技巧一子线路的差异化赋值

ipkiss的层级化设计,在调用子器件或者子线路时可以给它们赋值,那么同一子线路如何实现差异化的赋值呢,接下来,就以spiral的例子来进行讲解,这里会介绍调用同一个spiral子线路来画多个不同长度的spiral:
结果如下:
在这里插入图片描述
所有代码如下:

from si_fab import all as pdk
import ipkiss3.all as i3


class GenericSpiral(i3.Circuit):
    _name_prefix = "GenericSpiral"
    bend_radius = i3.PositiveNumberProperty(default=20.0, doc="the bend radius in the circuit")
    Spiral = i3.ChildCellProperty(doc="Spiral in circuit")
    gc_distance_x = i3.PositiveNumberProperty(default=1000.0, doc="distance between the grating couplers ")
    gc_distance_y = i3.PositiveNumberProperty(default=400.0, doc="distance between the grating couplers ")
    space_y = i3.PositiveNumberProperty(default=50, doc="gc space in y direction")
    space_x = i3.PositiveNumberProperty(default=200, doc="space between gc and spiral ")
    space_y_spiral = i3.PositiveNumberProperty(default=200, doc="spiral space in y direction")
    space_x_spiral = i3.PositiveNumberProperty(default=500, doc="spiral space in x direction")
    spiral_length = i3.PositiveNumberProperty(default=4000, doc="length of sigle spiral")
    num_Spiral_y = i3.IntProperty(default=4, doc="number of spiral in y direction")
    num_Spiral_x = i3.IntProperty(default=1, doc="number of spiral in x direction")
    y_offset = i3.PositiveNumberProperty(default=5)
    waveguide_space = i3.PositiveNumberProperty(default=20)
    spiral_length_step = i3.PositiveNumberProperty(default=2000, doc="step length of waveguide under test")

    def _default_Spiral(self):
        return pdk.FixedPortWithLengthSpiral(total_length=self.spiral_length, n_o_loops=4)

    def _default_insts(self):
        insts = {}
        for m in range(self.num_Spiral_y):
            insts["gc_in_{}".format(m)] = pdk.GratingCoupler()
            insts["gc_out_{}".format(m)] = pdk.GratingCoupler()
            for n in range(self.num_Spiral_x):
                insts["Spiral_{}_{}".format(m, n)] = self.Spiral.modified_copy(
                    total_length=self.spiral_length + self.spiral_length_step * m, n_o_loops=4 + m*2 )

        return insts

    def _default_specs(self):
        specs = []
        for m in range(self.num_Spiral_y):
            for n in range(self.num_Spiral_x):
                specs += [
                    i3.Place("Spiral_{}_{}:in".format(m, n), (self.space_x_spiral * n, self.space_y_spiral * m)),
                ]

        for m in range(self.num_Spiral_y):
            for n in range(self.num_Spiral_x - 1):
                specs += [
                    i3.ConnectManhattan("Spiral_{}_{}:out".format(m, n), "Spiral_{}_{}:in".format(m, n + 1)),
                ]
        for m in range(self.num_Spiral_y):
            specs += [
                i3.PlaceRelative("gc_in_{}:out".format(m), "Spiral_{}_{}:in".format(self.num_Spiral_y - 1, 0),
                                 (-self.space_x, -m * self.space_y)),
                i3.PlaceRelative("gc_out_{}:out".format(m), "gc_in_{}:out".format(self.num_Spiral_y - 1 - m),
                                 (self.gc_distance_x, -self.gc_distance_y),
                                 angle=180),
            ]
            specs += [
                i3.ConnectManhattan(
                    [
                        ("gc_in_{}:out".format(m), "Spiral_{}_{}:in".format(self.num_Spiral_y - 1 - m, 0)),
                    ],
                    bend_radius=self.bend_radius,
                    start_straight=10,
                    end_straight=10,
                    control_points=[i3.V(i3.END - 50 - self.waveguide_space * m)],
                ),
                i3.ConnectManhattan(
                    [
                        ("gc_out_{}:out".format(m), "Spiral_{}_{}:out".format(m, self.num_Spiral_x - 1)),
                    ],
                    bend_radius=self.bend_radius,
                    start_straight=10,
                    end_straight=10,
                    control_points=[i3.V(i3.END + 50 + self.waveguide_space * m)],
                )
            ]

        return specs


if __name__ == '__main__':
    Spiral_c_layout = GenericSpiral().Layout()
    Spiral_c_layout.visualize(annotate=False)

整个线路还是i3.Circuit的框架,在定义线路中的子器件时用了两个for循环:

    def _default_insts(self):
        insts = {}
        for m in range(self.num_Spiral_y):
            insts["gc_in_{}".format(m)] = pdk.GratingCoupler()
            insts["gc_out_{}".format(m)] = pdk.GratingCoupler()
            for n in range(self.num_Spiral_x):
                insts["Spiral_{}_{}".format(m, n)] = self.Spiral.modified_copy(
                    total_length=self.spiral_length + self.spiral_length_step * m, n_o_loops=4 + m*2 )

        return insts

线路中用到的spiral都是si_fab库中:pdk.FixedPortWithLengthSpiral这个pdk,
为了给线路中多个spiral设定一个步长,除了前面有定义步长:spiral_length_step,在添加线路中的spiral的时候,通过modified_copy对定义的Spiral进行复制,就可以对每一个spiral设定不同的长度

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
The `copy` module in Python provides functions for creating copies of objects. The `copy()` function creates a shallow copy of an object, while the `deepcopy()` function creates a deep copy. A shallow copy creates a new object with the same values as the original object, but any mutable objects within the original object are still references to the original object. In other words, changes to the mutable objects in the copy will also be reflected in the original object. A deep copy creates a new object with the same values as the original object, and any mutable objects within the original object are also copied recursively, so changes to the mutable objects in the copy will not be reflected in the original object. Here is an example to illustrate the difference between shallow copy and deep copy: ``` import copy # create a list with a nested list original_list = [1, 2, [3, 4]] shallow_copy = copy.copy(original_list) deep_copy = copy.deepcopy(original_list) # modify the nested list in the shallow copy shallow_copy[2][0] = 5 # print the original list and the shallow copy print(original_list) # [1, 2, [5, 4]] print(shallow_copy) # [1, 2, [5, 4]] # modify the nested list in the deep copy deep_copy[2][0] = 6 # print the original list and the deep copy print(original_list) # [1, 2, [5, 4]] print(deep_copy) # [1, 2, [6, 4]] ``` In this example, we create a list with a nested list `[3, 4]`. We then create a shallow copy of the original list using `copy.copy()`, and a deep copy using `copy.deepcopy()`. We modify the nested list in the shallow copy by changing the first element from 3 to 5, and we modify the nested list in the deep copy by changing the first element from 3 to 6. When we print the original list and the shallow copy, we see that the nested list has been modified in both, because the shallow copy only creates a new reference to the nested list. However, when we print the original list and the deep copy, we see that the nested list has only been modified in the deep copy, because the deep copy creates a new copy of the nested list.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值