neurophysik / jitcdde

Just-in-time compilation for delay differential equations
Other
57 stars 15 forks source link

Failing to compile is extremely noisy #3

Closed rgommers closed 7 years ago

rgommers commented 7 years ago

When trying the first example in the docs:

from jitcdde import jitcdde, y, t
import numpy

τ = 15
n = 10
β = 0.25
γ = 0.1

f = [ β * y(0,t-τ) / (1 + y(0,t-τ)**n) - γ*y(0) ]
DDE = jitcdde(f)

DDE.add_past_point(-1.0, [1.0], [0.0])
DDE.add_past_point( 0.0, [1.0], [0.0])

DDE.step_on_discontinuities()

This is the output I see before the output array([ 1.18037923]) is returned:

Generating, compiling, and loading C code.
Using default integration parameters.

C:\Users\Gommersr\AppData\Local\Continuum\Anaconda3\lib\site-packages\jitcdde\_jitcdde.py:470: UserWarning: Traceback (most recent call last):
  File "C:\Users\Gommersr\AppData\Local\Continuum\Anaconda3\lib\distutils\_msvccompiler.py", line 382, in compile
    self.spawn(args)
  File "C:\Users\Gommersr\AppData\Local\Continuum\Anaconda3\lib\distutils\_msvccompiler.py", line 501, in spawn
    return super().spawn(cmd)
  File "C:\Users\Gommersr\AppData\Local\Continuum\Anaconda3\lib\distutils\ccompiler.py", line 909, in spawn
    spawn(cmd, dry_run=self.dry_run)
  File "C:\Users\Gommersr\AppData\Local\Continuum\Anaconda3\lib\distutils\spawn.py", line 38, in spawn
    _spawn_nt(cmd, search_path, dry_run=dry_run)
  File "C:\Users\Gommersr\AppData\Local\Continuum\Anaconda3\lib\distutils\spawn.py", line 81, in _spawn_nt
    "command %r failed with exit status %d" % (cmd, rc))
distutils.errors.DistutilsExecError: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Gommersr\AppData\Local\Continuum\Anaconda3\lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "C:\Users\Gommersr\AppData\Local\Continuum\Anaconda3\lib\distutils\dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "C:\Users\Gommersr\AppData\Local\Continuum\Anaconda3\lib\distutils\dist.py", line 974, in run_command
    cmd_obj.run()
  File "C:\Users\Gommersr\AppData\Local\Continuum\Anaconda3\lib\site-packages\setuptools-27.2.0-py3.6.egg\setuptools\command\build_ext.py", line 77, in run
    _build_ext.run(self)
  File "C:\Users\Gommersr\AppData\Local\Continuum\Anaconda3\lib\site-packages\Cython\Distutils\old_build_ext.py", line 185, in run
    _build_ext.build_ext.run(self)
  File "C:\Users\Gommersr\AppData\Local\Continuum\Anaconda3\lib\distutils\command\build_ext.py", line 339, in run
    self.build_extensions()
  File "C:\Users\Gommersr\AppData\Local\Continuum\Anaconda3\lib\site-packages\Cython\Distutils\old_build_ext.py", line 193, in build_extensions
    self.build_extension(ext)
  File "C:\Users\Gommersr\AppData\Local\Continuum\Anaconda3\lib\site-packages\setuptools-27.2.0-py3.6.egg\setuptools\command\build_ext.py", line 198, in build_extension
    _build_ext.build_extension(self, ext)
  File "C:\Users\Gommersr\AppData\Local\Continuum\Anaconda3\lib\distutils\command\build_ext.py", line 533, in build_extension
    depends=ext.depends)
  File "C:\Users\Gommersr\AppData\Local\Continuum\Anaconda3\lib\distutils\_msvccompiler.py", line 384, in compile
    raise CompileError(msg)
distutils.errors.CompileError: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Gommersr\AppData\Local\Continuum\Anaconda3\lib\site-packages\jitcdde\_jitcdde.py", line 468, in _initiate
    self.generate_f_C()
  File "C:\Users\Gommersr\AppData\Local\Continuum\Anaconda3\lib\site-packages\jitcdde\_jitcdde.py", line 458, in generate_f_C
    verbose = verbose
  File "C:\Users\Gommersr\AppData\Local\Continuum\Anaconda3\lib\distutils\core.py", line 163, in setup
    raise SystemExit("error: " + str(msg))
SystemExit: error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2

  warn(format_exc())
C:\Users\Gommersr\AppData\Local\Continuum\Anaconda3\lib\site-packages\jitcdde\_jitcdde.py:471: UserWarning: Generating compiled integrator failed; resorting to lambdified functions.
  warn("Generating compiled integrator failed; resorting to lambdified functions.")

That's way too noisy; shouldn't be too hard to silence that - I would expect just a UserWarning.

Wrzlprmft commented 7 years ago

I see where you are coming from, but compiling is a core aspect of this module and essential for making it fast. Therefore I expect that most users will be interested in fixing such problems when they arise. To this purpose, they usually need the entire error message (though it’s admittedly rather useless in you case – for reasons beyond my control). I also cannot filter this error as all sorts of things can go wrong and I cannot predict them.

I can make the order of messages more meaningful and also tell the user how to suppress this, if they really want to use the Python backend, namely by calling generate_f_lambda to explicitly initialise and use the Python backend.

By the way: Feel free to file an issue about the code not compiling, specifying your system. If you manage to solve this, please share your insights. I haven’t done any testing on Windows yet.

rgommers commented 7 years ago

I can make the order of messages more meaningful and also tell the user how to suppress this,

That would be useful, thanks!

Feel free to file an issue about the code not compiling, specifying your system. If you manage to solve this, please share your insights. I haven’t done any testing on Windows yet.

I'll look into it when I find some time. At the moment I just need it to work on Windows (Python-only is fine) to show to colleagues in a notebook. When I need it to be fast, I have a Linux box.

MSVC is set up correctly though (can compile numpy/scipy with it), so not sure if this is my setup or something in your package.

rgommers commented 7 years ago

Aside from the noise I'm quite happy so far by the way:)

Wrzlprmft commented 7 years ago

I can make the order of messages more meaningful and also tell the user how to suppress this,

That would be useful, thanks!

Turned out, it’s not that easy, since I cannot move the compiler warnings (at least not with reasonable effort). Instead, I made the main warning very prominent (and more informative).

rgommers commented 7 years ago

Thanks, that does help. And that message does say how to avoid compilation.

Small issue still with it though, the public method is generate_f_lambda not generate_lambdas (at least for the simple example in the docs). Which is weird if I look at the call diagram in http://jitcode.readthedocs.io/en/latest/#details-of-the-building-process - it should be generate_lambdas. generate_jac_* is also not a method of the DDE instance. What am I missing?

Wrzlprmft commented 7 years ago

generate lambdas will be new in the next release (which I am processing right now). I should have made the documentation default differently though. The call diagram for JiTCODE is really only for JiTCODE, as compiling a separate Jacobian only makes sense there. For JiTCDDE, things are much simpler and I didn’t feel the need for a diagram.

rgommers commented 7 years ago

Ah great, I'll install latest master for now then. Thanks again.

Wrzlprmft commented 7 years ago

FYI: JiTCDDE should now work with the Microsoft compiler.

rgommers commented 7 years ago

Awesome, thanks!