rodluger / starry

Tools for mapping stars and planets.
https://starry.readthedocs.io
MIT License
145 stars 33 forks source link

Starry crashes following Quickstart tutorial #307

Open catrionamurray opened 1 year ago

catrionamurray commented 1 year ago

Going through the Quickstart tutorial here (under Computing Light Curves) I get this error when I try to calculate the flux of a system:

time = np.linspace(-0.25, 3.25, 10000)
flux_system = system.flux(time)
Compiling `X`... Done.

You can find the C code in this temporary file: /var/folders/zp/t1q7mq8j2vs68_3mbjscd9qw0000gp/T/theano_compilation_error_qhog32ss
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
File <timed exec>:2

File ~/opt/anaconda3/envs/starry/lib/python3.8/site-packages/starry/kepler.py:1015, in System.flux(self, t, total, integrated)
   1005 def flux(self, t, total=True, integrated=False):
   1006     """Compute the system flux at times ``t``.
   1007 
   1008     Args:
   (...)
   1013             from each body.
   1014     """
-> 1015     X = self.design_matrix(t)
   1017     # Weight the ylms by amplitude
   1018     if self._reflected:
   1019         # If we're doing reflected light, scale the amplitude of
   1020         # each of the secondaries by the amplitude of the primary
   1021         # (the illumination source).

File ~/opt/anaconda3/envs/starry/lib/python3.8/site-packages/starry/kepler.py:914, in System.design_matrix(self, t)
    895 def design_matrix(self, t):
    896     """Compute the system flux design matrix at times ``t``.
    897 
    898     .. note::
   (...)
    912             the design matrix in units of :py:attr:`time_unit`.
    913     """
--> 914     return self.ops.X(
    915         self._math.reshape(self._math.to_array_or_tensor(t), [-1])
    916         * self._time_factor,
    917         self._primary._r,
    918         self._primary._m,
    919         self._primary._prot,
    920         self._primary._t0,
    921         self._primary._theta0,
    922         self._math.to_array_or_tensor(
    923             1.0
    924         ),  # we treat `amp` seprately in `flux()`
    925         getattr(
    926             self._primary._map,
    927             "_inc",
    928             self._math.to_array_or_tensor(0.5 * np.pi),
    929         ),
    930         getattr(
    931             self._primary._map, "_obl", self._math.to_array_or_tensor(0.0)
    932         ),
    933         getattr(
    934             self._primary._map, "fproj", self._math.to_array_or_tensor(0.0)
    935         ),
    936         self._primary._map._u,
    937         self._primary._map._f,
    938         self._math.to_array_or_tensor(
    939             [sec._r for sec in self._secondaries]
    940         ),
    941         self._math.to_array_or_tensor(
    942             [sec._m for sec in self._secondaries]
    943         ),
    944         self._math.to_array_or_tensor(
    945             [sec._prot for sec in self._secondaries]
    946         ),
    947         self._math.to_array_or_tensor(
    948             [sec._t0 for sec in self._secondaries]
    949         ),
    950         self._math.to_array_or_tensor(
    951             [sec._theta0 for sec in self._secondaries]
    952         ),
    953         self._get_periods(),
    954         self._math.to_array_or_tensor(
    955             [sec._ecc for sec in self._secondaries]
    956         ),
    957         self._math.to_array_or_tensor(
    958             [sec._w for sec in self._secondaries]
    959         ),
    960         self._math.to_array_or_tensor(
    961             [sec._Omega for sec in self._secondaries]
    962         ),
    963         self._math.to_array_or_tensor(
    964             [sec._inc for sec in self._secondaries]
    965         ),
    966         self._math.to_array_or_tensor(
    967             np.ones(
    968                 len(self._secondaries)
    969             )  # we treat `amp` seprately in `flux()`
    970         ),
    971         self._math.to_array_or_tensor(
    972             [
    973                 getattr(
    974                     sec._map,
    975                     "_inc",
    976                     self._math.to_array_or_tensor(0.5 * np.pi),
    977                 )
    978                 for sec in self._secondaries
    979             ]
    980         ),
    981         self._math.to_array_or_tensor(
    982             [
    983                 getattr(
    984                     sec._map, "_obl", self._math.to_array_or_tensor(0.0)
    985                 )
    986                 for sec in self._secondaries
    987             ]
    988         ),
    989         self._math.to_array_or_tensor(
    990             [sec._map._u for sec in self._secondaries]
    991         ),
    992         self._math.to_array_or_tensor(
    993             [sec._map._f for sec in self._secondaries]
    994         ),
    995         self._math.to_array_or_tensor(
    996             [
    997                 getattr(
    998                     sec._map, "_sigr", self._math.to_array_or_tensor(0.0)
    999                 )
   1000                 for sec in self._secondaries
   1001             ]
   1002         ),
   1003     )

