  Optical metasurfaces are planar substrates with custom-designed, nanoscale
features that selectively modulate incident light with respect to direction,
wavelength, and polarization. When coupled with photodetectors and appropriate
post-capture processing, they provide a means to create computational imagers
and sensors that are exceptionally small and have distinctive capabilities. We
introduce D-Flat, a framework in TensorFlow that renders physically-accurate
images induced by metasurface optical systems. This framework is fully
differentiable with respect to metasurface shape and post-capture computational
parameters and allows simultaneous optimization with respect to almost any
measure of sensor performance. D-Flat enables simulation of millimeter to
centimeter diameter metasurfaces on commodity computers, and it is modular in
the sense of accommodating a variety of wave optics models for scattering at
the metasurface and for propagation to photosensors. We validate D-Flat against
symbolic calculations and previous experimental measurements, and we provide
simulations that demonstrate its ability to discover novel computational sensor
designs for two applications: single-shot depth sensing and single-shot spatial
frequency filtering.
