These are chat archives for symengine/symengine

15th
Jun 2015
Isuru Fernando
@isuruf
Jun 15 2015 15:01
@abinashmeher999, I built libsymengine as a shared library by using cmake -DBUILD_SHARED_LIBS=yes . and everything is working fine with the patch I mentioned in sciruby-dev
Abinash Meher
@abinashmeher999
Jun 15 2015 15:03
@certik Yes. They shouldn't have one, but by default have_library searches for main and some librarie do have it.
Updated instructions are here. README.md
Abinash Meher
@abinashmeher999
Jun 15 2015 15:10
@isuruf Will -DWITH_SHARED_LIBS=yes be different from -DWITH_SHARED_LIBS=on? Because I used the latter.
Ondřej Čertík
@certik
Jun 15 2015 15:15
@abinashmeher999 I installed it. How do I try it in Ruby?
Can you post some minimal commands?
Abinash Meher
@abinashmeher999
Jun 15 2015 15:21
Great! Did it build successfully? You can try making a new variable for Basic.
require 'symengine'
a = SymEngine::Basic.new
let's discuss it here, instead of the PR.
Let's only post the final instructions once I figure out how to make it work to the PR.
It can't find the symengine library, even though rake install succeeds.
@abinashmeher999 can you post the patch that I need to apply to make it work?
Abinash Meher
@abinashmeher999
Jun 15 2015 15:31
@certik Did you do rake compile before rake install. That's the step that makes the file symengine.so, the library that contains the wrappers
Ondřej Čertík
@certik
Jun 15 2015 15:31
Yes, I did.
Ah, I guess I didn't.
I rerun rake compile and rake install
Abinash Meher
@abinashmeher999
Jun 15 2015 15:32
I do know the patch. But I already committed that. So, that shouldn't be the issue
Ondřej Čertík
@certik
Jun 15 2015 15:32
Now I get:
2.2.1 :001 > require 'symengine'
 => true 
2.2.1 :002 > a = SymEngine::Basic.new
irb: symbol lookup error: /local/certik/rvm/gems/ruby-2.2.1/gems/symengine-0.0.0.pre/lib/symengine/symengine.so: undefined symbol: basic_init
Is this the error that you were hitting yesterday?
Abinash Meher
@abinashmeher999
Jun 15 2015 15:34
Yes. That's the one I was getting yesterday. But after applying the patch @isuruf suggested I was getting a different error.
Ondřej Čertík
@certik
Jun 15 2015 15:34
Can you post the patch?
Abinash Meher
@abinashmeher999
Jun 15 2015 15:35
Ondřej Čertík
@certik
Jun 15 2015 15:35
Just do git diff in your tree, if you didn't commit yet, or just git show HASH if you already committed.
Abinash Meher
@abinashmeher999
Jun 15 2015 15:37
abinashmeher999@JARVIS:~/gsoc/symengine/src/ruby$ git show 93715f5b61849fc8b8bac568aa86e9ce15f855f
commit 93715f5b61849fc8b8bac568aa86e9ce15f855fd
Author: Abinash Meher <abinashdakshana999@gmail.com>
Date:   Mon Jun 15 20:28:52 2015 +0530

    Tried to use `g++` compiler

diff --git a/src/ruby/ext/symengine/extconf.rb b/src/ruby/ext/symengine/extconf.
index bf426f2..480842a 100644
--- a/src/ruby/ext/symengine/extconf.rb
+++ b/src/ruby/ext/symengine/extconf.rb
@@ -37,8 +37,11 @@ $CFLAGS << ' -Werror' unless $CFLAGS.split.include?('-Werror'
 $CFLAGS << ' -fPIC' unless $CFLAGS.split.include?('-fpic')
 # $CFLAGS << ' -std=c99' unless $CFLAGS.split.include?('-std=c99')

+RbConfig::CONFIG['CC'] = 'g++'
+RbConfig::CONFIG['CXX'] = 'g++'
+$CPPFLAGS='-Wall -O3 -Wall -Wcast-qual -Wconversion -DSGI__gnu_cxx -DREADLINE'
 # Gives the ability to easily use alternate compilers to build the extension
-RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
+#RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']

 # Giving it a name
 extension_name = 'symengine/symengine'
@@ -52,10 +55,15 @@ dir_config(extension_name)
 # unless pkg_config('symengine')
 #    raise "libsymengine not found"
 # end
-# unless have_library('symengine', 'basic_init')
-#     abort 'Unable to find basic_init in library symengine!'
-# end
-# $libs = append_library($libs, 'symengine')
+unless have_header('cwrapper.h')
+    raise 'cwrapper.h not found'
+end
+unless have_library('symengine',
+                    'basic p; basic_init(p); basic_free(p)',
+                    'cwrapper.h')
+    abort 'Unable to find basic_init in library symengine!'
+end
+$libs = append_library($libs, 'symengine')

 # creates the header file extconf.h, based on the results from all of the
 # previous have_*() functions.
Ondřej Čertík
@certik
Jun 15 2015 15:40
So with this patch, I get:
certik@redhawk:~/repos/symengine/src/ruby(pr-414)$ rake compile
cd tmp/x86_64-linux/symengine/2.2.1
/local/certik/rvm/rubies/ruby-2.2.1/bin/ruby -I. ../../../../ext/symengine/extconf.rb
checking for cwrapper.h... no
../../../../ext/symengine/extconf.rb:62:in `<main>': cwrapper.h not found (RuntimeError)
rake aborted!
Command failed with status (1): [/local/certik/rvm/rubies/ruby-2.2.1/bin/ru...]
/local/certik/rvm/gems/ruby-2.2.1/gems/rake-compiler-0.9.5/lib/rake/extensiontask.rb:191:in `block (2 levels) in define_compile_tasks'
/local/certik/rvm/gems/ruby-2.2.1/gems/rake-compiler-0.9.5/lib/rake/extensiontask.rb:188:in `block in define_compile_tasks'
Tasks: TOP => compile => compile:x86_64-linux => compile:symengine:x86_64-linux => copy:symengine:x86_64-linux:2.2.1 => tmp/x86_64-linux/symengine/2.2.1/symengine.so => tmp/x86_64-linux/symengine/2.2.1/Makefile
(See full trace by running task with --trace)

Ok, this last error can be fixed by:

--- a/src/ruby/ext/symengine/extconf.rb
+++ b/src/ruby/ext/symengine/extconf.rb
@@ -27,6 +27,7 @@ LIB_DIRS = [

     # Check the ruby install locations
     LIBDIR,
+    '/home/certik/repos/symengine/src',

     # Finally fall back to /usr
     '/usr/lib'
@@ -58,14 +59,14 @@ dir_config(extension_name)
 # unless pkg_config('symengine')
 #    raise "libsymengine not found"
 # end
-unless have_header('cwrapper.h')
-    raise 'cwrapper.h not found'
-end
-unless have_library('symengine',
-                    'basic p; basic_init(p); basic_free(p)',
-                    'cwrapper.h')
-    abort 'Unable to find basic_init in library symengine!'
-end
+#unless have_header('cwrapper.h')
+#    raise 'cwrapper.h not found'
+#end
+#unless have_library('symengine',
+#                    'basic p; basic_init(p); basic_free(p)',
+#                    'cwrapper.h')
+#    abort 'Unable to find basic_init in library symengine!'
+#end
 $libs = append_library($libs, 'symengine')

 # creates the header file extconf.h, based on the results from all of the

now it compiles and works!!

Abinash Meher
@abinashmeher999
Jun 15 2015 15:43
I guess the path can be set by using some flags as per the instruction given here. I don't exactly know how. So something like -with-symengine-dir= something.
Ondřej Čertík
@certik
Jun 15 2015 15:43
I.e.:
2.2.1 :001 > require 'symengine'
 => true 
2.2.1 :002 > a = SymEngine::Basic.new
 => #<SymEngine::Basic:0x00000001111e48>
What else can I try in irb?
Abinash Meher
@abinashmeher999
Jun 15 2015 15:45
Wow. great! make two variables, add them and store them in a new variable.
I might be missing something. It works in your as well as Isuru's system
Ondřej Čertík
@certik
Jun 15 2015 15:47
Can you post the Ruby commands?
I tried the following:
2.2.1 :002 > a = SymEngine::Symbol("a")
NoMethodError: undefined method `Symbol' for SymEngine:Module
    from (irb):2
    from /local/certik/rvm/rubies/ruby-2.2.1/bin/irb:11:in `<main>'
2.2.1 :003 > a = SymEngine::Symbol.new("x")
NameError: uninitialized constant SymEngine::Symbol
    from (irb):3
    from /local/certik/rvm/rubies/ruby-2.2.1/bin/irb:11:in `<main>'
Harsh Gupta
@hargup
Jun 15 2015 15:49
@Sumith1896 by background I meant information like, What are expand2b and expand2c and why there are significant differences in the speed for the other part of the community which is not closely following you work.
Ondřej Čertík
@certik
Jun 15 2015 15:50
@hargup expand2b is using a polynomial datastructure of std::vector<int> for exponents, so it is faster than the expand2 which uses the general symbolic expressions. expand2c is just like expand2b, except that it packs the exponents into a machine integer, thus it is even faster.
Harsh Gupta
@hargup
Jun 15 2015 15:52
And how does it compare with the python code?
By python code I mean the expand function in SymPy
Ondřej Čertík
@certik
Jun 15 2015 15:55
@hargup I don't remember the timings. expand2, which tests general symbolic code is probably 30x or so faster than sympy. expand2b and 2c are a bit faster than the polynomials in sympy (perhaps 2x or so, but I don't remember the benchmarks off top of my head). We are still not done with all the optimizations. Piranha is still about 2x faster than expand2c.
Isuru Fernando
@isuruf
Jun 15 2015 15:55
@certik, Symbol and other methods are not implemented by @abinashmeher999 right now
Harsh Gupta
@hargup
Jun 15 2015 15:55
That's pretty cool.
Abinash Meher
@abinashmeher999
Jun 15 2015 15:55
new, +, -, *, /, ** and -@ the prefix operator.
Ondřej Čertík
@certik
Jun 15 2015 15:56
@isuruf I see. Is there anything else to try then?
Abinash Meher
@abinashmeher999
Jun 15 2015 15:56
All only with Basic class
Isuru Fernando
@isuruf
Jun 15 2015 15:56
@abinashmeher999 you cannot do additions without initializing them and setting it to some value
Ondřej Čertík
@certik
Jun 15 2015 15:57
Exactly, it segfaults.
Abinash Meher
@abinashmeher999
Jun 15 2015 15:58
I see. What other methods do I need to add to initialize?
Ondřej Čertík
@certik
Jun 15 2015 15:58
Anyway, that we'll fix later. Now we need to make it work on @abinashmeher999's computer.
Isuru Fernando
@isuruf
Jun 15 2015 15:59
@abinashmeher999, did you build the shared library libsymengine.so?
Ondřej Čertík
@certik
Jun 15 2015 15:59
No, he didn't.
@abinashmeher999 if you can follow the instructions I posted, step by step, it should work for you.
@isuruf how exactly do you build the Ruby wrappers? Do you do something differently than to what I posted in abinashmeher999/symengine#1
Abinash Meher
@abinashmeher999
Jun 15 2015 16:02
OK. I am trying it out
Ondřej Čertík
@certik
Jun 15 2015 16:03
The Ruby build script is really hackish. That's my experience with the Python distutils, they are equally hackish. That's why I prefer to just use cmake to build and install the extension. One just needs to tell it where to find the Ruby header files and where to install it. That's it.
@abinashmeher999 once you get this working, then the next step is to make it work on Travis, so that your PR gets tested automatically. Then we'll start improving the wrappers.
Isuru Fernando
@isuruf
Jun 15 2015 16:05

What I did was, build symengine
cmake -DBUILD_SHARED_LIBS=on .
sudo make install #install in /usr/local/lib/
Add this patch

diff --git a/src/ruby/ext/symengine/extconf.rb b/src/ruby/ext/symengine/extconf.rb
index bf426f2..4d46e4f 100644
--- a/src/ruby/ext/symengine/extconf.rb
+++ b/src/ruby/ext/symengine/extconf.rb
@@ -43,6 +43,9 @@ RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
 # Giving it a name
 extension_name = 'symengine/symengine'

+have_header('cwrapper.h')
+have_library('symengine', 'basic p; basic_init(p); basic_free(p)', 'cwrapper.h')
+
 # The destination
 dir_config(extension_name)

bundle install - just once
rake compile
rake install

Ondřej Čertík
@certik
Jun 15 2015 16:05
@isuruf what is the purpose of those have_header?
Do they just check if the header is there (somewhere), or do they set some internal paths in Rake?
Btw, you should never use sudo while developing, in fact you should never install like this on your computer.
The PR I posted does not need sudo for anything (it installs rvm, ruby, symengine etc. into my home directory).
It currently requires hardwiring some paths, but that we will fix.
Isuru Fernando
@isuruf
Jun 15 2015 16:08
@certik, @abinashmeher999 , why not use cmake to install this, then we would not have to worry about flags, libraries, headers etc.?
Ondřej Čertík
@certik
Jun 15 2015 16:10
@isuruf that's what I am trying to say.
Abinash Meher
@abinashmeher999
Jun 15 2015 16:10
The plan is to do the same. But till now my main focus was to get them working.
Ondřej Čertík
@certik
Jun 15 2015 16:11
I think @abinashmeher999 felt it would be easier using Rake. I am glad he tried it that way, as it shows that while possible, it's not easy at all.
Abinash Meher
@abinashmeher999
Jun 15 2015 16:12
@certik What is $HASHSTACK? Where can I read more about it?
Ondřej Čertík
@certik
Jun 15 2015 16:12
It's just a variable, where I installed the openssl dependency.
I think you already have it systemwide. It's for installing RVM and Ruby.
You already have all that, so you can ignore it.
(I don't have root access to my computer, so I need to install without root.)
But otherwise you can read more about the Hashdist project here: http://hashdist.github.io/
Abinash Meher
@abinashmeher999
Jun 15 2015 16:14
Oh ok. By the way, I don't see any variable by that name. I guess, it was made while installing?
Ondřej Čertík
@certik
Jun 15 2015 16:15
I created the HASHSTACK variable.
and pointed it to my installed openssl. To be precise, Hashdist did it for me, but as I said, you don't need to worry about any of that.
Abinash Meher
@abinashmeher999
Jun 15 2015 16:18
Ok. Is there a standard procedure to uninstall libsymengine? Will make uninstall do the job? Or I manually delete the files from the install locations?
Ondřej Čertík
@certik
Jun 15 2015 16:23
@abinashmeher999 There is no way to uninstall. That's why you should not use sudo, because then you have to manually remove things. To get uninstall, you need to use some kind of a package manager, like Hashdist.
(or apt-get, or Conda, ....)
Abinash Meher
@abinashmeher999
Jun 15 2015 16:26
How about the users who install from source? Do we have a .deb package too. I guess apt-get works only for debian packages. We should provide a feature to uninstall. like make uninstall
Isuru Fernando
@isuruf
Jun 15 2015 16:36
@certik, I just tried with cmake, you only need a few tweaks to get it working. I used rake install to install it into the right location.
Ondřej Čertík
@certik
Jun 15 2015 16:49
@isuruf can you post a PR?
Ondřej Čertík
@certik
Jun 15 2015 16:54
@abinashmeher999 make uninstall is not the way to go. You can do it, e.g. http://www.cmake.org/Wiki/CMake_FAQ#Can_I_do_.22make_uninstall.22_with_CMake.3F, but even they discourage you to. If you need packages, you need to use a package manager. If you want to install from source, you a source package manager (like Hashdist), as opposed to a binary package manager (like apt-get). If you want this just for development, install it somewhere in your home directory. P.S. We are adding a better support for this in Hashdist: hashdist/hashdist#341
Isuru Fernando
@isuruf
Jun 15 2015 16:55
abinashmeher999/symengine#2
Abinash Meher
@abinashmeher999
Jun 15 2015 16:55
@certik @isuruf They are working now. I have kept the have_header and have_library functions.
Ondřej Čertík
@certik
Jun 15 2015 16:56
@abinashmeher999 nice!!
@isuruf how do you use your PR?
I am trying it now.
Isuru Fernando
@isuruf
Jun 15 2015 16:57
cmake -DWITH_RUBY=yes .
cd src/ruby
rake install
Abinash Meher
@abinashmeher999
Jun 15 2015 16:57
@isuruf Thanks!! I am trying it too.
Isuru Fernando
@isuruf
Jun 15 2015 16:57
Do not do rake compile as it will override the library created by cmake
Isuru Fernando
@isuruf
Jun 15 2015 16:59
Fixed the typo
I hadn't commited it
Ondřej Čertík
@certik
Jun 15 2015 17:00
@isuruf it works for me.
Isuru Fernando
@isuruf
Jun 15 2015 17:00
great
Ondřej Čertík
@certik
Jun 15 2015 17:00
I bet it works with a static library as well
Isuru Fernando
@isuruf
Jun 15 2015 17:01
Yeah, libsymengine can be static, although symengine has to be dynamic
Ondřej Čertík
@certik
Jun 15 2015 17:01
Right, of course.
It works!!
Both static and dynamic work. Great job @isuruf.
I would suggest to remove stuff that we do not need from the wrappers now.
What are the minimal changes that we need to do to master in order to use cmake + rake install?
Abinash Meher
@abinashmeher999
Jun 15 2015 17:03
If it is installed by cmake, then I suppose we don't need to link the dependencies ourselves. Is that why it works with both static and dynamic libraries?
Ondřej Čertík
@certik
Jun 15 2015 17:03
Yes.
CMake knows how to link the library properly (be it static or dynamic).
The question is what exactly does rake install need to succeed?
Now when cmake prepares the symengine.so wrappers.
Abinash Meher
@abinashmeher999
Jun 15 2015 17:05
Shall I merge the PR to my branch?
Ondřej Čertík
@certik
Jun 15 2015 17:06
+1 from me.
if I do rake install, then it installs it into my ~/.rvm/ directory. How do I uninstall it?
I would guess rvm has some machinery to handle different profiles or something.
Ondřej Čertík
@certik
Jun 15 2015 17:20
@abinashmeher999 I've added a TODO list here: https://github.com/sympy/symengine/pull/414#issue-61625012
Let me know if you agree with it, and if it is clear.
Abinash Meher
@abinashmeher999
Jun 15 2015 17:25
@certik It's perfectly clear and covers sufficient things
Ondřej Čertík
@certik
Jun 15 2015 17:33
Cool.