Package: magnumnp
magnum.np 1.1.5magnum.np is a Python library for the solution of micromagnetic problems with the finite-difference method. It implements state-of-the-art algorithms and is based onpytorch, which allows to seamlessly run code either on GPU or on CPU. Simulation scripts are written in Python which leads to very readable yet flexible code. Due topytorchintegration, extensive postprocessing can be done directly in the simulations scripts. Furthermorepytorch's autograd feature makes it possible to solve inverse problems without significant modifications of the code. This manual is meant to give you both a quick start and a reference to magnum.np.FeaturesExplicit / Implicit time-integration of the Landau-Lifshitz-Gilbert EquationFast FFT Demagnetization-field computation optimized for small memory footprintFast FFT Oersted-field optimized for small memory footprintPeriodic Boundary Conditions in 1D, 2D, and 3D (True and Pseudo-Periodic)Non-Equidistant Mesh for Multilayer StructuresArbitrary Material Parameters varying in space and timeSpin-torque model by SlonczewskiSpin-torque model by Zhang and LiSpin-Orbit torque (SOT)Antiferromagnetic coupling layers (RKKY)Dzyaloshinskii-Moriya interaction (interface, bulk, D2d)String method for energy barrier computationsSophisticated domain handling, e.g. for spatially varying material parametersSeamless VTK import / export viapyvistaInverse Problems viapytorch's autograd featureDocumented Demos:Demo scripts for various applications are available in thedemodirectory.The following demos are also stored on Google Colab, where they can directly be run without any local installation:Slonczewski Spin Torque(Colab)Softmagnetic Composite(Colab)Spin Orbit Torque(Colab)Standard Problem #4(Colab)Standard Problem #5(Colab)Standard Problem Domainwall Pinning(Colab)Standard Problem DMI(Colab)Standard Problem FMR(Colab)Standard Problem RKKY(Colab)Stochastic Integration(Colab)[Dispersion Calculator] (demos/dispersion_calculator.ipynb) (Colab)Installationfrom Python Package Index (PyPi)For a clean and independent system, we start with a clean virtual python environment (this step could be omitted, if you would like to install magnum.np the available python environment)mkdir venv
python -m venv venv
source venv/bin/activateFinally install a release versions of magnum.np by means of pip:pip install magnumnpYou can also easily install different versions from private repositories. E.g. use the following command to install the latest version of the main branch:pip install git+https://gitlab.com/magnum.np/magnum.np@mainfrom source code (gitlab.com)More advanced users can also install magnum.np from source code.
It can be downloaded fromhttps://gitlab.com/magnum.np/magnum.np.After activating the virtual environment magnum.np can be simply installed using pip. For example
installing with the -e option also allows to modify the source code:pip install -e .Note that a default version ofpytorchis included in magnum.np's dependecy list. If you would like to uses a specific pytorch version (fitting your installed CUDA library) it needs to be installed in advance.run remotely via Google ColabMagnum.np could also be used without any hardware by executing it remotely on resources provided byGoogle Colab. The platform offers different runtime types like CPU(None), GPU or TPU. This allows users to directly test magnum.np, whithout needing their own hardware. Advanced users can use Google Colab(Pro), which provides access to current GPUs like the A100.Some jupyter-notebook examples are included in thedemodirectory, which also include links to Colab, where they can directly be run without any local installation.ExampleThe following demo code shows the solution of the muMAG Standard Problem #5 and can be found in the demos directory:frommagnumnpimport*importtorchTimer.enable()# initialize staten=(40,40,1)dx=(2.5e-9,2.5e-9,10e-9)mesh=Mesh(n,dx)state=State(mesh)state.material={"Ms":8e5,"A":1.3e-11,"alpha":0.1,"xi":0.05,"b":72.17e-12}# initialize magnetization that relaxes into s-statestate.m=state.Constant([0,0,0])state.m[:20,:,:,1]=-1.state.m[20:,:,:,1]=1.state.m[20,20,:,1]=0.state.m[20,20,:,2]=1.state.j=state.Tensor([1e12,0,0])# initialize field termsdemag=DemagField()exchange=ExchangeField()torque=SpinTorqueZhangLi()# initialize sstatellg=LLGSolver([demag,exchange])llg.relax(state)write_vti(state.m,"data/m0.vti",state)# perform integration with spin torquellg=LLGSolver([demag,exchange,torque])logger=ScalarLogger("data/m.dat",['t','m'])whilestate.t<5e-9:llg.step(state,1e-10)logger<<stateTimer.print_report()DocumentationThe documentation is located in the doc directory and can be built usingsphinx.
For example the following commands build an HTML documentation of the actual source code and stores it in thepublicfolder:sphinx-build -b html docs publicAlternatively, the latest version of the documentation is always available onhttps://magnum.np.gitlab.io/magnum.np/CitationIf you use magnum.np in your work or publication, please cite the following reference:[1] Bruckner, Florian, et al. "magnum.np -- A pytorch based GPU enhanced Finite Difference Micromagnetic Simulation Framework for High Level Development and Inverse Design", to be published (2023).ContributingContributions are gratefully accepted.
The source code is hosted onwww.gitlab.com/magnum.np/magnum.np.
If you have any issues or question, just open an issue via gitlab.com.
To contribute code, fork our repository on gitlab.com and create a corresponding merge request.