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

Issue with oommf - compile from source on M1/M2 #270

Open
MiroCaf opened this issue Dec 27, 2023 · 43 comments
Open

Issue with oommf - compile from source on M1/M2 #270

MiroCaf opened this issue Dec 27, 2023 · 43 comments

Comments

@MiroCaf
Copy link

MiroCaf commented Dec 27, 2023

Hello,

I am working on a MacOs. I have installed anaconda and python 3.10. I followed the instructions which suggested to install Ubermag using conda, but I get the error below.

Schermata 2023-12-27 alle 09 00 14

I thus used pip and everything seemed ok in the terminal. However when running the first simulation, I get the error below

Schermata 2023-12-27 alle 09 16 16

Any help would be greatly appreciated.

Thanks,

Miro

@fangohr
Copy link
Member

fangohr commented Jan 6, 2024

I am guessing you may have a M1/M2/M3 processor? If so, then the problem is that there is no conda package for OOMMF for the M1/M2/M3 architecture at the moment.

Try to follow the instructions in the MacOS tab at https://ubermag.github.io/installation.html#advanced-installation . I think this should work.

@MiroCaf
Copy link
Author

MiroCaf commented Jan 6, 2024

Hello, and thanks for your reply and for your help. As I mentioned above, I firstly tried conda and then the advanced installation using pip, but still I get the error "cannot find OOMMF". Any help would be greatly appreciated

@fangohr
Copy link
Member

fangohr commented Jan 6, 2024

Did you compile OOMMF?

@MiroCaf
Copy link
Author

MiroCaf commented Jan 6, 2024

yep, I typed cd oommf and then make build

@MiroCaf
Copy link
Author

MiroCaf commented Jan 6, 2024

Schermata 2024-01-06 alle 17 14 14

@MiroCaf
Copy link
Author

MiroCaf commented Jan 6, 2024

I have just compiled once again as per attachment above. It seems to be compiling okay but it keeps on returning the same error:

Schermata 2024-01-06 alle 17 17 07

@fangohr
Copy link
Member

fangohr commented Jan 6, 2024

The compilation of OOMMF looks fine.

By the way, you can copy and paste code into these issues (rather than posting screenshots). That's generally better as there is less data to move, and we can search the charactors you post. This is explained here for example.

@MiroCaf
Copy link
Author

MiroCaf commented Jan 6, 2024

Ok, sorry for that- I will copy and paste code from now onwards.

Any suggestions by the way on what to do with the error? Thanks again

@fangohr
Copy link
Member

fangohr commented Jan 6, 2024

Did you do anything to export the OOMMFTCL variable? (Step 6 in the instructions).

[This is a good occasion to check the instructions work for you and are correct.]

Could you (in a Terminal App window) run the command

python3 -c "import oommfc; oommfc.runner.runner.status"

from https://ubermag.github.io/installation.html#check-the-installation and post the command and output, please.

@fangohr
Copy link
Member

fangohr commented Jan 6, 2024

Also a

echo $OOMMFTCL

would be interesting to run in the same shell (i.e. in the Terminal App window).

@MiroCaf
Copy link
Author

MiroCaf commented Jan 6, 2024

mirocafolla@192 oommf % export OOMMFTCL="/Users/mirocafolla/oommf/oommf.tcl"

this is what I did after make build

@MiroCaf
Copy link
Author

MiroCaf commented Jan 6, 2024

(base) mirocafolla@192 oommf % python3 -c "import oommfc; oommfc.runner.runner.status"
OOMMFTCL is set, but OOMMF could not be run.
stdout:
b''
stderr:
b'couldn't read file "/Users/mirocafolla/anaconda3/lib/python3.10/site-packages/oommf/oommf.tcl": no such file or directory\n'
Docker was not found.
Traceback (most recent call last):
File "", line 1, in
File "/Users/mirocafolla/anaconda3/lib/python3.10/site-packages/oommfc/oommf/oommf.py", line 435, in runner
self.autoselect_runner()
File "/Users/mirocafolla/anaconda3/lib/python3.10/site-packages/oommfc/oommf/oommf.py", line 572, in autoselect_runner
raise EnvironmentError("Cannot find OOMMF.")
OSError: Cannot find OOMMF.

