luceda ipkiss教程 71:统计线路中器件的个数

**案例分享:**统计线路中某一器件的个数
如,统计SplitterTree中mmi的个数:
在这里插入图片描述
在这里插入图片描述
所有代码如下:

# Copyright (C) 2020 Luceda Photonicsfrom si_fab import all as pdk
from ipkiss3 import all as i3class GeneralizedSplitterTree(i3.Circuit):splitter = i3.ChildCellProperty(doc="Splitter used.")n_levels = i3.PositiveIntProperty(default=3, doc="Number of tree levels.")spacing_x = i3.PositiveNumberProperty(default=100.0, doc="Horizontal spacing between the splitter levels.")spacing_y = i3.PositiveNumberProperty(default=50.0, doc="Vertical spacing between the splitters in the last level.")def _default_splitter(self):return pdk.MMI1x2Optimized1550()  # try changing this to the y-junction in the si_fab PDKdef _default_insts(self):insts = {}# 1.  Using nested for loops we can add all the splitters we need for the circuit, as well as name them# according to their position (level) in the circuit. Also note that the splitter is a parameter, so we could# easily replace all the MMIs with different MMIs or a y-splitter with just one change to the code.for level in range(self.n_levels):for splitter_no in range(2 ** level):insts[f"sp_{level}_{splitter_no}"] = self.splitterreturn instsdef _default_specs(self):specs = []# 2. Placing the MMIs is fairly straight forward, using local variables of x and y coordinates to help improve# the readability of the code. The "y-coord" in particular is not obvious, however the coordinate is derived# from the level and number in each level due to the relationship between each MMI. Again we use nested for# loops to achieve this.for level in range(self.n_levels):for splitter in range(2 ** level):x_coord = level * self.spacing_xy_coord = self.spacing_y * (-0.5 * 2 ** (self.n_levels - 1) + ((splitter + 0.5) * 2 ** (self.n_levels - level - 1)))specs.append(i3.Place(f"sp_{level}_{splitter}", (x_coord, y_coord)))# 3. For each MMI there are two output ports that need connecting. We decide how best to do this, using# "splitter % 2" which returns the remainder from dividing by 2. This will be 0 for even numbers and non-zero# for odd numbers. In this way we can separate the two outputs correctly.# In the level loop we start at 1, but then subtract 1 during the naming as the final level will not have any# connections.for level in range(1, self.n_levels):for splitter in range(2 ** level):if splitter % 2 == 0:in_port = f"sp_{level - 1}_{int(splitter / 2)}:out1"else:in_port = f"sp_{level - 1}_{int(splitter / 2)}:out2"out_port = f"sp_{level}_{splitter}:in1"specs.append(i3.ConnectBend(in_port, out_port))return specsdef _default_exposed_ports(self):# 4. In the same way we can expose the ports in the circuit. By default, all unconnected ports would be exposed,# but we want to rename them for simplicity.exposed_ports = {"sp_0_0:in1": "in"}  # adding the input portcnt = 1  # we use a local variable to keep track of how many output we have labeledlevel = self.n_levels - 1n_splitters = 2 ** levelfor splitter in range(n_splitters):  # looping over the output portsexposed_ports[f"sp_{level}_{splitter}:out1"] = f"out{cnt}"cnt += 1exposed_ports[f"sp_{level}_{splitter}:out2"] = f"out{cnt}"cnt += 1return exposed_portsif __name__ == "__main__":splitter_tree1 = GeneralizedSplitterTree(n_levels=5, splitter=pdk.MMI1x2Optimized1550())splitter_tree1_layout = splitter_tree1.Layout()splitter_tree1_layout.visualize()component_counted = pdk.MMI1x2Optimized1550()num_mmi = sum(1 for elems in splitter_tree1.Layout().layout if component_counted.name in elems.reference.name)print(num_mmi)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/689050.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Codeforces Round 605 (Div. 3) A~D

本人水平不高,开这个专栏主要是督促自己补题,有些题对目前的我来说还比较难,还补不动,等以后能力上来了再补。。。 原题链接:Dashboard - Codeforces Round 605 (Div. 3) - Codeforces 目录 A. Three Friends B. Sn…

