Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Oct 11 23:06
    cairdac-rd starred symengine/symengine
  • Oct 08 08:06
    bjodah closed #1618
  • Oct 08 08:06
    bjodah commented #1618
  • Oct 08 03:58
    certik commented #1618
  • Oct 08 03:17
    isuruf commented #1618
  • Oct 07 15:01
    isuruf commented #1616
  • Oct 07 15:01

    isuruf on master

    add specialization for julia fix namespace Avoid duplicating code and 2 more (compare)

  • Oct 07 15:01
    isuruf closed #1616
  • Oct 07 06:16
    isuruf synchronize #1616
  • Oct 07 06:01
    isuruf synchronize #1616
  • Oct 07 05:41
    Roger-luo synchronize #1616
  • Oct 06 12:08
    bjodah opened #1618
  • Oct 03 18:58
    jmig5776 commented #1617
  • Oct 02 22:33
    certik commented #1617
  • Oct 02 22:26
    certik commented #1617
  • Oct 02 22:24
    certik commented #1617
  • Oct 02 22:13
    certik commented #1617
  • Oct 02 11:55
    darioizzo starred symengine/symengine
  • Oct 02 09:56
    mahge starred symengine/symengine
  • Oct 02 06:44
    jmig5776 commented #1617
Richard Otis
@richardotis
We are SymEngine and LLVM newbies though, if there are any new superpowers we may have gained, please let us know. ;)
Isuru Fernando
@isuruf
Can you post the symbolic expressions for something like mass_hess?
Richard Otis
@richardotis
We could probably pickle the sympy versions of the objects
Isuru Fernando
@isuruf
yeah, that works
python >3.4
Richard Otis
@richardotis
@bocklund probably has a good one for a complex system. With the latest update we're hoping to push beyond the limits of what the commercial codes can do in terms of function complexity
Isuru Fernando
@isuruf
For something like mass_hess, it might be beneficial to have a loop with the data in column major format to get SIMD benefits
Brandon Bocklund
@bocklund

Pickling and unpickling the LLVMDouble does not correctly reset the LLVMDoubleVisitor that is supposed to be in llvm_double[0].

Reproducing the bug

from symengine import symbols
x, y, z = symbols('x y z')
ex = x**2 + y**2 + z**2
from symengine import lambdify
l = lambdify([x, y, z], [ex], backend='llvm')
import pickle
print('pickle.loads(pickle.dumps(l)) == l  :: ', pickle.loads(pickle.dumps(l)) == l)
print(l.__reduce__())
print(pickle.loads(pickle.dumps(l)).__reduce__())

gives

pickle.loads(pickle.dumps(l)) == l  ::  False
(<built-in function llvm_loading_func>, (3, 1, [()], True, 1, 'C', [0, 1], <class 'numpy.float64'>, b"\xcf\xfa\xed\xfe\x07\x00\x00\x01\x03\x00\x00\x00\x01\x00\x00\x00\x04\x00\x00\x00`\x01\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x19\x00\x00\x00\xe8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00`\x00\x00\x00\x00\x00\x00\x00\x80\x01\x00\x00\x00\x00\x00\x00`\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x07\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00__text\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00__TEXT\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\x00\x00\x00\x00\x00\x00\x00\x80\x01\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00__eh_frame\x00\x00\x00\x00\x00\x00__TEXT\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00(\x00\x00\x00\x00\x00\x00\x008\x00\x00\x00\x00\x00\x00\x00\xa8\x01\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0b\x00\x00h\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00$\x00\x00\x00\x10\x00\x00\x00\x00\x0e\n\x00\x00\x00\x00\x00\x02\x00\x00\x00\x18\x00\x00\x00\xe0\x01\x00\x00\x01\x00\x00\x00\xf0\x01\x00\x00\x10\x00\x00\x00\x0b\x00\x00\x00P\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf2\x0f\x10\x07\xf2\x0f\x10O\x08\xf2\x0f\x10W\x10\xf2\x0fY\xd2\xf2\x0fY\xc0\xf2\x0fX\xc2\xf2\x0fY\xc9\xf2\x0fX\xc8\xf2\x0f\x11\x0e\xc3\x00\x14\x00\x00\x00\x00\x00\x00\x00\x01zR\x00\x01x\x10\x01\x10\x0c\x07\x08\x90\x01\x00\x00\x1c\x00\x00\x00\x1c\x00\x00\x00\xb8\xff\xff\xff\xff\xff\xff\xff'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x0e\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00___unnamed_1\x00\x00\x00"))
(<built-in function llvm_loading_func>, (3, 1, [()], True, 1, 'C', [0, 1], <class 'numpy.float64'>, b''))

You can see that the pickled/unpickled version gives an empty byte string for the dumped LLVMDoubleVisitor bytes. @richardotis and I were tracking this down and the issue looks to be that the membuffer is not correctly reset in LLVMDoubleVisitor.loads here when called in self.llvm_double[0].loads as part of the LLVMDouble._load method here. In that case, the root fix would be to set the membuffer in LLVMDoubleVisitor.loads in the same way as LLVMDoubleVisitor.__init__.

