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.

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

相关推荐
AI量化投资实验室17 小时前
年化398%,回撤11%,夏普比5,免费订阅,5积分可查看参数|多智能体的架构设计|akshare的期货MCP代码
人工智能·python
夫唯不争,故无尤也18 小时前
AI调度框架全解析:从通用到LLM专用
python·大模型·调用框架
Brookty18 小时前
【算法】位运算| & ^ ~ -n n-1
学习·算法·leetcode·位运算
shenghaide_jiahu18 小时前
数学分析简明教程——1.4(未完)
学习
MATLAB代码顾问18 小时前
MATLAB实现模糊PID控制
开发语言·matlab
wudl556618 小时前
Python 虚拟环境和包管理
数据库·python·sqlite
tritone19 小时前
在优豆云的免费云服务器上开启MongoDB学习之旅
服务器·学习·mongodb
Geoking.20 小时前
PyTorch torch.unique() 基础与实战
人工智能·pytorch·python
俊俊谢20 小时前
【第一章】金融数据的获取——金融量化学习入门笔记
笔记·python·学习·金融·量化·akshare
Yupureki20 小时前
从零开始的C++学习生活 20:数据结构与STL复习课(4.4w字全解析)
c语言·数据结构·c++·学习·visual studio·1024程序员节