Ansys Lumerical API

Inter-product integration configuration guide

This article shows how to configure Lumerical for use with the inter-product API feature. This feature is built into all Lumerical products and does not require an additional license. 

Windows configuration

This is configured during the product installation. No further configuration is required.

Linux configuration

NOTE: The configuration shown is for supported Linux systems with gnome-terminal running the bash shell.

  1. Adding a Lumerical product's installation path to the system path allows you to start any product, by typing the product executable in your Terminal without having to specify the full path.
  2. Change directory to your local folder, '~/' or '/home/USERNAME/'
    $ cd ~ 
    $ vi .bash_profile 
  3. Edit/append your [[.bash_profile]] file with the following lines. (default install path shown)
    PATH=/opt/lumerical/v232/bin:$PATH
    export PATH
  4. Save and close the editor.
  5. Quit Terminal or disconnect your current session.
  6. Reconnect or open Terminal.
  7. Typing the 'launcher' or the 'product executable' should open the launcher or product's IDE (respectively). 
    $  launcher 
       OR
    $  fdtd-solutions &
    $  mode-solutions &
    $  device &
    $  interconnect &
  8. You should be able to launch and another Lumerical product from within the 'Script prompt.'
    > opensession('mode')

macOS configuration 

NOTE: Run Lumerical using the Terminal on macOS. The API does not work when Lumerical is run from the LaunchPad or Finder.

  1. Open Terminal
  2. Add the Lumerical installation path to your current shell. (i.e. All products added to path)
    export PATH=$PATH:/Applications/Lumerical\ v232.app/Contents/Applications/FDTD\ Solutions.app/Contents/MacOS
    export PATH=$PATH:/Applications/Lumerical\ v232.app/Contents/Applications/MODE\ Solutions.app/Contents/MacOS
    export PATH=$PATH:/Applications/Lumerical\ v232.app/Contents/Applications/DEVICE.app/Contents/MacOS
    export PATH=$PATH:/Applications/Lumerical\ v232.app/Contents/Applications/INTERCONNECT.app/Contents/Mac
    
    $ fdtd-solutions &
    $ mode-solutions &
    $ device &
    $ interconnect &
  3. You should be able to launch and open other Lumerical product applications from any Lumerical product when these are executed from your current shell/terminal window.
Note: Do not close or terminate your current shell/Terminal. Once you close the current shell/terminal window, you will have to run the above export commands again on your new shell/Terminal.  To permanently add PATH to your shell profile, check out this article

MATLAB script integration configuration guide

This article describes how to set up MATLAB script integration features with Lumerical products.

Notes

  • Lumerical does not guarantee that all versions of our products will be compatible with all MATLAB versions on all operating systems (the number of permutations is very large!), although we have found that it works for most customers.
  • Only the 64-bit version of MATLAB is supported.
  • Some releases of MATLAB include newer versions of system libraries than are provided by the operating system.  The new libraries are saved in a private location that only MATLAB can 'see'.  This creates problems for the Matlab script integration since the Lumerical application will use the standard version of the system library while MATLAB will use its private version of the same library. This creates a conflict, which stops the script integration from working. See below for possible solutions.
  • The MATLAB script integration feature requires MATLAB version 2006b to 2019a.

Lumerical to MATLAB script integration 

The MATLAB script integration feature allows MATLAB script functions to be called from within Lumerical's scripts via the matlab, matlabput and matlabget script functions. 

Check feature status

To check the status of the MATLAB script integration feature, go to the Help menu and select Matlab integration status.

mceclip1.png

mceclip0.png

See details below for configuration instructions for your operating system. 

Windows

Step 1

The products should be able to locate the MATLAB libraries.  If they are not in the system library path, you must manually specify their location.

  1. Open the Matlab integration status window from the Help menu.
  2. Use the Select button to manually locate the MATLAB system libraries.
  3. Restart the Product for the change to take effect.

    mceclip2.png

Step 2 

MATLAB must be registered as an automation server on your system before the script integration feature will work. Registration normally occurs during the MATLAB install process, but occasionally the registration fails or is lost.  

In such cases, manual registration is required. Manual registration may also be required when you have multiple versions of MATLAB installed and would like to register MATLAB for the desired version, e.g. if the MATLAB license of one version is not available.

