{ "info": { "author": "Tyler Hughes", "author_email": "tylerwhughes91@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# ceviche [![Build Status](https://travis-ci.com/twhughes/ceviche.svg?token=ZCPktA3Ki2eYVXYnfbrz&branch=master)](https://travis-ci.com/twhughes/ceviche)\n\nElectromagnetic Simulation Tools + Automatic Differentiation. Code for the arxiv preprint [Forward-Mode Differentiation of Maxwell's Equations](https://arxiv.org/abs/1908.10507).\n\n## What is ceviche?\n\n`ceviche` provides two core electromagnetic simulation tools for solving Maxwell's equations:\n\n- finite-difference frequency-domain (FDFD)\n\n- finite-difference time-domain (FDTD)\n\nBoth are written in `numpy` / `scipy` and are compatible with the [HIPS autograd package](https://github.com/HIPS/autograd).\n\nThis allows you to write code to solve your E&M problem, and then use automatic differentiation on your results.\n\nAs a result, you can do gradient-based optimization or sensitivity analysis without the tedius process of deriving your derivatives analytically.\n\n### A simple example\n\nLets say we have a domain of where we wish to inject light at position `source` and measure its intensity at `probe`.\n\nBetween these two points, there's a box at location `pos_box` with permittivity `eps`.\n\nWe can write a function computing the intensity as a function of `eps` using our FDFD solver\n\n```python\nimport autograd.numpy as np # import the autograd wrapper for numpy\nfrom ceviche import fdfd_ez as fdfd # import the FDFD solver\n\n# make an FDFD simulation\nf = fdfd(omega, dl, eps_box, npml=[10, 10])\n\ndef intensity(eps):\n \"\"\" computes electric intensity at `probe` for a given box permittivity of `eps`\n\n source |-----| probe\n . | eps | .\n |_____|\n \"\"\"\n\n # set the permittivity in the box region to the input argument\n fdfd.eps_r[box_pos] = eps\n\n # solve the fields\n Ex, Ey, Hz = f.solve(source)\n\n # compute the intensity at `probe`\n I = np.square(np.abs(Ex)) + np.square(np.abs(Ex))\n return = np.sum(I * probe)\n```\n\nThen, we can very easily differentiate this function using automatic differentiation\n\n```python\n\n# use autograd to differentiate `intensity` function\ngrad_fn = jacobian(intensity)\n\n# then, evaluate it at the current value of `eps`\ndI_deps = grad_fn(eps_curr)\n\n# or do gradient based optimization\nfor _ in range(10):\n eps_current += step_size * dI_deps_fn(eps_current)\n```\n\n## Design Principle\n\n`ceviche` is designed with simplicity in mind and is meant to serve as a base package for building your projects from. However, with some exceptions, it does not provide streamlined interfaces for optimization, source or device creation, or visualization. If you want that kind of thing, you need to build it around the base functionality of ceviche in your own project. This decision was made to keep things clean and easy to understand, with a focus on the meaty bits that make this package unique. For some inspiration, see the `examples` directory. \n\n\nFor more user friendly features, check out our [`angler`](https://github.com/fancompute/angler) package. We plan to merge the two packages at a later date to give these automatic differentiation capabilities to `angler`.\n\n## Installation\n\n`ceviche` is not on PyPI yet.\nTo install locally from source:\n\n git clone https://github.com/twhughes/ceviche.git\n pip install -e ceviche\n pip install -r ceviche/requirements.txt\n\nfrom the main directory.\n\nAlternatively, just import the package from within your python script\n\n import sys\n sys.path.append('path/to/ceviche')\n\n## Package Structure\n\n### Ceviche\n\nThe `ceviche` directory contains everything needed.\n\nTo get the FDFD and FDTD simulators, import directly `from ceviche import fdtd, fdfd_ez, fdfd_hz, fdfd_ez_nl`\n\nTo get the differentiation, import `from ceviche import jacobian`.\n\n`constants.py` contains some constants `EPSILON_0`, `C_0`, `ETA_0`, `Q_E`, which are needed throughout the package\n\n`utils.py` contains a few useful functions for plotting, autogradding, and various other things.\n\n### Examples\n\nThere are many demos in the `examples` directory, which will give you a good sense of how to use the package.\n\n### Tests\n\nTests are located in `tests`. To run, `cd` into `tests` and\n\n python -m unittest\n\nto run all or\n\n python specific_test.py\n\nto run a specific one. Some of these tests involve visual inspection of the field plots rather than error checking on values.\n\nTo run all of the gradient checking functions, run \n\n bash tests/test_all_gradients.sh\n\n## Citation\n\nIf you use this for your research or work, please cite\n\n @misc{1908.10507,\n Author = {Tyler W Hughes and Ian A D Williamson and Momchil Minkov and Shanhui Fan},\n Title = {Forward-Mode Differentiation of Maxwell's Equations},\n Year = {2019},\n Eprint = {arXiv:1908.10507},\n }", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/twhughes/ceviche", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "ceviche", "package_url": "https://pypi.org/project/ceviche/", "platform": "", "project_url": "https://pypi.org/project/ceviche/", "project_urls": { "Homepage": "https://github.com/twhughes/ceviche" }, "release_url": "https://pypi.org/project/ceviche/0.0.1/", "requires_dist": null, "requires_python": "", "summary": "Ceviche", "version": "0.0.1" }, "last_serial": 5774129, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "22fd0bdfeab330c7170489b6561fbc0c", "sha256": "72f29725b31cf63dc51db59199c8d8e00cd7154ab96e3cc5802cbc85ed00c611" }, "downloads": -1, "filename": "ceviche-0.0.1.tar.gz", "has_sig": false, "md5_digest": "22fd0bdfeab330c7170489b6561fbc0c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20665, "upload_time": "2019-09-03T06:07:29", "url": "https://files.pythonhosted.org/packages/ac/d4/b541083a55a202ad3358db5bb57fcc34f65efa2d8b6bcb2973ade321c42a/ceviche-0.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "22fd0bdfeab330c7170489b6561fbc0c", "sha256": "72f29725b31cf63dc51db59199c8d8e00cd7154ab96e3cc5802cbc85ed00c611" }, "downloads": -1, "filename": "ceviche-0.0.1.tar.gz", "has_sig": false, "md5_digest": "22fd0bdfeab330c7170489b6561fbc0c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20665, "upload_time": "2019-09-03T06:07:29", "url": "https://files.pythonhosted.org/packages/ac/d4/b541083a55a202ad3358db5bb57fcc34f65efa2d8b6bcb2973ade321c42a/ceviche-0.0.1.tar.gz" } ] }