exoplanet-dev / exoplanet

Fast & scalable MCMC for all your exoplanet needs!
https://docs.exoplanet.codes
MIT License
206 stars 52 forks source link

Cannot run on Mac OS 10.15 without suppressing compiler errors #129

Closed elnjensen closed 3 years ago

elnjensen commented 3 years ago

When running the transit-fitting demo on OS X, I cannot compute a LimbDarkLightCurve model without errors unless I explicitly pass a flag to theano to suppress compiler warnings.

The final error looks like this:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/ejensen1/opt/anaconda3/envs/exoplanetTest/lib/python3.8/site-packages/theano/gof/graph.py", line 522, in eval
    self._fn_cache[inputs] = theano.function(inputs, self)
  File "/Users/ejensen1/opt/anaconda3/envs/exoplanetTest/lib/python3.8/site-packages/theano/compile/function.py", line 306, in function
    fn = pfunc(params=inputs,
  File "/Users/ejensen1/opt/anaconda3/envs/exoplanetTest/lib/python3.8/site-packages/theano/compile/pfunc.py", line 483, in pfunc
    return orig_function(inputs, cloned_outputs, mode,
  File "/Users/ejensen1/opt/anaconda3/envs/exoplanetTest/lib/python3.8/site-packages/theano/compile/function_module.py", line 1841, in orig_function
    fn = m.create(defaults)
  File "/Users/ejensen1/opt/anaconda3/envs/exoplanetTest/lib/python3.8/site-packages/theano/compile/function_module.py", line 1714, in create
    _fn, _i, _o = self.linker.make_thunk(
  File "/Users/ejensen1/opt/anaconda3/envs/exoplanetTest/lib/python3.8/site-packages/theano/gof/link.py", line 697, in make_thunk
    return self.make_all(input_storage=input_storage,
  File "/Users/ejensen1/opt/anaconda3/envs/exoplanetTest/lib/python3.8/site-packages/theano/gof/vm.py", line 1087, in make_all
    thunks.append(node.op.make_thunk(node,
  File "/Users/ejensen1/opt/anaconda3/envs/exoplanetTest/lib/python3.8/site-packages/theano/gof/op.py", line 954, in make_thunk
    return self.make_c_thunk(node, storage_map, compute_map,
  File "/Users/ejensen1/opt/anaconda3/envs/exoplanetTest/lib/python3.8/site-packages/theano/gof/op.py", line 857, in make_c_thunk
    outputs = cl.make_thunk(input_storage=node_input_storage,
  File "/Users/ejensen1/opt/anaconda3/envs/exoplanetTest/lib/python3.8/site-packages/theano/gof/cc.py", line 1215, in make_thunk
    cthunk, module, in_storage, out_storage, error_storage = self.__compile__(
  File "/Users/ejensen1/opt/anaconda3/envs/exoplanetTest/lib/python3.8/site-packages/theano/gof/cc.py", line 1153, in __compile__
    thunk, module = self.cthunk_factory(error_storage,
  File "/Users/ejensen1/opt/anaconda3/envs/exoplanetTest/lib/python3.8/site-packages/theano/gof/cc.py", line 1623, in cthunk_factory
    module = get_module_cache().module_from_key(
  File "/Users/ejensen1/opt/anaconda3/envs/exoplanetTest/lib/python3.8/site-packages/theano/gof/cmodule.py", line 1189, in module_from_key
    module = lnk.compile_cmodule(location)
  File "/Users/ejensen1/opt/anaconda3/envs/exoplanetTest/lib/python3.8/site-packages/theano/gof/cc.py", line 1520, in compile_cmodule
    module = c_compiler.compile_str(
  File "/Users/ejensen1/opt/anaconda3/envs/exoplanetTest/lib/python3.8/site-packages/theano/gof/cmodule.py", line 2398, in compile_str
    raise Exception('Compilation failed (return status=%s): %s' %
Exception: ('The following error happened while compiling the node', Elemwise{Composite{AND(GE(Composite{(i0 + ((i1 + i2) % i3))}(i0, i1, i2, i3), i4), LE(Composite{(i0 + ((i1 + i2) % i3))}(i0, i1, i2, i3), i5))}}(TensorConstant{(1, 1) of -1.728}, TensorConstant{(1, 1) of 1.728}, TensorConstant{[[-0.1    ..1       ]]}, TensorConstant{(1, 1) of 3.456}, TensorConstant{(1, 1) of ..2375883906}, TensorConstant{(1, 1) of ..2375883906}), '\n', "Compilation failed (return status=1): /Users/ejensen1/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmp8ij3adb_/mod.cpp:979:27: error: non-constant-expression cannot be narrowed from type 'npy_intp' (aka 'long') to 'int' in initializer list [-Wc++11-narrowing].     int init_totals[2] = {V7_n0, V1_n1};.                           ^~~~~. /Users/ejensen1/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmp8ij3adb_/mod.cpp:979:27: note: insert an explicit cast to silence this issue.     int init_totals[2] = {V7_n0, V1_n1};.                           ^~~~~.                           static_cast<int>( ). /Users/ejensen1/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmp8ij3adb_/mod.cpp:979:34: error: non-constant-expression cannot be narrowed from type 'npy_intp' (aka 'long') to 'int' in initializer list [-Wc++11-narrowing].     int init_totals[2] = {V7_n0, V1_n1};.                                  ^~~~~. /Users/ejensen1/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmp8ij3adb_/mod.cpp:979:34: note: insert an explicit cast to silence this issue.     int init_totals[2] = {V7_n0, V1_n1};.                                  ^~~~~.                                  static_cast<int>( ). /Users/ejensen1/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmp8ij3adb_/mod.cpp:993:1: error: non-constant-expression cannot be narrowed from type 'ssize_t' (aka 'long') to 'int' in initializer list [-Wc++11-narrowing]. V7_stride0, 0, . ^~~~~~~~~~. /Users/ejensen1/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmp8ij3adb_/mod.cpp:993:1: note: insert an explicit cast to silence this issue. V7_stride0, 0, . ^~~~~~~~~~. static_cast<int>( ). /Users/ejensen1/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmp8ij3adb_/mod.cpp:997:1: error: non-constant-expression cannot be narrowed from type 'ssize_t' (aka 'long') to 'int' in initializer list [-Wc++11-narrowing]. V1_stride0, V1_stride1. ^~~~~~~~~~. /Users/ejensen1/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmp8ij3adb_/mod.cpp:997:1: note: insert an explicit cast to silence this issue. V1_stride0, V1_stride1. ^~~~~~~~~~. static_cast<int>( ). /Users/ejensen1/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmp8ij3adb_/mod.cpp:997:13: error: non-constant-expression cannot be narrowed from type 'ssize_t' (aka 'long') to 'int' in initializer list [-Wc++11-narrowing]. V1_stride0, V1_stride1.             ^~~~~~~~~~. /Users/ejensen1/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmp8ij3adb_/mod.cpp:997:13: note: insert an explicit cast to silence this issue. V1_stride0, V1_stride1.             ^~~~~~~~~~.             static_cast<int>( ). 5 errors generated.. ", '[Elemwise{Composite{AND(GE(Composite{(i0 + ((i1 + i2) % i3))}(i0, i1, i2, i3), i4), LE(Composite{(i0 + ((i1 + i2) % i3))}(i0, i1, i2, i3), i5))}}(TensorConstant{(1, 1) of -1.728}, TensorConstant{(1, 1) of 1.728}, TensorConstant{[[-0.1    ..1       ]]}, TensorConstant{(1, 1) of 3.456}, TensorConstant{(1, 1) of ..2375883906}, TensorConstant{(1, 1) of ..2375883906})]')

and is preceded by several instances of errors like this:

ERROR (theano.gof.opt): Optimization failure due to: constant_folding
ERROR (theano.gof.opt): node: Elemwise{Cast{float64}}(TensorConstant{(1, 1) of 0.0})
ERROR (theano.gof.opt): TRACEBACK:
ERROR (theano.gof.opt): Traceback (most recent call last):
  File "/Users/ejensen1/opt/anaconda3/envs/exoplanetTest/lib/python3.8/site-packages/theano/gof/opt.py", line 2034, in process_node
    replacements = lopt.transform(node)
  File "/Users/ejensen1/opt/anaconda3/envs/exoplanetTest/lib/python3.8/site-packages/theano/tensor/opt.py", line 6515, in constant_folding
    thunk = node.op.make_thunk(node, storage_map, compute_map,
  File "/Users/ejensen1/opt/anaconda3/envs/exoplanetTest/lib/python3.8/site-packages/theano/gof/op.py", line 954, in make_thunk
    return self.make_c_thunk(node, storage_map, compute_map,
  File "/Users/ejensen1/opt/anaconda3/envs/exoplanetTest/lib/python3.8/site-packages/theano/gof/op.py", line 857, in make_c_thunk
    outputs = cl.make_thunk(input_storage=node_input_storage,
  File "/Users/ejensen1/opt/anaconda3/envs/exoplanetTest/lib/python3.8/site-packages/theano/gof/cc.py", line 1215, in make_thunk
    cthunk, module, in_storage, out_storage, error_storage = self.__compile__(
  File "/Users/ejensen1/opt/anaconda3/envs/exoplanetTest/lib/python3.8/site-packages/theano/gof/cc.py", line 1153, in __compile__
    thunk, module = self.cthunk_factory(error_storage,
  File "/Users/ejensen1/opt/anaconda3/envs/exoplanetTest/lib/python3.8/site-packages/theano/gof/cc.py", line 1623, in cthunk_factory
    module = get_module_cache().module_from_key(
  File "/Users/ejensen1/opt/anaconda3/envs/exoplanetTest/lib/python3.8/site-packages/theano/gof/cmodule.py", line 1189, in module_from_key
    module = lnk.compile_cmodule(location)
  File "/Users/ejensen1/opt/anaconda3/envs/exoplanetTest/lib/python3.8/site-packages/theano/gof/cc.py", line 1520, in compile_cmodule
    module = c_compiler.compile_str(
  File "/Users/ejensen1/opt/anaconda3/envs/exoplanetTest/lib/python3.8/site-packages/theano/gof/cmodule.py", line 2398, in compile_str
    raise Exception('Compilation failed (return status=%s): %s' %
Exception: ("Compilation failed (return status=1): /Users/ejensen1/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmpze9t2tim/mod.cpp:396:27: error: non-constant-expression cannot be narrowed from type 'npy_intp' (aka 'long') to 'int' in initializer list [-Wc++11-narrowing].     int init_totals[2] = {V1_n0, V3_n1};.                           ^~~~~. /Users/ejensen1/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmpze9t2tim/mod.cpp:396:27: note: insert an explicit cast to silence this issue.     int init_totals[2] = {V1_n0, V3_n1};.                           ^~~~~.                           static_cast<int>( ). /Users/ejensen1/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmpze9t2tim/mod.cpp:396:34: error: non-constant-expression cannot be narrowed from type 'npy_intp' (aka 'long') to 'int' in initializer list [-Wc++11-narrowing].     int init_totals[2] = {V1_n0, V3_n1};.                                  ^~~~~. /Users/ejensen1/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmpze9t2tim/mod.cpp:396:34: note: insert an explicit cast to silence this issue.     int init_totals[2] = {V1_n0, V3_n1};.                                  ^~~~~.                                  static_cast<int>( ). /Users/ejensen1/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmpze9t2tim/mod.cpp:408:12: error: non-constant-expression cannot be narrowed from type 'ssize_t' (aka 'long') to 'int' in initializer list [-Wc++11-narrowing].         0, V3_stride1, .            ^~~~~~~~~~. /Users/ejensen1/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmpze9t2tim/mod.cpp:408:12: note: insert an explicit cast to silence this issue.         0, V3_stride1, .            ^~~~~~~~~~.            static_cast<int>( ). /Users/ejensen1/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmpze9t2tim/mod.cpp:409:1: error: non-constant-expression cannot be narrowed from type 'ssize_t' (aka 'long') to 'int' in initializer list [-Wc++11-narrowing]. V1_stride0, V1_stride1. ^~~~~~~~~~. /Users/ejensen1/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmpze9t2tim/mod.cpp:409:1: note: insert an explicit cast to silence this issue. V1_stride0, V1_stride1. ^~~~~~~~~~. static_cast<int>( ). /Users/ejensen1/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmpze9t2tim/mod.cpp:409:13: error: non-constant-expression cannot be narrowed from type 'ssize_t' (aka 'long') to 'int' in initializer list [-Wc++11-narrowing]. V1_stride0, V1_stride1.             ^~~~~~~~~~. /Users/ejensen1/.theano/compiledir_macOS-10.15.7-x86_64-i386-64bit-i386-3.8.5-64/tmpze9t2tim/mod.cpp:409:13: note: insert an explicit cast to silence this issue. V1_stride0, V1_stride1.             ^~~~~~~~~~.             static_cast<int>( ). 5 errors generated.. ", '[Elemwise{Cast{float64}}(TensorConstant{(1, 1) of 0.0})]')

You can find the C code in this temporary file: /var/folders/0p/j1z3pw0n5ljdzn121llsnw_r2t47wf/T/theano_compilation_error_9x5dqk34

This appears to be the same issue reported in this Stack Overflow post, and the workaround described there (theano.config.gcc.cxxflags = "-Wno-c++11-narrowing") results in successful compilation and allows the code to run.

To Reproduce Run the tutorial transit-fitting code under OS X (may depend on compiler used?)

Your setup:

Additional context It's possible that suppressing the errors in this way results in correct code and results, but I don't know enough about the internals to judge that.

dfm commented 3 years ago

Hi Eric, Thanks! The correct solution is to set that flag and the results will be fine.

It's not really an exoplanet issue - it'll happen with any Theano code on recent(ish) versions of macOS! But, if you run within a PyMC3 context, this won't happen because PyMC3 automatically adds this flag and there's an open issue to fix it directly within Theano.

For now, your best bet is to provide that flag yourself and perhaps we should add something to the exoplanet docs.

elnjensen commented 3 years ago

Thank you! I appreciate the quick response, and I'm enjoying exploring the code.