@MiroCaf
Copy link
Author

MiroCaf commented Jan 6, 2024

(base) mirocafolla@192 oommf % echo $OOMMFTCL
/Users/mirocafolla/anaconda3/lib/python3.10/site-packages/oommf/oommf.tcl

@MiroCaf
Copy link
Author

MiroCaf commented Jan 6, 2024

I think that it says
/Users/mirocafolla/anaconda3/lib/python3.10/site-packages/oommf/oommf.tcl

because I have tried to export OOMMF into different directories. Firstly into /Users/mirocafolla/oommf, and then into /Users/mirocafolla/anaconda3/lib/python3.10/site-packages/oommf/oommf.tcl as the former was not working. Neither works though

@fangohr
Copy link
Member

fangohr commented Jan 6, 2024

Please use

```console
fangohr@MBAM2 docker % echo "Hello world"
Hello world
```

to make your code snippets look nicer. You can use the "Preview" tab to check.

This should look like

fangohr@MBAM2 docker % echo "Hello world"
Hello world

@MiroCaf
Copy link
Author

MiroCaf commented Jan 6, 2024

(base) mirocafolla@192 oommf % echo "Hello world"
Hello world

@fangohr
Copy link
Member

fangohr commented Jan 6, 2024

The OOMMFTCL variable needs to point to the oommf.tcl file from the place where you have compiled OOMMF. Based on your screenshots, I guess this would be

export OOMMFTCL="/Users/mirocafolla/oommf/oommf.tcl"

Once you have done that, please run

echo $OOMMFTCL

so we can double check this has worked. Then please run

ls -l $OOMMFTCL

and finally

python3 -c "import oommfc; oommfc.runner.runner.status"

and copy and paste the commands and outputs here (all together in one code block is fine).

@MiroCaf
Copy link
Author

MiroCaf commented Jan 6, 2024

(base) mirocafolla@192 oommf % export OOMMFTCL="/Users/mirocafolla/oommf/oommf.tcl"
(base) mirocafolla@192 oommf % echo $OOMMFTCL
/Users/mirocafolla/oommf/oommf.tcl
(base) mirocafolla@192 oommf % ls -l $OOMMFTCL
ls: /Users/mirocafolla/oommf/oommf.tcl: No such file or directory
(base) mirocafolla@192 oommf % python3 -c "import oommfc; oommfc.runner.runner.status"
OOMMFTCL is set, but OOMMF could not be run.
stdout:
b''
stderr:
b'couldn't read file "/Users/mirocafolla/oommf/oommf.tcl": no such file or directory\n'
Docker was not found.
Traceback (most recent call last):
File "", line 1, in
File "/Users/mirocafolla/anaconda3/lib/python3.10/site-packages/oommfc/oommf/oommf.py", line 435, in runner
self.autoselect_runner()
File "/Users/mirocafolla/anaconda3/lib/python3.10/site-packages/oommfc/oommf/oommf.py", line 572, in autoselect_runner
raise EnvironmentError("Cannot find OOMMF.")
OSError: Cannot find OOMMF.

@fangohr
Copy link
Member

fangohr commented Jan 6, 2024

base) mirocafolla@192 oommf % ls -l $OOMMFTCL
ls: /Users/mirocafolla/oommf/oommf.tcl: No such file or directory

this means that the file (oommf.tcl) is not in that location. You need to find it, and point OOMMFTCL to it.

Perhaps it is /Users/mirocafolla/oommf/oommf/oommf.tcl instead?

@fangohr
Copy link
Member

fangohr commented Jan 7, 2024

(base) mirocafolla@192 oommf % echo "Hello world" Hello world

Thanks for running that. In particular, I was hoping for this formatting of your output:

(base) mirocafolla@192 oommf % echo "Hello world"
Hello world

@MiroCaf
Copy link
Author

MiroCaf commented Jan 7, 2024

Good morning, and thank you very much for all your help with this. I tried this and I think that we are getting there! :)

(base) mirocafolla@192 oommf % export OOMMFTCL="/Users/mirocafolla/oommf/oommf/oommf.tcl"
(base) mirocafolla@192 oommf % echo $oommftcl

