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

2024-05-11 20:28

本文主要是介绍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)

这篇关于luceda ipkiss教程 71:统计线路中器件的个数的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/980565

相关文章

MySQL Workbench 安装教程(保姆级)

《MySQLWorkbench安装教程(保姆级)》MySQLWorkbench是一款强大的数据库设计和管理工具,本文主要介绍了MySQLWorkbench安装教程,文中通过图文介绍的非常详细,对大... 目录前言:详细步骤:一、检查安装的数据库版本二、在官网下载对应的mysql Workbench版本,要是

通过Docker Compose部署MySQL的详细教程

《通过DockerCompose部署MySQL的详细教程》DockerCompose作为Docker官方的容器编排工具,为MySQL数据库部署带来了显著优势,下面小编就来为大家详细介绍一... 目录一、docker Compose 部署 mysql 的优势二、环境准备与基础配置2.1 项目目录结构2.2 基

Linux安装MySQL的教程

《Linux安装MySQL的教程》:本文主要介绍Linux安装MySQL的教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录linux安装mysql1.Mysql官网2.我的存放路径3.解压mysql文件到当前目录4.重命名一下5.创建mysql用户组和用户并修

一文详解SQL Server如何跟踪自动统计信息更新

《一文详解SQLServer如何跟踪自动统计信息更新》SQLServer数据库中,我们都清楚统计信息对于优化器来说非常重要,所以本文就来和大家简单聊一聊SQLServer如何跟踪自动统计信息更新吧... SQL Server数据库中,我们都清楚统计信息对于优化器来说非常重要。一般情况下,我们会开启"自动更新

最新Spring Security实战教程之Spring Security安全框架指南

《最新SpringSecurity实战教程之SpringSecurity安全框架指南》SpringSecurity是Spring生态系统中的核心组件,提供认证、授权和防护机制,以保护应用免受各种安... 目录前言什么是Spring Security?同类框架对比Spring Security典型应用场景传统

最新Spring Security实战教程之表单登录定制到处理逻辑的深度改造(最新推荐)

《最新SpringSecurity实战教程之表单登录定制到处理逻辑的深度改造(最新推荐)》本章节介绍了如何通过SpringSecurity实现从配置自定义登录页面、表单登录处理逻辑的配置,并简单模拟... 目录前言改造准备开始登录页改造自定义用户名密码登陆成功失败跳转问题自定义登出前后端分离适配方案结语前言

Centos环境下Tomcat虚拟主机配置详细教程

《Centos环境下Tomcat虚拟主机配置详细教程》这篇文章主要讲的是在CentOS系统上,如何一步步配置Tomcat的虚拟主机,内容很简单,从目录准备到配置文件修改,再到重启和测试,手把手带你搞定... 目录1. 准备虚拟主机的目录和内容创建目录添加测试文件2. 修改 Tomcat 的 server.X

Python中的输入输出与注释教程

《Python中的输入输出与注释教程》:本文主要介绍Python中的输入输出与注释教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、print 输出功能1. 基础用法2. 多参数输出3. 格式化输出4. 换行控制二、input 输入功能1. 基础用法2. 类

Java导入、导出excel用法步骤保姆级教程(附封装好的工具类)

《Java导入、导出excel用法步骤保姆级教程(附封装好的工具类)》:本文主要介绍Java导入、导出excel的相关资料,讲解了使用Java和ApachePOI库将数据导出为Excel文件,包括... 目录前言一、引入Apache POI依赖二、用法&步骤2.1 创建Excel的元素2.3 样式和字体2.

Spring Boot拦截器Interceptor与过滤器Filter详细教程(示例详解)

《SpringBoot拦截器Interceptor与过滤器Filter详细教程(示例详解)》本文详细介绍了SpringBoot中的拦截器(Interceptor)和过滤器(Filter),包括它们的... 目录Spring Boot拦截器(Interceptor)与过滤器(Filter)详细教程1. 概述1