Learning Meep FDTD with Colab for free (Update)

Po-Ting Shen
2 min readOct 17, 2023

--

Update Notice: The first script block no longer works as a reader points out in the comments because Colab made undocumented changes to the ways that users used to activate self-defined environments. But thanks to a helpful user @davifr_14351 providing a working script. Use this instead:

!apt update
!apt-get install python3-meep h5utils
import meep as mp
mp.__version__

And it even works across the cells!

The original article below:

Are you a physicist or an optical engineer who wants to get into diffractive optics (for exciting positions like this), but lacks the computation resources to do so?

Hot positions want you to know FDTD

Commercial packages like Lumerical or COMSOL are very expensive. If your lab doesn’t have one, or, you have already left university, this spells money trouble. To set up open-source solution like Meep could also be a hassle if you don’t have access to a fast Linux computer.

Not anymore! In this article, I am gonna teach you how to utilize free resources to learn Meep FDTD.

First, you need to sign up for Google Colab to access the free Linux computer that you don’t have.

Second, create a Colab Notebook and execute the following code block to install pymeep on your Colab virtual machine:

!wget -c https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
!chmod +x Miniconda3-latest-Linux-x86_64.sh
!bash ./Miniconda3-latest-Linux-x86_64.sh -b -u -p /usr/local
import os
if os.path.isdir('/content/anaconda'): root_path = '/content/anaconda'
else: root_path = '/usr/local/'
os.environ['PATH'] += f":{root_path}/bin"
!conda create -n mp -c conda-forge pymeep python=3.7 -y
print(">> ", root_path)
import sys
sys.path.append(f'{root_path}envs/mp/lib/python3.7/site-packages/')
!source activate mp && conda env list

Please note, it will take 5 to 10 minutes to execute the above code block depending on your assigned virtual machine.

You can pay a small price ($ 9.99 /mo) to sign up for Colab Pro for even faster Meep environment setup if you like.

Run a small code block to make sure your Meep is installed properly:

import sys
import meep as mp

modulename = 'meep'
if modulename not in sys.modules:
print("You have not imported the {} module".format(modulename))

Finally, you can move to the bootstrap project that teaches you how to use Meep. I like the following free tutorial made by Humatic Labs.

Tutorial: A Crash Course using Meep | Humatic Labs

That’s it! Enjoy your journey to master FDTD without spending a cent!

Follow me for more niche computer hacks for people who are broke.

--

--

Po-Ting Shen

Currently a grad student at Cornell. Broke and curious.