File ~/opt/anaconda3/envs/starry/lib/python3.8/site-packages/starry/_core/utils.py:161, in autocompile.<locals>.wrapper(instance, *args)
    159     with CompileLogMessage(func.__name__):
    160         with change_flags(compute_test_value="off"):
--> 161             compiled_func = theano.function(
    162                 [*dummy_args],
    163                 func(instance, *dummy_args),
    164                 on_unused_input="ignore",
    165                 profile=config.profile,
    166                 mode=config.mode,
    167             )
    168         setattr(instance, cname, compiled_func)
    170 # Return the compiled version

File ~/opt/anaconda3/envs/starry/lib/python3.8/site-packages/theano/compile/function/__init__.py:337, in function(inputs, outputs, mode, updates, givens, no_default_updates, accept_inplace, name, rebuild_strict, allow_input_downcast, profile, on_unused_input)
    331     fn = orig_function(
    332         inputs, outputs, mode=mode, accept_inplace=accept_inplace, name=name
    333     )
    334 else:
    335     # note: pfunc will also call orig_function -- orig_function is
    336     #      a choke point that all compilation must pass through
--> 337     fn = pfunc(
    338         params=inputs,
    339         outputs=outputs,
    340         mode=mode,
    341         updates=updates,
    342         givens=givens,
    343         no_default_updates=no_default_updates,
    344         accept_inplace=accept_inplace,
    345         name=name,
    346         rebuild_strict=rebuild_strict,
    347         allow_input_downcast=allow_input_downcast,
    348         on_unused_input=on_unused_input,
    349         profile=profile,
    350         output_keys=output_keys,
    351     )
    352 return fn

File ~/opt/anaconda3/envs/starry/lib/python3.8/site-packages/theano/compile/function/pfunc.py:524, in pfunc(params, outputs, mode, updates, givens, no_default_updates, accept_inplace, name, rebuild_strict, allow_input_downcast, profile, on_unused_input, output_keys)
    519         si = In(
    520             variable=sv, value=sv.container, mutable=False, borrow=True, shared=True
    521         )
    522     inputs.append(si)
--> 524 return orig_function(
    525     inputs,
    526     cloned_outputs,
    527     mode,
    528     accept_inplace=accept_inplace,
    529     name=name,
    530     profile=profile,
    531     on_unused_input=on_unused_input,
    532     output_keys=output_keys,
    533 )

File ~/opt/anaconda3/envs/starry/lib/python3.8/site-packages/theano/compile/function/types.py:1981, in orig_function(inputs, outputs, mode, accept_inplace, name, profile, on_unused_input, output_keys)
   1970     m = Maker(
   1971         inputs,
   1972         outputs,
   (...)
   1978         name=name,
   1979     )
   1980     with config.change_flags(compute_test_value="off"):
-> 1981         fn = m.create(defaults)
   1982 finally:
   1983     t2 = time.time()

File ~/opt/anaconda3/envs/starry/lib/python3.8/site-packages/theano/compile/function/types.py:1836, in FunctionMaker.create(self, input_storage, trustme, storage_map)
   1833 start_import_time = theano.link.c.cmodule.import_time
   1835 with config.change_flags(traceback__limit=config.traceback__compile_limit):
-> 1836     _fn, _i, _o = self.linker.make_thunk(
   1837         input_storage=input_storage_lists, storage_map=storage_map
   1838     )
   1840 end_linker = time.time()
   1842 linker_time = end_linker - start_linker

File ~/opt/anaconda3/envs/starry/lib/python3.8/site-packages/theano/link/basic.py:266, in LocalLinker.make_thunk(self, input_storage, output_storage, storage_map)
    265 def make_thunk(self, input_storage=None, output_storage=None, storage_map=None):