A test for this might be to do pickle.loads(pickle.dumps(pickle.loads(pickle.dumps(l)))), which currently will kill the kernel with a LLVM ERROR: The file was not recognized as a valid object file

Isuru Fernando
@isuruf
Want to send a PR?
Brandon Bocklund
@bocklund
I'm not sure what the correct fix for the LLVMDoubleVisitor.loads method looks like
I'm not very fluent in C++
Isuru Fernando
@isuruf
copying the string to membuffer
membuffer = s at the beginning of loads should fix it
Brandon Bocklund
@bocklund
I'll give it a shot. I'll try to set up dev environment so I can test it
Isuru Fernando
@isuruf
(Or just send a PR with a test. CI will catch it)
Btw, pickle.loads(pickle.dumps(l)) == l is always False because they don't have __eq__ implemented.
Brandon Bocklund
@bocklund
Right
I'll open a PR first (symengine/symengine#1549) with an addition to the dump/save test to verify it fails and the test is working as intended, then I'll push the fix
Isuru Fernando
@isuruf
Thanks. I cancelled tests without LLVM
Richard Otis
@richardotis
I'm trying to get a symengine development environment set up and I'm having some trouble. SymEngine builds and the test binaries pass, but when I try to build symengine.py, I get
(calphadpy3) rotis@x86_64-conda_cos6-linux-gnu ~/git/symengine.py (master) $ python setup.py install build_ext --symengine-dir=$HOME/git/symengine/build --inplace                          
running install
running build
running build_ext
SymEngine_DIR : /home/rotis/git/symengine/build/lib/cmake/symengine
SymEngine Version : 0.4.0
-- Python include path: /home/rotis/anaconda3/envs/calphadpy3/include/python3.7m
-- Python version: 3.7
-- Python install path: /home/rotis/anaconda3/envs/calphadpy3/lib/python3.7/site-packages
-- Found CYTHON: cython
CMAKE_BUILD_TYPE        : Release
CMAKE_CXX_FLAGS         : -fvisibility-inlines-hidden -std=c++17 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe 
CMAKE_CXX_FLAGS_RELEASE : -Wall -Wextra -Wno-unused-parameter -fno-common -O3 -march=native -funroll-loops -std=c++11 -fPIC -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -DNDEBUG -fopenmp
CMAKE_CXX_FLAGS_DEBUG   : -Wall -Wextra -Wno-unused-parameter -fno-common -g -ggdb -std=c++11 -fPIC -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fopenmp
HAVE_SYMENGINE_MPFR     : False
HAVE_SYMENGINE_MPC      : False
HAVE_SYMENGINE_PIRANHA  : False
HAVE_SYMENGINE_FLINT    : False
HAVE_SYMENGINE_LLVM     : True
Copying source of python wrappers into: /home/rotis/git/symengine.py
-- Configuring done
-- Generating done
-- Build files have been written to: /home/rotis/git/symengine.py
[ 25%] Building CXX object symengine/lib/CMakeFiles/symengine_wrapper.dir/symengine_wrapper.cpp.o
In file included from /home/rotis/git/symengine/build/lib/cmake/symengine/../../../include/symengine/mp_class.h:7:0,
                 from /home/rotis/git/symengine.py/symengine/lib/symengine_wrapper.cpp:620:
/home/rotis/git/symengine/build/lib/cmake/symengine/../../../include/symengine/mp_wrapper.h:5:10: fatal error: gmp.h: No such file or directory
 #include <gmp.h>
          ^~~~~~~
compilation terminated.
gmake[2]: *** [symengine/lib/CMakeFiles/symengine_wrapper.dir/build.make:69: symengine/lib/CMakeFiles/symengine_wrapper.dir/symengine_wrapper.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:177: symengine/lib/CMakeFiles/symengine_wrapper.dir/all] Error 2
gmake: *** [Makefile:130: all] Error 2
error: error building project
I am on master for both
Richard Otis
@richardotis
Also I have gmp installed on this computer, and my include file is at /usr/include/gmp.h
Richard Otis
@richardotis
It looks like adding "-I/usr/include" to CMAKE_CXX_FLAGS fixed the issue. I think it may be some kind of poor interaction between my conda environment and my system's cmake
specifically, cmake -DCMAKE_CXX_FLAGS="-I/usr/include -L/usr/lib64" seemed to do the trick
Richard Otis
@richardotis
I did eventually fix it and can run lambdify from symengine.py. The problem was some "mixing" between my conda toolchain (gcc 7) and my system toolchain (gcc 9). I rebuilt symengine completely isolated from conda. The line I used was cmake -DCMAKE_INSTALL_PREFIX=$HOME/git/symengine/build -DINTEGER_CLASS=boostmp -DWITH_LLVM=8.0 -DWITH_OPENMP=yes .
Then, still isolated from conda, I went to symengine.py and manually ran cmake -DSymEngine_DIR=$HOME/git/symengine/build . && make
Only at that point did I activate my conda environment and run pip install -e . to make symengine.py available to conda. Everything was built using my system gcc
Marcello
@torshind_gitlab

Hello there. Thanks for your awesome library.
Please have a look to this:

#include <symengine/expression.h>

int main(int argc, char* argv[]) {
  auto x = SymEngine::symbol("x");

  std::cout << "#1: " << SymEngine::Expression(SymEngine::abs(SymEngine::abs(x))) << "\n";
  std::cout << "#2: " << SymEngine::Expression(SymEngine::abs(SymEngine::mul(x, SymEngine::sign(x)))) << "\n";
  std::cout << "#3: " << SymEngine::Expression(SymEngine::floor(SymEngine::ceiling(x))) << "\n";
  std::cout << "#4: " << SymEngine::Expression(SymEngine::ceiling(SymEngine::floor(x))) << "\n";
  return 0;
}

Output:

#1: abs(abs(x))
#2: abs(x*sign(x))
#3: ceiling(x)
#4: floor(x)

Maybe I'm doing something wrong, but I'd expect #1 = #2 = abs(x)
What do you think about that?

Isuru Fernando
@isuruf
@torshind_gitlab, I think we can fix the first one, but the second one is hard. Even sympy cant do it.
Marcello
@torshind_gitlab

@isuruf thank you very much. To be honest I wouldn't even need the second one if the truncate function (aka static_cast<int>) was implemented. In fact, as a temporary solution, I solved it using

SymEngine::mul(SymEngine::sign(lhs), SymEngine::floor(SymEngine::abs(lhs)))

in its place.
Any chance that truncate function will be implemented?

Richard Otis
@richardotis
@isuruf Not sure if this is a big favor to ask, but would it be possible to cut a new release of symengine.py? Our downstream project would like to take advantage of symengine/symengine.py#288 to make some performance improvements
And @bocklund reminds me there's a quality-of-life improvement in main symengine too, symengine/symengine#1549, which we'd love to use as well
Isuru Fernando
@isuruf
@richardotis, if you could help write the release notes at https://github.com/symengine/symengine/wiki/Release-notes-for-v0.4.1 that'll speedup a new release
@torshind_gitlab, I don't have the time to do that, but I'll review a PR if you send one
Richard Otis
@richardotis
@isuruf I added a bit to your draft release notes. I started from symengine/symengine@cab0213 and worked my way to master HEAD. Let me know what you think and if there's anything else I can do to help.
Isuru Fernando
@isuruf
Thanks. I'll do a release this weekend
Richard Otis
@richardotis
Thanks again for your work. Absolute game-changer for our project.
Ondřej Čertík
@certik
@richardotis I am really glad SymEngine is working for you. Are you at the SciPy 2019 conference?
Richard Otis
@richardotis
@certik Not this year, no. There is an annual conference in June I always go to, and hitting a July one as well has always been a tough lift for my employer
I've been trying to convince @bocklund to go and present on his work
I have a March-April conference slot I've been looking to replace with a SciPy-type conference, though.
Ondřej Čertík
@certik
@richardotis no problem I understand. I haven't gone for SciPy in many years until this year I finally made it.
Marcello
@torshind_gitlab
Hello, please have a look at this:
    r1 = add(add(real_double(0.), x), y);
    std::cout << *r1 << std::endl;

    r1 = expand(add(add(real_double(0.), x), y));
    std::cout << *r1 << std::endl;

    r1 = expand(add(x, mul(real_double(4.), y)));
    std::cout << *r1 << std::endl;

    r1 = expand(add(x, mul(real_double(4.), add(y, z))));
    std::cout << *r1 << std::endl;

    r1 = expand(add(x, mul(integer(4), add(y, z))));
    std::cout << *r1 << std::endl;

    r1 = expand(mul(real_double(4.), add(y, z)));
    std::cout << *r1 << std::endl;

    r1 = expand(mul(integer(4), add(y, z)));
    std::cout << *r1 << std::endl;
Output:
x + y
x + y
x + 4.0*y
0.0 + x + 4.0*y + 4.0*z
x + 4*y + 4*z
0.0 + 4.0*y + 4.0*z
4*y + 4*z
Do you have any idea how to eliminate the spurious 0.0 when the coefficients are double?
Isuru Fernando
@isuruf
Its a tough one. We want expand(4.0*(x + y - (x+y))) to give 0.0 instead of 0 to make it clear that the expression is inexact (floating point vs integer)
You can eliminate 0.0 in the final expression by checking if the expression is an Add and if the coefficient is 0.0, remove it
But that doesn't fix 0.0 in intermediate expressions
On second thought, returning 0 for expand(4.0*(x + y - (x+y))) is totally fine