(base) mirocafolla@192 oommf % ls -l $OOMMFTCL
-rwxr-xr-x 1 mirocafolla staff 14625 26 Dic 18:43 /Users/mirocafolla/oommf/oommf/oommf.tcl
(base) mirocafolla@192 oommf % python3 -c "import oommfc; oommfc.runner.runner.status"
Running OOMMF (TclOOMMFRunner)[2024/01/07 10:03]... (2.4 s)
OOMMF found and running.
(base) mirocafolla@192 oommf %

@MiroCaf
Copy link
Author

MiroCaf commented Jan 7, 2024

However, when I run it in the console it keeps on returning the same error

runfile('/Users/mirocafolla/.spyder-py3/temp.py', wdir='/Users/mirocafolla/.spyder-py3')
Docker was not found.
Traceback (most recent call last):

File ~/anaconda3/lib/python3.10/site-packages/spyder_kernels/py3compat.py:356 in compat_exec
exec(code, globals, locals)

File ~/.spyder-py3/temp.py:22
oommfc.runner.autoselect_runner()

File ~/anaconda3/lib/python3.10/site-packages/oommfc/oommf/oommf.py:572 in autoselect_runner
raise EnvironmentError("Cannot find OOMMF.")

OSError: Cannot find OOMMF.

I tried close and relaunch, but still the same error :(

@MiroCaf
Copy link
Author

MiroCaf commented Jan 7, 2024

My bad. I think that it is now working. I slightly modified my Python code adding some extra lines with respect to the demo and it is seems okay

import numpy
import ubermag
import oommfc
import pandas as pd

oommfc.runner
oommfc.runner.envvar
import micromagneticmodel as mm # mm is just a shorter name we want to use later
import discretisedfield as df # df is just a shorter name we want to use later
oommfc.runner.oommf_exe
oommfc.runner.docker_exe

oommfc.runner.runner = oommfc.oommf.TclOOMMFRunner("/Users/mirocafolla/oommf/oommf/oommf.tcl")
print (oommfc.runner)

import matplotlib.pyplot as plt
oommfc.runner.runner.status
pd.options.display.max_rows = 5
pd.options.display.float_format = '{:,.2e}'.format

system = mm.System(name='first_ubermag_simulation')

A = 1e-12 # exchange energy constant (J/m)
H = (5e6, 0, 0) # external magnetic field in the x-direction (A/m)
system.energy = mm.Exchange(A=A) + mm.Demag() + mm.Zeeman(H=H)

L = 50e-9 # cubic sample edge length (m)
region = df.Region(p1=(0, 0, 0), p2=(L, L, L))
mesh = df.Mesh(region=region, n=(10, 10, 10))

Ms = 8e6 # saturation magnetisation (A/m)
system.m = df.Field(mesh, nvdim=3, value=(0, 1, 0), norm=Ms)

print (system.energy)
system.energy
system.m.mesh.region.mpl()
system.m.mesh.mpl()
system.m.sel('z').mpl()

print(f'{ubermag.version=}, {oommfc.version=}')

md = oommfc.MinDriver()
md.drive(system)

@MiroCaf
Copy link
Author

MiroCaf commented Jan 7, 2024

and this is the output

runfile('/Users/mirocafolla/.spyder-py3/temp.py', wdir='/Users/mirocafolla/.spyder-py3')
Running OOMMF (TclOOMMFRunner)[2024/01/07 10:10]... (2.1 s)
OOMMF found and running.
OOMMF runner: TclOOMMFRunner(/Users/mirocafolla/oommf/oommf/oommf.tcl)
runner is cached: True
Running OOMMF (TclOOMMFRunner)[2024/01/07 10:10]... (1.1 s)
OOMMF found and running.
Exchange(A=1e-12) + Demag() + Zeeman(H=(5000000.0, 0, 0))
ubermag.version='2023.11', oommfc.version='0.64.1'
Running OOMMF (TclOOMMFRunner)[2024/01/07 10:10]... (1.1 s)

@MiroCaf
Copy link
Author

MiroCaf commented Jan 7, 2024

Once again, thank you so much for all your help. I will now get through the other demo examples, and will then simulate my own system. Hopefully, I will not be bothering you again! :)

