chriskeraly / lumopt Goto Github PK
View Code? Open in Web Editor NEWPython based continuous adjoint optimization wrapper for Lumerical
License: Other
Python based continuous adjoint optimization wrapper for Lumerical
License: Other
Hi,
I would like to optimize (inverse design) by changing parameters in a structure group.
can I use LumOpt for that?
could you please guide or refer me?
thanks,
Dor
Hello,professor
I found that the code runs a long time and uses a little CPU running memory(about 4%).Will you publishe a version to improve code efficiency?Thank you very much!
Best wishes!
the splitter_opt_2D works but has an abnormal termination
Im using lumerical2019r6 python3 64 bits anaconda, centos7
.........
Making forward solve
Making adjoint solve
Running solves
Processing forward solve
FOM = 0.9494040667424216
Processing adjoint solve
Calculating gradients
Getting d eps: dx = 1e-09
..........
* * *
Tit = total number of iterations
Tnf = total number of function evaluations
Tnint = total number of segments explored during Cauchy searches
Skip = number of BFGS updates skipped
Nact = number of active bounds at final generalized Cauchy point
Projg = norm of the final projected gradient
F = final function value
* * *
N Tit Tnf Tnint Skip Nact Projg F
10 28 126 37 1 0 4.760D-01 -9.494D-01
F = -0.94940406674242162
ABNORMAL_TERMINATION_IN_LNSRCH
Line search cannot locate an adequate point after 20 function
and gradient evaluations. Previous x, f and g restored.
Possible causes: 1 error in function or gradient evaluation;
2 rounding error dominate computation.
Cauchy time 0.000E+00 seconds.
Subspace minimization time 0.000E+00 seconds.
Line search time 0.000E+00 seconds.
Total User time 0.000E+00 seconds.
FINAL FOM = 0.9494040667424216
FINAL PARAMETERS = [2.57831226e-07 2.74703945e-07 2.66536470e-07 3.19842826e-07
5.32599176e-07 6.04490828e-07 6.21801285e-07 6.25213501e-07
6.30480682e-07 6.02122513e-07]
When using LumOpt for simulation optimization, I noticed that when setting the optimizer, only one 'source name' can be set. So, if I want to input two different light sources at the same time in the script, how can I do it?
Im using centos lumerical 2019br6 python3.7.1 anaconda
the Ysplitter optimization works
However the crossing_2d example is failing
python cross_opt_2D.py 15:01:48
CONFIGURATION FILE {'root': '/home/centos/.lumerical/api/python', 'lumapi': '/home/centos/.lumerical/api/python'}
Accurate interface detection enabled
Running scipy optimizer
bounds = [[0.2 1. ]
[0.2 1. ]
[0.2 1. ]
[0.2 1. ]
[0.2 1. ]
[0.2 1. ]
[0.2 1. ]
[0.2 1. ]
[0.2 1. ]
[0.2 1. ]]
start = [0.25 0.28888889 0.32777778 0.36666667 0.40555556 0.44444444
0.48333333 0.52222222 0.56111111 0.6 ]
RUNNING THE L-BFGS-B CODE
* * *
Machine precision = 2.220D-16
N = 10 M = 10
At X0 0 variables are exactly at the bounds
Making forward solve
Making adjoint solve
Running solves
Processing forward solve
FOM = 0.764435735655069
Processing adjoint solve
Calculating gradients
Getting d eps: dx = 1e-10
..........
Saved frame
At iterate 0 f= -7.64436D-01 |proj g|= 6.33333D-01
Making forward solve
Making adjoint solve
Running solves
Processing forward solve
Traceback (most recent call last):
File "cross_opt_2D.py", line 54, in <module>
opt.run()
File "/home/centos/.lumerical/api/python/lumopt/optimization.py", line 397, in run
self.optimizer.run()
File "/home/centos/.lumerical/api/python/lumopt/optimizers/generic_optimizers.py", line 72, in run
method = self.method)
File "/home/centos/miniconda3/lib/python3.7/site-packages/scipy/optimize/_minimize.py", line 601, in minimize
callback=callback, **options)
File "/home/centos/miniconda3/lib/python3.7/site-packages/scipy/optimize/lbfgsb.py", line 335, in _minimize_lbfgsb
f, g = func_and_grad(x)
File "/home/centos/miniconda3/lib/python3.7/site-packages/scipy/optimize/lbfgsb.py", line 285, in func_and_grad
f = fun(x, *args)
File "/home/centos/miniconda3/lib/python3.7/site-packages/scipy/optimize/optimize.py", line 300, in function_wrapper
return function(*(wrapper_args + args))
File "/home/centos/.lumerical/api/python/lumopt/optimizers/generic_optimizers.py", line 47, in callable_fom_local
fom=callable_fom(params/self.scaling_factor)
File "/home/centos/.lumerical/api/python/lumopt/optimization.py", line 557, in callable_fom
return self.process_forward_sim(iter)
File "/home/centos/.lumerical/api/python/lumopt/optimization.py", line 516, in process_forward_sim
Optimization.check_simulation_was_successful(self.sim)
File "/home/centos/.lumerical/api/python/lumopt/optimization.py", line 738, in check_simulation_was_successful
raise UserWarning('FDTD simulation did not complete successfully: {0}'.format(simulation_status))
UserWarning: FDTD simulation did not complete successfully: 3.0
Hi,
I'm very new here and try to get used to how to use lumopt. I'm able to call the Lumerical FDTD from python but noticed that the figures are all blank. The IDE I used is PyCharm, and the figures will be shown directly in IDE's builtin plot window.
I have tried to add "plot_history= True" and "store_all_simulations=True" in Optimization command. As,
opt = Optimization(base_script = base_script, wavelengths = wavelengths, fom = fom, geometry = geometry, optimizer = optimizer, hide_fdtd_cad = False, plot_history= True, use_deps = True, store_all_simulations=True)
After several tries, I still cannot work out this issue.
Does anyone has the same issue before and know how to resolve this issue?
Any suggestion might help.
Thanks in advance.
Hi,
I was wondering if an optional sidewall angle can be added to the geometric building functions. This would be useful for folks working on lithium niobate which typically does not have vertical sidewalls.
Hi I am getting this error message while executing splitter-opt_2D. It seems to have something to do with matplotlib. Could you please look into this and may I also know the version of your python and matplotlib? Thank you!
Running on Python 3.6
Traceback (most recent call last):
File "C:/Users/MengHuang/Desktop/Meep/Lumerical/install/LumOpt/examples/Ysplitter/splitter_opt_2D.py", line 15, in <module>
from lumopt.optimization import Optimization
File "c:\users\menghuang\desktop\meep\lumerical\install\lumopt\lumopt\optimization.py", line 9, in <module>
import matplotlib.pyplot as plt
File "C:\Users\MengHuang\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\pyplot.py", line 32, in <module>
import matplotlib.colorbar
File "C:\Users\MengHuang\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\colorbar.py", line 31, in <module>
import matplotlib.contour as contour
File "C:\Users\MengHuang\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\contour.py", line 16, in <module>
import matplotlib.font_manager as font_manager
File "C:\Users\MengHuang\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\font_manager.py", line 103, in <module>
os.path.join(str(Path.home()), r'AppData\Local\Microsoft\Windows\Fonts'),
AttributeError: type object 'Path' has no attribute 'home'
Process finished with exit code 1
Just an update I solved this issue with Anaconda python 3.7 instead of the system python.
When I try "python setup.py install", the program starts running but then gets stuck. This is the output
running install
C:\Users\Joeri\conda\myenv\Lib\site-packages\setuptools_distutils\cmd.py:66: SetuptoolsDeprecationWarning: setup.py install is deprecated.
!!
********************************************************************************
Please avoid running ``setup.py`` directly.
Instead, use pypa/build, pypa/installer, pypa/build or
other standards-based tools.
See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details.
********************************************************************************
!!
self.initialize_options()
C:\Users\Joeri\conda\myenv\Lib\site-packages\setuptools_distutils\cmd.py:66: EasyInstallDeprecationWarning: easy_install command is deprecated.
!!
********************************************************************************
Please avoid running ``setup.py`` and ``easy_install``.
Instead, use pypa/build, pypa/installer, pypa/build or
other standards-based tools.
See https://github.com/pypa/setuptools/issues/917 for details.
********************************************************************************
!!
self.initialize_options()
running bdist_egg
running egg_info
writing LumOpt.egg-info\PKG-INFO
writing dependency_links to LumOpt.egg-info\dependency_links.txt
writing requirements to LumOpt.egg-info\requires.txt
writing top-level names to LumOpt.egg-info\top_level.txt
reading manifest file 'LumOpt.egg-info\SOURCES.txt'
adding license file 'LICENSE'
writing manifest file 'LumOpt.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
creating build\bdist.win-amd64\egg
creating build\bdist.win-amd64\egg\lumopt
copying build\lib\lumopt_init_.py -> build\bdist.win-amd64\egg\lumopt
copying build\lib\lumopt\optimization.py -> build\bdist.win-amd64\egg\lumopt
byte-compiling build\bdist.win-amd64\egg\lumopt_init_.py to init.cpython-311.pyc
byte-compiling build\bdist.win-amd64\egg\lumopt\optimization.py to optimization.cpython-311.pyc
creating build\bdist.win-amd64\egg\EGG-INFO
copying LumOpt.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO
copying LumOpt.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying LumOpt.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying LumOpt.egg-info\requires.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying LumOpt.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO
zip_safe flag not set; analyzing archive contents...
lumopt.pycache.init.cpython-311: module references file
lumopt.pycache.optimization.cpython-311: module MAY be using inspect.stack
creating 'dist\LumOpt-0.0.1-py3.11.egg' and adding 'build\bdist.win-amd64\egg' to it
removing 'build\bdist.win-amd64\egg' (and everything under it)
Processing LumOpt-0.0.1-py3.11.egg
removing 'c:\users\joeri\conda\myenv\lib\site-packages\LumOpt-0.0.1-py3.11.egg' (and everything under it)
creating c:\users\joeri\conda\myenv\lib\site-packages\LumOpt-0.0.1-py3.11.egg
Extracting LumOpt-0.0.1-py3.11.egg to c:\users\joeri\conda\myenv\lib\site-packages
Adding LumOpt 0.0.1 to easy-install.pth file
Dear author,
Could you give me some advice about how to optimize adding more than 3 monitors?
For example, if I want to inverse design an 8 channel structure with the symmetric condition, I still need to optimize 4 channels with 4 monitors, then I need 4 scripts, 4 geometry, 4 "fom" monitors and 4 optimizers, the final opt=opt_1+opt_2+opt_3+opt_4, which is related to the Co-optimization method. However, when I run the code, it gives me the error message:"superOptimization" attribute has no attribute "optimizer". This method works for 2 monitors(opt=opt_1+opt_2), but not worksfor 3 and more monitors Co-optimziation.
Thanks for your help
Best regards
Gang
when I change the SIZE of the corssing waveguide into a bigger one, the program has worked for a long time but don't get a result.
In Example One, I change the length of crossing waveguide to 6 um.Both of the "FDTD_crossing.lsf" and the "crossing_opt_3D.py" has changed. The program has running for several hours,but no FOM is calculated.
In example Two,I change the length of crossing waveguide to 6 um. I only change the "crossing_opt_3D.py" and don't change the "FDTD_crossing.lsf". In another word, the location of input waveguide, monitor and the size of FDTD do not change. (they are for the example of 4um- crossing waveguide). However, it has a result. it can calculate the FOM.
so I don't know where it is worng. could you give me some suggestions.
this is original result of example one.
example two do not have a original result.
example1.zip
example2.zip
I am trying to implement the examples for inverse design given in the lumerical website. I keep getting this error.
I am using Ubuntu 22.04
Lumerical v222
CONFIGURATION FILE {'root': '/opt/lumerical/v222/api/python', 'lumapi': '/opt/lumerical/v222/api/python'}
Couldn't find the file containing 2D optimization parameters. Starting with default parameters
Accurate interface detection enabled
Wavelength range of source object will be superseded by the global settings.
/opt/lumerical/v222/api/python/lumopt/utilities/plotter.py:62: UserWarning: Matplotlib is currently using module://matplotlib_inline.backend_inline, which is a non-GUI backend, so cannot show the figure.
self.fig.show()
Running scipy optimizer
bounds = [(0, 1), (0, 1), (0, 1), (0, 1), (0, 1), (0, 1), (0, 1), (0, 1), (0, 1), (0, 1)]
start = [0.08333333 0.14814815 0.21296296 0.27777778 0.34259259 0.40740741
0.47222222 0.53703704 0.60185185 0.66666667]
RUNNING THE L-BFGS-B CODE
* * *
Machine precision = 2.220D-16
N = 10 M = 10
At X0 0 variables are exactly at the bounds
Making forward solve
Making adjoint solve
Running solves
Processing forward solve
FOM = 0.701620026173104
Processing adjoint solve
Calculating gradients
Getting d eps: dx = 1e-09
..........
Saved frame
At iterate 0 f= -7.01620D-01 |proj g|= 5.27778D-01
Making forward solve
Making adjoint solve
Running solves
Processing forward solve
FOM = 0.4994039732372051
Processing adjoint solve
Calculating gradients
Getting d eps: dx = 1e-09
..........
Making forward solve
Making adjoint solve
Running solves
Processing forward solve
FOM = 0.8723096044475441
Processing adjoint solve
Calculating gradients
Getting d eps: dx = 1e-09
..........
At iterate 1 f= -8.72310D-01 |proj g|= 4.01646D-01
Saved frame
* * *
Tit = total number of iterations
Tnf = total number of function evaluations
Tnint = total number of segments explored during Cauchy searches
Skip = number of BFGS updates skipped
Nact = number of active bounds at final generalized Cauchy point
Projg = norm of the final projected gradient
F = final function value
* * *
N Tit Tnf Tnint Skip Nact Projg F
10 1 3 4 0 3 4.016D-01 -8.723D-01
F = -0.872309604447544
STOP: TOTAL NO. of ITERATIONS REACHED LIMIT
Number of FOM evaluations: 1
FINAL FOM = [0.8723096]
FINAL PARAMETERS = [3.08237291e-07 3.27586867e-07 3.07827661e-07 3.20648052e-07
3.48799264e-07 4.93115432e-07 5.70768702e-07 5.90978454e-07
5.88921615e-07 5.59012317e-07]
Traceback (most recent call last):
File "/home/satadrudas/lumerical_files/360042305274-inverse-design-of-y-branch/y_branch_opt_2D.py", line 127, in
results = opt.run()
File "/opt/lumerical/v222/api/python/lumopt/optimization.py", line 582, in run
self.optimizer.run()
File "/opt/lumerical/v222/python/lib/python3.9/contextlib.py", line 126, in exit
next(self.gen)
File "/opt/lumerical/v222/python/lib/python3.9/site-packages/matplotlib/animation.py", line 253, in saving
self.finish()
File "/opt/lumerical/v222/api/python/lumopt/utilities/plotter.py", line 30, in finish
return super().finish()
File "/opt/lumerical/v222/python/lib/python3.9/site-packages/matplotlib/animation.py", line 518, in finish
self._run()
File "/opt/lumerical/v222/python/lib/python3.9/site-packages/matplotlib/animation.py", line 346, in _run
cbook._pformat_subprocess(command))
File "/opt/lumerical/v222/python/lib/python3.9/site-packages/matplotlib/cbook/init.py", line 2177, in _pformat_subprocess
else " ".join(shlex.quote(os.fspath(arg)) for arg in command))
TypeError: 'NotImplementedError' object is not iterable
How to generate a photomask for fabrication after the optimization is finished in Topology optimization when the return result is global index but not a structure?
The method is mentioned in https://lumopt.readthedocs.io/en/latest/all_others.html#gradient-fields.
However, in the code gradients.py line 81-82, the summation has 2.0 inside the bracket, instead of outside.
Useful for people recently installing this software: You have to use an older version of matplotlib. Here is the requirement list that I obtain after executing pip freeze > requirements.txt
with a matplotlib 3.3.1 version.
requirements.txt
Could you please explain the reason this equation below is used? From Owen Miller's thesis, I saw that for the adjoint case, you had to drive with a source of strength df/dE.
def get_adjoint_field_scaling(self, sim):
omega = 2.0 * np.pi * sp.constants.speed_of_light / self.wavelengths
adjoint_source_power = ModeMatch.get_source_power(sim, self.wavelengths)
scaling_factor = np.conj(self.phase_prefactors) * omega * 1j / np.sqrt(adjoint_source_power)
return scaling_factor
Thanks,
Aditi
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.