Please enable JavaScript to view this site.

Knowledge Base

Navigation: FDTD Solutions > Data Transfer and Interoperability > Interoperability and Automation API > Python API

FDTD application example

We've made some changes. Use 'Ctrl-F5' to clear your browser cache.
Scroll Prev Top Next More

This example demonstrates the feasibility of integrating Lumerical FDTD with Python using Application Programming Interface (API). In this example, we will set the geometry based on nanowire application example and then run the simulation using Python script. Once the simulation is finished, simulation results will be imported to Python, and plots comparing simulation and theoretical results as well as a plot of Ey intensity will be provided.  






Note: versions

The example files were created using Lumerical 2018a R4, Python 3.6 (and numpy), matplotlib, and Windows 7


Note: working directory

It should be possible to store the files in any locations as desired. However, it is recommended to put the Lumerical and Python files in the same folder in order for the above script files to work properly. It is also important to check the Lumerical working directory has the correct path, see here for instructions to change the Lumerical working directory.


During the Lumerical product installation process, a file should be automatically installed in this location.




C:\Program Files\Lumerical\FDTD\api\python

This module is the key to enable Lumerical-Python API connection. Once the lumapi module is imported to Python, the integration should be ready. See this page for instructions for setting up Python API.


Note: Running Lumerical files from Python

If you already have the FDTD simulation or script files ready, you can run them from Python. For example, download the Lumerical script files (nanowire_build_script.lsf and nanowire_plotcs.lsf) and the nanowire_theory.csv text file and then run the script commands below in Python:

import imp

lumapi = imp.load_source("lumapi", "C:\\Program Files\\Lumerical\\FDTD\\api\\python\\")


nw = lumapi.FDTD("nanowire_build_script.lsf")"nanowire_test")

nw.feval("nanowire_plotcs.lsf")  # run the second script for plots


The commands above run the nanowire_build_script.lsf to set the geometry first, and then runs nanowire_plotcs.lsf to plot the simulation and theoretical results. These plots are created using Lumerical visualizer and will be identical to the plots in nanowire application example. In the rest of this page an explanation on how to build the geometry and analyze the results directly from Python will be provided.

Importing modules

Setting up the geometry from Python


Analysing simulation and theoretical results


Plotting the results


Copyright Lumerical Inc. | Privacy | Site Map