Giter Site home page Giter Site logo

pytoptics's Introduction

PyTorch Implementation of Optics Simulator and Optimizer (Pytoptics)

GitHub Logo

Pytoptics (PyTorch Implementation of Optics Simulator and Optimizer) is a python library extended from KrakenOS and based in Pytorch, Numpy, Matplotlib, PyVTK and PyVista libraries. In addition to the original utilities in KrakenOS including performing sequential exact ray tracing, generating off-axis systems and calculation of wavefront aberrations in terms of Zernike polynomials, Pytoptics enables users to optimize their optical systems with Pytorch optimizer:

Initial System Optimize RMS of Spot Diagram Optimized System

The project is still in implementation, more features are being tested and added.

Install Pytoptics

pip install git+https://github.com/clalanliu/pytoptics.git

You may install Prerequisites first:

pip install pyvista
pip install PyVTK
pip install vtk
pip install numpy
pip install scipy
pip install matplotlib
pip install csv342
pip install KrakenOS
pip install torch torchvision torchaudio

Optimizable Variable Types:

The following paramters are tested and optimizable for the current version:

Type Meaning
opticalsystem.surfaces[].Rc Radius of surface
opticalsystem.surfaces[].Thickness Thickness of surface

Usage

To construct a optical system and assign surface information with trainable pytorch parameters:

opticalsystem = pytoptics.OpticalSystem(5)
...
opticalsystem.surfaces[1].Rc = torch.nn.Parameter(torch.tensor(90.0).to(device))
opticalsystem.surfaces[1].Thickness = torch.nn.Parameter(torch.tensor(6.0).to(device))
opticalsystem.surfaces[1].Glass = "BK7"
opticalsystem.surfaces[1].Diameter = torch.tensor(30.0).to(device)
opticalsystem.surfaces[1].Axicon = torch.tensor(0).to(device)  

To add optimization constraints:

constraints = [
    [opticalsystem.surfaces[1].Rc, ">", 85.0],
    [opticalsystem.surfaces[1].Rc, "<", 95.0],
    [opticalsystem.surfaces[1].Thickness, "=", 6.0, 0.5],  # half-width = 0.5
]
opticalsystem.AddConstraint(constraints)

To configure the system:

opticalsystem.SetAperture(pytoptics.ApertureType.ENTRANCE_PUPIL_DIAMETER, 10.0)
opticalsystem.SetFields(pytoptics.FieldType.ANGLE, [[0, 0, 1.0], [0, 5, 1.0], [0, -5, 1.0]])
opticalsystem.SetWavelength([0.55])

To initialize, optimize, and show the system:

opticalsystem.Initialize()
opticalsystem.Optimize_GradientDescent(MXC=100, lr=10)
opticalsystem.ShowOptimizeLoss()
opticalsystem.ShowSpotDiagram()
opticalsystem.ShowModel2D()

See Example_*.py to get more information.

Reference

If you find the codes useful, please cite this paper

@article{pytoptics,
  title={Pytoptics: Optimzie Optical System in PyTorch},
  author={Chang-Le, Liu}
}

pytoptics's People

Contributors

clalanliu avatar

Stargazers

 avatar Guangyuan Zhao avatar

Watchers

James Cloos avatar  avatar

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.