Administrator access is required for these configurations. For more information, please refer to MATLAB documentation.

  1. To register MATLAB, open a MATLAB session and type the following command:
    !matlab /regserver 
  2. The ! operator in MATLAB just executes the remainder of the line at the command prompt, so this is equivalent to running a command below from the Windows command prompt as Administrator,
    "C:\Program Files\MATLAB\<version>\bin\win64\matlab" /regserver
  3. To test the registration, open Lumerical and use one of the MATLAB script integration functions. You can also test the registration within MATLAB by running;
    h = actxserver('Matlab.Application')
    h.Execute('plot(1:10)')
  4. The first command starts a second background instance of MATLAB, very similar to the way our software starts a MATLAB session. The second command sends the plot command from the original MATLAB session to the new MATLAB session. You should see a simple plot window.

Linux

The following two configuration steps are often required to setup the MATLAB script integration on Linux. Occasionally, the third step will be required.

Step 1

The matlab command must be in the path, so if you type 'matlab' at the terminal, the MATLAB application will start. To do this you can either add the folder where you installed MATLAB to your PATH, or you can create a symbolic link to the matlab command in another folder that is already in the path.

$  sudo ln -s /usr/local/MATLAB/<version>/bin/matlab  /usr/bin/matlab
Step 2

Your Lumerical Product must be able to locate the MATLAB libraries.  If they are not in the system library path, you must manually specify their location.

  1. Open the Matlab integration status window from the Help menu.
  2. Use the Select button to manually locate the MATLAB system libraries.
  3. Restart the Product for the change to take effect. 
     

    mceclip0.png

     
Step 3

Some versions of MATLAB include newer versions of system libraries than the standard version provided by the OS.  The newer libraries are saved in a private location that only MATLAB can access.  This creates problems for the Matlab script integration, since your Lumerical Product will load the standard version of the system library, while MATLAB will load it's private version of the same library.  This creates a conflict, which stops the script integration from working.

The easiest way to avoid this is to roll back to an older version of MATLAB.

Alternatively, you can try to configure your Lumerical Product to work with your current version of MATLAB. This requires configuring our software to use the newer system libraries provided by MATLAB, so both products load the same version of the libraries.  This can be setup by creating a simple shell file that configures the library paths.  Once this file is created, Lumerical can be started with a command new shell file. 

(shell file for FDTD)

$ sudo cat /opt/lumerical/v232/bin/fdtd-matlab.sh 
(Add the following lines into the file)
    #!/bin/bash
    export LD_LIBRARY_PATH=/opt/MATLAB/<version>/sys/os/glnxa64/
    /opt/lumerical/v232/bin/fdtd-solutions $@
(make the file executable)
$ sudo chmod +x /opt/lumerical/v232/bin/fdtd-matlab.sh

(shell file for MODE)

$ sudo cat /opt/lumerical/v232/bin/mode-matlab.sh 
(Add the following lines into the file)
    #!/bin/bash
    export LD_LIBRARY_PATH=/opt/MATLAB/<version>/sys/os/glnxa64/
    /opt/lumerical/v232/bin/mode-solutions $@
(make the file executable)
$ sudo chmod +x /opt/lumerical/v232/bin/mode-matlab.sh

(shell file for CHARGE / HEAT / FEEM & DGTD)

$ sudo cat /opt/lumerical/v232/bin/device-matlab.sh
(Add the following lines into the file)
    #!/bin/bash
    export LD_LIBRARY_PATH=/opt/MATLAB/<version>/sys/os/glnxa64/
    /opt/lumerical/v232/bin/device $@
(make the file executable)
$ sudo chmod +x /opt/lumerical/v232/bin/device-matlab.sh

(shell file for INTERCONNECT)

$ sudo cat /opt/lumerical/v232/bin/interconnect-matlab.sh 
(Add the following lines into the file)
    #!/bin/bash
    export LD_LIBRARY_PATH=/opt/MATLAB/<version>/sys/os/glnxa64/
    /opt/lumerical/v232/bin/interconnect $@ 
(make the file executable)
$ sudo chmod +x /opt/lumerical/v232/bin/interconnect-matlab.sh

Run Lumerical using the new shell file.

$ /opt/lumerical/v232/bin/interconnect-matlab.sh &
$ /opt/lumerical/v232/bin/device-matlab.sh &
$ /opt/lumerical/v232/bin/mode-matlab.sh &
$ /opt/lumerical/v232/bin/fdtd-matlab.sh &

macOS

Step 1

Your Lumerical Product must be able to locate the MATLAB libraries.  If they are not in the system library path, you must manually specify their location. 