--> 266     return self.make_all(
    267         input_storage=input_storage,
    268         output_storage=output_storage,
    269         storage_map=storage_map,
    270     )[:3]

File ~/opt/anaconda3/envs/starry/lib/python3.8/site-packages/theano/link/vm.py:1131, in VMLinker.make_all(self, profiler, input_storage, output_storage, storage_map)
   1126 thunk_start = time.time()
   1127 # no-recycling is done at each VM.__call__ So there is
   1128 # no need to cause duplicate c code by passing
   1129 # no_recycling here.
   1130 thunks.append(
-> 1131     node.op.make_thunk(node, storage_map, compute_map, [], impl=impl)
   1132 )
   1133 linker_make_thunk_time[node] = time.time() - thunk_start
   1134 if not hasattr(thunks[-1], "lazy"):
   1135     # We don't want all ops maker to think about lazy Ops.
   1136     # So if they didn't specify that its lazy or not, it isn't.
   1137     # If this member isn't present, it will crash later.

File ~/opt/anaconda3/envs/starry/lib/python3.8/site-packages/theano/graph/op.py:634, in COp.make_thunk(self, node, storage_map, compute_map, no_recycling, impl)
    630 self.prepare_node(
    631     node, storage_map=storage_map, compute_map=compute_map, impl="c"
    632 )
    633 try:
--> 634     return self.make_c_thunk(node, storage_map, compute_map, no_recycling)
    635 except (NotImplementedError, MethodNotDefined):
    636     # We requested the c code, so don't catch the error.
    637     if impl == "c":

File ~/opt/anaconda3/envs/starry/lib/python3.8/site-packages/theano/graph/op.py:600, in COp.make_c_thunk(self, node, storage_map, compute_map, no_recycling)
    598         print(f"Disabling C code for {self} due to unsupported float16")
    599         raise NotImplementedError("float16")
--> 600 outputs = cl.make_thunk(
    601     input_storage=node_input_storage, output_storage=node_output_storage
    602 )
    603 thunk, node_input_filters, node_output_filters = outputs
    605 def rval():

File ~/opt/anaconda3/envs/starry/lib/python3.8/site-packages/theano/link/c/basic.py:1203, in CLinker.make_thunk(self, input_storage, output_storage, storage_map)
   1175 """
   1176 Compiles this linker's fgraph and returns a function to perform the
   1177 computations, as well as lists of storage cells for both the inputs
   (...)
   1200   first_output = ostor[0].data
   1201 """
   1202 init_tasks, tasks = self.get_init_tasks()
-> 1203 cthunk, module, in_storage, out_storage, error_storage = self.__compile__(
   1204     input_storage, output_storage, storage_map
   1205 )
   1207 res = _CThunk(cthunk, init_tasks, tasks, error_storage, module)
   1208 res.nodes = self.node_order

File ~/opt/anaconda3/envs/starry/lib/python3.8/site-packages/theano/link/c/basic.py:1138, in CLinker.__compile__(self, input_storage, output_storage, storage_map)
   1136 input_storage = tuple(input_storage)
   1137 output_storage = tuple(output_storage)
-> 1138 thunk, module = self.cthunk_factory(
   1139     error_storage,
   1140     input_storage,
   1141     output_storage,
   1142     storage_map,
   1143 )
   1144 return (
   1145     thunk,
   1146     module,
   (...)
   1155     error_storage,
   1156 )

File ~/opt/anaconda3/envs/starry/lib/python3.8/site-packages/theano/link/c/basic.py:1634, in CLinker.cthunk_factory(self, error_storage, in_storage, out_storage, storage_map)
   1632     for node in self.node_order:
   1633         node.op.prepare_node(node, storage_map, None, "c")
-> 1634     module = get_module_cache().module_from_key(key=key, lnk=self)
   1636 vars = self.inputs + self.outputs + self.orphans
   1637 # List of indices that should be ignored when passing the arguments
   1638 # (basically, everything that the previous call to uniq eliminated)

File ~/opt/anaconda3/envs/starry/lib/python3.8/site-packages/theano/link/c/cmodule.py:1191, in ModuleCache.module_from_key(self, key, lnk)
   1189 try:
   1190     location = dlimport_workdir(self.dirname)
