SJ001 / AI-Feynman

MIT License
607 stars 186 forks source link

pip install aifeynman fails on M1 #58

Open NAThompson opened 2 years ago

NAThompson commented 2 years ago

Virtualenv settings:

(feynman) tmp$ python3
Python 3.9.9 (main, Nov 21 2021, 03:16:13)
[Clang 13.0.0 (clang-1300.0.29.3)] on darwin
(feynman) tmp$ python3 -m pip install aifeynman
~/tmp/lib/python3.9/site-packages/numpy/distutils/checks/cpu_asimdfhm.c:13:35: error: implicit declaration of function 'vfmlal_low_u32' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        int ret  = (int)vget_lane_f32(vfmlal_low_u32(vlf, vlhp, vlhp), 0);
...
   Warning: Nonconforming tab character at (1) [-Wtabs]
    aifeynman/symbolic_regress1.f90:45:2:

       45 |         real*8 f, newloss, minloss, maxloss, rmsloss, xy(nvarmax+1,nmax), epsilon, DL, DL2, DL3
          |         1
    ld: library not found for -lm
    collect2: error: ld returned 1 exit status

This first error can be fixed by just bumping the minimal numpy version, as the most recent numpy is good on M1.

The -lm flag seems to be more difficult, as it appears to be inherited from gfortran?

dbl001 commented 2 years ago

Does this solve the gfortran -lm issue?

export LIBRARY_PATH="$LIBRARY_PATH:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"

Jiacheng-Liu commented 1 year ago

@dbl001 seems not, this is the newest error I got running on m1 mac after running your suggested command:

  customize Gnu95FCompiler
  Could not locate executable gfortran
  Could not locate executable f95
  customize NAGFCompiler
  customize AbsoftFCompiler
  Could not locate executable f90
  Could not locate executable f77
  customize IBMFCompiler
  Could not locate executable xlf90
  Could not locate executable xlf
  customize IntelFCompiler
  Could not locate executable ifort
  Could not locate executable ifc
  customize GnuFCompiler
  Could not locate executable g77
  customize G95FCompiler
  Could not locate executable g95
  customize PGroupFCompiler
  Could not locate executable pgfortran
  don't know how to compile Fortran code on platform 'posix'
  warning: build_ext: f77_compiler=None is not available.
  building 'aifeynman._symbolic_regress1' extension
  error: extension 'aifeynman._symbolic_regress1' has Fortran sources but no Fortran compiler found
dbl001 commented 1 year ago

Did you install gfortran? E.g.

 % which gfortran
/Users/davidlaxer/anaconda3/bin/gfortran

% gfortran --version
gfortran: warning: could not understand version 13.01.00
GNU Fortran (GCC) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

The AI-Feynman installation appears to be using:

"/Users/davidlaxer/anaconda3/bin/x86_64-apple-darwin13.4.0-gfortran -Wall -g -arch x86_64 -Wall -g -undefined dynamic_lookup -bundle build/temp.macosx-10.9-x86_64-3.8/build/src.macosx-10.9-x86_64-3.8/aifeynman/_symbolic_regress1module.o build/temp.macosx-10.9-x86_64-3.8/build/src.macosx-10.9-x86_64-3.8/build/src.macosx-10.9-x86_64-3.8/aifeynman/fortranobject.o build/temp.macosx-10.9-x86_64-3.8/aifeynman/symbolic_regress1.o build/temp.macosx-10.9-x86_64-3.8/build/src.macosx-10.9-x86_64-3.8/aifeynman/_symbolic_regress1-f2pywrappers.o -L/Users/davidlaxer/anaconda3/bin/../lib/gcc/x86_64-apple-darwin11.4.2/4.8.5 -L/Users/davidlaxer/anaconda3/bin/../lib/gcc/x86_64-apple-darwin11.4.2/4.8.5/../../.. -L/Users/davidlaxer/anaconda3/bin/../lib/gcc/x86_64-apple-darwin11.4.2/4.8.5/../../.. -lgfortran -o build/lib.macosx-10.9-x86_64-3.8/aifeynman/_symbolic_regress1.cpython-38-darwin.so
Jiacheng-Liu commented 1 year ago

I see, thanks. that fixed the installation! However, I'm running the following error just by importing aifeynman, any idea how to fix this?

OMP: Error #15: Initializing libomp.dylib, but found libomp.dylib already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://openmp.llvm.org/
zsh: abort      python test.py
dbl001 commented 1 year ago

Try adding this to the beginning of your script:

import os
os.environ['KMP_DUPLICATE_LIB_OK']='True'

from aifeynman import run_aifeynman

run_aifeynman("/Users/davidlaxer/AI-Feynman/example_data/", "GoedelTableFourParameters.txt", 30, "14ops.txt", polyfit_deg=3, NN_epochs=400)
Jiacheng-Liu commented 1 year ago

This worked, thanks mate!