zanellia / prometeo Goto Github PK
View Code? Open in Web Editor NEWAn experimental Python-to-C transpiler and domain specific language for embedded high-performance computing
License: BSD 2-Clause "Simplified" License
An experimental Python-to-C transpiler and domain specific language for embedded high-performance computing
License: BSD 2-Clause "Simplified" License
Hey, after reading a little bit about this project, I love it but I'm a little confused one a few parts; does it transpile to exe? Or what does it transpile the python code to so users can run? Also; would I have to write my python programs in such a way so prometeo is able to access and execute it?
TY.
This is part of a brainstorming with the development team on how to define meta-information structures for classes and methods within prometeo's parser. Rough draft:
class ClassA:
def __init__(self):
self.attr1 : int = 0
def method1(self, arg1 : int) -> int:
return self.attr1 + arg1
class ClassB:
def __init__(self):
self.attr1 : int = 0
self.attr2 : ClassA = ClassA()
def method1(self, arg1 : int) -> ClassA:
return self.attr2
[
'ClassA' : [
'constructor_args' :
[('self', 'self')],
'attributes' :
[('attr1', 'int', 0)],
'methods' : [
'method1' :
'args' :
[('self','self'), ('arg1', 'int')],
'return_type' : 'int'
]
]
]
[
'ClassB' : [
'constructor_args' :
[('self', 'self')],
'attributes' :
[('attr1', 'int', 0), ('attr2', 'ClassA', 'None')],
'methods' : [
'method1' :
'args' :
[('self','self'), ('arg1', 'int')],
'return_type' : 'ClassA'
]
]
]
Sorry if I've missed something, but is there a method you have to allow tests to run on the transpiled C to ensure it's working? (and presumably that it gives the same results as the python code, unless you've got some way of being 100% sure that is guaranteed due to your language restrictions)
As of now, only class attributes are implemented.
As of now sized type checking is carried out in a rather case-specific fashion. At some point, the typed_record (https://github.com/zanellia/prometeo/blob/master/prometeo/cgen/code_gen_c.py#L324) and the var_dim_record (https://github.com/zanellia/prometeo/blob/master/prometeo/cgen/code_gen_c.py#L328) generated during the static analysis should be merged into a single dictionary and they should support any valid sized type e.g
n : dims = 10
A : pmat = pmat(n,n)
class ClassA():
A : pmat = pmat(n,n)
class ClassB():
A : pmat = pmat(n,n)
B : ClassA = ClassA()
As of now 1) and 2) work fine, but to support 3) and more sophisticated user-defined sized types the code needs some restructuring.
In particular, if we analyze
from prometeo import *
n : dims = 10
class ClassA():
A : pmat = pmat(n,n)
def main() -> int:
A : pmat = pmat(n,n)
return 0
it will result in the following typed_record:
{
"global": {
"n": "dims"
},
"global@ClassA": {
"A": "pmat"
},
"global@main": {
"A": "pmat"
}
}
and the following var_dim_record:
{
"global": {},
"global@ClassA": {
"A": [
"n",
"n"
]
},
"global@main": {
"A": [
"n",
"n"
]
}
}
It should suffice mangling function and method names everywhere.
macOs BigSur 11.4
MacBookPro 13-inch, M1, 2020
I cloned the repo, installed with pip install -e .
, ran ipython, and tried import prometeo
. I get the error:
Python 3.8.8 (default, Apr 13 2021, 12:59:45)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.22.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import prometeo
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-1-371e560288bc> in <module>
----> 1 import prometeo
~/repos/lib/prometeo/prometeo/__init__.py in <module>
1 from . import cgen
----> 2 from . import linalg
3 from . import mem
4 from . import auxl
5 from . import cmdline
~/repos/lib/prometeo/prometeo/linalg/__init__.py in <module>
----> 1 from .pmat_blasfeo_wrapper import *
2 from .pvec_blasfeo_wrapper import *
3 from .pmat import *
4 from .pvec import *
5 from .blasfeo_wrapper import *
~/repos/lib/prometeo/prometeo/linalg/pmat_blasfeo_wrapper.py in <module>
----> 1 from .blasfeo_wrapper import *
2 from ctypes import *
3
4
5 bw.blasfeo_dgeex1.restype = c_double
~/repos/lib/prometeo/prometeo/linalg/blasfeo_wrapper.py in <module>
2 import os
3
----> 4 bw = CDLL(os.path.dirname(__file__) + '/../lib/blasfeo/libblasfeo.so')
5
6 class blasfeo_dmat(Structure):
~/opt/anaconda3/lib/python3.8/ctypes/__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error, winmode)
379
380 if handle is None:
--> 381 self._handle = _dlopen(self._name, mode)
382 else:
383 self._handle = handle
OSError: dlopen(/Users/vas/repos/lib/prometeo/prometeo/linalg/../lib/blasfeo/libblasfeo.so, 6): image not found
Hi!
I was looking forward to installing the module but came across this error while trying to install the module on Python v3.9.10:
C:\Users\HP>py -3.9 -m pip install prometeo-dsl
ERROR: Ignored the following versions that require a different python version: 0.0.1 Requires-Python >=3.6, <=3.9; 0.0.10 Requires-Python >=3.6, <=3.9; 0.0.2 Requires-Python >=3.6, <=3.9; 0.0.3 Requires-Python >=3.6, <=3.9; 0.0.4 Requires-Python >=3.6, <=3.9; 0.0.5 Requires-Python >=3.6, <=3.9; 0.0.6 Requires-Python >=3.6, <=3.9; 0.0.7 Requires-Python >=3.6, <=3.9; 0.0.9 Requires-Python >=3.6, <=3.9
ERROR: Could not find a version that satisfies the requirement prometeo-dsl (from versions: none)
ERROR: No matching distribution found for prometeo-dsl
The current interface to BLAS and LAPACK routines should be made more flexible, in the sense that different levels of granularity should be accessible though the same method without adding unnecessary complexity to simple calls. Below is a draft signature for gemm
suggested by @giaf:
gemm(A[1:2,1:2], B.T, C[3:4,1:2], D=None, alpha=1.0, beta=1.0)
,
where A
, B
, C
and D
can also be transposed through e.g. A.T
and views are possible too, for example:
gemm(A[1:2,1:2], B.T, C[3:4,1:2], D, beta=2.0)
.
This is easily implementable in Python, but will require some work in prometeo's parser. In particular in the argument inspection here
prometeo/prometeo/cgen/code_gen_c.py
Line 1826 in f45a634
we'd need to do something like this:
nargs = len(args)
# extract keyword arguments
...
# check expression in views (if any) using https://github.com/zanellia/prometeo/blob/f45a6347ea524164cc812fad80c9db1f4f94e17f/prometeo/cgen/code_gen_c.py#L244
# extract and unparse views of matrix arguments (if any)
first_index = astu.unparse(node.targets[0].slice.value.elts[0]).strip('\n')
second_index = astu.unparse(node.targets[0].slice.value.elts[1]).strip('\n')
# check for transposition (look if arg has an attribute an if it is 'T')
# pass this info to a generic `process_arg()` method
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.