Code Monkey home page Code Monkey logo

micromagneticdata's Introduction

ubermag

Marijan Beg1,2, Martin Lang2, Samuel Holt2,3, Swapneel Amit Pathak2,4, Ryan A. Pepper5, Thomas Kluyver6, Jeroen Mulkers7, Jonathan Leliaert7, and Hans Fangohr2,4,8

1 Department of Earth Science and Engineering, Imperial College London, London SW7 2AZ, UK
2 Faculty of Engineering and Physical Sciences, University of Southampton, Southampton SO17 1BJ, UK
3 Department of Physics, University of Warwick, Coventry CV4 7AL, UK
4 Max Planck Institute for the Structure and Dynamics of Matter, Luruper Chaussee 149, 22761 Hamburg, Germany
5 Research Software Group, University of Birmingham, Birmingham B15 2TT, UK
6 European XFEL GmbH, Holzkoppel 4, 22869 Schenefeld, Germany
7 Faculty of Sciences, Ghent University, Krijgslaan 281, S12, 9000 Ghent, Belgium
8 Center for Free-Electron Laser Science, Luruper Chaussee 149, 22761 Hamburg, Germany

Description Badge
Tests Build status
conda
Linting pre-commit.ci status
Code style: black
Releases PyPI version
Anaconda-Server Badge
Coverage codecov
Documentation Documentation
YouTube YouTube
Binder Binder
Platforms Platforms
Downloads Downloads
License License
DOI DOI

About

ubermag is a Python package, integrated with Jupyter, providing:

  • Meta package for Ubermag project,

  • Logging control in Ubermag packages.

It is available on Windows, MacOS, and Linux. It requires Python 3.8+.

Documentation

APIs and tutorials are available in the documentation. To access the documentation, use the badge in the table above.

Installation, testing, and upgrade

We recommend installation using conda package manager. Instructions can be found in the documentation.

Binder

This package can be used in the cloud via Binder. To access Binder, use the badge in the table above.

YouTube

YouTube video tutorials are available on the Ubermag channel.

Support

If you require support, have questions, want to report a bug, or want to suggest an improvement, please raise an issue in ubermag/help repository.

Contributions

All contributions are welcome, however small they are. If you would like to contribute, please fork the repository and create a pull request. If you are not sure how to contribute, please contact us by raising an issue in ubermag/help repository, and we are going to help you get started and assist you on the way.

Contributors:

License

Licensed under the BSD 3-Clause "New" or "Revised" License. For details, please refer to the LICENSE file.

How to cite

  1. M. Beg, M. Lang, and H. Fangohr. Ubermag: Towards more effective micromagnetic workflows. IEEE Transactions on Magnetics 58, 7300205 (2022).

  2. M. Beg, R. A. Pepper, and H. Fangohr. User interfaces for computational science: A domain specific language for OOMMF embedded in Python. AIP Advances 7, 56025 (2017).

  3. Marijan Beg, Martin Lang, Samuel Holt, Swapneel Amit Pathak, Ryan A. Pepper, Thomas Kluyver, Jeroen Mulkers, Jonathan Leliaert, and Hans Fangohr. ubermag: Meta package for Ubermag project. DOI: 10.5281/zenodo.3539495 (2022).

Acknowledgements

  • OpenDreamKit – Horizon 2020 European Research Infrastructure project (676541)

  • EPSRC Programme Grant on Skyrmionics (EP/N032128/1)

micromagneticdata's People

Contributors

gamdow avatar kzqureshi avatar lang-m avatar marijanbeg avatar pre-commit-ci[bot] avatar samjrholt avatar sergii-mamedov avatar swapneelap avatar ubermag-bot avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

gamdow stibus

micromagneticdata's Issues

Consider computing test data during tests.

We have a script to compute the test data used and commited to the repository. It runs in a few seconds. We should consider recreating the data for the tests because we do not detect changes in the code that creates the data. Therefore, we initially missed the recent change in the HysteresisDriver (renaming the hysteresis field) that should have broken the tests in micromagnetictests.

Rewrite `data.info`

The implementation of data.info is quite fragile and easily breaks, e.g. if there are missing drives or the info.json of one of the drives cannot be read.

Loading subregions from Mumax3 run fails

Mumax3 shifts pmin to the origin when writing output files. Micromagneticdata tries to load subregions from the json file that is created when writing the input files. This fails if pmin in the input is not at (0, 0, 0).

Accessing saved magnetisation data

When accessing data of a drive drive[<number>] we currently use an index based on the available files on disk. We should consider using data from drive.table.data instead. That could be useful when one wants to keep only a few selected magnetisation configurations and the scalar data.

Initialisation of `Data` object

Currently, Data takes two arguments: name and dirname, both have to be strings. It would be more convenient to:

  1. convert this or additionally allow a single argument, the full (relative) path to the data folder, i.e. dirname/name
  2. support pathlib.Path in addition to str

Check EOL

Check line endings for the following files when running a simulation on Windows:

  • OOMMF odt
  • Mumax3 ovf
  • Mumax3 txt

Update .gitignores accordingly (in micromagneticdata and ubermag).

Test data does not work on windows

Loading drive 0, magnetisation snapshot 4 on Windows results in wrong numbers (looks like overflow/encoding problems). Linux and Mac are not affected.

Allow concatenation of drives

We currently support concatenating tables using the << syntax.

Similar functionality would be very useful for drive objects, e.g. to concatenate two consecutive calls to TimeDriver with drive1 << drive2 and create an interactive plot.

However, there are a few methods/properties that are very specific to one drive:

  • m0
  • info (a small json file with some information about that drive, e.g. date)
  • mif (returns the content of the mif file)

Operating on the drive objects would be good as these are memory efficient (e.g. do not load all data) and I plan to add holoviews based interactive plotting functionality to Drive. Furthermore, the drive object has a reference to the corresponding table object with all the scalar data.

An alternative would be to try to delegate this to xarray. The obvious downside is that this would immediately load all data to memory (probably okay for our typical file sizes). Also, we should then have a different set of plotting functions that operate on the xarray instead of the Drive object. And we would loose the direct link to the table object.

Invalid data on windows

The ovf rectangle drive[0][4] is not read properly on Windows (Linux and Mac are fine), the full error message when running pytest is shown further down. Other ovf files in the output data (same drive) do not show the problem. Re-computing the test data (including changing the system name to get rid of any potential issues in the git history) did not fix the issue.

@samjrholt and I looked at the problematic file on Windows and Mac using a HEX editor (also comparing with a different file from the same drive on Windows that did not have the problem). It appears that in the problematic file on Windows all line endings are changed from LF ('\n') -> LFCR ('\n\r'). It is not clear why:

  1. this happens for the binary file (OOMMF always writes just LF, independent of the OS)
  2. why the same does not happen for the other ovf files.

We only looked at the ASCII header of the ovf file in detail and did not check for changes in the actual data. We know that the data read from the file is wrong but not whether this is a cause of the broken header or whether the binary part is also modified.

When re-computing the data (running python micromagneticdata/tests/generate_test_data.py) on Windows the file is written correctly (just LF). After committing, pushing and pulling in a fresh clone the data is wrong (on Windows, the same commit is fine on Mac/Linux). We did not try deactivating the automatic LF <-> LFCR conversion in git (such a change should not be required!).

_________________________ TestDrive.test_getitem_int __________________________

self = <micromagneticdata.tests.test_drive.TestDrive object at 0x0000026A70514F70>

    def test_getitem_int(self):
        for i in range(self.data[0].n):
>           assert isinstance(self.data[0][i], df.Field)

i          = 4
self       = <micromagneticdata.tests.test_drive.TestDrive object at 0x0000026A70514F70>

micromagneticdata\tests\test_drive.py:97: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
micromagneticdata\drive.py:212: in __getitem__
    return super().__getitem__(item)
        __class__  = <class 'micromagneticdata.drive.Drive'>
        item       = 4
        self       = OOMMFDrive(name='rectangle', number=0, dirname='D:\a\micromagneticdata\micromagneticdata\micromagneticdata\tests\test_sample', x='t')