-> 1191     module = lnk.compile_cmodule(location)
   1192     name = module.__file__
   1193     assert name.startswith(location)

File ~/opt/anaconda3/envs/starry/lib/python3.8/site-packages/theano/link/c/basic.py:1543, in CLinker.compile_cmodule(self, location)
   1541 try:
   1542     _logger.debug(f"LOCATION {location}")
-> 1543     module = c_compiler.compile_str(
   1544         module_name=mod.code_hash,
   1545         src_code=src_code,
   1546         location=location,
   1547         include_dirs=self.header_dirs(),
   1548         lib_dirs=self.lib_dirs(),
   1549         libs=libs,
   1550         preargs=preargs,
   1551     )
   1552 except Exception as e:
   1553     e.args += (str(self.fgraph),)

File ~/opt/anaconda3/envs/starry/lib/python3.8/site-packages/theano/link/c/cmodule.py:2546, in GCC_compiler.compile_str(module_name, src_code, location, include_dirs, lib_dirs, libs, preargs, py_module, hide_symbols)
   2542     # We replace '\n' by '. ' in the error message because when Python
   2543     # prints the exception, having '\n' in the text makes it more
   2544     # difficult to read.
   2545     compile_stderr = compile_stderr.replace("\n", ". ")
-> 2546     raise Exception(
   2547         f"Compilation failed (return status={status}): {compile_stderr}"
   2548     )
   2549 elif config.cmodule__compilation_warning and compile_stderr:
   2550     # Print errors just below the command line.
   2551     print(compile_stderr)

Exception: ('The following error happened while compiling the node', GetClOp(<TensorType(float64, vector)>), '\n', 'Compilation failed (return status=1): In file included from /Users/camu5866/.theano/compiledir_macOS-12.4-arm64-arm-64bit-arm-3.8.15-64/tmpydx46758/mod.cpp:8:. /Users/camu5866/opt/anaconda3/envs/starry/lib/python3.8/site-packages/starry/_core/ops/lib/include/ellip.h:56:5: error: cannot use \'throw\' with exceptions disabled.     throw std::runtime_error("Elliptic integral `CEL` ".     ^. /Users/camu5866/opt/anaconda3/envs/starry/lib/python3.8/site-packages/starry/_core/ops/lib/include/ellip.h:103:3: error: cannot use \'throw\' with exceptions disabled.   throw std::runtime_error("Elliptic integral CEL did not converge.");.   ^. /Users/camu5866/opt/anaconda3/envs/starry/lib/python3.8/site-packages/starry/_core/ops/lib/include/ellip.h:132:5: error: cannot use \'throw\' with exceptions disabled.     throw std::invalid_argument(.     ^. /Users/camu5866/opt/anaconda3/envs/starry/lib/python3.8/site-packages/starry/_core/ops/lib/include/ellip.h:215:5: error: cannot use \'throw\' with exceptions disabled.     throw std::runtime_error("Elliptic integral CEL did not converge.");.     ^. In file included from /Users/camu5866/.theano/compiledir_macOS-12.4-arm64-arm-64bit-arm-3.8.15-64/tmpydx46758/mod.cpp:9:. /Users/camu5866/opt/anaconda3/envs/starry/lib/python3.8/site-packages/starry/_core/ops/lib/include/limbdark.h:368:5: error: cannot use \'throw\' with exceptions disabled.     throw std::runtime_error(.     ^. /Users/camu5866/opt/anaconda3/envs/starry/lib/python3.8/site-packages/starry/_core/ops/lib/include/limbdark.h:467:5: error: cannot use \'throw\' with exceptions disabled.     throw std::runtime_error(.     ^. 6 errors generated.. ', 'FunctionGraph(GetClOp(<TensorType(float64, vector)>))')

Context

I just created a conda environment and installed starry. I had an issue where tqdm wasn't installed with Starry so I also pip installed tqdm.

