-
Notifications
You must be signed in to change notification settings - Fork 641
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
Fix images in MPB data analysis tutorial #695
Conversation
Oh, it's because |
Hi Chris,
I visited your links to the various Github page in your previous message (pull request, file changes, and patch links). Is there some way that I can replace my existing mpb_data_analysis.py with the revised version that should now work? In other words is there somewhere on GitHub that I can download the fixed file or clone it? Or does it just get incorporated into an overall revised version of MPB?
Best regards,
John
… On 31 Jan 2019, at 23:28, Christopher Hogan ***@***.***> wrote:
Oh, it's because geometry_lattice is a libctl global variable. Importing one ModeSolver after the other overwrote that parameter.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub <#695 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AHg6eN_0bhGSTJ_REkLxMPxgONJ10rihks5vI24YgaJpZM4adR-O>.
|
Hi again Chris,
A propos of this fix, you might be interested to know that even if all the code related to importing the diamond structure is commented out in mpb_data_analysis.py:
***********************************************************************************
# Import the ModeSolver from the mpb_tri_rods.py example
from mpb_tri_rods import ms as tr_ms
#from mpb_diamond import ms as d_ms
def tri_rods():
efields = []
# Band function to collect the efields
def get_efields(tr_ms, band):
efields.append(tr_ms.get_efield(band))
tr_ms.run_tm(mpb.output_at_kpoint(mp.Vector3(1 / -3, 1 / 3), mpb.fix_efield_phase,
get_efields))
# Create an MPBData instance to transform the efields
md = mpb.MPBData(rectify=True, resolution=32, periods=3)
converted = []
for f in efields:
# Get just the z component of the efields
f = f[..., 0, 2]
converted.append(md.convert(f))
tr_ms.run_te()
eps = tr_ms.get_epsilon()
plt.imshow(eps.T, interpolation='spline36', cmap='binary')
plt.axis('off')
plt.show()
md = mpb.MPBData(rectify=True, resolution=32, periods=3)
rectangular_data = md.convert(eps)
plt.imshow(rectangular_data.T, interpolation='spline36', cmap='binary')
plt.axis('off')
plt.show()
for i, f in enumerate(converted):
plt.subplot(331 + i)
plt.contour(rectangular_data.T, cmap='binary')
plt.imshow(np.real(f).T, interpolation='spline36', cmap='RdBu', alpha=0.9)
plt.axis('off')
plt.show()
#def diamond():
# dpwr = []
# def get_dpwr(ms, band):
# dpwr.append(ms.get_dpwr(band))
# d_ms.run(mpb.output_at_kpoint(mp.Vector3(0, 0.625, 0.375), get_dpwr))
# md = mpb.MPBData(rectify=True, periods=2, resolution=32)
# converted_dpwr = [md.convert(d) for d in dpwr]
# TODO: Plot
if __name__ == '__main__':
tri_rods()
# diamond()
********************************************************************************************************
If I run:
python mpb_data_analysi.py
I get a segmentation fault at the point where the solver is invoked:
(mp) johnweiner@johns-imac-pro-paris:~/pymeep/my_tutorials$ python mpb_data_analysis.py
Initializing eigensolver data
Computing 8 bands with 1e-07 tolerance
Working in 2 dimensions.
Grid size is 32 x 32 x 1.
Solving for 8 bands at a time.
Creating Maxwell data...
Mesh size is 3.
Lattice vectors:
(0.866025, 0.5, 0)
(0.866025, -0.5, 0)
(0, 0, 1)
Cell volume = 0.866025
Reciprocal lattice vectors (/ 2 pi):
(0.57735, 1, -0)
(0.57735, -1, 0)
(-0, 0, 1)
Geometric objects:
cylinder, center = (0,0,0)
radius 0.2, height 1e+20, axis (0, 0, 1)
Geometric object tree has depth 1 and 1 object nodes (vs. 1 actual objects)
Initializing epsilon function...
Allocating fields...
Solving for band polarization: tm.
Initializing fields to random numbers...
16 k-points
Vector3<0.0, 0.0, 0.0>
Vector3<0.0, 0.1, 0.0>
Vector3<0.0, 0.2, 0.0>
Vector3<0.0, 0.30000000000000004, 0.0>
Vector3<0.0, 0.4, 0.0>
Vector3<0.0, 0.5, 0.0>
Vector3<-0.06666666666666667, 0.4666666666666667, 0.0>
Vector3<-0.13333333333333333, 0.43333333333333335, 0.0>
Vector3<-0.2, 0.39999999999999997, 0.0>
Vector3<-0.26666666666666666, 0.36666666666666664, 0.0>
Vector3<-0.3333333333333333, 0.3333333333333333, 0.0>
Vector3<-0.26666666666666666, 0.26666666666666666, 0.0>
Vector3<-0.19999999999999998, 0.19999999999999998, 0.0>
Vector3<-0.1333333333333333, 0.1333333333333333, 0.0>
Vector3<-0.06666666666666665, 0.06666666666666665, 0.0>
Vector3<0.0, 0.0, 0.0>
elapsed time for initialization: 0.0019359588623046875
solve_kpoint (0,0,0):
tmfreqs:, k index, k1, k2, k3, kmag/2pi, tm band 1, tm band 2, tm band 3, tm band 4, tm band 5, tm band 6, tm band 7, tm band 8
Solving for bands 2 to 8...
Segmentation fault: 11
I am running this on an iMac, but I doubt if that is relevant.
Best regards,
John
… On 31 Jan 2019, at 23:27, Christopher Hogan ***@***.***> wrote:
Fixes #694 <#694>. I'm not sure exactly what happened here, but #644 <#644> broke mpb_data_analysis.py. It looks like one ms import was overwriting the other somehow. Importing them in separate functions fixes it.
@stevengj <https://github.com/stevengj> @oskooi <https://github.com/oskooi>
You can view, comment on, or merge this pull request online at:
#695 <#695>
Commit Summary
Fix images in MPB data analysis tutorial
File Changes
M python/examples/mpb_data_analysis.py <https://github.com/NanoComp/meep/pull/695/files#diff-0> (10)
Patch Links:
https://github.com/NanoComp/meep/pull/695.patch <https://github.com/NanoComp/meep/pull/695.patch>
https://github.com/NanoComp/meep/pull/695.diff <https://github.com/NanoComp/meep/pull/695.diff>
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub <#695>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AHg6eLDAUJCMUGDUfVkE4izokFKNSUaxks5vI23kgaJpZM4adR-O>.
|
In general, once a PR is merged into the master branch the change will trigger a rebuild of the nightly conda package, which should be on the Alternatively, if you want to experiment before the PR is merged, you can check out the PR branch and build from source. |
@JohnWeiner, did you build from source or install a conda package? Can you run the following command to show the pymeep version? $ python -c 'import meep; print(meep.__version__)' It should work with the latest master branch. |
Sorry for the last premature “send mail”…
I installed the conda package, but I haven’t tried with the nightly build.
The present conda-installed version, using the command line below, is
1.6.0-35-g3621a79b
John
… On 4 Feb 2019, at 14:48, Christopher Hogan ***@***.***> wrote:
@JohnWeiner <https://github.com/JohnWeiner>, did you build from source or install a conda package? Can you run the following command to show the pymeep version?
$ python -c 'import meep; print(meep.__version__)'
It should work with the latest master branch.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#695 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AHg6eP5EdqrYBidnJdbLyX86zLb_ytW2ks5vKDo1gaJpZM4adR-O>.
|
Yes, that's a bit outdated. You can try updating the pymeep package like this $ conda update -c chogan/label/dev -c chogan -c conda-forge pymeep # or pymeep-parallel However, I've found that $ conda create -n mp1.7 -c chogan/label/dev -c chogan -c conda-forge pymeep
$ conda activate mp1.7 |
OK thanks Chris…will do.
John
… On 4 Feb 2019, at 15:00, Christopher Hogan ***@***.***> wrote:
Yes, that's a bit outdated. You can try updating the pymeep package like this
$ conda update -c chogan/label/dev -c chogan -c conda-forge pymeep # or pymeep-parallel
However, I've found that conda update can often break an environment so I usually prefer to create a new environment (since they're cheap), keeping the old one in case you need to roll back.
$ conda create -n mp1.7 -c chogan/label/dev -c chogan -c conda-forge pymeep
$ conda activate mp1.7
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#695 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AHg6eLXLmrKd84wd05JEC9tVrfSwNiizks5vKDz1gaJpZM4adR-O>.
|
For activating the environment for the nightly builds (once created), is the command “conda activate mp_test” and “conda activate pmp_test”?
… On 4 Feb 2019, at 15:02, John Weiner ***@***.***> wrote:
OK thanks Chris…will do.
John
> On 4 Feb 2019, at 15:00, Christopher Hogan ***@***.*** ***@***.***>> wrote:
>
> Yes, that's a bit outdated. You can try updating the pymeep package like this
>
> $ conda update -c chogan/label/dev -c chogan -c conda-forge pymeep # or pymeep-parallel
> However, I've found that conda update can often break an environment so I usually prefer to create a new environment (since they're cheap), keeping the old one in case you need to roll back.
>
> $ conda create -n mp1.7 -c chogan/label/dev -c chogan -c conda-forge pymeep
> $ conda activate mp1.7
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub <#695 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AHg6eLXLmrKd84wd05JEC9tVrfSwNiizks5vKDz1gaJpZM4adR-O>.
>
|
The general command is $ conda activate <environment name> The name of the environment is whatever you pass to the $ source activate <environment name> which accomplishes the same thing, but |
OK, thanks
… On 4 Feb 2019, at 15:10, Christopher Hogan ***@***.***> wrote:
The general command is
$ conda activate <environment name>
The name of the environment is whatever you pass to the -n flag in the conda create command. I think the meep docs still say
$ souce activate <environment name>
which accomplishes the same thing, but source activate is deprecated and conda activate is now preferred.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#695 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AHg6eDPEnHsoe_MPF8KjlV6GOdJ8onf5ks5vKD9RgaJpZM4adR-O>.
|
Hi again Chris,
I created the “nightly build” environment and the mp1.7 environment and activated them, and tried running,
python .//miniconda3/pkgs/pymeep-1.7.1.dev-py36_nomkl_25/info/test/python/examples/mpb_data_analysis.py
It still thows a seg fault at the point where the solver is invoked, for example:
elapsed time for initialization: 0.0017228126525878906
solve_kpoint (0,0,0):
tmfreqs:, k index, k1, k2, k3, kmag/2pi, tm band 1, tm band 2, tm band 3, tm band 4, tm band 5, tm band 6, tm band 7, tm band 8
Solving for bands 2 to 8...
Segmentation fault: 11
John
… On 4 Feb 2019, at 15:21, John Weiner ***@***.***> wrote:
OK, thanks
> On 4 Feb 2019, at 15:10, Christopher Hogan ***@***.*** ***@***.***>> wrote:
>
> The general command is
>
> $ conda activate <environment name>
> The name of the environment is whatever you pass to the -n flag in the conda create command. I think the meep docs still say
>
> $ souce activate <environment name>
> which accomplishes the same thing, but source activate is deprecated and conda activate is now preferred.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub <#695 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AHg6eDPEnHsoe_MPF8KjlV6GOdJ8onf5ks5vKD9RgaJpZM4adR-O>.
>
|
Is that after commenting out the |
No, I didn’t touch anything…just ran the mpb_data_analysis.py script as is from the examples directory in the mp1.7 environment. Ditto for the nightly build. So the import command for both tri_rods and diamond should be there.
… On 4 Feb 2019, at 15:54, Christopher Hogan ***@***.***> wrote:
Is that after commenting out the from mpb_diamond import ms as d_ms and diamond() lines (since this fix isn't applied yet to the nightly builds)?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#695 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AHg6eHl6w9Q96dPreOHN3cHrrLGZA0YSks5vKEmwgaJpZM4adR-O>.
|
I can reproduce this. MPB seems to be linking with a system |
I just activated the mp1.7 environment on a pc box I have that is running Ubuntu Linux. I tried the same thing as on the iMac, running python ./…../examples/mpb_data_analysis.py. It DOES run on the pc box, and generates figures, but the “corrected” lattice does not look like round holes and the array of Ez fields superimposed on the lattice contour gives very strange looking results. However it does not throw the segmentation fault.
… On 4 Feb 2019, at 15:54, Christopher Hogan ***@***.***> wrote:
Is that after commenting out the from mpb_diamond import ms as d_ms and diamond() lines (since this fix isn't applied yet to the nightly builds)?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#695 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AHg6eHl6w9Q96dPreOHN3cHrrLGZA0YSks5vKEmwgaJpZM4adR-O>.
|
Right, that behavior is what this PR fixes. If you move the imports to their respective functions (the changes in this PR) you will see the correct images. |
Chris you just lost me in the dust…
If you move the imports to their respective functions (the changes in this PR) you will see the correct images.
I’m not quite sure what to do to make that happen.
… On 4 Feb 2019, at 17:12, Christopher Hogan ***@***.***> wrote:
Right, that behavior is what this PR fixes. If you move the imports to their respective functions (the changes in this PR) you will see the correct images.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#695 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AHg6eF7jWdUoEc1I0bejqKL_8659sxWmks5vKFvzgaJpZM4adR-O>.
|
This conversation is happening in a thread for a pull request, the diff of which is at https://github.com/NanoComp/meep/pull/695/files. Those changes fix the issue you see on Linux. |
The Mac issue is different though. It has to do with the way the conda packages are built. I'm investigating that now. |
I just hand-typed your modifications in your PR into the mpb_data_analysis.py file on the PC box. Then ran the script again and it works perfectly!
Is there a better way to incorporate the PR into the py file? There must be something more intelligent than hand copying and typing!
John
… On 4 Feb 2019, at 17:19, Christopher Hogan ***@***.***> wrote:
The Mac issue is different though. It has to do with the way the conda packages are built. I'm investigating that now.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#695 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AHg6eAXfRNKsYqBVyOklB0zte6cy36okks5vKF2bgaJpZM4adR-O>.
|
That's the process I explained in the comment here: #695 (comment) Instructions on checking out a local copy of a PR are here: https://help.github.com/articles/checking-out-pull-requests-locally/ |
OK…I’m beginning to get it. Haven’t played with pull requests before, but the checking out of pull requests locally looks like something I should know.
John
… On 4 Feb 2019, at 17:52, Christopher Hogan ***@***.***> wrote:
Is there a better way to incorporate the PR into the py file?
That's the process I explained in the comment here: #695 (comment) <#695 (comment)>
Instructions on checking out a local copy of a PR are here: https://help.github.com/articles/checking-out-pull-requests-locally/ <https://help.github.com/articles/checking-out-pull-requests-locally/>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#695 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AHg6eKgF-OIuHIGeFDvjEifzbJxv5i29ks5vKGVYgaJpZM4adR-O>.
|
The Mac issue is due to the
$ mkdir -p ~/.matplotlib
$ echo "backend: TkAgg" > ~/.matplotlib/matplotlibrc |
I incorporated the changes you propose in mpb_data_analysis.py: to wit, import meep before matplotlib, and def tri_rods():
def get_efields(tr_ms, band): def diamond():
def get_dpwr(ms, band): However the mpb_data_analysis.py script still does not run. I get this puzzling error when I execute python command on the file: It is as if the subroutine, def tri_rods(): is not read or something. Here is what the tri_rods part of the mpb_data_analysis.py file looks like after the modifications: from __future__ import division
import os
import sys
import numpy as np
import meep as mp
import matplotlib.pyplot as plt
from meep import mpb
examples_dir = os.path.realpath(os.path.dirname(__file__))
sys.path.insert(0, examples_dir)
def tri_rods():
# Import the ModeSolver defined in the mpb_tri_rods.py example
from mpb_tri_rods import ms as tr_ms
efields = []
# Band function to collect the efields
def get_efields(tr_ms, band):
efields.append(tr_ms.get_efield(band))
tr_ms.run_tm(mpb.output_at_kpoint(mp.Vector3(1 / -3, 1 / 3), mpb.fix_efield_phase,
get_efields))
# Create an MPBData instance to transform the efields
md = mpb.MPBData(rectify=True, resolution=32, periods=3)
converted = []
for f in efields:
# Get just the z component of the efields
f = f[..., 0, 2]
converted.append(md.convert(f))
tr_ms.run_te()
eps = tr_ms.get_epsilon()
plt.imshow(eps.T, interpolation='spline36', cmap='binary')
plt.axis('off')
plt.show()
md = mpb.MPBData(rectify=True, resolution=32, periods=3)
rectangular_data = md.convert(eps)
plt.imshow(rectangular_data.T, interpolation='spline36', cmap='binary')
plt.axis('off')
plt.show()
for i, f in enumerate(converted):
plt.subplot(331 + i)
plt.contour(rectangular_data.T, cmap='binary')
plt.imshow(np.real(f).T, interpolation='spline36', cmap='RdBu', alpha=0.9)
plt.axis('off')
plt.show() |
I'm not sure if this is just a cut-and-paste issue, but the |
Yes! Now it is working with the correct indentation…I had not grasped the overall structure of the tri_rods subroutine and had “cleaned up” the indentation…to my chagrin and regret.
… On 5 Feb 2019, at 14:37, Christopher Hogan ***@***.***> wrote:
I'm not sure if this is just a cut-and-paste issue, but the tri_rods code you show has some indentation issues that would break things. Can you make sure the indentation is exactly the same as https://github.com/NanoComp/meep/blob/master/python/examples/mpb_data_analysis.py <https://github.com/NanoComp/meep/blob/master/python/examples/mpb_data_analysis.py>?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#695 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AHg6eLpqwPqnNodN2ATl8JwlHkEm3B1Aks5vKYk3gaJpZM4adR-O>.
|
Great! |
* Fix images in MPB data analysis tutorial * Add matplotlib troubleshooting for mac * Import meep before matplotlib to work around macOS issues * Fix typo in docs
Fixes #694. I'm not sure exactly what happened here, but #644 broke
mpb_data_analysis.py
. It looks like onems
import was overwriting the other somehow. Importing them in separate functions fixes it.@stevengj @oskooi