Flexcompute maintains a python package called “Tidy3D”, which provides a rich interface for defining and running FDTD simulations completely within python. While python is used for set up and analysis of the simulation results, the FDTD algorithm itself is run in the background on flexcompute’s servers, which are highly optimized for solving FDTD efficiently.
Installation instructions are given in the package documentation, linked here. In short, because Tidy3D is hosted using the PyPI service, it can be done through the command line (if you have internet connection) by running the command
Then, the package can be imported in a python script or interpreter as
The full front end code is hosted at this GitHub repository, for reference.
The Tidy3D package allows users to define their simulation programmatically as a collection of basic components, such as geometries, materials, sources, and monitors. Each of these components is a data structure with a well-defined schema combined with validations that ensure that the contents are properly set up. These validations ensure that if a simulation is set up incorrectly, it is immediately caught before starting the FDTD, which saves time and effort. Here is an example
All components are combined into a single Simulation object, which defines an FDTD simulation and can be easily visualized, validated, and exported to a json file. We leverage the pudantic python package to define these components. Here is a minimum working example of a Simulation object containing 5 cylinders that are defined programmatically by looping over their positions.
Next, the simulation is sent to Flexcompute’s servers through a simple API call from python. The progress of the job is monitored in real time and other functionalities for controlling the job are available directly from python.
Finally, the results are loaded into a SimulationData object, which contains the data for each of the supplied monitors. The data is stored in .hdf5 format the xarray python package is used to provide a convenient interface for performant plotting, selection, interpolation, and post-processing of the data.
As the simulation times are typically on the order of seconds to minutes, this whole process is seamlessly performed within the same python session or broken into different sessions if desired. If one wants to run several simulations in parallel, there is an interface for batch processing of jobs.
Tidy3D consistently outperforms other conventional FDTD solvers by an order of 100x or more. We achieve this performance improvement through the use of our custom hardware, which is optimized specifically for large scale FDTD simulation. As such, simulations that may take several hours or days on conventional hardware may be done in just minutes using Tidy3D. Furthermore, we can handle simulations with several billions of spatial degrees of freedom, which require too much memory to handle using conventional FDTD solvers. For more details, see one one of our papers:
Tidy3D contains all of the standard features found in FDTD software, as such it is applicable to almost all problems. A few of the main features include:
If we have a working Simulation defined, one easy way to visualize it is through the .plot method, which accepts spatial coordinates. For example, using the simulation defined earlier.
gives the following plot.
Data can be plotted in a similar way as the SimulationData object and its contents contain .plot_field() and .plot() methods, respectively. More information on plotting and visualization can be seen in the following examples in our documentation
Many of the examples in the Tidy3D documentation are written in the form of jupyter notebooks. These notebooks allow users to run code in different sections, which can also contain text or images. It is also a convenient format for sharing code examples or running python through the browser, for example google colab. All of the examples found in our documentation can be downloaded directly as jupyter notebooks from the GitHub repository for the documentation, linked here.
Tidy3D can be run in notebook format, or regular python script, which may be more convenient for “power users” who may want to create more complex workflows surrounding Tidy3D simulations.
Tidy3D works on any python version 3.7 or above. As such, it can be run using your local version of python. For more details on setting up python locally, more information can be found here. If one doesn’t want to set up python locally, another alternative is to use a web- based service for running python in the browser, such as google colab or binder.
Since the FDTD simulations themselves are run through Flexcompute servers, all of the previous approaches are compatible with the python client, which allows users to initialize simulations and work with their resulting data.