@fangohr
Copy link
Member

fangohr commented Jan 7, 2024

(base) mirocafolla@192 oommf % ls -l $OOMMFTCL
 -rwxr-xr-x 1 mirocafolla staff 14625 26 Dic 18:43 /Users/mirocafolla/oommf/oommf/oommf.tcl 
(base) mirocafolla@192 oommf % python3 -c "import oommfc; oommfc.runner.runner.status" 
Running OOMMF (TclOOMMFRunner)[2024/01/07 10:03]... (2.4 s) 
OOMMF found and running. 
(base) mirocafolla@192 oommf %

just to confirm that this is the output we are hoping for. So the OOMMFTCL variable is correct then, and Ubermag can find and execute OOMMF at that location. At least if you call Python from that command line (where the OOMMFTCL environment variable is defined).

@fangohr
Copy link
Member

fangohr commented Jan 7, 2024

However, when I run it in the console it keeps on returning the same error

runfile('/Users/mirocafolla/.spyder-py3/temp.py', wdir='/Users/mirocafolla/.spyder-py3')

So here you are running inside Spyder. This Python instance presumably doesn't know about the OOMMFTCL variable; perhaps because you started Spyder in a different shell or before you defined the OOMMFTCL variable.

One thing you can try to to set the variable as before (export OOMMFTCL="/Users/mirocafolla/oommf/oommf/oommf.tcl") and then start spyder.

Does it work then?

@fangohr
Copy link
Member

fangohr commented Jan 7, 2024

