evcc: 0.131.4 -> 0.131.5
[NixPkgs.git] / pkgs / development / python-modules / meep / default.nix
blobab8e238dc6d04f52e6aa990329f731d1e6d21fab
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   python,
23   numpy,
24   scipy,
25   matplotlib,
26   h5py-mpi,
27   cython,
28   autograd,
29   mpi4py,
32 assert !blas.isILP64;
33 assert !lapack.isILP64;
35 buildPythonPackage rec {
36   pname = "meep";
37   version = "1.29.0";
39   src = fetchFromGitHub {
40     owner = "NanoComp";
41     repo = pname;
42     rev = "refs/tags/v${version}";
43     hash = "sha256-TB85obdk8pSWRaz3+3I6P6+dQtCHosWHRnKGck/wG9Q=";
44   };
46   format = "other";
48   # https://github.com/NanoComp/meep/issues/2819
49   postPatch = lib.optionalString (!pythonOlder "3.12") ''
50     substituteInPlace configure.ac doc/docs/setup.py python/visualization.py \
51       --replace-fail "distutils" "setuptools._distutils"
52   '';
54   # MPI is needed in nativeBuildInputs too, otherwise MPI libs will be missing
55   # at runtime
56   nativeBuildInputs = [
57     autoreconfHook
58     gfortran
59     pkg-config
60     swig
61     mpi
62   ];
64   buildInputs = [
65     gsl
66     blas
67     lapack
68     fftw
69     hdf5-mpi
70     harminv
71     libctl
72     libGDSII
73     guile
74     gsl
75   ];
77   propagatedBuildInputs =
78     [
79       mpi
80       numpy
81       scipy
82       matplotlib
83       h5py-mpi
84       cython
85       autograd
86       mpi4py
87     ]
88     ++ lib.optionals (!pythonOlder "3.12") [
89       setuptools # used in python/visualization.py
90     ];
92   propagatedUserEnvPkgs = [ mpi ];
94   dontUseSetuptoolsBuild = true;
95   dontUsePipInstall = true;
96   dontUseSetuptoolsCheck = true;
98   enableParallelBuilding = true;
100   preConfigure = ''
101     export HDF5_MPI=ON
102     export PYTHON=${python}/bin/${python.executable};
103   '';
105   configureFlags = [
106     "--without-libctl"
107     "--enable-shared"
108     "--with-mpi"
109     "--with-openmp"
110     "--enable-maintainer-mode"
111   ];
113   passthru = {
114     inherit mpi;
115   };
117   /*
118     This test is taken from the MEEP tutorial "Fields in a Waveguide" at
119     <https://meep.readthedocs.io/en/latest/Python_Tutorials/Basics/>.
120     It is important, that the test actually performs a calculation
121     (calls `sim.run()`), as only then MPI will be initialised and MPI linking
122     errors can be caught.
123   */
124   nativeCheckInputs = [
125     mpiCheckPhaseHook
126   ];
127   checkPhase = ''
128     runHook preCheck
130     export PYTHONPATH="$out/${python.sitePackages}:$PYTHONPATH"
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
152     ${mpi}/bin/mpiexec -np 2 python3 test.py
154     runHook postCheck
155   '';
157   meta = with lib; {
158     description = "Free finite-difference time-domain (FDTD) software for electromagnetic simulations";
159     homepage = "https://meep.readthedocs.io/en/latest/";
160     license = licenses.gpl2Only;
161     platforms = platforms.linux;
162     maintainers = with maintainers; [
163       sheepforce
164       markuskowa
165     ];
166   };