FDTD与matlab、python耦合

项目10:与matlab、python耦合

10.1 Getting Started with lumopt - Python API

Getting Started with lumopt - Python API

Inverse design using lumopt can be run from the CAD script editor, the command line or any python IDE. In the first sub-section, we will briefly describe how to import the lumopt and lumapi modules; although an experienced python user can likely skip this part. As a starting point, it is recommended to run the AppGallery examples and use these as templates for your own project. It may be helpful following along with these files as you read this page or you may simply reference this page when running the examples later. In the Project Init section, we outline the project inputs and necessary simulation objects that should be included. Important lumopt specific considerations are highlighted; however, a valid simulation set-up is imperative, so convergence testing should be considered a pre-requisite. Next important lumopt set-up classes, that should be updated to reflect your specifications are documented. Finally, a description of the scipy optimizer and lumopt optimization classes are presented. Shape and topology optimization primarily differ in how they handle the optimizable geometry which is the subject of the next page in this series.

使用 lumopt 进行逆向设计可以从 CAD 脚本编辑器、命令行或任何 Python 集成开发环境(IDE)中运行。在第一个子部分中,我们将简要介绍如何导入 lumopt 和 lumapi 模块;尽管经验丰富的 Python 用户可能可以跳过此部分。作为起点,建议运行 AppGallery 示例,并将其用作您自己项目的模板。在阅读本页时,跟随这些文件可能会有所帮助,或者您也可以在稍后运行示例时参考本页。在"项目初始化"部分,我们概述了项目输入和应包含的必要仿真对象。强调了 lumopt 特定的重要注意事项;然而,有效的仿真设置至关重要,因此收敛测试应被视为先决条件。接下来,记录了应根据您的规格进行更新的重要 lumopt 设置类。最后,介绍了 scipy 优化器和 lumopt 优化类。形状优化和拓扑优化主要在处理可优化几何的方式上有所不同,这是本系列下一页的主题。

Please note that the version of lumopt shipped with the Lumerical products, documented in this Knowledge Base, differs from the initial efforts undertaken by Christopher Keraly, which is documented using Lumopt Read the Docs. Even though there are many commonalities, in these documentations, we exclusively refer to the bundled Lumerical version of lumopt.

请注意,随 Lumerical 产品附带的 lumopt 版本(在本知识库中有相关文档)与克里斯托弗·凯拉利(Christopher Keraly)最初所做的工作有所不同,后者使用 Lumopt Read the Docs 进行了文档记录。尽管两者有很多共同之处,但在这些文档中,我们仅指随 Lumerical 产品捆绑的 lumopt 版本。

从 CAD 脚本编辑器安装运行具有无需设置的优势,并且使用的是随 Lumerical 安装程序一起提供的 Python 3 发行版,因此无需单独安装 Python。此方法会自动配置工作区以找到 lumopt 和 lumapi 模块,对于 Python 经验较少的用户来说是首选方法。对于更有经验的用户,使用自己的 Python 版本并在集成开发环境(IDE)或命令行中运行可能更可取。要做到这一点,只需导入 lumopt 和 lumapi 模块,这需要指定正确的路径。可以使用 importlibutil 传递显式路径,或者永久更新搜索路径,将 PythonPath 对象附加到末尾。使用众多库的高级用户可能希望创建一个 Lumerical 虚拟环境。有关这些方法和特定操作系统路径的更多信息,请参阅"会话管理 - Python API"。注意:Lumerical 随附已安装的 Python 3 版本,包括 lumapi 和 lumopt 模块。要"开箱即用"运行我们的任何示例,只需从 CAD 中的脚本文件编辑器运行脚本即可。

Project Init

Base Simulation

The base simulation needs to be defined using one of the following options

Predefined simulation file - Initialize a python variable that specifies the path to the base file. Example Grating coupler.

预定义的模拟文件------初始化一个python变量,指定基本文件的路径。使用实例光栅耦合器。

base_sim = os.path.join(os.path.dirname(file), 'grating_base.fsp')

An lsf set-up script - Create a python variable using the load_from_lsf function. Example Waveguide crossing.

一个 LSF 设置脚本 - 使用 load_from_lsf 函数创建一个 Python 变量。示例:波导交叉。

from lumopt.utilities.load_lumerical_scripts import load_from_lsf

crossing_base = load_from_lsf('varFDTD_crossing.lsf')

Callable python code that does the set-up using the API - This can be a function defined in the same file or an imported function. Example Y-branch.

使用API进行设置的可调用python代码-这可以是在同一文件中定义的函数或导入的函数。Y-branch示例。

sys.path.append(os.path.dirname(file)) #Add current directory to Python path

from varFDTD_y_branch import y_branch_init_ #Import y_branch_init function from file

y_branch_base = y_branch_init_ #New handle for function

Each method produces a file which the optimizer updates and runs. Since the resulting project files should be equivalent; the method each user employs is a matter of preference or convenience.

每种方法都会生成一个文件,优化器会对其进行更新和运行。由于生成的项目文件应该是等效的,所以每个用户采用哪种方法只是个人偏好或方便程度的问题。

相关推荐
递归不收敛9 小时前
吴恩达机器学习课程(PyTorch 适配)学习笔记大纲
pytorch·学习·机器学习
不太可爱的叶某人9 小时前
【学习笔记】kafka权威指南——第10章 监控kafka (7-10章只做了解)
笔记·学习·kafka
递归不收敛11 小时前
吴恩达机器学习课程(PyTorch适配)学习笔记:2.4 激活函数与多类别处理
pytorch·学习·机器学习
加油201911 小时前
如何快速学习一个网络协议?
网络·网络协议·学习·方法论
F_D_Z12 小时前
数据集相关类代码回顾理解 | StratifiedShuffleSplit\transforms.ToTensor\Counter
python·torchvision·transforms
A9better12 小时前
嵌入式开发学习日志36——stm32之USART串口通信前述
stm32·单片机·嵌入式硬件·学习
不太可爱的叶某人12 小时前
【学习笔记】kafka权威指南——第6章 可靠的数据传递
笔记·学习·kafka
tao35566713 小时前
【Python刷力扣hot100】283. Move Zeroes
开发语言·python·leetcode
小宁爱Python14 小时前
从零搭建 RAG 智能问答系统1:基于 LlamaIndex 与 Chainlit实现最简单的聊天助手
人工智能·后端·python