Python
This is a list of some of my projects in Python. It ranges from small scripts to small packages.
spikingtorch
Implementation of backpropagation through spikes in pytorch. Link to the source code in github: spikingtorch
machball
Implementation of an absorbing Markov chain model for reactive ballistic transport, including the simulation of self-limited growth inside nanostructures. Link to the source code in github: machball
gris
Simple package for reading/writing bibliographic entries in RIS format. Link to Python package. You can find the source code in github: gris
While still bumpy, we used this package to extract the information in our work on the evolution of ALD research community
dcel
This package implements a doubly connected edge list and a 2D polygonal map with basic functionality for saving/reading from file and plotting postscript and eps figures of the 2D maps. Source code though github: dcel.
fresnel
Package to simulate the simulation of light with surfaces and multilayers. Source code available through github: fresnel.
Others:
python + beamer
This is a simple snippet to collect a series of image files on a pdf slideshow using beamer.
The following gist reads a csv file with three columns containing a filename, a title for your slide and some description, and prints out latex output based on the beamer package:
Then the only thing that you have to do is to redirect the output to a file, and use latex or pdflatex.
fpython
Transforming python into a pseudo functional programming language
fpython is the result of a simple experiment looking into using Python to implement a small programming language based on variable and function definitions. The right hand side of each assignment will be a Python expression. However, except for import and output statements, all expressions will be assigned to a variable or a function.
In Python, there are two ways of defining functions: using def
and
lambda
. Instead, in math the way you typically define a function is as
follows:
fpython defines functions using this assignment syntax, and it
transforms the source into the corresponding Python code using lambda
functions.
This is an example of the fpython interpreter:
fpython 0.1.0
... 100 years transforming Python
into a pseudo-functional programming language...
>>> import math as m
>>> f(x) = m.sin(x)
>>> a = f(1)
>>> print a
0.841470984808
>>> a
fpython SyntaxError: not a valid assignment
>>> ^D
Implementation details
At the core of fpython interface is the code module of python's standard library. This module defines the InteractiveConsole class, which helps implement read-eval-print loops in Python. By subclassing InteractiveConsole, our input is first transformed into python code and this code is then pushed into the Python interpreter:
As it is shown above, our push
method handles line continuation. It
then passes the resulting source to transform
, which takes care of
parsing the function definition and returning the modified source. If no
function is identified, transform
returns None
as the first element
of the tuple, in which case the first token is checked against the
import and output keywords.
Finally, we can use Fpython
both as an interactive console or as an
interpreter:
In total, less than 200 lines of code.