-
Notifications
You must be signed in to change notification settings - Fork 626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plotting and animation #872
Conversation
Nice job! I agree that a standard built-in module for visualizing geometries and fields would be a big advance, and it looks like you're off to a solid start in the direction of proposing and implementing one. For your reference, I proposed and implemented one too, and in fact the code for mine has been in the master source repository since #795---but this shouldn't dissuade you from pursuing yours, as perhaps it will align better with the plans of the meep development team. Documentation and sample images for mine are here: https://homerreid.github.io/meep-adjoint-documentation/AdjointSolver/Visualization/ and there are other sample images scattered throughout the adjoint-solver documentation. I'm traveling today and have to dash off right now, but I'll try to expand on this comment later tonight or tomorrow. |
Thanks for your comments, @HomerReid! I had no idea you already developed a visualization interface. I'll go through your code and incorporate your ideas. |
Would be good to move most of this stuff out of the |
python/simulation.py
Outdated
@@ -1255,6 +1299,7 @@ def stop_cond(sim): | |||
for func in step_funcs: | |||
_eval_step_func(self, func, 'step') | |||
self.fields.step() | |||
sys.stdout.flush() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought #865 should have made this unnecessary. Are you seeing buffered output somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, that slipped through. I'll fix that in the next commit. Thanks!
In an effort to make the visualization library as modular as possible, I separated it from the The main 2D visualizer is now a function called There is a run function (Animate2D) which can demonstrate live updates of the fields, or store an animation to be viewed after the fact. The animations can be manipulated inline a Jupyter notebook. The easiest way to visualize the new features is with some notebooks I updated. You can view them in your browser here: https://nbviewer.jupyter.org/github/smartalecH/meep/tree/animation/python/examples/ Specifically, I modified |
A few things:
|
By the way, if we ever want to give the opportunity get/plot the field on an arbitrary mesh, one option would be to call |
This latest update includes the following new features:
I still plan on integrating a few more features:
|
Would be nice to add a Tests would be good as well. |
Updated with the following changes:
Once this passes, I think this is ready for merging. One important note: The Jupyter notebooks that contain animations are rather large, for obvious reasons. Do you use Git Large File Storage for large files? Future work (perhaps a separate PR) could include:
|
update travis add pyqt to travis revise qt in travis fixes for python2 switch from qt to wxpython try again try pyside again and again better error catching and remove mayavi from travis and test for now remove modified jupyter notebooks
One of the builds fails (something to do with an MPB callback), while a few others simply time out while testing I'm not really sure why — any ideas? |
The jobs timing out are all MPI builds. Have you tried running The py 2.7 build fails when building without MPB because of #891. I'll push a fix shortly. |
#894 Fixes the |
Nice catch! There are indeed deadlocks. Unfortunately, it's not just from writing the animations to disk. Even something simple, like calling This is weird, since |
python/visualization.py
Outdated
|
||
if not mp.am_master(): | ||
return | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All processes must call init_sim
. Moving this check below line 494 may fix the deadlock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I switched it, but still see deadlocks. I'm trying to use your visualize_chunks()
function as a template now. For whatever reason, that function does not deadlock, even though it is pretty similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although after carefully debugging, it did get rid of some deadlocks...
extent = [xmin,xmax,ymin,ymax] | ||
xlabel = 'X' | ||
ylabel = 'Y' | ||
fields = sim.get_array(center=center, size=cell_size, component=fields) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_array
must be called on all procs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the issue. I'll go through and fix all of those. Thanks so much!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that requirement documented anywhere? We may want to add a page about using mp.am_master()
with matplotlib
and when am_master()
shouldn't be used (i.e. with get_array()
It looks like all of the other tests are passing now. Once #894 is merged, that last test should pass too. |
Computes the resonant mode frequencies of a 2D ring resonator using `harminv`. | ||
|
||
5. __`visualization.ipynb`__ - | ||
Demonstrates various visualization and animation features. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is visualization.ipynb
supposed to be part of this PR? I don't see it anywhere.
When I run For
The
It would be nice to print this error info rather than having to inspect values in the debugger. I installed |
* first stab at unified plotting and video * minor fix to pml boundaries * incomplete changes * begin support for arbitrary planes * consolidate bug fixes * debugging * small bugs * bug fixes * fixed bugs with slicing, added animation run time object * use mixins * retrofit straight waveguide tutorial with animations * fix naming error * refactor visualization as standalone component * Cleanup and examples * check for library imports * attempt to fix import error python2 * Add tutorials * update straight example * more cleanup * refactor run function and visualization base * update docs, tutorials, tests, and customization * add test file update travis add pyqt to travis revise qt in travis fixes for python2 switch from qt to wxpython try again try pyside again and again better error catching and remove mayavi from travis and test for now remove modified jupyter notebooks * fix matplotlib issues in test * remove mp4 and gif on make clean * fix tabs * fixed deadlocking * fix test for mpi * visualization movie bug with ffmpeg * remove hashing * fix jshtml with python2
First stab at creating a python interface for visualizing the simulation domain and generating animations. The goal is to create a simple python function that doesn't require any writing to disk or extra command line steps.
I've added two major functions to the
simulation
class:visualize_domain
andanimate_fields
.visualize_domain
This function is used to produce a
pyplot
of the simulation domain. It visualizes the geometry, simulation bounds, boundary layers (green), all of the sources (red) and all of the monitors (blue).Several helper functions are used to pull the metadata from sources, monitors, PML layers, etc. I'm sure there are much more efficient methods to implement each of these, however.
The user can pass a
numpy
array of field data and the function will automatically superimpose the fields over the simulation domain.Note, I've made several assumptions with each of these helper functions:
1.) The simulation domain lies along the XY plane (i.e. Z is coming out of the board)
2.) Everything is centered at Z=0 (in other words, if monitors/sources are above this plane, they won't be plotted).
Here are some examples grabbed from various tutorials:
holey-wvg-cavity.py
metal-cavity-ldos.py
metasurface_lens.py
coupler.py
wvg-src.py
animate_fields
animate_fields()
uses thevisualize_domain()
function to create an animation video of the fields.matplotlib
relies on theffmpeg
library to generate the mp4 videos. I'm sure there are more efficient ways to do this.temp.mp4.zip