Giter VIP home page Giter VIP logo

vtmm's Introduction

vtmm (vectorized transfer matrix method)

vtmm is a vectorized implementation of the transfer matrix method for computing the optical reflection and transmission of multilayer planar stacks. This package is in beta.

The vtmm package supports some of the same functionality as the tmm Python package developed by Steven Byrnes. However, in vtmm all operations are vectorized over angles / wavevectors as well as frequencies. Due to the small size of the matrices involved in the transfer matrix method (2 x 2), such vectorization results in significant performance gains, especially for large structures and many frequencies / wavevectors.

In some cases we have observed approximately two orders of magnitude difference in execution time between the two implementations (see below). The much lower execution time in vtmm may be useful for applications which require many evaluations of the reflection and transmission coefficients, such as in fitting or optimization.

Gradients

Currently vtmm uses Tensor Flow as its backend. This means that gradients of scalar loss / objective functions of the transmission and reflection can be taken for free. At a later time a numpy backend may be implemented for users that do not need gradient functionality and/or do not want Tensor Flow as a requirement.

Example

The entry point to vtmm is the function tmm_rt(pol, omega, kx, n, d). See the example below for a basic illustration of how to use the package.

import tensorflow as tf
from vtmm import tmm_rt

pol = 's'
n = tf.constant([1.0, 3.5, 1.0]) # Layer refractive indices 
d = tf.constant([2e-6]) # Layer thicknesses 
kx = tf.linspace(0.0, 2*np.pi*220e12/299792458, 1000) # Parallel wavevectors
omega = tf.linspace(150e12, 220e12, 1000) * 2 * np.pi # Angular frequencies

# t and r will be 2D tensors of shape [ num kx, num omega ]
t, r = tmm_rt(pol, omega, kx, n, d)

Benchmarks

See tests/test_benchmark.py for a comparison between vtmm and the non-vectorized tmm package. The benchmarks shown below are for len(omega) == len(kx) == 50 and 75 timeit evaluations.

python -W ignore ./tests/test_benchmark.py
Single omega / kx benchmark
vtmm: 0.2432 s
tmm:  0.0401 s

Large stack benchmark
vtmm: 0.7811 s
tmm:  79.8765 s

Medium stack benchmark
vtmm: 0.4607 s
tmm:  52.2255 s

Small stack benchmark
vtmm: 0.3367 s
tmm:  41.0926 s

vtmm's People

Contributors

ianwilliamson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vtmm's Issues

Dispersive layer

Hey,

just wondering how to best implement a dispersive layer without loosing the performance benefits of your vectorized version.

Thanks for your help!

Add backend for toggling between numpy and tensorflow

Only thing preventing this currently is figuring out how to implement the "batch" dims on eye and diag for numpy. Tensor flow currently works completely, but has additional options that are not present in numpy's version of the functions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.