Setting the path directly from Python (oommfc.runner.runner = oommfc.oommf.TclOOMMFRunner("/Users/mirocafolla/oommf/oommf/oommf.tcl") is okay: it should work reliably on this computer where you have OOMMF installed in that location. If you want to run the same script on a different machine, you would need to update that line.

@MiroCaf
Copy link
Author

MiroCaf commented Jan 7, 2024

Thanks!

@fangohr
Copy link
Member

fangohr commented Jan 7, 2024

This is a different problem. Please open a new issue.

@fangohr fangohr closed this as completed Jan 7, 2024
@fangohr fangohr changed the title Issue with oommf Issue with oommf - compile from source on M1/M2 Jan 7, 2024
@fangohr
Copy link
Member

fangohr commented Jan 7, 2024

However, when I run it in the console it keeps on returning the same error
runfile('/Users/mirocafolla/.spyder-py3/temp.py', wdir='/Users/mirocafolla/.spyder-py3')

So here you are running inside Spyder. This Python instance presumably doesn't know about the OOMMFTCL variable; perhaps because you started Spyder in a different shell or before you defined the OOMMFTCL variable.

One thing you can try to to set the variable as before (export OOMMFTCL="/Users/mirocafolla/oommf/oommf/oommf.tcl") and then start spyder.

Does it work then?

@MiroCaf - can you please try what I suggested above? (It might be useful info to fix your next problem.)

Also, in your home directory, you probably have a file call .profile. Try to list it with this command.

ls -l -a ~/.profile

If it exists, then open it in a text editor (you can use Spyder), and add a line at the end containing export OOMMFTCL="/Users/mirocafolla/oommf/oommf/oommf.tcl". Then open a new shell, and see if OOMMFTCL is defined, and if the Ubermag runner tests succeeds. This should work, and should be a better solution than always repeating the export OOMMFTCL="/Users/mirocafolla/oommf/oommf/oommf.tcl" at the shell, and also better than having this line oommfc.runner.runner = oommfc.oommf.TclOOMMFRunner("/Users/mirocafolla/oommf/oommf/oommf.tcl") in all your simulation files.

@fangohr fangohr reopened this Jan 7, 2024
@MiroCaf
Copy link
Author

MiroCaf commented Jan 7, 2024

Thanks again. Shall I open a new issue anyway with the other problem?

@MiroCaf
Copy link
Author

MiroCaf commented Jan 7, 2024

I tried to do what you were suggesting. Maybe I am doing something wrong but this is what I get

(base) mirocafolla@192 ~ % ls -l -a ~/.profile
ls: /Users/mirocafolla/.profile: No such file or directory
(base) mirocafolla@192 ~ % cd ..
(base) mirocafolla@192 /Users % pwd
/Users
(base) mirocafolla@192 /Users % ls -l -a ~/.profile
ls: /Users/mirocafolla/.profile: No such file or directory
(base) mirocafolla@192 /Users % cd ..
(base) mirocafolla@192 / % ls -l -a ~/.profile
ls: /Users/mirocafolla/.profile: No such file or directory
(base) mirocafolla@192 / %

@fangohr
Copy link
Member

fangohr commented Jan 7, 2024

That's interesting, thank you.

Could you run a ls -l -a ~/ and paste the output here? (Feel free to remove your own/confidential filenames - I am only interested in the ones starting with a .) Thanks.

@MiroCaf
Copy link
Author

MiroCaf commented Jan 7, 2024

ls: /Users/mirocafolla/.profile: No such file or directory
(base) mirocafolla@192 / % ls -l -a ~/
total 832
drwxr-xr-x+ 41 mirocafolla  staff    1312  6 Gen 21:15 .
drwxr-xr-x   5 root         admin     160  4 Apr  2020 ..
-rw-r--r--@  1 mirocafolla  staff   14340 31 Dic 10:53 .DS_Store
drwx------@  2 mirocafolla  staff      64  6 Gen 19:18 .Trash
drwxr-xr-x   4 mirocafolla  staff     128 26 Dic 20:21 .anaconda
-rw-------   1 mirocafolla  staff     539 27 Dic 08:56 .bash_history
-rw-r--r--   1 mirocafolla  staff     503  8 Apr  2023 .bash_profile
drwxr-xr-x   4 mirocafolla  staff     128  7 Gen 19:39 .conda
-rw-r--r--   1 mirocafolla  staff      49 29 Dic 15:26 .condarc
drwxr-xr-x   4 mirocafolla  staff     128 17 Apr  2023 .config
drwxr-xr-x   3 mirocafolla  staff      96 11 Apr  2023 .continuum
drwxr-xr-x   3 mirocafolla  staff      96 27 Dic 09:48 .ipynb_checkpoints
drwxr-xr-x   3 mirocafolla  staff      96 11 Apr  2023 .ipython
drwxr-xr-x   4 mirocafolla  staff     128 27 Dic 09:48 .jupyter
drwxr-xr-x   3 mirocafolla  staff      96 11 Apr  2023 .matplotlib
drwxr-xr-x   6 mirocafolla  staff     192 29 Dic 19:12 .pytest_cache
drwxr-xr-x  19 mirocafolla  staff     608  7 Gen 13:04 .spyder-py3
-rw-r--r--   1 mirocafolla  staff     323  8 Apr  2023 .tcshrc
drwxr-xr-x   3 mirocafolla  staff      96 30 Dic 09:25 .virtual_documents
drwx------   4 mirocafolla  staff     128 27 Set  2020 .vnc
-rw-r--r--   1 mirocafolla  staff     691  8 Apr  2023 .xonshrc
-rw-r--r--   1 mirocafolla  staff     243 23 Dic 19:14 .zprofile
-rw-------   1 mirocafolla  staff    8706  6 Gen 16:45 .zsh_history
-rw-r--r--   1 mirocafolla  staff     502  8 Apr  2023 .zshrc

@fangohr
Copy link
Member

fangohr commented Jan 8, 2024

Okay, thanks. I'd like to know if you are using bash or zsh. Please enter

echo $SHELL

and post the output.

@fangohr
Copy link
Member

fangohr commented Jan 8, 2024

Can you also edit your ~/.bash_profile (you can use Spyder), and add a line at the end containing export OOMMFTCL="/Users/mirocafolla/oommf/oommf/oommf.tcl". Then open a new shell, and see if OOMMFTCL is defined (i.e. echo $OOMMFTCL), and if the Ubermag runner tests succeed.

@MiroCaf
Copy link
Author

MiroCaf commented Jan 8, 2024

Good morning and thank you very much once again for all your help :)
I think I am using zsh
(base) mirocafolla@192 / % echo $SHELL
/bin/zsh
(base) mirocafolla@192 / %

