1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 pythonOlder,
6 setuptools,
7 autoreconfHook,
8 pkg-config,
9 mpiCheckPhaseHook,
10 gfortran,
11 mpi,
12 blas,
13 lapack,
14 fftw,
15 hdf5-mpi,
16 swig,
17 gsl,
18 harminv,
19 libctl,
20 libGDSII,
21 guile,
22 mpb,
23 python,
24 numpy,
25 scipy,
26 matplotlib,
27 h5py-mpi,
28 cython,
29 autograd,
30 mpi4py,
31 distutils,
32}:
33
34assert !blas.isILP64;
35assert !lapack.isILP64;
36
37buildPythonPackage rec {
38 pname = "meep";
39 version = "1.31.0";
40
41 src = fetchFromGitHub {
42 owner = "NanoComp";
43 repo = "meep";
44 tag = "v${version}";
45 hash = "sha256-x5OMdV/LJfklcK1KlYS0pdotsXP/SYzF7AOW5DlJvq0=";
46 };
47
48 format = "other";
49
50 # MPI is needed in nativeBuildInputs too, otherwise MPI libs will be missing
51 # at runtime
52 nativeBuildInputs = [
53 autoreconfHook
54 gfortran
55 pkg-config
56 swig
57 mpi
58 ];
59
60 buildInputs = [
61 gsl
62 blas
63 lapack
64 fftw
65 hdf5-mpi
66 harminv
67 libctl
68 libGDSII
69 guile
70 gsl
71 mpb
72 ];
73
74 propagatedBuildInputs = [ mpi ];
75
76 dependencies = [
77 numpy
78 scipy
79 matplotlib
80 h5py-mpi
81 cython
82 autograd
83 mpi4py
84 ]
85 ++ lib.optionals (!pythonOlder "3.12") [
86 setuptools # used in python/visualization.py
87 distutils
88 ];
89
90 propagatedUserEnvPkgs = [ mpi ];
91
92 dontUseSetuptoolsBuild = true;
93 dontUsePipInstall = true;
94
95 enableParallelBuilding = true;
96
97 preConfigure = ''
98 export HDF5_MPI=ON
99 export PYTHON=${python.interpreter};
100 '';
101
102 configureFlags = [
103 "--without-libctl"
104 "--enable-shared"
105 "--with-mpi"
106 "--with-openmp"
107 "--enable-maintainer-mode"
108 ];
109
110 passthru = {
111 inherit mpi;
112 };
113
114 /*
115 This test is taken from the MEEP tutorial "Fields in a Waveguide" at
116 <https://meep.readthedocs.io/en/latest/Python_Tutorials/Basics/>.
117 It is important, that the test actually performs a calculation
118 (calls `sim.run()`), as only then MPI will be initialised and MPI linking
119 errors can be caught.
120 */
121 nativeCheckInputs = [
122 mpiCheckPhaseHook
123 ];
124 pythonImportsCheck = [
125 "meep.mpb"
126 ];
127 checkPhase = ''
128 runHook preCheck
129
130 export PYTHONPATH="$out/${python.sitePackages}:$PYTHONPATH"
131
132 # Generate a python test script
133 cat > test.py << EOF
134 import meep as mp
135 cell = mp.Vector3(16,8,0)
136 geometry = [mp.Block(mp.Vector3(mp.inf,1,mp.inf),
137 center=mp.Vector3(),
138 material=mp.Medium(epsilon=12))]
139 sources = [mp.Source(mp.ContinuousSource(frequency=0.15),
140 component=mp.Ez,
141 center=mp.Vector3(-7,0))]
142 pml_layers = [mp.PML(1.0)]
143 resolution = 10
144 sim = mp.Simulation(cell_size=cell,
145 boundary_layers=pml_layers,
146 geometry=geometry,
147 sources=sources,
148 resolution=resolution)
149 sim.run(until=200)
150 EOF
151
152 ${mpi}/bin/mpiexec -np 2 python3 test.py
153
154 runHook postCheck
155 '';
156
157 meta = {
158 description = "Free finite-difference time-domain (FDTD) software for electromagnetic simulations";
159 homepage = "https://meep.readthedocs.io/en/latest/";
160 license = lib.licenses.gpl2Only;
161 platforms = lib.platforms.linux;
162 maintainers = with lib.maintainers; [
163 sheepforce
164 markuskowa
165 ];
166 };
167}