(starry) camu5866@CatMsMBP chromatic_fitting % pip list
Package                  Version
------------------------ -----------
aesara-theano-fallback   0.1.0
anyio                    3.6.2
appnope                  0.1.3
argon2-cffi              21.3.0
argon2-cffi-bindings     21.2.0
arrow                    1.2.3
arviz                    0.12.1
astropy                  5.2.1
asttokens                2.2.1
attrs                    22.2.0
backcall                 0.2.0
beautifulsoup4           4.11.1
bleach                   5.0.1
bokeh                    3.0.3
cachetools               5.2.1
certifi                  2022.12.7
cffi                     1.15.1
cftime                   1.6.2
comm                     0.1.2
contourpy                1.0.6
cycler                   0.11.0
debugpy                  1.6.5
decorator                5.1.1
defusedxml               0.7.1
deprecat                 2.1.1
dill                     0.3.6
entrypoints              0.4
executing                1.2.0
exoplanet                0.5.3
exoplanet-core           0.1.2
fastjsonschema           2.16.2
fastprogress             1.0.3
filelock                 3.9.0
fonttools                4.38.0
fqdn                     1.5.1
idna                     3.4
importlib-metadata       6.0.0
importlib-resources      5.10.2
ipykernel                6.20.1
ipython                  8.8.0
ipython-genutils         0.2.0
ipywidgets               8.0.4
isoduration              20.11.0
jedi                     0.18.2
Jinja2                   3.1.2
jsonpointer              2.3
jsonschema               4.17.3
jupyter                  1.0.0
jupyter_client           7.4.9
jupyter-console          6.4.4
jupyter_core             5.1.3
jupyter-events           0.6.3
jupyter_server           2.0.6
jupyter_server_terminals 0.4.4
jupyterlab-pygments      0.2.2
jupyterlab-widgets       3.0.5
kiwisolver               1.4.4
MarkupSafe               2.1.1
matplotlib               3.6.3
matplotlib-inline        0.1.6
mistune                  2.0.4
nbclassic                0.4.8
nbclient                 0.7.2
nbconvert                7.2.7
nbformat                 5.7.3
nest-asyncio             1.5.6
netCDF4                  1.6.2
notebook                 6.5.2
notebook_shim            0.2.2
numpy                    1.21.6
packaging                23.0
pandas                   1.5.2
pandocfilters            1.5.0
parso                    0.8.3
patsy                    0.5.3
pexpect                  4.8.0
pickleshare              0.7.5
Pillow                   9.4.0
pip                      22.3.1
pkgutil_resolve_name     1.3.10
platformdirs             2.6.2
prometheus-client        0.15.0
prompt-toolkit           3.0.36
psutil                   5.9.4
ptyprocess               0.7.0
pure-eval                0.2.2
pycparser                2.21
pyerfa                   2.0.0.1
Pygments                 2.14.0
pymc3                    3.11.5
pymc3-ext                0.1.1
pyparsing                3.0.9
pyrsistent               0.19.3
python-dateutil          2.8.2
python-json-logger       2.0.4
pytz                     2022.7
PyYAML                   6.0
pyzmq                    25.0.0
qtconsole                5.4.0
QtPy                     2.3.0
rfc3339-validator        0.1.4
rfc3986-validator        0.1.1
scipy                    1.7.3
semver                   2.13.0
Send2Trash               1.8.0
setuptools               65.6.3
setuptools-scm           7.1.0
six                      1.16.0
sniffio                  1.3.0
soupsieve                2.3.2.post1
stack-data               0.6.2
starry                   1.2.0
terminado                0.17.1
Theano-PyMC              1.1.2
tinycss2                 1.2.1
tomli                    2.0.1
tornado                  6.2
tqdm                     4.64.1
traitlets                5.8.1
typing_extensions        4.4.0
uri-template             1.2.0
wcwidth                  0.2.5
webcolors                1.12
webencodings             0.5.1
websocket-client         1.4.2
wheel                    0.37.1
widgetsnbextension       4.0.5
wrapt                    1.14.1
xarray                   2022.12.0
xarray-einstats          0.4.0
xyzservices              2022.9.0
zipp                     3.11.0

Additional context Add any other context about the problem here.

dfm commented 1 year ago

@catrionamurray — thanks! This is a known issues that we definitely need to fix! You can get around this using the following suggestion: https://github.com/rodluger/starry/issues/302#issuecomment-1094136350 (although I think it perhaps actually needs to go after you import starry?)

import theano
theano.config.gcc__cxxflags += " -fexceptions"
catrionamurray commented 1 year ago

Oh great thanks that works! I had tried including those lines before importing starry before I opened this pull request and that didn't work.