Add Lumerical installation path to your shell.

  1. Open Terminal
  2. Add the Lumerical installation path to your current shell. (i.e. All products added to path)
    export PATH=$PATH:/Applications/Lumerical\ v232.app/Contents/Applications/FDTD\ Solutions.app/Contents/MacOS
    export PATH=$PATH:/Applications/Lumerical\ v232.app/Contents/Applications/MODE\ Solutions.app/Contents/MacOS
    export PATH=$PATH:/Applications/Lumerical\ v232.app/Contents/Applications/DEVICE.app/Contents/MacOS
    export PATH=$PATH:/Applications/Lumerical\ v232.app/Contents/Applications/INTERCONNECT.app/Contents/MacOS
    
  3. Do not close or terminate your current shell/Terminal.
  4. Once you close the current shell/terminal window, you will have to run the above "export" commands again on your new shell/Terminal.
  5. To permanently add PATH to your shell profile, checkout this article
  6. Open and run Lumerical from your current shell/Terminal window.
    The new PATH settings will only work when the application is launched from the Terminal window.
    $  fdtd-solutions &
    $  mode-solutions &
    $  device &
    $  interconnect &
  7. Open the Matlab integration status window from the Help menu from within the product.
  8. Use the select button to manually locate the MATLAB system libraries.
  9. Restart Lumerical for the change to take effect. 

mceclip0.png

Step 2

It may be necessary to create the following symbolic link to the MATLAB executable.

sudo ln –s /Applications/MATLAB_<version>.app/bin/matlab /usr/bin/matlab

The exact command will depend on your MATLAB version and install directory.  The above example command is appropriate for MATLAB 2009B installed in the default location.

Test script integration

  • The MATLAB script integration status can sometimes be reported incorrectly.
  • If the status utility reports inactive even after the above configuration, it is still possible that the integration script functions will work.
  • Try a matlab script command on the script prompt of Lumerical's design environment,
    > matlab("plot(1:10)");

mceclip0.png

MATLAB to Lumerical API integration  

The MATLAB API functions allow Lumerical applications and scripts to be called from MATLAB. The Lumerical install and Matlab API paths need to be added to your system and Matlab paths. 

Notes 

A more convenient way to add the Lumerical install path is in MATLAB's path is to add them to the MATLAB's 'startup.m' file, which runs automatically each time MATLAB starts or add Lumerical's product installation folder into your MATLAB's search path. See your MATLAB documentation for more information.

Windows

Include Lumerical installation in the system and MATLAB paths.

  1. Add the Matlab install path and the Lumerical and Matlab API install paths to your system. See this post for details.   
  2. MATLAB must be configured to know the location of the Lumerical API functions.  The API functions are located in the \api\matlab subdirectory of the Lumerical product installation folder. To manually add this location to the MATLAB path, run the following commands in MATLAB:
    path(path,'C:\Program Files\Lumerical\v232\api\matlab')

Linux 

Include Lumerical installation in the system path.

  1. The Lumerical installation bin directory must be added to the system path.
  2. This is done automatically as part of the product configuration script.
  3. It is necessary to add each Lumerical product to the system path.
  4. Change directory to your home directory
  5. Append your .bash_profile with the Lumerical installation path (default install path shown)
    $ cd ~ 
    $ vi .bash_profile
    
    # add the following at the end of you .bash_profile
    PATH=$PATH:/opt/lumerical/v232/bin
    export PATH

Include Lumerical installation in MATLAB path

  1. MATLAB must be configured to know the location of the Lumerical API functions.
  2. The API functions are located in the /api/matlab subdirectory of the Lumerical installation folder.
  3. Manually add this path to the MATLAB path,
    path(path,'/opt/lumerical/v232/api/matlab')

macOS

Include Lumerical installation in system path

Important:

  • Run MATLAB from Terminal. 
  • The API does not work when Matlab is run from Launchpad or Finder using the Icon.
  1. Add the Lumerical installation path to your shell (as shown above)
  2. Run 'matlab' from your current Terminal window
$ /Applications/MATLAB_<version>.app/bin/matlab 

Include Lumerical installation in MATLAB path 

  1. Open the MATLAB application and add the Lumerical MATLAB API file location to the MATLAB path,
    path(path,'/Applications/Lumerical v232.app/Contents/API/Matlab')

Test API functions

In MATLAB run the following,
  1. Confirm that the Lumerical installation directory is included in the system path as seen by MATLAB
    !echo $PATH
  2. Confirm that the Lumerical installation directory is included in the MATLAB path,
    path
  3. Use the MATLAB 'appopen' function to start Lumerical (e.g. FDTD),
    appopen('fdtd')
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值