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.30.1";
40
41 src = fetchFromGitHub {
42 owner = "NanoComp";
43 repo = "meep";
44 tag = "v${version}";
45 hash = "sha256-rXmOCkWm8SymhLiKNskSiS2bsHCmTlKMfLg5u3XniOk=";
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 [
78 numpy
79 scipy
80 matplotlib
81 h5py-mpi
82 cython
83 autograd
84 mpi4py
85 ]
86 ++ lib.optionals (!pythonOlder "3.12") [
87 setuptools # used in python/visualization.py
88 distutils
89 ];
90
91 propagatedUserEnvPkgs = [ mpi ];
92
93 dontUseSetuptoolsBuild = true;
94 dontUsePipInstall = true;
95
96 enableParallelBuilding = true;
97
98 preConfigure = ''
99 export HDF5_MPI=ON
100 export PYTHON=${python.interpreter};
101 '';
102
103 configureFlags = [
104 "--without-libctl"
105 "--enable-shared"
106 "--with-mpi"
107 "--with-openmp"
108 "--enable-maintainer-mode"
109 ];
110
111 passthru = {
112 inherit mpi;
113 };
114
115 /*
116 This test is taken from the MEEP tutorial "Fields in a Waveguide" at
117 <https://meep.readthedocs.io/en/latest/Python_Tutorials/Basics/>.
118 It is important, that the test actually performs a calculation
119 (calls `sim.run()`), as only then MPI will be initialised and MPI linking
120 errors can be caught.
121 */
122 nativeCheckInputs = [
123 mpiCheckPhaseHook
124 ];
125 pythonImportsCheck = [
126 "meep.mpb"
127 ];
128 checkPhase = ''
129 runHook preCheck
130
131 export PYTHONPATH="$out/${python.sitePackages}:$PYTHONPATH"
132
133 # Generate a python test script
134 cat > test.py << EOF
135 import meep as mp
136 cell = mp.Vector3(16,8,0)
137 geometry = [mp.Block(mp.Vector3(mp.inf,1,mp.inf),
138 center=mp.Vector3(),
139 material=mp.Medium(epsilon=12))]
140 sources = [mp.Source(mp.ContinuousSource(frequency=0.15),
141 component=mp.Ez,
142 center=mp.Vector3(-7,0))]
143 pml_layers = [mp.PML(1.0)]
144 resolution = 10
145 sim = mp.Simulation(cell_size=cell,
146 boundary_layers=pml_layers,
147 geometry=geometry,
148 sources=sources,
149 resolution=resolution)
150 sim.run(until=200)
151 EOF
152
153 ${mpi}/bin/mpiexec -np 2 python3 test.py
154
155 runHook postCheck
156 '';
157
158 meta = {
159 description = "Free finite-difference time-domain (FDTD) software for electromagnetic simulations";
160 homepage = "https://meep.readthedocs.io/en/latest/";
161 license = lib.licenses.gpl2Only;
162 platforms = lib.platforms.linux;
163 maintainers = with lib.maintainers; [
164 sheepforce
165 markuskowa
166 ];
167 };
168}