LumAPI 1.0.1__tar.gz → 1.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ {
2
+ "lumerical_path": "D:\\Program Files\\Lumerical",
3
+ "version": "v241"
4
+ }
@@ -489,104 +489,136 @@ def RorySommerfeld_Vector(lamb, x_near, y_near, E_near_x, E_near_y, x_far, y_far
489
489
  return E_far, E_far_x, E_far_y, E_far_z
490
490
 
491
491
 
492
- class lumapi:
492
+ class lumerical:
493
493
  def __init__(self, lumerical_path='', version='', config_path=CONFIG_PATH):
494
494
  self.config_path = config_path
495
-
496
- # 如果没有提供路径,尝试从配置文件加载
497
- if not lumerical_path:
498
- try:
499
- with open(self.config_path, 'r') as f:
500
- config = json.load(f)
501
- lumerical_path = config.get('lumerical_path')
502
- version = config.get('version')
503
-
504
- if not lumerical_path:
505
- raise ValueError("配置文件中缺少lumerical_path字段")
506
-
507
- except Exception as e:
508
- raise ValueError(f"配置文件读取失败: {str(e)}")
509
-
510
- # 验证路径
511
- self.lumapi = validate_path(lumerical_path, version)
512
-
513
- # 检测路径是否有效
514
- if not self.lumapi:
515
- raise ValueError(f"错误:Lumerical路径无效,请检查路径{lumerical_path}和版本{version}")
516
-
495
+ self.lumapi = None
517
496
  self.lumerical_path = lumerical_path
518
497
  self.version = version
519
-
520
- def FDTD(self, filename=None, key = None, hide = False, serverArgs = {}, remoteArgs = {}, **kwargs):
498
+
499
+ # 尝试加载配置
500
+ self._load_config()
501
+
502
+ def _load_config(self):
503
+ """内部方法:尝试从参数或配置文件加载 lumapi"""
504
+ try:
505
+ path = self.lumerical_path
506
+ ver = self.version
507
+
508
+ # 如果初始化时没给路径,尝试读配置
509
+ if not path:
510
+ if os.path.exists(self.config_path):
511
+ with open(self.config_path, 'r', encoding='utf-8') as f:
512
+ config = json.load(f)
513
+ path = config.get('lumerical_path')
514
+ ver = config.get('version')
515
+
516
+ if path:
517
+ self.lumapi = validate_path(path, ver)
518
+ self.lumerical_path = path
519
+ self.version = ver
520
+ except Exception:
521
+ self.lumapi = None
522
+
523
+ def _check_config_and_prompt(self):
524
+ """核心逻辑:检查配置状态,若无效则引导用户使用 LumAPI 命令"""
525
+ if self.lumapi is None:
526
+ print("\n" + "*" * 60)
527
+ print("【配置错误】未检测到有效的 Lumerical 环境。")
528
+ print("原因可能是:")
529
+ print("1. 尚未进行初始化配置。")
530
+ print("2. 配置文件 config.json 损坏或路径已失效。")
531
+ print("\n请在终端执行以下命令进行配置:")
532
+ print(" LumAPI")
533
+ print("或者使用命令行配置程序:")
534
+ print(" LumAPI_CLI")
535
+ print("*" * 60 + "\n")
536
+ # 退出程序或抛出异常,防止后续调用崩溃
537
+ sys.exit(1)
538
+
539
+ def FDTD(self, filename=None, key=None, hide=False, serverArgs={}, remoteArgs={}, **kwargs):
540
+ self._check_config_and_prompt()
521
541
  return FDTD(self.lumapi, filename, key, hide, serverArgs, remoteArgs, **kwargs)
522
542
 
523
- def MODE(self, filename=None, key = None, hide = False, serverArgs = {}, remoteArgs = {}, **kwargs):
543
+ def MODE(self, filename=None, key=None, hide=False, serverArgs={}, remoteArgs={}, **kwargs):
544
+ self._check_config_and_prompt()
524
545
  return MODE(self.lumapi, filename, key, hide, serverArgs, remoteArgs, **kwargs)
525
546
 
526
- def DEVICE(self, filename=None, key = None, hide = False, serverArgs = {}, remoteArgs = {}, **kwargs):
527
- return MODE(self.lumapi, filename, key, hide, serverArgs, remoteArgs, **kwargs)
547
+ def DEVICE(self, filename=None, key=None, hide=False, serverArgs={}, remoteArgs={}, **kwargs):
548
+ self._check_config_and_prompt()
549
+ return DEVICE(self.lumapi, filename, key, hide, serverArgs, remoteArgs, **kwargs)
528
550
 
529
- def INTERCONNECT(self, filename=None, key = None, hide = False, serverArgs = {}, remoteArgs = {}, **kwargs):
530
- return MODE(self.lumapi, filename, key, hide, serverArgs, remoteArgs, **kwargs)
531
-
532
- class FDTD():
533
- def __init__(self, lumapi, filename=None, key = None, hide = False, serverArgs = {}, remoteArgs = {}, **kwargs):
534
- self.lumapi = lumapi
535
- self.filename = filename
536
-
537
- self.fdtd = lumapi.FDTD(filename, key, hide, serverArgs, remoteArgs, **kwargs)
551
+ def INTERCONNECT(self, filename=None, key=None, hide=False, serverArgs={}, remoteArgs={}, **kwargs):
552
+ self._check_config_and_prompt()
553
+ return INTERCONNECT(self.lumapi, filename, key, hide, serverArgs, remoteArgs, **kwargs)
554
+
555
+ class LumFuncBase:
556
+ """Lumerical 功能基类,处理通用的 API 转发和参数预处理"""
557
+ def __init__(self, target_handle):
558
+ # 隐藏内部句柄,避免与转发逻辑冲突
559
+ self._handle = target_handle
560
+
561
+ def _process_arg(self, arg):
562
+ """
563
+ 核心预处理逻辑:
564
+ 1. 整型 ndarray -> 浮点型
565
+ 2. 一维 ndarray (len > 1) -> 二维 [[...]]
566
+ """
567
+ if isinstance(arg, np.ndarray):
568
+ # 规则 1: 检查是否为整型数组并转换
569
+ if np.issubdtype(arg.dtype, np.integer):
570
+ arg = arg.astype(float)
571
+
572
+ # 规则 2: 检查一维数组且长度不为 1,进行升维
573
+ if arg.ndim == 1 and arg.shape[0] != 1:
574
+ arg = arg[np.newaxis, :]
575
+ return arg
538
576
 
539
577
  def __getattr__(self, name):
540
- '''
541
- 将原本函数转发回去
542
- '''
543
- return getattr(self.fdtd, name)
544
-
545
- class MODE():
546
- def __init__(self, lumapi, filename=None, key = None, hide = False, serverArgs = {}, remoteArgs = {}, **kwargs):
547
- self.lumapi = lumapi
548
- self.filename = filename
578
+ # 从 Lumerical 原始句柄中获取属性或方法
579
+ attr = getattr(self._handle, name)
549
580
 
550
- if not filename:
551
- self.mode = lumapi.MODE()
552
- else:
553
- self.mode = lumapi.MODE(filename, key, hide, serverArgs, remoteArgs, **kwargs)
554
-
555
- def __getattr__(self, name):
556
- '''
557
- 将原本函数转发回去
558
- '''
559
- return getattr(self.mode, name)
581
+ # 如果不是可调用对象(如变量、常量),直接返回
582
+ if not callable(attr):
583
+ return attr
584
+
585
+ # 如果是方法,返回包装函数进行参数拦截处理
586
+ def wrapper(*args, **kwargs):
587
+ # 处理位置参数
588
+ new_args = tuple(self._process_arg(arg) for arg in args)
589
+ # 处理关键字参数
590
+ new_kwargs = {k: self._process_arg(v) for k, v in kwargs.items()}
591
+
592
+ # 调用原始 API 并返回结果
593
+ return attr(*new_args, **new_kwargs)
594
+
595
+ return wrapper
560
596
 
561
- class DEVICE():
562
- def __init__(self, lumapi, filename=None, key = None, hide = False, serverArgs = {}, remoteArgs = {}, **kwargs):
563
- self.lumapi = lumapi
597
+ class FDTD(LumFuncBase):
598
+ def __init__(self, lumapi, filename=None, key=None, hide=False, serverArgs={}, remoteArgs={}, **kwargs):
599
+ handle = lumapi.FDTD(filename, key, hide, serverArgs, remoteArgs, **kwargs)
600
+ super().__init__(handle)
564
601
  self.filename = filename
565
-
566
- if not filename:
567
- self.device = lumapi.DEVICE()
568
- else:
569
- self.device = lumapi.DEVICE(filename, key, hide, serverArgs, remoteArgs, **kwargs)
570
602
 
571
- def __getattr__(self, name):
572
- '''
573
- 将原本函数转发回去
574
- '''
575
- return getattr(self.device, name)
576
-
577
- class INTERCONNECT():
578
- def __init__(self, lumapi, filename=None, key = None, hide = False, serverArgs = {}, remoteArgs = {}, **kwargs):
579
- self.lumapi = lumapi
603
+ class MODE(LumFuncBase):
604
+ def __init__(self, lumapi, filename=None, key=None, hide=False, serverArgs={}, remoteArgs={}, **kwargs):
605
+ handle = lumapi.MODE(filename, key, hide, serverArgs, remoteArgs, **kwargs)
606
+ super().__init__(handle)
580
607
  self.filename = filename
581
-
582
- self.interconnect = lumapi.INTERCONNECT(filename, key, hide, serverArgs, remoteArgs, **kwargs)
583
608
 
584
- def __getattr__(self, name):
585
- '''
586
- 将原本函数转发回去
587
- '''
588
- return getattr(self.interconnect, name)
609
+ class DEVICE(LumFuncBase):
610
+ def __init__(self, lumapi, filename=None, key=None, hide=False, serverArgs={}, remoteArgs={}, **kwargs):
611
+ handle = lumapi.DEVICE(filename, key, hide, serverArgs, remoteArgs, **kwargs)
612
+ super().__init__(handle)
613
+ self.filename = filename
589
614
 
615
+ class INTERCONNECT(LumFuncBase):
616
+ def __init__(self, lumapi, filename=None, key=None, hide=False, serverArgs={}, remoteArgs={}, **kwargs):
617
+ handle = lumapi.INTERCONNECT(filename, key, hide, serverArgs, remoteArgs, **kwargs)
618
+ super().__init__(handle)
619
+ self.filename = filename
620
+
621
+ lumapi = lumerical()
590
622
 
591
623
  if __name__ == '__main__':
592
624
  um = 1e-6
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: LumAPI
3
- Version: 1.0.1
3
+ Version: 1.0.2
4
4
  Summary: Lumerical Python API 自动化配置工具
5
5
  Requires-Python: >=3.7
6
6
  Description-Content-Type: text/markdown
@@ -25,6 +25,57 @@ Dynamic: license-file
25
25
 
26
26
  ## 🚀 快速开始
27
27
 
28
+ ## 📦 pip安装(推荐)
29
+
30
+ ### 1. 库文件下载
31
+ 通过运行以下命令安装`LumAPI`库
32
+ ```bash
33
+ pip install LumAPI
34
+ ```
35
+ ### 2. 配置lumerical路径
36
+ 在安装完库后运行下面的命令即可打开lumerical路径配置页面
37
+ 图形界面配置:
38
+ ```bash
39
+ LumAPI
40
+ ```
41
+ 命令行配置:
42
+ ```bash
43
+ LumAPI_CLI
44
+ ```
45
+ ### 3. 使用
46
+ 通过下述代码即可调用 Lumerical API:
47
+ ```python
48
+ from LumAPI import *
49
+
50
+ filename = 'simulation.fsp'
51
+ fdtd = lumapi.FDTD(filename)
52
+ fdtd.close()
53
+ ```
54
+ 或者不进行lumerical配置,直接传入lumerical路径:
55
+ ```python
56
+ from LumAPI import *
57
+ lumerical_path = 'C:/Program Files/Lumerical'
58
+ version = 'v241'
59
+ fdtd = lumerical(lumerical_path=lumerical_path, version=version).FDTD(filename)
60
+ fdtd.close()
61
+ ```
62
+ 或者传入config.json路径:
63
+ ```python
64
+ from LumAPI import *
65
+ config_path = './config.json'
66
+ fdtd = lumerical(config_path=config_path).FDTD(filename)
67
+ fdtd.close()
68
+ ```
69
+ 其中config.json文件内容如下:
70
+ ```python
71
+ {
72
+ "lumerical_path": "C:\\Program Files\\Lumerical",
73
+ "version": "v241"
74
+ }
75
+ ```
76
+
77
+ ## 📦 打包程序安装
78
+
28
79
  ### 1. 获取程序
29
80
  请前往 [Releases 页面](releases) 下载适配您操作系统(Windows/Linux)及架构(AMD64/ARM64)的预编译程序。`LumAPI_GUI`为带图形界面版本的配置程序,`LumAPI_CLI`为无图形界面版本的命令行配置工具,二者选择其一即可。
30
81
 
@@ -66,7 +117,7 @@ Dynamic: license-file
66
117
 
67
118
  **代码示例:**
68
119
  ```python
69
- import LumAPI.lumapi as lumapi # 根据实际导出结构调整导入路径
120
+ from LumAPI import lumapi
70
121
 
71
122
  # 定义基础参数
72
123
  um = 1e-6
@@ -11,4 +11,5 @@ LumAPI.egg-info/SOURCES.txt
11
11
  LumAPI.egg-info/dependency_links.txt
12
12
  LumAPI.egg-info/entry_points.txt
13
13
  LumAPI.egg-info/requires.txt
14
- LumAPI.egg-info/top_level.txt
14
+ LumAPI.egg-info/top_level.txt
15
+ test/test.py
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: LumAPI
3
- Version: 1.0.1
3
+ Version: 1.0.2
4
4
  Summary: Lumerical Python API 自动化配置工具
5
5
  Requires-Python: >=3.7
6
6
  Description-Content-Type: text/markdown
@@ -25,6 +25,57 @@ Dynamic: license-file
25
25
 
26
26
  ## 🚀 快速开始
27
27
 
28
+ ## 📦 pip安装(推荐)
29
+
30
+ ### 1. 库文件下载
31
+ 通过运行以下命令安装`LumAPI`库
32
+ ```bash
33
+ pip install LumAPI
34
+ ```
35
+ ### 2. 配置lumerical路径
36
+ 在安装完库后运行下面的命令即可打开lumerical路径配置页面
37
+ 图形界面配置:
38
+ ```bash
39
+ LumAPI
40
+ ```
41
+ 命令行配置:
42
+ ```bash
43
+ LumAPI_CLI
44
+ ```
45
+ ### 3. 使用
46
+ 通过下述代码即可调用 Lumerical API:
47
+ ```python
48
+ from LumAPI import *
49
+
50
+ filename = 'simulation.fsp'
51
+ fdtd = lumapi.FDTD(filename)
52
+ fdtd.close()
53
+ ```
54
+ 或者不进行lumerical配置,直接传入lumerical路径:
55
+ ```python
56
+ from LumAPI import *
57
+ lumerical_path = 'C:/Program Files/Lumerical'
58
+ version = 'v241'
59
+ fdtd = lumerical(lumerical_path=lumerical_path, version=version).FDTD(filename)
60
+ fdtd.close()
61
+ ```
62
+ 或者传入config.json路径:
63
+ ```python
64
+ from LumAPI import *
65
+ config_path = './config.json'
66
+ fdtd = lumerical(config_path=config_path).FDTD(filename)
67
+ fdtd.close()
68
+ ```
69
+ 其中config.json文件内容如下:
70
+ ```python
71
+ {
72
+ "lumerical_path": "C:\\Program Files\\Lumerical",
73
+ "version": "v241"
74
+ }
75
+ ```
76
+
77
+ ## 📦 打包程序安装
78
+
28
79
  ### 1. 获取程序
29
80
  请前往 [Releases 页面](releases) 下载适配您操作系统(Windows/Linux)及架构(AMD64/ARM64)的预编译程序。`LumAPI_GUI`为带图形界面版本的配置程序,`LumAPI_CLI`为无图形界面版本的命令行配置工具,二者选择其一即可。
30
81
 
@@ -66,7 +117,7 @@ Dynamic: license-file
66
117
 
67
118
  **代码示例:**
68
119
  ```python
69
- import LumAPI.lumapi as lumapi # 根据实际导出结构调整导入路径
120
+ from LumAPI import lumapi
70
121
 
71
122
  # 定义基础参数
72
123
  um = 1e-6
@@ -11,6 +11,57 @@
11
11
 
12
12
  ## 🚀 快速开始
13
13
 
14
+ ## 📦 pip安装(推荐)
15
+
16
+ ### 1. 库文件下载
17
+ 通过运行以下命令安装`LumAPI`库
18
+ ```bash
19
+ pip install LumAPI
20
+ ```
21
+ ### 2. 配置lumerical路径
22
+ 在安装完库后运行下面的命令即可打开lumerical路径配置页面
23
+ 图形界面配置:
24
+ ```bash
25
+ LumAPI
26
+ ```
27
+ 命令行配置:
28
+ ```bash
29
+ LumAPI_CLI
30
+ ```
31
+ ### 3. 使用
32
+ 通过下述代码即可调用 Lumerical API:
33
+ ```python
34
+ from LumAPI import *
35
+
36
+ filename = 'simulation.fsp'
37
+ fdtd = lumapi.FDTD(filename)
38
+ fdtd.close()
39
+ ```
40
+ 或者不进行lumerical配置,直接传入lumerical路径:
41
+ ```python
42
+ from LumAPI import *
43
+ lumerical_path = 'C:/Program Files/Lumerical'
44
+ version = 'v241'
45
+ fdtd = lumerical(lumerical_path=lumerical_path, version=version).FDTD(filename)
46
+ fdtd.close()
47
+ ```
48
+ 或者传入config.json路径:
49
+ ```python
50
+ from LumAPI import *
51
+ config_path = './config.json'
52
+ fdtd = lumerical(config_path=config_path).FDTD(filename)
53
+ fdtd.close()
54
+ ```
55
+ 其中config.json文件内容如下:
56
+ ```python
57
+ {
58
+ "lumerical_path": "C:\\Program Files\\Lumerical",
59
+ "version": "v241"
60
+ }
61
+ ```
62
+
63
+ ## 📦 打包程序安装
64
+
14
65
  ### 1. 获取程序
15
66
  请前往 [Releases 页面](releases) 下载适配您操作系统(Windows/Linux)及架构(AMD64/ARM64)的预编译程序。`LumAPI_GUI`为带图形界面版本的配置程序,`LumAPI_CLI`为无图形界面版本的命令行配置工具,二者选择其一即可。
16
67
 
@@ -52,7 +103,7 @@
52
103
 
53
104
  **代码示例:**
54
105
  ```python
55
- import LumAPI.lumapi as lumapi # 根据实际导出结构调整导入路径
106
+ from LumAPI import lumapi
56
107
 
57
108
  # 定义基础参数
58
109
  um = 1e-6
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "LumAPI"
7
- version = "1.0.1"
7
+ version = "1.0.2"
8
8
  description = "Lumerical Python API 自动化配置工具"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.7"
@@ -0,0 +1,13 @@
1
+ from LumAPI import *
2
+
3
+ fdtd = lumapi.FDTD()
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes