Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby wrappers initial file structure and Basic class #414

Merged
merged 13 commits into from
Jun 24, 2015

Conversation

abinashmeher999
Copy link
Contributor

Addresses issue #413.
Most of the files are empty. I have tried to use the standard tools like RSpec and bundler which I am not very familiar with, but believe will prove to be very useful during the development. The main reason for choosing RSpec was because SciRuby prefers RSpec.

TODO list before we can merge this PR:

  • Build the wrappers with CMake
  • Test the wrappers on Travis (building + running Ruby tests)
  • Expose some minimal functionality and test it using Ruby tests (make sure they are run by Travis)
  • Remove unnecessary things and files from the wrappers (e.g. src/ruby/bin/htmldiff is probably not needed)

After this is merged, we will then expose more functionality of SymEngine (both in the C wrappers as well as the Ruby wrappers).

@certik
Copy link
Contributor

certik commented Mar 15, 2015

I think this looks good so far.

@certik
Copy link
Contributor

certik commented Mar 15, 2015

The next step is to try to create the actual wrappers by compiling a simple C++ code and calling it from Ruby.

@translunar
Copy link

I will say that if you want to use a different spec library, you're welcome to. We use rspec because we had hoped originally to incorporate NMatrix into ruby-core. These days that's less likely. I know some people prefer cucumber.

Just have a good justification for it. =)

@translunar
Copy link

Looks good so far. Looking forward to seeing some wrapper code. Tag me when you push some. =)

@abinashmeher999
Copy link
Contributor Author

So I went through this blog and a few other places. What I have guessed is RSpec tests it the way a developer would like it to, to make sure all works as he intended them. More like the unit tests. Whereas, Cucumber tests it the way a client/consumer would expect from the software. Like the integration tests. Most of the places, people suggest that both go hand in hand. But is it really required to have integration testing while writing the wrappers? Feels like overkill. Since I am new, I would like you to suggest.

@certik
Copy link
Contributor

certik commented Mar 20, 2015

The tests are needed to ensure the wrappers work correctly (things like
typos and other issues that only show up at runtime). You are right that we
do not need to test the underlying C++ library, as that's already tested
elsewhere.

Sent from my mobile phone.
On Mar 20, 2015 1:09 PM, "Abinash Meher" notifications@github.com wrote:

So I went through this blog
http://blog.brianguthrie.com/2011/03/29/when-to-use-rspec-when-to-use-cucumber/
and a few other places. What I have guessed is RSpec tests it the way a
developer would like it to, to make sure all works as he intended them.
More like the unit tests. Whereas, Cucumber tests it the way a
client/consumer would expect from the software. Like the integration tests.
Most of the places, people suggest that both go hand in hand. But is it
really required to have integration testing while writing the wrappers?
Feels like overkill. Since I am new, I would like you to suggest.


Reply to this email directly or view it on GitHub
#414 (comment).

#unless have_library("libcsympy")
# raise "libcsympy not found"
#end
#How is libcsympy installed? Not able to find libcsympy
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@certik I couldn't find anything like libcsympy. How is csympy's library installed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends how you install symengine, but it is either src/libsymengine.a or src/libsymengine.so. After it gets installed, it will be in lib/.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still no luck. I searched in /lib, /usr/lib, /usr/local/lib and /opt/lib.

@abinashmeher999 abinashmeher999 changed the title Ruby wrappers initial file structure [WIP] Ruby wrappers initial file structure and Basic class May 22, 2015
@certik
Copy link
Contributor

certik commented May 22, 2015

@abinashmeher999 thanks for pushing your latest changes in. How do I compile it? Can you write step by step instructions how you test this? I'll try to get it working on my machine and then provide some feedback.

@abinashmeher999
Copy link
Contributor Author

@certik They are actually incomplete now. There will be errors. I will put that in a separate README.md in the src/ruby directory once I complete it.
We need to execute rake compile in the directory src/ruby to build the extensions.

@certik
Copy link
Contributor

certik commented May 22, 2015

Thanks, I'll try it out later today. Why not just wrap a single function, to make sure the wrappers compile, and then iteratively keep adding more and more functions, while making sure the wrappers still compile?

@abinashmeher999
Copy link
Contributor Author

Ok. I will do that.

@agarie
Copy link

agarie commented May 25, 2015

Hi @abinashmeher999! Good work so far. :)

Please, don't forget to update .travis.yml to compile and test your Ruby extensions.

@certik
Copy link
Contributor

certik commented May 25, 2015

@agarie yes, exactly. Thanks for looking at it.

@abinashmeher999
Copy link
Contributor Author

@agarie Thanks for having a look at it. I haven't forgotten that. I will surely update it after I set building of ruby extensions from cmake with a -DWITH_RUBY flag.

@certik
Copy link
Contributor

certik commented May 28, 2015

@abinashmeher999 here is what I tried, per your instructions:

ondrej@eagle:~/repos/symengine/src/ruby(pr-414)$ rake1.9.1 compile
rake aborted!
cannot load such file -- bundler

(See full trace by running task with --trace)

I previously compiled symengine with:

$ cmake -DCMAKE_BUILD_TYPE=Debug -DWITH_SYMENGINE_ASSERT=yes -DWITH_BFD=yes .
$ make

Can you tell me what you get when you run rake? I'll try to fix my machine to work.

@abinashmeher999
Copy link
Contributor Author

@certik Seems you are missing bundler. I forgot to mention this.
It can be installed by simply executing gem install bundler. Then bundle install to install the required gems which it needs. Then after that rake compile to compile the extensions.
I just updated the README and rebased the branch. You might need to pull it again before trying it out.

basic_free(basic_ptr);
}

static VALUE cbasic_alloc(VALUE klass){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line generates the following error:

ruby_basic.c:8:14: error: ‘cbasic_alloc’ defined but not used [-Werror=unused-function]
 static VALUE cbasic_alloc(VALUE klass){
              ^

I think that's because the function is declared static, so it is local to this file. I don't think you should declare it as static.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had referred to this guide for declaring functions. I will give a try without static and post the results.

@abinashmeher999
Copy link
Contributor Author

@certik I apologise for the delay. The good news is the wrappers compile ✨ . The bad news is I still can't load them from ruby interpreter . I am on it.

gem.authors = ['Abinash Meher']
gem.email = ["abinashdakshana999@gmail.com"]
gem.extensions = ['ext/symengine/extconf.rb']
gem.files = Dir["lib/**/*.rb", "bin/*", "LICENSE", "*.md"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With lib/**/*.rb you are excluding lib/symengine/symengine.so. That's why you are getting a file not found error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@isuruf I can't thank you enough. I was stuck at this for a while now. This is exactly the thing I was missing. 😌

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @isuruf!

@abinashmeher999 please push in the working wrappers, so that others can try your PR out.

@certik
Copy link
Contributor

certik commented Jun 15, 2015

@abinashmeher999 can you post step by step instructions how to compile it?
I checked out 345dbfc and did:

$ sudo apt-get install rake bundler
$ cmake -DWITH_RUBY=yes .
$ make
$ cd src/ruby
$ rake
rake aborted!
cannot load such file -- rake/extensiontask
/home/ondrej/repos/symengine/src/ruby/Rakefile:8:in `<top (required)>'
(See full trace by running task with --trace)

How do I install the rake/extensiontask? I wasn't able to find it online. (I posted the same question on gitter yesterday: https://gitter.im/sympy/symengine?at=557e0be7c030cae67ed3a339.)

@isuruf
Copy link
Member

isuruf commented Jun 15, 2015

@certik, there's a README in src/ruby.

I was able to build it using the instructions there. Two things he missed was, build shared libs for libsymengine and do rake install

@abinashmeher999
Copy link
Contributor Author

@certik I haven't added the option to compile from cmake yet. Will have to do with rake compile for now. @isuruf I didn't know that we could simply rake install to install the gem directly. I was going through the long procedure of gem build and gem install. I will update the docs.

@certik
Copy link
Contributor

certik commented Jun 15, 2015

The installation instructions are insufficient for me. Here is a better version:

# Steps to compile the extensions

## Install RVM

None of this requires root access.

Follow the instructions at https://rvm.io to install RVM, e.g.:

    gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
    curl -sSL https://get.rvm.io | bash -s stable

Then use RVM to install Ruby and dependencies:

    rvm autolibs disable
    rvm install ruby --with-openssl-dir=$HASHSTACK
    gem install bundler

## Install SymEngine

    cmake -DCOMMON_DIR=$HASHSTACK -DWITH_RUBY=yes -DBUILD_SHARED_LIBS=yes .
    make

## Install the Ruby wrappers

    cd src/ruby
    bundle install
    rake compile

When I follow these steps, the last rake compile gives me:

certik@redhawk:~/repos/symengine/src/ruby(pr-414)$ rake compile
mkdir -p lib/symengine
mkdir -p tmp/x86_64-linux/symengine/2.2.1
cd tmp/x86_64-linux/symengine/2.2.1
/local/certik/rvm/rubies/ruby-2.2.1/bin/ruby -I. ../../../../ext/symengine/extconf.rb
creating extconf.h
creating Makefile
cd -
cd tmp/x86_64-linux/symengine/2.2.1
gmake
compiling ../../../../ext/symengine/ruby_basic.c
In file included from ../../../../ext/symengine/ruby_basic.c:1:0:
../../../../ext/symengine/ruby_basic.h:2:22: fatal error: cwrapper.h: No such file or directory
 #include "cwrapper.h"
                      ^
compilation terminated.
gmake: *** [ruby_basic.o] Error 1
rake aborted!
Command failed with status (2): [gmake...]
/local/certik/rvm/gems/ruby-2.2.1/gems/rake-compiler-0.9.5/lib/rake/extensiontask.rb:155: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:154:in `block in define_compile_tasks'
/local/certik/rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
/local/certik/rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'
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
(See full trace by running task with --trace)

How do you fix this error? Are you perhaps installing symengine and then giving rake a path to it somehow?

@certik
Copy link
Contributor

certik commented Jun 15, 2015

This seems to fix it:

--- a/src/ruby/ext/symengine/extconf.rb
+++ b/src/ruby/ext/symengine/extconf.rb
@@ -14,6 +14,8 @@ HEADER_DIRS = [
     # Check the ruby install locations
     INCLUDEDIR,

+    '/home/certik/repos/symengine/src',
+
     # Finally fall back to /usr
     '/usr/include'
 ]

So clearly something is wrong.

@abinashmeher999
Copy link
Contributor Author

Currently, the extconf.rb searches for header files mentioned in '/opt/local/include', '/usr/local/include', '/usr/include' and the include dir of the path where ruby is installed, like it is /home/abinashmeher999/.rvm/rubies/ruby-2.2.0/include for me.
While adding dir_config, I came to know that other paths can be added with flags, but I don't exactly know how. This link might help.

@certik
Copy link
Contributor

certik commented Jun 15, 2015

Anyway, so I did:

certik@redhawk:~/repos/symengine/src/ruby(pr-414)$ rake install
symengine 0.0.0.pre built to pkg/symengine-0.0.0.pre.gem.
symengine (0.0.0.pre) installed.
certik@redhawk:~/repos/symengine/src/ruby(pr-414)$ irb
Readline was unable to be required, if you need completion or history install readline then reinstall the ruby.
You may follow 'rvm notes' for dependencies and/or read the docs page https://rvm.io/packages/readline/ . Be sure you 'rvm remove X ; rvm install X' to re-compile your ruby with readline support after obtaining the readline libraries.
2.2.1 :001 > require 'symengine'
LoadError: cannot load such file -- symengine/symengine
    from /local/certik/rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /local/certik/rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /local/certik/rvm/gems/ruby-2.2.1/gems/symengine-0.0.0.pre/lib/symengine.rb:1:in `<top (required)>'
    from /local/certik/rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `require'
    from /local/certik/rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `rescue in require'
    from /local/certik/rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:39:in `require'
    from (irb):1
    from /local/certik/rvm/rubies/ruby-2.2.1/bin/irb:11:in `<main>'

@abinashmeher999, @isuruf, how did you manage to load it?

@certik
Copy link
Contributor

certik commented Jun 15, 2015

I now followed the steps I posted above in a new terminal to make sure things work when started from scratch. All went fine, until:

certik@redhawk:~/repos/symengine/src/ruby(pr-414)$ rake compile
mkdir -p lib/symengine
mkdir -p tmp/x86_64-linux/symengine/2.2.1
cd tmp/x86_64-linux/symengine/2.2.1
/local/certik/rvm/rubies/ruby-2.2.1/bin/ruby -I. ../../../../ext/symengine/extconf.rb
creating extconf.h
creating Makefile
cd -
cd tmp/x86_64-linux/symengine/2.2.1
gmake
compiling ../../../../ext/symengine/ruby_basic.c
In file included from ../../../../ext/symengine/ruby_basic.h:2:0,
                 from ../../../../ext/symengine/ruby_basic.c:1:
/home/certik/repos/symengine/src/cwrapper.h:4:17: fatal error: gmp.h: No such file or directory
 #include <gmp.h>
                 ^
compilation terminated.
gmake: *** [ruby_basic.o] Error 1
rake aborted!
Command failed with status (2): [gmake...]
/local/certik/rvm/gems/ruby-2.2.1/gems/rake-compiler-0.9.5/lib/rake/extensiontask.rb:155: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:154: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
(See full trace by running task with --trace)

It's missing the gmp include, but somehow previously it found it... This can be fixed by:

index bf426f2..70a0bf6 100644
--- a/src/ruby/ext/symengine/extconf.rb
+++ b/src/ruby/ext/symengine/extconf.rb
@@ -14,6 +14,9 @@ HEADER_DIRS = [
     # Check the ruby install locations
     INCLUDEDIR,

+    '/home/certik/repos/symengine/src',
+    '/local/certik/bld/profile/xt33omorophg/include',
+
     # Finally fall back to /usr
     '/usr/include'
 ]

@abinashmeher999
Copy link
Contributor Author

@isuruf Could you please check why shippable is failing. I keep getting this message

{"id":1005,"message":"Internal API error : getPermissionByProjectId","methodName":"chkPermForId|_getSByProjectId"} 

@isuruf
Copy link
Member

isuruf commented Jun 22, 2015

One test timed out which is unrelated to the PR. I've restarted the build
as we can't restart just one job.
By the way, ruby is not tested in shippable.

On Mon, Jun 22, 2015 at 1:02 PM, Abinash Meher notifications@github.com
wrote:

@isuruf https://github.com/isuruf Could you please check why shippable
is failing. I keep getting this message

{"id":1005,"message":"Internal API error : getPermissionByProjectId","methodName":"chkPermForId|_getSByProjectId"}


Reply to this email directly or view it on GitHub
#414 (comment).

@abinashmeher999
Copy link
Contributor Author

An unrelated question. The config files are very similar for both travis-ci and shippable. Any specific reason we are testing this at both the places?

@certik
Copy link
Contributor

certik commented Jun 22, 2015

I think that looks good enough to be merged. The shippable failure is just some timeout, that is a bug at Shippable, so I think we can ignore it. Can you create a few nice commits out of these? The 49 commits are not needed in my opinion, as they show some of the dead ends when we were trying to figure out how to write the wrappers. For other people it will be much easier to see in the git history instead of the 49 commits.

Why don't you create a few nice commits, then we can merge it.

@abinashmeher999 abinashmeher999 force-pushed the ruby_file_structure branch 4 times, most recently from 578b16a to a3f217a Compare June 23, 2015 16:40
Deleted Rakefile and extconf.rb
Currently only for operators like +,-,*,/,**,and -@
Rewrote Ruby C wrappers w/o typedefed array basic
- Removed the `basic` type variables because they were not required
- Changed the incorrect code in wrappers
- Removed the `static` qualifier in wrappers
- Added functions for binary, unary op
test passes and also pending tests
Added display messages in CMakeLists.txt for Ruby
Added WITH_RUBY flags to CMakeLists.txt
Added src/ruby/pkg
Added src/ruby/LICENSE
for building and testing the extensions
To avoid file duplication and also gem needs the LICENSE
to support new container-based infrastructure in travis-ci
@abinashmeher999
Copy link
Contributor Author

@certik I have cleaned up the commit history. Please have a look.

@certik
Copy link
Contributor

certik commented Jun 23, 2015

I think this looks very good. +1 to merge if tests pass.

@certik
Copy link
Contributor

certik commented Jun 24, 2015

Tests pass on Travis, merging.

certik added a commit that referenced this pull request Jun 24, 2015
Ruby wrappers initial file structure and Basic class
@certik certik merged commit 1559726 into symengine:master Jun 24, 2015
@certik certik mentioned this pull request Jun 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants