Accelerate Python code by importing Taichi
docs.taichi-lang.org
docs.taichi-lang.org
Taichi vs. Numba: As its name indicates, Numba is tailored for Numpy. Numba is recommended if your functions involve vectorization of Numpy arrays. Compared with Numba, Taichi enjoys the following advantages:
Taichi supports multiple data types, including struct, dataclass, quant, and sparse, and allows you to adjust memory layout flexibly. This feature is extremely desirable when a program handles massive amounts of data. However, Numba only performs best when dealing with dense NumPy arrays. Taichi can call different GPU backends for computation, making large-scale parallel programming (such as particle simulation or rendering) as easy as winking. But it would be hard even to imagine writing a renderer in Numba.
1) "Diffussion" is species vs time equals species spatial laplacian.
2) The "reaction" equations are non-painfully derived from Baez stochastic Petri nets/chemical reaction networks in [1] (species vs time = multivariate polynomial in species, "space dependant rate equation")
So Reaction-Diffusion is just adding up. Species vs time = species spatial laplacian plus multivariate polynomial in species. One more for the toolbox!
Then the diffusive part says
du(x, t)/dt = \nabla_x u(x, t).
The \nabla term is the laplacian: a multivariate form of the second derivative.
The equation says that a short time from now, u(x, t) will change in proportion to the average value of u, calculated over a small ball surrounding the point x, minus the value of u at the point x itself.
If there's less "stuff" in the points that neighbour x than at x itself, the function will decrease over time. Similarly if there's more stuff at the neighbours of x, u(x, t) will increase. This is the basis of diffusive behaviour.
(Edit: I think the equation in the article is wrong, unless I've misunderstood something: they have a delta (first derivative) when they should have a nabla (laplacian))
From what I understand, just \nabla(f) describes the gradient of a function f -- meaning all the first order partial derivatives (of a certain point) in a vector.
\nabla * f describes the divergence of the function f -- meaning a scalar field of the quantity of the vector field's sources at each point.
\nabla * \nabla(f), divergence of gradient, then describes the Laplace operator. Also written as \nabla^2(f) or \Delta(f) -- note that it's an uppercase delta.
Maybe there are add-ons that detect valid LaTeX math symbols and convert them whenever possible but as-is you can't get it to render within the comments.
Mathematicians and biologists have a hammer, so everything looks like a nail.
An extremely interesting area. I keep wanting to use it for something but haven't had a good use case yet, nor frankly do I think I really understand it.
how faster can the code in those SO answers be?
https://stackoverflow.com/questions/73473074/speed-up-set-pa...
This code is recursive and generate set partitions for large N values (N larger than 12), it essentially works by skipping small partitions and small subsets to target desirable set partitions. Solutions that don't skip those suffer from "combinatory explosion".
I did not write this code, I want to test it later with taichi, but I'm curious if taichi can run this faster.
Regarding Nutika AFAIK its goal is not a speed up and performance gains are pretty modest in most cases.
Was Nuitka better? Pythran is quite simple to install and use in Jupyter.
Nuitka aims for 100% compatibility first. If you have some random python code that works under CPython, but not Nuitka, then that is a bug that will be fixed. To achieve this compatibility there are a lot of optimisations that cannot be done. If you have code that works under both Nuitka and Pythran then it will almost certainly be faster in Pythran.
EDIT: title of the thread was "Accelerate Python code 100x by import taichi as ti" like TFA
*may have been fixed in recent versions of Python - I heard of this many years ago!
Because any reference in the whole hierarchy could change during the looping (e.g. one could say “multiple.levels = {}” at some point), the interpreter really would need to check it every time unless it can somehow “prove” that these changes will never happen / haven’t happened.
Just keeping a reference to “a” is semantically very different, and I’d consider that a normal optimisation.
def f(i):
...
def g():
_f = f
for i in range(100000):
_f(i)
because looking up a local variable was faster than looking up a global. I'm not sure if that's still true in newer versions.Which entity is behind this? Usually you have some details on the genesis of projects like this.
I will never get approval to use this on the HPC systems of my org if its developed by an unknown entity in China ( as the wechat link might indicate ), which is sad since it looks useful.
Crunchbase lists their headquarter as Beijing.
Taichi supports multiple data types, including struct, dataclass, quant, and sparse, and allows you to adjust memory layout flexibly. This feature is extremely desirable when a program handles massive amounts of data. However, Numba only performs best when dealing with dense NumPy arrays. Taichi can call different GPU backends for computation, making large-scale parallel programming (such as particle simulation or rendering) as easy as winking. But it would be hard even to imagine writing a renderer in Numba.
any Taichi v Julia benchmarks?
https://www.semanticscholar.org/paper/The-chemical-basis-of-...
This does not sound correct. Why would there be a tradeoff between readability and performance?
That said, the readability itself shouldn't have much to do with the performance, as many reimplementations of the Python runtime already show.
For example, the prime-counting example in the article could've been optimised slightly by inlining the is_prime function into the body of the count_primes function (thus removing the overhead of calling a function).
My comment simply observes the reality, and does not recommend any given practice.
bwasti@bwasti-mbp code % time python3 prime.py
78498
python3 prime.py 3.86s user 0.02s system 98% cpu 3.938 total
bwasti@bwasti-mbp code % time bun prime.js
78498
bun prime.js 0.07s user 0.02s system 74% cpu 0.125 total src time node primes.js
78498
node primes.js 1.75s user 0.05s system 102% cpu 1.761 total
src time node --jitless primes.js
78498
node --jitless primes.js 5.06s user 0.04s system 100% cpu 5.088 total
src time python primes.py
78498
python primes.py 4.27s user 0.03s system 100% cpu 4.276 total
src asdf shell python pypy3.9-7.3.9
src time python primes.py
78498
python primes.py 0.91s user 0.07s system 100% cpu 0.970 total
Actually relatively on par with one another.I think I found your problem. TBH you might like Julia more than Python and you won't have to invent a new DSL in the process.
Not too far off. This paper [0] compared 27 languages for speed and energy efficiency (which is very interesting).
Python was 72 times slower than C and consumed 76 times more energy.
I think Python is a very useful language at many levels. Great for prototyping stuff. No doubt about that. If performance and energy efficiency are important, it seems obvious one has to look elsewhere.
Not if you're porting from Fortran in the first place as the author claims.
Specially with SYCL or CUDA with standard C++ latest efforts.
def is_prime(n: int):
result = True
for k in range(2, int(n ** 0.5) + 1):
if n % k == 0:
result = False
break
return result
Which is just a more complicated (n % 2 != 0). Obviously the break should be in the if block.* Tosses doctoral thesis in the trash.