@MiroCaf
Copy link
Author

MiroCaf commented Jan 8, 2024

(base) mirocafolla@192 / % ~/.bash_profile
zsh: permission denied: /Users/mirocafolla/.bash_profile
(base) mirocafolla@192 / % export OOMMFTCL="/Users/mirocafolla/.bash_profile/oommf/oommf/oommf.tcl"

@MiroCaf
Copy link
Author

MiroCaf commented Jan 8, 2024

(base) mirocafolla@192 / % python -c "import ubermag; ubermag.test()"

......
========================== 114 failed, 3799 passed, 2 skipped, 673 warnings in 322.82s (0:05:22) ===========================
couldn't read file "/Users/mirocafolla/.bash_profile/oommf/oommf/oommf.tcl": not a directory
Exception ignored in atexit callback: <function _global_cleanup at 0x7fdbb0612cb0>
Traceback (most recent call last):
File "/Users/mirocafolla/anaconda3/lib/python3.10/site-packages/oommfc/oommf/oommf.py", line 27, in _global_cleanup
instance._terminate()
File "/Users/mirocafolla/anaconda3/lib/python3.10/site-packages/oommfc/oommf/oommf.py", line 52, in _terminate
self._kill()
File "/Users/mirocafolla/anaconda3/lib/python3.10/site-packages/oommfc/oommf/oommf.py", line 231, in _kill
sp.run(command, env=self.env)
AttributeError: 'ExeOOMMFRunner' object has no attribute 'env'
(base) mirocafolla@192 / % python3 -c "import oommfc; oommfc.runner.runner.status"
OOMMFTCL is set, but OOMMF could not be run.
stdout:
b''
stderr:
b'couldn't read file "/Users/mirocafolla/.bash_profile/oommf/oommf/oommf.tcl": not a directory\n'
Docker was not found.
Traceback (most recent call last):
File "", line 1, in
File "/Users/mirocafolla/anaconda3/lib/python3.10/site-packages/oommfc/oommf/oommf.py", line 435, in runner
self.autoselect_runner()
File "/Users/mirocafolla/anaconda3/lib/python3.10/site-packages/oommfc/oommf/oommf.py", line 572, in autoselect_runner
raise EnvironmentError("Cannot find OOMMF.")
OSError: Cannot find OOMMF.

@MiroCaf
Copy link
Author

MiroCaf commented Jan 8, 2024

(base) mirocafolla@192 oommf % python3 -c "import oommfc; oommfc.runner.runner.status"
OOMMFTCL is set, but OOMMF could not be run.
stdout:
b''
stderr:
b'couldn't read file "/Users/mirocafolla/.bash_profile/oommf/oommf/oommf.tcl": not a directory\n'
Docker was not found.
Traceback (most recent call last):
File "", line 1, in
File "/Users/mirocafolla/anaconda3/lib/python3.10/site-packages/oommfc/oommf/oommf.py", line 435, in runner
self.autoselect_runner()
File "/Users/mirocafolla/anaconda3/lib/python3.10/site-packages/oommfc/oommf/oommf.py", line 572, in autoselect_runner
raise EnvironmentError("Cannot find OOMMF.")
OSError: Cannot find OOMMF.
(base) mirocafolla@192 oommf %

@MiroCaf
Copy link
Author

MiroCaf commented Jan 8, 2024

But now python seems to be running okay with just

import ubermag
import oommfc as oc
import discretisedfield as df

without the need for oommfc.runner.runner = oommfc.oommf.TclOOMMFRunner("/Users/mirocafolla/oommf/oommf/oommf.tcl"

@DebanjanPolley
Copy link

Recently, I found an easier way to install UBERMAG on a Mac (M1/M2 chip).

I had to build an osx-64 environment within my M2 Mac in the following way:

  1. Create an osx-64 virtual environment, ubermag_env
    CONDA_SUBDIR=osx-64 conda create -n ubermag_env python
  2. activate the virtual environment
    conda activate ubermag_env
  3. config osx-64
    conda config --env --set subdir osx-64

Then use $ conda install --channel conda-forge ubermag to install UBERMAG

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

No branches or pull requests

3 participants