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