GithubHelp home page GithubHelp logo

asanet / dasslc2py Goto Github PK

View Code? Open in Web Editor NEW
14.0 5.0 9.0 410 KB

Dasslc is a solver for differential-algebraic equations inspired by DASSL. A python module for dasslc is provided.

License: MIT License

Shell 0.01% C 91.36% Python 1.36% TeX 6.57% Roff 0.54% Makefile 0.16%
c mit python

dasslc2py's Introduction

Python wrapper for DASSLC

This is a simple wrapper for using the "Differential-Algebraic System Solver in C" by Argimiro R. Secchi (PEQ/COPPE/UFRJ) in python.

Getting Started

All the information about the usage of this package can be found in example file

Dasslc2py/dasslc_example.py

Prerequisites

  • C compiler:
archlinux: $ sudo pacman -S gcc gcc-libs

Python 3 with numpy, pip and (optionally) matplotlib

archlinux: $ sudo pacman -S python python-numpy python-matplotlib
OBS: matplotlib is needed by the **dasslc_example.py** file
  • If you want sparse algebra support, you need to first compile Sparse. On linux, open a terminal in sparse/src directory and run:
$ make

Installing

  • In order to locally build this module, open a terminal at the dir Dasslc2py and run the following command
$ python setup.py build_ext --inplace
  • Instead, if you want to install it along with your python distribution, run
$ pip install .

Author

dasslc2py's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

dasslc2py's Issues

fails to build on colab with current compiler gcc11

< gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 >

ERROR:

$ python setup.py build_ext --inplace

-> COMPILING dasslc.c works
-> COMPILING dasslcmodule.c works
-> LINKING dasslc.cpython-310-x86_64-linux-gnu.so fails

-> log

/usr/bin/ld: build/temp.linux-x86_64-cpython-310/dasslcmodule.o:/content/dasslc2py/dasslc2py/dasslc/dasslc.h:551: multiple definition of `user_init'; build/temp.linux-x86_64-cpython-310/dasslc/dasslc.o:/content/dasslc2py/dasslc2py/dasslc/dasslc.h:551: first defined here

/usr/bin/ld: build/temp.linux-x86_64-cpython-310/dasslcmodule.o:/content/dasslc2py/dasslc2py/dasslc/dasslc.h:550: multiple definition of `ujacFree'; build/temp.linux-x86_64-cpython-310/dasslc/dasslc.o:/content/dasslc2py/dasslc2py/dasslc/dasslc.h:550: first defined here

/usr/bin/ld: build/temp.linux-x86_64-cpython-310/dasslcmodule.o:/content/dasslc2py/dasslc2py/dasslc/dasslc.h:549: multiple definition of `ujacPrint'; build/temp.linux-x86_64-cpython-310/dasslc/dasslc.o:/content/dasslc2py/dasslc2py/dasslc/dasslc.h:549: first defined here

/usr/bin/ld: build/temp.linux-x86_64-cpython-310/dasslcmodule.o:/content/dasslc2py/dasslc2py/dasslc/dasslc.h:548: multiple definition of `ujacSolve'; build/temp.linux-x86_64-cpython-310/dasslc/dasslc.o:/content/dasslc2py/dasslc2py/dasslc/dasslc.h:548: first defined here

/usr/bin/ld: build/temp.linux-x86_64-cpython-310/dasslcmodule.o:/content/dasslc2py/dasslc2py/dasslc/dasslc.h:547: multiple definition of `ujacFactor'; build/temp.linux-x86_64-cpython-310/dasslc/dasslc.o:/content/dasslc2py/dasslc2py/dasslc/dasslc.h:547: first defined here

collect2: error: ld returned 1 exit status

WORKAROUND:

DASSLC.C modificado a partir da linha 120

//120
#include "dasslc.h"

//>>+
BOOL (*ujacFactor) (PTR_ROOT *);
BOOL (*ujacSolve) (PTR_ROOT *, REAL *, REAL *);
void (*ujacPrint) (PTR_ROOT *);
void (*ujacFree) (PTR_ROOT *);
BOOL (*user_init) (PTR_ROOT *);
//<<+

DASSLC.H modificado na linha 543

//543
/* user provided functions */
#ifndef DASSLC_H
#  define DASSLC_H

//>>-
//BOOL (*ujacFactor) (PTR_ROOT *);
//BOOL (*ujacSolve) (PTR_ROOT *, REAL *, REAL *);
//void (*ujacPrint) (PTR_ROOT *);
//void (*ujacFree) (PTR_ROOT *);
//BOOL (*user_init) (PTR_ROOT *);
//<<-

#endif /* DASSLC_H */

em resumo, comentei 5 linhas do DASSLC.H e adicionei elas manualmente no DASSLC.C

Cannot install package

Hello, Great work. Unfortunately, I was not able to install the package. I reproduced below the error message. Please, I would be very grateful if you could help me to figure it out. I need this piece of software to work on my thesis. Thanks.

As recommended in the README, I've run the following command:

sudo python3 setup.py instal (Also tried the local installation, same issue)

And obtained the following error. Important to say, apparently the dasslc module is installed in my python env, however no methods are shown. Trying to run the example, the interpreter complains about 'solve' method that is absent. It endorsed the hypothesis that the method are installed, however the compilation of the C code is failing (as shown below).

running install
running build
running build_ext
building 'dasslc' extension
C compiler: x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC

compile options: '-I/usr/local/lib/python3.5/dist-packages/numpy/core/include -I/usr/include/python3.5m -c'
x86_64-linux-gnu-gcc: dasslc/dasslc.c
x86_64-linux-gnu-gcc: dasslcmodule.c
In file included from dasslcmodule.c:27:0:
dasslc/dasslc.h:457:2: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
  SET (*vfunc)();
  ^
dasslcmodule.c: In function ‘jacobian’:
dasslcmodule.c:524:17: warning: implicit declaration of function ‘daSparse_value’ [-Wimplicit-function-declaration]
                 daSparse_value(pd,i,j) = *(double*)PyArray_GETPTR2(pd_array,i,j);
                 ^
dasslcmodule.c:524:40: error: lvalue required as left operand of assignment
                 daSparse_value(pd,i,j) = *(double*)PyArray_GETPTR2(pd_array,i,j);
                                        ^
In file included from dasslcmodule.c:27:0:
dasslc/dasslc.h:457:2: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
  SET (*vfunc)();
  ^
dasslcmodule.c: In function ‘jacobian’:
dasslcmodule.c:524:17: warning: implicit declaration of function ‘daSparse_value’ [-Wimplicit-function-declaration]
                 daSparse_value(pd,i,j) = *(double*)PyArray_GETPTR2(pd_array,i,j);
                 ^
dasslcmodule.c:524:40: error: lvalue required as left operand of assignment
                 daSparse_value(pd,i,j) = *(double*)PyArray_GETPTR2(pd_array,i,j);
                                        ^
error: Command "x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/local/lib/python3.5/dist-packages/numpy/core/include -I/usr/include/python3.5m -c dasslcmodule.c -o build/temp.linux-x86_64-3.5/dasslcmodule.o" failed with exit status 1

Installing procedures

Hi,

I have Windows 10 and Python 3.12 running. What are the procedures to install dasslc2?

Thanks

Problems with user provided functions causing duplicate symbol

Hi Ataíde,

I am trying to compile it using MacOS I found two problems:

(1) Dasslc includes an malloc.h dependence that for MacOS is not valid. As malloc.h is included in stdio.h, I commented this line in Dasslc and it solved. I recommended a compilation directive to Argimiro specific for MacOS.

(2) Dasslc user provided functions are causing a duplicate symbol error when compiling dasslc and dasslc_module together:

duplicate symbol '_ujacPrint' in: build/temp.macosx-10.9-x86_64-3.8/dasslcmodule.o build/temp.macosx-10.9-x86_64-3.8/dasslc/dasslc.o duplicate symbol '_user_init' in: build/temp.macosx-10.9-x86_64-3.8/dasslcmodule.o build/temp.macosx-10.9-x86_64-3.8/dasslc/dasslc.o duplicate symbol '_ujacFactor' in: build/temp.macosx-10.9-x86_64-3.8/dasslcmodule.o build/temp.macosx-10.9-x86_64-3.8/dasslc/dasslc.o duplicate symbol '_ujacSolve' in: build/temp.macosx-10.9-x86_64-3.8/dasslcmodule.o build/temp.macosx-10.9-x86_64-3.8/dasslc/dasslc.o duplicate symbol '_ujacFree' in: build/temp.macosx-10.9-x86_64-3.8/dasslcmodule.o build/temp.macosx-10.9-x86_64-3.8/dasslc/dasslc.o ld: 5 duplicate symbols for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

To solve it I defined these objects as extern in dasslc. Don't you have a similar problem?

Thanks for the excellent job in dasslc2py.

Cannot compile sparse on Ubuntu 18.04

Hi, Ataíde.

This is the compiling output

(ML) ggus@CHBE-AM-GUSMAOG:~/RESEARCH/dasslc2py/sparse/src$ sudo make
gcc -O -fPIC   -c -o spAllocate.o spAllocate.c
gcc -O -fPIC   -c -o spBuild.o spBuild.c
spBuild.c: In function ‘spFindElement’:
spBuild.c:187:20: warning: overflow in implicit constant conversion [-Woverflow]
 int StartAt, Min = LARGEST_LONG_INTEGER;
                    ^~~~~~~~~~~~~~~~~~~~
gcc -O -fPIC   -c -o spFactor.o spFactor.c
gcc -O -fPIC   -c -o spOutput.o spOutput.c
gcc -O -fPIC   -c -o spSolve.o spSolve.c
gcc -O -fPIC   -c -o spUtils.o spUtils.c
gcc -O -fPIC   -c -o spFortran.o spFortran.c
ar r   ../lib/sparse.a spAllocate.o spBuild.o spFactor.o spOutput.o spSolve.o spUtils.o spFortran.o
ar: creating ../lib/sparse.a
ranlib ../lib/sparse.a
gcc -O -fPIC   -c -o spTest.o spTest.c
spTest.c:69:33: warning: conflicting types for built-in function ‘strlen’ [-Wbuiltin-declaration-mismatch]
 extern int strcmp(), strncmp(), strlen();
                                 ^~~~~~
spTest.c: In function ‘Time’:
spTest.c:141:11: warning: implicit declaration of function ‘times’; did you mean ‘Time’? [-Wimplicit-function-declaration]
     (void)times(&time);
           ^~~~~
           Time
spTest.c: In function ‘main’:
spTest.c:360:9: warning: implicit declaration of function ‘exit’ [-Wimplicit-function-declaration]
         exit(1);
         ^~~~
spTest.c:360:9: warning: incompatible implicit declaration of built-in function ‘exit’
spTest.c:360:9: note: include ‘<stdlib.h>’ or provide a declaration of ‘exit’
spTest.c:710:61: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
         printf("    Virtual memory used = %d kBytes.\n\n", ((int)sbrk(0))/1000);
                                                             ^
spTest.c: In function ‘ReadMatrixFromFile’:
spTest.c:897:13: warning: incompatible implicit declaration of built-in function ‘exit’
             exit(1);
             ^~~~
spTest.c:897:13: note: include ‘<stdlib.h>’ or provide a declaration of ‘exit’
spTest.c: In function ‘CheckOutComplexArray’:
spTest.c:157:38: warning: implicit declaration of function ‘malloc’ [-Wimplicit-function-declaration]
 #define  ALLOC(type,number) ((type *)malloc((unsigned)(sizeof(type)*(number))))
                                      ^
spTest.c:1068:16: note: in expansion of macro ‘ALLOC’
     {   pBin = ALLOC( struct Bin, 1);
                ^~~~~
spTest.c:157:38: warning: incompatible implicit declaration of built-in function ‘malloc’
 #define  ALLOC(type,number) ((type *)malloc((unsigned)(sizeof(type)*(number))))
                                      ^
spTest.c:1068:16: note: in expansion of macro ‘ALLOC’
     {   pBin = ALLOC( struct Bin, 1);
                ^~~~~
spTest.c:157:38: note: include ‘<stdlib.h>’ or provide a declaration of ‘malloc’
 #define  ALLOC(type,number) ((type *)malloc((unsigned)(sizeof(type)*(number))))
                                      ^
spTest.c:1068:16: note: in expansion of macro ‘ALLOC’
     {   pBin = ALLOC( struct Bin, 1);
                ^~~~~
spTest.c:1073:13: warning: incompatible implicit declaration of built-in function ‘exit’
             exit(1);
             ^~~~
spTest.c:1073:13: note: include ‘<stdlib.h>’ or provide a declaration of ‘exit’
spTest.c: In function ‘Usage’:
spTest.c:1289:5: warning: incompatible implicit declaration of built-in function ‘exit’
     exit(1);
     ^~~~
spTest.c:1289:5: note: include ‘<stdlib.h>’ or provide a declaration of ‘exit’
spTest.c: In function ‘EnlargeVectors’:
spTest.c:1318:13: warning: implicit declaration of function ‘free’ [-Wimplicit-function-declaration]
         {   free( (char *)Solution );
             ^~~~
spTest.c:1318:13: warning: incompatible implicit declaration of built-in function ‘free’
spTest.c:1318:13: note: include ‘<stdlib.h>’ or provide a declaration of ‘free’
spTest.c:157:38: warning: incompatible implicit declaration of built-in function ‘malloc’
 #define  ALLOC(type,number) ((type *)malloc((unsigned)(sizeof(type)*(number))))
                                      ^
spTest.c:1321:15: note: in expansion of macro ‘ALLOC’
         RHS = ALLOC( RealNumber, SCALE*(NewSize+1) );
               ^~~~~
spTest.c:157:38: note: include ‘<stdlib.h>’ or provide a declaration of ‘malloc’
 #define  ALLOC(type,number) ((type *)malloc((unsigned)(sizeof(type)*(number))))
                                      ^
spTest.c:1321:15: note: in expansion of macro ‘ALLOC’
         RHS = ALLOC( RealNumber, SCALE*(NewSize+1) );
               ^~~~~
spTest.c:1327:13: warning: incompatible implicit declaration of built-in function ‘exit’
             exit(1);
             ^~~~
spTest.c:1327:13: note: include ‘<stdlib.h>’ or provide a declaration of ‘exit’
spTest.c:1357:27: warning: incompatible implicit declaration of built-in function ‘free’
         if (MaxSize != 0) free( (char *)OldRHS );
                           ^~~~
spTest.c:1357:27: note: include ‘<stdlib.h>’ or provide a declaration of ‘free’
gcc -O -fPIC -o ../bin/sparse spTest.o ../lib/sparse.a -lm

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.