Emacs Lisp (nano) cheat sheet

Invoke function (C-x C-e to evaluate)

(f x0 x1)
(f x0 x1 x2)

Function definition

(defun my-fun (x0 x1)
  "function description"
  (+ x0 x1))

Lambda function

(setq my-f (lambda (x y) (+ x y)))
(funcall my-f 1 2)

Setting variables, with quote is the name of the variable
(setq x y) is equivalent to (set (quote x) y)

(setq name "nautilus")
(setq name value)
'x ;; is the name of x, not the value (like the pointer in C)
'(a b c)  ;; is a list
(setq x '(0 1 2 3)) ;; x is a list

To Python or not to Python, to C++ or not to C++ (with MATLAB, MPI, CUDA, and FORTRAN)

Programming in C is the best for scientific computing.

You certainly disagree; tools like MATLAB increase productivity.

I remember when I started working as a researcher, with a lot of computing. I was facing with my professors used to dinosaurs like FORTRAN or C. MATLAB was not used too much, it was more than 20 years ago!

But MATLAB is a very professional tool, it works like a charm, and many scientific papers are done by MATLAB.

Nowadays, however, most of the students love and want to use Python, or more fashionable things like Julia or R. Python is a beauty, and it is a must for machine learning. Python is free (but many universities give access to MATLAB to the students). But I do not find it very professional. You continuously need to tweak the code, or install a missing package, or -worst of all- check with the filesystem permissions or access, because it is an interpreted language. MATLAB is also interpreted, but its ecosystem is stable and well-integrated in operating systems like Windows, OSX, or Linux. Of more than 200 papers that I wrote, only in one so far I used a Python code.

At the end of the day, for professional pictures, I use MATLAB (with some help from Illustrator or Powerpoint or Gimp, etc.). Many codes in my papers are written in MATLAB, as in the recent work on neuromorphic computing with waves. Also, the deep learning toolbox of MATLAB is valuable.

I made some papers on parallel computing, mainly by the MPI protocol. In the beginning, for MPI, I used FORTRAN, but lately (nearly 15 years ago) I switched to C++. I am still writing codes with MPI and C++, and I am practicing CUDA. You can use CUDA in Python, but you understand CUDA only by C++.

But as far as I enter in the details of a code (and I age), improve or optimize, I realize that I am progressively switching back to C. Just pure C (sic!). The reason is that at a lower programming level, I have better control of what the code does, I can understand better the side effects of some routine. In C, dealing with complex variables, or arrays is more clear to me, despite being much more complicated (but using pointers makes you feel a lot smarter!).

As a side effect, the code is simpler to read and understand, but much less cool and modern. Even if, I have to admit that maintaining a code in C++ is still more efficient for me, with respect to FORTRAN or to C, Notably enough, my last FORTRAN paper is dated 2017!

I am not a boomer, so you cannot say “ok boomer”, but I think that this python-mania is not the best for scientific computing and is not the best for students. It not only an issue of speed (and obviously C is the fastest, with FORTRAN as a good competitor). It is also a matter of how to learn to write programs for scientific computing from scratch. For me, to learn and practice scientific computing, the best is still a wise combination of C and C++, with MATLAB for visualization! While Python (and TensorFlow and all of that) gives its best in machine learning.

Emacs, latex, and all that

GNU Emacs is great, superfun

You can play a lot with things like latex, and org-mode, and coding in emacs
I use emacs in windows and linux systems

Windows 10 WSL

I was used to the windows version of emacs 25 in windows 10, but WSL is a supernice tool, thus I recently switched to WSL Ubuntu 20.04, and installed emacs27 via the PPA repository. You may install the APP ubuntu 20.04 in Windows Store. See this post

In windows 10 new need a good X10 server for opening windows, I found that X410 works nicely (it is not freeware)

You need to modify your .bashrc and add

DISPLAY=localhost:0
export DISPLAY

The windows filesystem in the ubuntu WSL terminal is automatically mounted in /mnt/c/Users/

To install emacs27 in ubuntu 20.04 WSL

sudo add-apt-repository ppa:kelleyk/emacs
sudo apt update
sudo apt install emacs27

Ubuntu 20.04

Same as above, works fine

My emacs configuration

As for many Linux things, the nice feature in emacs and all that is that you can easily configure anything. The problem is that you may become addicted in continuously changing the settings, because you do not like the window size, the font, etc. The good news is that this is also true in emacs!

To configure emacs you can either change the file .emacs, whic you can put or find in your home directory. Or you may change the file .emacs.d/init.el where .emacs.d is a config directory that is also in the home. The two methods are exclusive, meaning that either you use .emacs, or .emacs.d/init.el. I prefer to used .emacs.d/init.el as it is more recent.

For example, if you want to change the font, you have to put the following line in .emacs.d/init.el

(set-face-attribute 'default (selected-frame) :height 100)

This may seem weird, as it is not something like fontsize=12, but it is a glimpse into the supersmart world of Lisp. Indeed emacs is written in Lisp, a proper Lisp, the “emacs-lisp” and that is the reason why emacs is so cool.

to be continued

Experiments on adiabatic evolution in Ising machines in Optica

Combinatorial optimization problems are crucial for widespread applications but remain difficult to solve on a large scale with conventional hardware. Novel optical platforms, known as coherent or photonic Ising machines, are attracting considerable attention as accelerators on optimization tasks formulable as Ising models. Annealing is a well-known technique based on adiabatic evolution for finding optimal solutions in classical and quantum systems made by atoms, electrons, or photons. Although various Ising machines employ annealing in some form, adiabatic computing on optical settings has been only partially investigated. Here, we realize the adiabatic evolution of frustrated Ising models with 100 spins programmed by spatial light modulation. We use holographic and optical control to change the spin couplings adiabatically, and exploit experimental noise to explore the energy landscape. Annealing enhances the convergence to the Ising ground state and allows to find the problem solution with probability close to unity. Our results demonstrate a photonic scheme for combinatorial optimization in analogy with adiabatic quantum algorithms and classical annealing methods but enforced by optical vector-matrix multiplications and scalable photonic technology.

https://www.osapublishing.org/optica/fulltext.cfm?uri=optica-7-11-1535&id=442147

See also https://arxiv.org/abs/2005.08690