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