国产银河麒麟V10SP1系统下搭建TiDB数据库操作步骤图文

开发目的:在国产银河麒麟系统中搭建TiDB数据库运行环境。 开发工具:银河麒麟系统V10SP1TiDBMySql数据库8.0。 具体步骤: 1、在VmWare虚拟机中安装好国产银河麒麟V10Sp1操作系统。 2、打开终端命令,安装TiDB相关软件&#xff1…

Abiotic Factor 非生物因素开服教程

1、购买后登录服务器(百度搜索莱卡云)game.lcayun.com 进入控制面板后会出现正在安装的界面,安装时长约5分钟左右(如长时间处于安装中请联系我们的客服人员) 2、复制查询端口 点击网络可以看到两个端口,首…

【Python基础】装饰器(3848字)

文章目录 [toc]闭包什么是装饰器装饰器示例不使用装饰器语法使用装饰器语法 装饰器传参带参数的装饰器类装饰器魔术方法\__call__()类装饰器示例带参数类装饰器property装饰器分页操作商品价格操作 个人主页:丷从心 系列专栏:Python基础 学习指南&…

信创应用软件之办公流版签

信创应用软件之办公流版签 文章目录 信创应用软件之办公流版签概述流式文件版式文件电子签章厂商金山办公永中-永中Office中标-中标普华Office福昕科技e签宝法大大 概述 办公流版签软件主要包括办公中常用到的流式软件、版式软件以及电子签章。 版式文件和流式文件都是文书类…

飞利浦|西圣开放式耳机怎么选?爆款机型深度对比!

现在,开放式耳机以其独特的非入耳设计,成为了市场上的新宠。开放式耳机在佩戴上不仅能让我们长时间享受舒适的体验,更告别了入耳式耳机会导致的耳闷头昏的烦恼。但是现在,面对市场上琳琅满目的品牌和型号,许多消费者感…

LabVIEW学习记录4-局部变量、全局变量、共享变量

【LabVIEW】局部变量、全局变量、共享变量 一、变量定义二、内存分配三、竞争状态四、变量创建及简单使用示例4.1 局部变量4.1.1 局部变量的创建4.1.2 局部变量的编程实例 4.2 全局变量4.2.1 创建4.2.2 调用4.2.3 编程实例 4.3 共享变量 一、变量定义 LabVIEW(Labor…

C++:二叉搜索树的底层模拟实现

概念: 二叉搜索树又称二叉排序树,它或者是一棵空树,或者是具有以下性质的二叉树: 搜索二叉树的操作: int a[] {8, 3, 1, 10, 6, 4, 7, 14, 13};二叉搜索树需要满足左子树比根小,右子树比根大,…

2024第十六届“中国电机工程学会杯”数学建模A题B题思路分析

文章目录 1 赛题思路2 比赛日期和时间3 竞赛信息4 建模常见问题类型4.1 分类问题4.2 优化问题4.3 预测问题4.4 评价问题 5 建模资料 1 赛题思路 (赛题出来以后第一时间在CSDN分享) https://blog.csdn.net/dc_sinor?typeblog 2 比赛日期和时间 报名截止时间:2024…

SQL注入(sqli-labs第一关)

sqli-labs第一关 方法一:手工注入 来到第一关,图上说我们需要一个数字的参数 于是我们先手工注入?id1 and 11 跟?id1 and 12发现页面没有报错 每张截图上面页面中有select查询语句,这是我在第一关的源码中加上了echo "$sql ";…

若依修改表格滚动条宽度

找到目录ruoyi-ui/src/assets/styles/ruoyi.scss 添加滚动条样式 //修改滚动条的宽度和高度(横向是高度,纵向是宽度)::-webkit-scrollbar {width: 14px;height: 14px;background-color: transparent;}

A计算机上的程序与B计算机上部署的vmware上的虚拟机的程序通讯 如何配置?

环境: 在A计算机上运行着Debian11.3 Linux操作系统;在B计算机上运行着Windows10操作系统,并且安装了VMware软件,然后在VMware上创建了虚拟机C并安装了CentOS 6操作系统 需求: 现在A计算机上的程序需要同虚拟机C上的软…