Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ubermag with mumax3 #208

Closed
Siyuanq opened this issue Jun 22, 2022 · 21 comments
Closed

ubermag with mumax3 #208

Siyuanq opened this issue Jun 22, 2022 · 21 comments
Labels
question General question

Comments

@Siyuanq
Copy link

Siyuanq commented Jun 22, 2022

The conda install method will install ubermag and oommf together. Is there any way to install ubermag with mumax?

@samjrholt
Copy link
Member

Hi @Siyuanq, unfortunately mumax3 does not currently have a package that you can install via python. We recommend downloading it directly from the mumax3 website and adding it to your PATH.

@Siyuanq
Copy link
Author

Siyuanq commented Jun 30, 2022

What is the equivalent command for "export OOMMFTCL="/path/to/your/oommf.tcl"" in the case of mumax3?

@lang-m
Copy link
Member

lang-m commented Jul 4, 2022

Hi @Siyuanq, as @samjrholt mentioned already, you have to manually install Mumax3 and ensure it is in PATH. The syntax depends on the operating system, on Linux/MacOS you could add export PATH="/full/path/to/mumax3/directory:$PATH" to .bashrc. More detailed instructions will be provided on the website soon.

To then use Mumax3 from within ubermag please install ubermag version 0.64.0 which comes with mumax3c the interface required for Mumax3.

@lang-m lang-m added question General question documentation labels Jul 4, 2022
@code-whale
Copy link

@Siyuanq ,By reading the source code of API and mumax3c project, I summed up a feasible method for your reference, and asked @lang-m to check its correctness.

mumax3runner=mc.mumax3.ExeMumax3Runner(mumax3_exe='The folder path where you installed mumax3\\mumax3.exe')
td = mc.TimeDriver()
td.drive(system, runner=mumax3runner,t=1e-9, n=10,verbose=2)

This method can be used without adding Mumax3 to PATH (at least on my device)

@lang-m
Copy link
Member

lang-m commented Jul 5, 2022

Hi @Siyuanq as already suggested by @code-whale (thank you!) you can use Mumax3 installed in a custom directory by passing the full path to you Mumax3 executable to ExeMumax3Runner. Note, that there is also the option to globally specify a default runner (per notebook/Python session) as follows:

import mumax3c as mc
mc.runner.runner = mc.mumax3.ExeMumax3Runner(mumax3_exe='Full\\Path\\To\\Mumax3\\mumax3.exe')
# adjust path depending on your operating system
# the syntax for 'mc.runner.runner' might change in the future
...
td = mc.TimeDriver()
td.drive(system, t=1e-9, n=10)  # internally uses mc.runner.runner to find the default runner

@SeregaKR
Copy link

SeregaKR commented Jul 8, 2022

Hi.
I'm trying to check ubermag. I'm using Ubuntu 20.04 with ubermag 0.64, mumax 3.10. The mumax path is added to the path variable so mumax3 command is working from the terminal.

But when I try running this example https://github.com/ubermag/workshop/blob/2022-06-29/tutorials/01_vortex.ipynb (changing oomfc to mumax3c and oc with mc) I receive an error "mumax3 not found".

The docs and API don't say that I need to change anything else. I see the above responses in this issue to use mc.runner.runner but I have mumax3 added to the path. Should this not be sufficient?

UPD. I managed to run the example with added "mc.runner.runner", but it's still not clear why PATH is not sufficient

@lang-m
Copy link
Member

lang-m commented Jul 8, 2022

Hi @SeregaKR, normally Ubermag should find mumax3 on the path. Could you please enable logging like explained here: file:///home/mlang/repos/ubermag-devtools/repos/ubermag.github.io/build/html/documentation/notebooks/ubermagutil/logging.html and post the output. Maybe there is some bug in our detection of the mumax3 installation.

@SeregaKR
Copy link

SeregaKR commented Jul 8, 2022

Hopefully this is what you need. @lang-m
Thried mc.runner.autoselect_runner()

2022-07-08:15:26:45,728  mumax3c:DEBUG  [/home/serg/ubermag_env/lib/python3.9/site-packages/mumax3c/mumax3/mumax3.py:autoselect_runner:179] Starting autoselect_runner: cache_runner=True, mumax3_exe=mumax3, optirun_exe=optirun, 
2022-07-08:15:26:45,730  mumax3c:DEBUG  [/home/serg/ubermag_env/lib/python3.9/site-packages/mumax3c/mumax3/mumax3.py:autoselect_runner:190] Step 1: Checking for optirun.
2022-07-08:15:26:45,731  mumax3c:DEBUG  [/home/serg/ubermag_env/lib/python3.9/site-packages/mumax3c/mumax3/mumax3.py:autoselect_runner:192] Output from 'which optirun_exe=None
2022-07-08:15:26:45,733  mumax3c:DEBUG  [/home/serg/ubermag_env/lib/python3.9/site-packages/mumax3c/mumax3/mumax3.py:autoselect_runner:199] Step 2: Checking for mumax3
--- Logging error ---
Traceback (most recent call last):
  File "/home/serg/anaconda3/lib/python3.9/logging/__init__.py", line 1083, in emit
    msg = self.format(record)
  File "/home/serg/anaconda3/lib/python3.9/logging/__init__.py", line 927, in format
    return fmt.format(record)
  File "/home/serg/anaconda3/lib/python3.9/logging/__init__.py", line 663, in format
    record.message = record.getMessage()
  File "/home/serg/anaconda3/lib/python3.9/logging/__init__.py", line 367, in getMessage
    msg = msg % self.args
TypeError: format requires a mapping
Call stack:
  File "/home/serg/anaconda3/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/serg/anaconda3/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/serg/ubermag_env/lib/python3.9/site-packages/ipykernel_launcher.py", line 17, in <module>
    app.launch_new_instance()
  File "/home/serg/ubermag_env/lib/python3.9/site-packages/traitlets/config/application.py", line 976, in launch_instance
    app.start()
  File "/home/serg/ubermag_env/lib/python3.9/site-packages/ipykernel/kernelapp.py", line 712, in start
    self.io_loop.start()
  File "/home/serg/ubermag_env/lib/python3.9/site-packages/tornado/platform/asyncio.py", line 215, in start
    self.asyncio_loop.run_forever()
  File "/home/serg/anaconda3/lib/python3.9/asyncio/base_events.py", line 601, in run_forever
    self._run_once()
  File "/home/serg/anaconda3/lib/python3.9/asyncio/base_events.py", line 1905, in _run_once
    handle._run()
  File "/home/serg/anaconda3/lib/python3.9/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/serg/ubermag_env/lib/python3.9/site-packages/ipykernel/kernelbase.py", line 510, in dispatch_queue
    await self.process_one()
  File "/home/serg/ubermag_env/lib/python3.9/site-packages/ipykernel/kernelbase.py", line 499, in process_one
    await dispatch(*args)
  File "/home/serg/ubermag_env/lib/python3.9/site-packages/ipykernel/kernelbase.py", line 406, in dispatch_shell
    await result
  File "/home/serg/ubermag_env/lib/python3.9/site-packages/ipykernel/kernelbase.py", line 730, in execute_request
    reply_content = await reply_content
  File "/home/serg/ubermag_env/lib/python3.9/site-packages/ipykernel/ipkernel.py", line 383, in do_execute
    res = shell.run_cell(
  File "/home/serg/ubermag_env/lib/python3.9/site-packages/ipykernel/zmqshell.py", line 528, in run_cell
    return super().run_cell(*args, **kwargs)
  File "/home/serg/ubermag_env/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 2881, in run_cell
    result = self._run_cell(
  File "/home/serg/ubermag_env/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 2936, in _run_cell
    return runner(coro)
  File "/home/serg/ubermag_env/lib/python3.9/site-packages/IPython/core/async_helpers.py", line 129, in _pseudo_sync_runner
    coro.send(None)
  File "/home/serg/ubermag_env/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3135, in run_cell_async
    has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
  File "/home/serg/ubermag_env/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3338, in run_ast_nodes
    if await self.run_code(code, result, async_=asy):
  File "/home/serg/ubermag_env/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3398, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "/tmp/ipykernel_185846/2021039201.py", line 1, in <cell line: 1>
    mc.runner.autoselect_runner()
  File "/home/serg/ubermag_env/lib/python3.9/site-packages/mumax3c/mumax3/mumax3.py", line 201, in autoselect_runner
    log.debug(
Message: "Output from 'which mumax3_exe=%(mumax3_exe)s"
Arguments: ({None, 'mumax3_exe'},)

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
Input In [31], in <cell line: 1>()
----> 1 mc.runner.autoselect_runner()

File ~/ubermag_env/lib/python3.9/site-packages/mumax3c/mumax3/mumax3.py:213, in Runner.autoselect_runner(self)
    207 else:
    208     msg = (
    209         "Mumax3 cannot be found. Mumax3 does not come automatically with"
    210         " Ubermag. Make sure it is properly installed and can be found on the"
    211         " command line."
    212     )
--> 213     raise EnvironmentError(msg)

OSError: Mumax3 cannot be found. Mumax3 does not come automatically with Ubermag. Make sure it is properly installed and can be found on the command line.

If you need some additional logs, please write. The PATH variable screenshot is attached. When I use:
mc.runner.runner = mc.mumax3.ExeMumax3Runner(mumax3_exe='/home/konstantin/mumax3.10_linux_cuda11.0/mumax3')
everything works

Screenshot from 2022-07-08 15-34-20

@samjrholt
Copy link
Member

Hi @SeregaKR , thank you for posting the log messages. Could you please let us know what
import shutil; shutil.which('mumax3') returns?

As a temporary solution you could try

mc.runner.runner = mc.mumax3.ExeMumax3Runner(mumax3_exe='Full/Path/To/Mumax3/mumax3')

td = mc.TimeDriver()
td.drive(system, t=1e-9, n=10)  # internally uses mc.runner.runner to find the default runner

@SeregaKR
Copy link

SeregaKR commented Jul 8, 2022

@samjrholt
import shutil; shutil.which('mumax3')
returns nothing.

Already tried a temporary solution you offered - it works fine. I just wanted to understand why mumax3 installation is not detected automatically

@lang-m
Copy link
Member

lang-m commented Jul 11, 2022

@SeregaKR Thanks for the log messages and your other tests. Your case is really strange. It would be great if we could find out what is going on there. Could you please check/report a few more things:

  1. Does you mumax3 executable maybe have a special name? Could you please show the output of ls -l /home/konstantin/mumax3.10_linux_cuda11.0?
  2. What does which mumax3 on the command line return?
  3. What is the output when you run mumax3 (without input script on the command line)?
  4. Just as a safety check: What machine/GPU setup do you have? Desktop/laptop/HPC, integrated+dedicated GPU/dedicated GPU only, ...
  5. Could you please run the following in the same ipython console (to make sure that the environment does not change) and report all the ...:
    In [1]: !echo $PATH
    ...
    In [2]: !which mumax3
    ...
    In [3]: import os; os.environ['PATH']
    ...
    In [4]: import shutil; shutil.which('mumax3')  # should you have a different name please replace mumax3
    ...  # I assume this will be 'None'
    In [5]: import ubermagutil as uu; uu.setup_logging('DEBUG')
    In [6]: import mumax3c; mumax3c.runner.runner
    ...  # This will presumably be the same error message as before. Can you conform this?
    

@SeregaKR
Copy link

@lang-m, the responses are attached.

  1. mumax3 doesn't have any special name - the screenshot is attached.
    Screenshot from 2022-07-11 10-20-58
  2. which mumax3 in the command line provides the correct output.
    Screenshot from 2022-07-11 10-22-12
  3. mumax3 output in command line - see below.
    Screenshot from 2022-07-11 10-21-14
  4. We have a desktop PC (Intel® Core™ i7-7800X CPU @ 3.50GHz × 12) with Ubuntu 20.04. It has 2 video cards - NVIDIA 1080 Ti and NVIDIA 980 Ti. If you need other parameters, please write.
  5. The output from the Jupiter notebook is below. It's also accessible here - https://github.com/SeregaKR/random/blob/cc8cc9cb0eaa425bc483a35355d1d4e4869dd5a8/test_mumax.ipynb
!echo $PATH
/sbin:/bin:/usr/bin:/usr/local/bin:/snap/bin
!which mumax3
(no output)
import os; os.environ['PATH']
'/sbin:/bin:/usr/bin:/usr/local/bin:/snap/bin'
import shutil; shutil.which('mumax3')  # should you have a different name please replace mumax3
(no output)
import ubermagutil as uu; uu.setup_logging('DEBUG')
import mumax3c; mumax3c.runner.runner
(same error)

It seems that python doesn't import full PATH. Just for reference - I add mumax3 in PATH by .bashrc file in the Home folder like this:

export PATH="/home/konstantin/mumax3.10_linux_cuda11.0:$PATH"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64"
export CUDA_HOME=/usr/local/cuda

@lang-m
Copy link
Member

lang-m commented Jul 11, 2022

@SeregaKR Apparently your Jupyter notebook is started from a different environment (without conda activated (?)) that does not have the path to mumax3 in the PATH variable.

How do you normally start your jupyter notebook? Do you know if your .bashrc is used/read in that process?

Could you please try the following in a shell:

conda activate <your ubermag environment>
echo $PATH
...
python -c "import os; print(os.environ['PATH'])"
...
jupyter notebook  # please run the same "import shutil; shutil.which('mumax3')" in that notebook.

@SeregaKR
Copy link

@lang-m, ok - I tried this and now it looks like it's working. Which is very strange.

I used Pyzo as an IDE usually and there were no problems before. I run Jupiter from the .desktop shortcut (attached) - which still should work. I'll try to troubleshoot it and write back. Thank you for the assistance

@lang-m
Copy link
Member

lang-m commented Jul 11, 2022

@SeregaKR I can't see the .desktop attachment but I assume it starts from some environment that does not source your .bashrc. (No need to upload it)

@Siyuanq
Copy link
Author

Siyuanq commented Jul 15, 2022

I have a problem when import mumax3c. it says
module 'micromagneticamodel' has no attribute external runner

@Siyuanq
Copy link
Author

Siyuanq commented Jul 17, 2022

AttributeError                            Traceback (most recent call last)
Input In [1], in <cell line: 6>()
      4 import discretisedfield as df
      5 import micromagneticmodel as mm
----> 6 import mumax3c as mc
      7 mc.runner.runner = mc.mumax3.ExeMumax3Runner(mumax3_exe='/home/siyuanq3/mumax/mumax')

File ~/anaconda3/envs/mumax/lib/python3.8/site-packages/mumax3c/__init__.py:5, in <module>
      2 import pkg_resources
      3 import pytest
----> 5 import mumax3c.mumax3
      6 import mumax3c.scripts
      8 # from .compute import compute  # compute is not yet supported

File ~/anaconda3/envs/mumax/lib/python3.8/site-packages/mumax3c/mumax3/__init__.py:1, in <module>
----> 1 from .mumax3 import ExeMumax3Runner, Mumax3Runner, Runner, overhead

File ~/anaconda3/envs/mumax/lib/python3.8/site-packages/mumax3c/mumax3/mumax3.py:17, in <module>
     12 import mumax3c as mc
     14 log = logging.getLogger("mumax3c")
---> 17 class Mumax3Runner(mm.ExternalRunner):
     18     """Abstract class for running mumax3."""
     20     @property
     21     def package_name(self):

AttributeError: module 'micromagneticmodel' has no attribute 'ExternalRunner'

Above is the detailed error report

@lang-m
Copy link
Member

lang-m commented Jul 18, 2022

@Siyuanq Apparently, you have an older version of micromagneticmodel installed. Please always use the ubermag meta-package to install a consistent set of packages.

@SeregaKR
Copy link

Hello again.

I'm checking documentation about making hysteresis loops. It seems that the mumax3c module doesn't have this function from the box yet. It's possible to do this now in a roundabout way by setting Zeeman energy directly and doing minimize and relax functions afterward. But this is not described in examples and docs very well. The code below shows how I tried implementing it (I needed only the Bx component changed). The code is only for the virgin curve. But now, each step generates 2 files for each field (minimize and relax) which is a bit too much.

Bmin = -1e6
Bmax =  1e6
Bstep = 1e-2

md = mc.MinDriver()
rd = mc.RelaxDriver()

for B in range(0, Bmax+Bstep,Bstep):
    system.energy.zeeman.H = (B, 0, 0)
    rd.drive(system)
    md.drive(system)

and then the same can be done for the downward and upward curves. The corresponding code in mumax3 is also attached for reference.

Bmin := -1e6
Bmax :=  1e6
Bstep := 1e-2

for B:=0.0; B<=Bmax; B+=Bstep{
    B_ext = vector(B, 0, 0)
    minimize()
    relax()
    save(m_full)
    tablesave()
}

I hope that in the future, HysteresisDriver will be implemented from the box for mumax3. It took me an embarrassingly long time to find that you can set system.energy.zeeman.H

@samjrholt
Copy link
Member

@SeregaKR I have created a new issue in which we can discuss the HysteresisDriver #214

@lang-m
Copy link
Member

lang-m commented Jul 29, 2022

Instructions how to use different calculators are now available on the website: https://ubermag.github.io/installation.html#installing-a-calculator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question General question
Projects
None yet
Development

No branches or pull requests

5 participants