• Stars
    star
    330
  • Rank 127,657 (Top 3 %)
  • Language
    Python
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿฆ Electromagnetic Simulation + Automatic Differentiation

ceviche Build Status

Electromagnetic Simulation Tools + Automatic Differentiation. Code for paper Forward-Mode Differentiation of Maxwell's Equations.

ceviche

What is ceviche?

ceviche provides two core electromagnetic simulation tools for solving Maxwell's equations:

  • finite-difference frequency-domain (FDFD)

  • finite-difference time-domain (FDTD)

Both are written in numpy / scipy and are compatible with the HIPS autograd package, supporting forward-mode and reverse-mode automatic differentiation.

This allows you to write code to solve your E&M problem, and then use automatic differentiation on your results.

As a result, you can do gradient-based optimization, sensitivity analysis, or plug your E&M solver into a machine learning model without having to go through the tedious process of deriving your derivatives by hand.

Examples

There is a comprehensive ceviche tutorial available at this link with several ipython notebook examples:

  1. Running FDFD simulations in ceviche.
  2. Performing inverse design of a mode converter.
  3. Adding fabrication constraints and device parameterizations.
  4. Inverse design of a wavelength-division multiplexer and advanced topics.

There are also a few examples in the examples/* directory.

Installation

There are many ways to install ceviche.

The easiest is by

pip install ceviche

But to install from a local copy, one can instead do

git clone https://github.com/twhughes/ceviche.git
pip install -e ceviche
pip install -r ceviche/requirements.txt

from the main directory.

Alternatively, just download it:

git clone https://github.com/twhughes/ceviche.git

and then import the package from within your python script

import sys
sys.path.append('path/to/ceviche')

Package Structure

Ceviche

The ceviche directory contains everything needed.

To get the FDFD and FDTD simulators, import directly from ceviche import fdtd, fdfd_ez, fdfd_hz

To get the differentiation, import from ceviche import jacobian.

constants.py contains some constants EPSILON_0, C_0, ETA_0, Q_E, which are needed throughout the package

utils.py contains a few useful functions for plotting, autogradding, and various other things.

optimizers.py contains optimizer functions for doing inverse design.

viz.py are functions that help with plotting fields and sructures.

modes.py contains a mode sorter (WIP) that can be used to create waveguide mode profiles for the simulation, for example.

Examples

There are many demos in the examples directory, which will give you a good sense of how to use the package.

Tests

Tests are located in tests. To run, cd into tests and

python -m unittest

to run all or

python specific_test.py

to run a specific one. Some of these tests involve visual inspection of the field plots rather than error checking on values.

To run all of the gradient checking functions, run

chmod +x test/test_all_gradients.sh
tests/test_all_gradients.sh

Credits

If you use this for your research or work, please cite

@article{hughes2019forward,
  title={Forward-Mode Differentiation of Maxwellโ€™s Equations},
  author={Hughes, Tyler W and Williamson, Ian AD and Minkov, Momchil and Fan, Shanhui},
  journal={ACS Photonics},
  volume={6},
  number={11},
  pages={3010--3016},
  year={2019},
  publisher={ACS Publications}
}

Our logo was created by @nagilmer

More Repositories

1

wavetorch

๐ŸŒŠ Numerically solving and backpropagating through the wave equation
Python
510
star
2

neuroptica

Flexible simulation package for optical neural networks
Python
205
star
3

angler

Frequency-domain photonic simulation and inverse design optimization for linear and nonlinear devices
Python
157
star
4

legume

๐ŸŒฑ Guided-mode expansion of photonic crystal slabs
Python
102
star
5

qpga

Simulations of photonic quantum programmable gate arrays
Jupyter Notebook
100
star
6

workshop-invdesign

๐Ÿ“ Workshop material for optical inverse design and automatic differentiation
Jupyter Notebook
95
star
7

fdfdpy

Pure Python implementation of the finite difference frequency domain (FDFD) method for electromagnetics
Jupyter Notebook
53
star
8

ising-compiler

๐Ÿฐ Compiling your code to an Ising Hamiltonian so you don't have to!
Jupyter Notebook
48
star
9

FDFD.jl

Pure Julia implementation of the finite difference frequency domain (FDFD) method for electromagnetics
Jupyter Notebook
32
star
10

Rigorous-Coupled-Wave-Analysis

Rigorous coupled wave analysis and PWEM implemented in short readable python codes
Jupyter Notebook
31
star
11

vtmm

Vectorized transfer matrix method (TMM) for computing the optical reflection and transmission of multilayer planar stacks
Python
17
star
12

simphox

Another inverse design library (wip)
Python
17
star
13

neuroptica-notebooks

Jupyter notebooks for the neuroptica simulator
Jupyter Notebook
8
star
14

Isolators_CMT

๐ŸŽญ Coupled-mode theory for some modulation-based optical isolators
Jupyter Notebook
7
star
15

electro-optic-activation

This notebook contains code for the machine learning tasks in the electro-optic activation function paper
Jupyter Notebook
5
star
16

FDFDViz.jl

Visualization and plotting helper functions for FDFD.jl
Julia
4
star
17

synthetic-hamiltonians

Jupyter Notebook
3
star
18

rcwa4d

Rigorous Coupled Wave Analyses (RCWA) for layered structures with incommensurate periodicities
Jupyter Notebook
1
star
19

bilevel-inverse-design-of-optical-switch

inverse design of optical switch based on bilevel optimization inspired by meta-learning
Jupyter Notebook
1
star