Hi all,
(Sorry I've been absent for a while.)
It's my pleasure to announce the initial "alpha testing" release of the project I started work on, back in January:
Pymod = Auto-generate a Python module to wrap the procs in a Nim module.
Pymod consists of Nim bindings & Python scripts to auto-generate Python C-API extension module boilerplate for Nim procs. Pymod will create an auto-generated, auto-compiled Python module.
The auto-generated boilerplate code:
There's even a Nim interface to Numpy arrays, so you can pass Numpy arrays into your Nim procs and access them natively.
Pymod is definitely still in the alpha phase, and it's far from feature-complete, but it's been usable for our work for about 9 months now (and we've been using it regularly during that time). There's a lot of hacky code in there, but it gets the job done.
There's more info, including a simple usage example, in the Pymod README on Github.
I would be grateful towards anyone who can test out Pymod on their own system, and let me know whether Pymod compiles & works for them or not (and either way, what their system is -- look in the file ITWORKS for details of the specifications I need).
And if there's anything in the documentation that's ambiguous or confusing, please let me know!
Thanks!
This is really interesting and well worth the wait! Unfortunately, I can't run even the simplest example (fails with this longish output). I'm using Nim 0.12.0 (release), Python 2.7.10/3.5.0, gcc 5.2.0.
Keep up the good work, you're on to something here!
Hi @nvill, thank you for testing this!
That is indeed strange. I've just downloaded & compiled Nim 0.12.0 (release) and I have reproduced that error.
I'm looking into it now.
The error that the Nim compiler is reporting:
lib/system/sysio.nim(203, 5) Error: cannot 'importc' variable at compile time
close(f)
^
make: *** [pmgen] Error 1
is regarding this proc in lib/system/sysio.nim:
proc writeFile(filename, content: string) =
var f = open(filename, fmWrite)
try:
f.write(content)
finally:
close(f)
but that proc is exactly the same in the version of Nim that I've been using.
I'll keep looking into it.
OK, the error appears to occur because I'm using system.writeFile at compile time.
To the Nim devs: Is it intended that system.writeFile is now no longer available at compile time, or is this a bug that I should report?
I can't see any mention of system.writeFile in the 0.12.0 release notes.
In fact, the most recent mention of system.writeFile on that page is in the 0.10.2 release notes, where system.writeFile is listed in the "Compiler Additions" section as one of the procs that "are now available at compile-time".
The only issue on Github that I can find that relates to both system.writeFile and "compile time" is this JS backend bug from July: writeFile not available at compile time when using the JS backend.
So I'm going to assume that this system.writeFile issue was a temporary regression in 0.12.0 that has already been fixed in master & devel on Github. :)
(Please correct me if I'm wrong.)
You are wrong. The brew package is missing lib/stdlib.nimble which is used to create a pseudo Nimble package of the stdlib which is then used to override system.writeFile so that it becomes available at compile-time.
It's not a Nim bug, it's a packaging bug.
For anyone who might be interested, I've significantly expanded the README file on Github, to provide much more information about the PyArrayObject type & how to use it.
PS: OK, thanks for the clarification, @Araq. But does that change the practical upshot that system.writeFile is unusable at compile-time in any Nim 0.12.0 release?
And is there anything that Pymod can do to re-enable system.writeFile in a 0.12.0 release?
Well not everbody uses Macs, and of those who use Macs, not everybody uses brew... Maybe the maintainer of the brew package can fix this showstopper bug?
And is there anything that Pymod can do to re-enable system.writeFile in a 0.12.0 release?
Well you can try to create an empty file named stdlib.nimble in Nim's $lib directory which might be in /usr/local/lib/nim and might not require sudo. Who knows.
MAC USERS: I would highly suggest to remove Homebrew Nim and use "nim-vm" https://github.com/ekarlso/nim-vm instead. This has multiple advantages like easy way to install multiple release versions and easy update to current devel versions of Nim.
I am kind of maintaining this script and use it since some months. So if there are problems I may can help!
About the Homebrew version see: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/nim.rb
I am going to contact the maintainer and point him to this forum-topic. It seems like Github has some performance problems atm.
Fixing the homebrew version should work like this:
touch /usr/local/Cellar/nim/0.12.0/nim/lib/stdlib.nimble
Linux x86_64 GNU/Linux
Python 2.7.10 :: Continuum Analytics, Inc.
Nim Compiler Version 0.12.1 (2015-11-13) [Linux: amd64]
gcc (Ubuntu 4.9.2-10ubuntu13) 4.9.2
Numpy 1.10.1
ven 13 nov 2015, 12.58.17, CET
Wonderful, thank you @andrea! I've added your success info to ITWORKS.
I've enjoyed reading your articles about scientific Nim, and I've followed your work on unicredit/linear-algebra with interest.
I'd be very interested to hear any feedback you would like to offer on Pymod -- and on PyArrayObject in particular.
This was resolved by touching /usr/lib/nim/stdlib.nimble as @Araq mentioned. I just noticed that this was recently resolved by #3508 (the file was not copied with koch install) so this is probably an issue for those using distro packages (like myself) until the next release. @jboy, it is probably a good idea to mention this workaround in the readme.
Testing with a simple recursive fibonacci, I'm getting ~55x speedup on my laptop for n=35. Sweet!
Linux x86_64 GNU/Linux
Python 3.5.0
Nim Compiler Version 0.12.0 (2015-10-30) [Linux: amd64]
gcc (GCC) 5.2.0
Numpy 1.10.1
Sat Nov 14 01:07:57 CET 2015
Excellent, thank you @nvill! I've added your success info to ITWORKS.
I don't use OSX or brew or a distro package for Nim, and there's no directory /usr/lib/nim or /usr/local/lib/nim on my computer, so I don't really understand any of this -- but I've added a link back to this forum thread in the Pymod README.