micromagneticdata\abstract_drive.py:208: in __getitem__
    field.valid = "norm"
        field      = Field(Mesh(Region(pmin=[-5e-08, -2.5e-08, 0.0], pmax=[5e-08, 2.5e-08, 2e-08], dims=['x', 'y', 'z'], units=['m', 'm', '....0], pmax=[5e-08, 2.5e-08, 2e-08], dims=['x', 'y', 'z'], units=['m', 'm', 'm']))), nvdim=3, vdims: (x, y, z), unit=A/m)
        item       = 4
        self       = OOMMFDrive(name='rectangle', number=0, dirname='D:\a\micromagneticdata\micromagneticdata\micromagneticdata\tests\test_sample', x='t')
C:\Miniconda\envs\conda-environment\lib\site-packages\discretisedfield\field.py:561: in valid
    valid = ~np.isclose(self.norm.array, 0)
        self       = Field(Mesh(Region(pmin=[-5e-08, -2.5e-08, 0.0], pmax=[5e-08, 2.5e-08, 2e-08], dims=['x', 'y', 'z'], units=['m', 'm', '....0], pmax=[5e-08, 2.5e-08, 2e-08], dims=['x', 'y', 'z'], units=['m', 'm', 'm']))), nvdim=3, vdims: (x, y, z), unit=A/m)
        valid      = 'norm'
C:\Miniconda\envs\conda-environment\lib\site-packages\discretisedfield\field.py:527: in norm
    res = np.linalg.norm(self.array, axis=-1, keepdims=True)
        self       = Field(Mesh(Region(pmin=[-5e-08, -2.5e-08, 0.0], pmax=[5e-08, 2.5e-08, 2e-08], dims=['x', 'y', 'z'], units=['m', 'm', '....0], pmax=[5e-08, 2.5e-08, 2e-08], dims=['x', 'y', 'z'], units=['m', 'm', 'm']))), nvdim=3, vdims: (x, y, z), unit=A/m)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

x = array([[[[-6.43428711e+249, -6.31358452e+206,  6.95375381e-025],
         [ 6.95375381e-025, -6.45299271e+009,  4.1692...45299271e+009,  4.16922004e+264, -3.54059361e+186],
         [-3.54059361e+186,  3.01554046e-260, -1.66647543e-246]]]])
ord = None, axis = (-1,), keepdims = True

    @array_function_dispatch(_norm_dispatcher)
    def norm(x, ord=None, axis=None, keepdims=False):
        ...
                # special case for speedup
>               s = (x.conj() * x).real
E               RuntimeWarning: overflow encountered in multiply

axis       = (-1,)
keepdims   = True
nd         = 4
ord        = None
x          = array([[[[-6.43428711e+249, -6.31358452e+206,  6.95375381e-025],
         [ 6.95375381e-025, -6.45299271e+009,  4.1692...45299271e+009,  4.16922004e+264, -3.54059361e+186],
         [-3.54059361e+186,  3.01554046e-260, -1.66647543e-246]]]])

x is the numpy array containing the magnetisation, expected values (i.e. values read on Mac/Linuxr are on the order 1e6.

Numpy does not fail, just shows a warning. Our pytest configuration escalates warnings to errors (see below).

All tests that access the broken file are affected:

=========================== short test summary info ===========================
FAILED micromagneticdata/tests/test_combined_drive.py::TestDrive::test_iter - RuntimeWarning: overflow encountered in multiply
FAILED micromagneticdata/tests/test_combined_drive.py::TestDrive::test_to_xarray - RuntimeWarning: overflow encountered in multiply
FAILED micromagneticdata/tests/test_combined_drive.py::TestDrive::test_register_callback - RuntimeWarning: overflow encountered in multiply
FAILED micromagneticdata/tests/test_drive.py::TestDrive::test_getitem_int - RuntimeWarning: overflow encountered in multiply
FAILED micromagneticdata/tests/test_drive.py::TestDrive::test_getitem_slice - RuntimeWarning: overflow encountered in multiply
FAILED micromagneticdata/tests/test_drive.py::TestDrive::test_iter - RuntimeWarning: overflow encountered in multiply
FAILED micromagneticdata/tests/test_drive.py::TestDrive::test_ovf2vtk - RuntimeWarning: overflow encountered in multiply
FAILED micromagneticdata/tests/test_drive.py::TestDrive::test_to_xarray - RuntimeWarning: overflow encountered in multiply
FAILED micromagneticdata/tests/test_drive.py::TestDrive::test_register_callback - RuntimeWarning: overflow encountered in multiply
FAILED micromagneticdata/tests/test_drive.py::TestDrive::test_cache - RuntimeWarning: overflow encountered in multiply

The problem is probably not new. It showed up now because we changed all warnings to errors (to notice such problems). We decided to for now ignore this particular problem as we do not know how to fix it (re-computing the test data as part of the CI is not an option because some of the simulations require Mumax3, hence a GPU [not available in the CI], to cover a broader range of possible files that we should test for).

Any ideas where the problem could come from would be highly appreciated @fangohr, @swapneelap, @marijanbeg .

Extend `data.info`

Currently, it is not possible to see, if the runs have actually been completed. It would be useful to add an extra column that indicates the final status (success/finished or failure/interrupted) and for time drives (maybe also hysteresis drives) the number of steps that have actually been calculated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.