Skip to content

Commit

Permalink
Fix images in MPB data analysis tutorial (NanoComp#695)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ChristopherHogan authored and stevengj committed Feb 5, 2019
1 parent 6cbe41b commit e22ff80
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
9 changes: 7 additions & 2 deletions doc/docs/Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ This creates an environment called "mp" (you can name this anything you like) wi
Next, we need to activate the environment before we can start using it.

```bash
source activate mp
conda activate mp
```

Now, `python -c 'import meep'` should work, and you can try running some of the examples in the `meep/python/examples` directory.
Expand All @@ -50,7 +50,7 @@ Installing parallel PyMeep follows the same pattern, but the package is called `

```bash
conda create -n pmp -c chogan -c conda-forge pymeep-parallel
source activate pmp
conda activate pmp
```

The environment includes `mpi4py`, so you can run an MPI job with 4 processes like this:
Expand All @@ -61,6 +61,11 @@ mpirun -np 4 python <script_name>.py

If you run into issues, make sure your `PYTHONPATH` environment variable is unset.

**Note:** If you experience crashes when using `matplotlib` on macOS, try importing `meep` before importing `matplotlib`. In addition add the following line to your `~/.matplotlib/matplotlibrc` file to force the `TkAgg` backend:
```
backend: TkAgg
```

**Note:** For pymeep-parallel on macOS, a [bug](https://github.com/open-mpi/ompi/issues/2956) in openmpi requires that the environment variable `TMPDIR` be set to a short path like `/tmp`. Without this workaround, you may see errors similar to this:

```bash
Expand Down
12 changes: 7 additions & 5 deletions python/examples/mpb_data_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@

import os
import sys
import matplotlib.pyplot as plt
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)

# 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():
# 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
Expand Down Expand Up @@ -57,6 +56,9 @@ def get_efields(tr_ms, band):


def diamond():
# Import the ModeSolver from the mpb_diamond.py example
from mpb_diamond import ms as d_ms

dpwr = []

def get_dpwr(ms, band):
Expand Down

0 comments on commit e22ff80

Please sign in to comment.