Before DEM Audio, I did a PhD in condensed matter physics at Aix-Marseille University, on electronic transport in graphene and in two-dimensional topological insulators with magnetic disorder (2015). The codes of that thesis were written in Fortran 90 with MPI, with Python 2 for the analysis. This year, after building a boundary element solver for loudspeakers with Claude (the one behind the BEM article), I wanted to see what the same way of working would give on those old codes.
The result is caroli, a Rust toolbox for quantum transport, named after the Caroli formula for the transmission. It is free software, on GitHub and crates.io, and its documentation describes the mathematics and the physics of every method. This article tells how it was made and what it found. It has nothing to do with audio, hence this separate section.
In short
- caroli reproduces the outputs of my thesis codes on 26 test cases, to rounding error, with the same random impurity configurations.
- On the same Hamiltonians, it computes a transmission 4.6 to 20 times faster than the fastest of Kwant, TBtrans and Quantica.jl on one core, with 3 to 4.5 times less memory than Kwant on the largest two-terminal samples.
- A review of its 27,000 lines found one memory error, in a block where the compiler's checks had been switched off for speed. Rewritten with the checks on, that code runs as fast as before.
- Rebuilding the self-consistent Born approximation from the Hamiltonian exposed a sign error in the analysis we published in 2015. With the sign corrected, the Born lines predict the one-channel plateau of our conductance maps over 99.9 % of its points instead of 20 %.
1. Why rewrite old codes
A thesis code is written to produce the figures of a few papers, often by someone who is learning the physics at the same time. Mine did its job. It was also hard to reuse: one program per study, inputs in files with fixed names, MPI in every corner, and a few memory errors that I only found years later.
I wanted a library that someone else could pick up: as complete as Kwant, the reference code of the field, easier to use, faster, and with every result checked against the thesis. Claude, Anthropic's AI model, writes the code under my supervision. I set the scope from the thesis, decide between the options it proposes and check the results. The repository says so from its first line, and nothing is accepted on the model's word.
2. The thesis as a test bench
The first step was to make the old programs run again. I compiled the Fortran with gfortran, a serial stand-in for MPI, LAPACK95 and FFTW, and ran 26 small cases that cover the whole thesis: flake spectra, ribbon bands, two- and four-terminal conductances with magnetic impurities, local currents out of equilibrium, the Born approximation, densities of states by the kernel polynomial method, and graphene under a strong electric field. Their outputs are frozen in the repository. They are the regression baseline of caroli and are never recorded again to make a change pass.
With disorder, the two codes can only be compared if they place the same impurities. caroli's random generator reproduces gfortran's bit for bit, seeding included, and its disorder generators draw in the order of the thesis. The same configurations then give the same numbers: the local currents agree to \(10^{-17}\), the densities of states to \(10^{-15}\), the conductances to \(10^{-13}\).
The thesis codes themselves are not published. Some of them contain code written by collaborators, which is not mine to publish. caroli's models and mathematics were written from their documentation, and only their outputs are in the repository.
When the two codes disagreed, either could be wrong, and more than once it was the thesis. The most widespread error was in every conductance code: the broadening of a lead, \(\Gamma = i\,(\Sigma - \Sigma^\dagger)\), was truncated to its real part. \(\Gamma\) is Hermitian, but it is not real in general. In clean ribbons the truncation put the conductance off by up to 1 %, where caroli gives exact integers. With magnetic impurities on small samples, the thesis formula, which also gave the leads a small imaginary energy, differs from the exact transmission by up to \(0.22\, e^2/h\). On the 400 × 64 ribbons of our published maps the truncation made no visible difference, which caroli checked. The error that mattered most is the subject of section 5.
3. Speed
Most of the speed comes from the algorithms. The thesis computed transmissions slice by slice, with the recursive Green's function, whose cost grows as the length times the cube of the width. caroli uses nested dissection: the sample is cut recursively by thin separator layers into a tree of domains, each node eliminates its separator and passes a small dense matrix to its parent, and the two slices that touch the leads are kept until the end. For an \(n \times n\) sample the cost falls from \(n^4\) to \(n^3\), and the independent branches of the tree run in parallel.
The leads are semi-infinite, and their effect on the sample comes from their propagating and evanescent modes, through a reordered Schur decomposition. It is exact at a real energy, with no artificial broadening. On Apple silicon, the dense linear algebra runs on Accelerate, Apple's LAPACK.
Before any time counts, every code must give the same transmissions on the same exported Hamiltonians. Kwant agrees with caroli to between \(10^{-13}\) and \(10^{-7}\), TBtrans to about \(10^{-5}\) (its electrodes need a small broadening), Quantica.jl to \(10^{-4}\) to \(10^{-3}\). Then, on one core of a Mac mini M4 Pro, the time per energy for disordered samples:
| Sample | caroli | Kwant | Speed-up | Memory, caroli / Kwant |
|---|---|---|---|---|
| Square lattice, 256 × 256 | 0.071 s | 1.07 s | 15× | 152 / 655 MB |
| Square lattice, 512 × 512 | 0.40 s | 6.8 s | 17× | 545 / 1982 MB |
| Graphene, 256 cells wide | 0.33 s | 2.4 s | 7.3× | 312 / 947 MB |
| HgTe quantum well (BHZ), 256 × 256 | 3.2 s | 29 s | 9.1× | 808 / 2942 MB |
At these sizes Kwant is the fastest of the other three codes. On a four-terminal cross the gain reaches 20. On all fourteen cores, for 56 energies, caroli is about ten times faster than Kwant run as fourteen processes, and five times on graphene.
The other example is a quantum walk on a graph whose edges carry spins, a model of K. Sellapillay and A. D. Verga. A scan of 8192 walks of 2000 steps would take 4.4 hours with a Python version written for the comparison (timed on 8 of the walks). It takes 3.7 minutes with caroli in single precision on the CPU and the GPU together, with the same results to \(2 \times 10^{-5}\).
4. Memory safety
In safe Rust, the compiler refuses out-of-bounds writes, uses of freed memory and data races between threads. My thesis codes had a few errors of that kind. In Fortran they go unnoticed until a result looks odd, or they are never noticed at all.
Rust lets a programmer switch the checks off in a block marked unsafe, to call a C library or to go faster. When I had the code reviewed this month, such blocks sat in five files out of 102. Four of these files call system libraries (Accelerate for the linear algebra, Metal and CUDA for the GPU), which cannot be done otherwise. The fifth used a raw pointer so that several threads could write into the state vector of the quantum walk without the compiler's checks, for speed.
The only memory error of the codebase was there. A public function took the state vector without checking its length, and wrote past its end when the vector was too short. Ordinary code could crash the program with one call.
The fix removed the shortcut. The walk now cuts its vector into disjoint slices, which the compiler can check, and hands them to the threads. On every case I tried, rings of 4 to 19 nodes and a graph of degree 3, in double and single precision, on one thread and on all of them, the results are identical to the bit, and the time is the same or shorter. The workspace now refuses unsafe code outside the modules that call system libraries, and every block left there states why it is sound.
5. The sign in the Born approximation
In 2015, with Laurent Raymond and Alberto Verga, we studied a two-dimensional topological insulator, a HgTe quantum well described by the BHZ model, with magnetic impurities. Its two spin blocks each carry one edge channel. The conductance maps showed a phase where disorder takes the conductance from two channels to one, \(G = e^2/h\): an anomalous quantum Hall effect induced by the impurities.
To interpret the maps, we used the self-consistent Born approximation. It replaces the disorder by an averaged self-energy, which renormalises the parameters of each spin block: its mass \(m\), which sets its gap and its topology, and its chemical potential \(\mu\). The Born phase diagram drew the band edges and the lines where a renormalised mass changes sign. These lines followed the conductance maps only loosely, and we were a little disappointed by it at the time. We put it down to the limits of a weak-disorder approximation.
The thesis had two Born programs: a matrix one, and a reduced analytic one, which drew the phase diagram of the paper. caroli reproduces both on their test cases to \(10^{-15}\), so each did what it was written to do. But when caroli computed the matrix form from the Hamiltonian for the parameters of the paper, it disagreed with the reduced one, and the difference was the sign of the mass correction.
The error
The averaged Green's function of a spin block is written as the Green's function of a clean block with renormalised parameters \(\bar m\) and \(\bar\mu\). In our derivation, this definition read
$$ \mathrm{Re}\,\Sigma \equiv -\big[(\bar m - m)\,\tau_z + (\bar\mu - \mu)\,\tau_0\big]. $$
The mass enters the Hamiltonian as \(+m\,\tau_z\) and the chemical potential as \(-\mu\,\tau_0\), so the identification gives
$$ \mathrm{Re}\,\Sigma = (\bar m - m)\,\tau_z - (\bar\mu - \mu)\,\tau_0. $$
The minus sign is right for \(\mu\) and wrong for \(m\). A one-line check shows it: a uniform term \(\delta\,\tau_z\), treated as a self-energy, must shift the mass to \(m + \delta\), and the published definition gives \(m - \delta\). A second, smaller error made the weight of the longitudinal fluctuations of the moments too large, by a factor \(1 + n_I\) for a concentration \(n_I\) of impurities.
Three checks
Three calculations that do not depend on the derivation agree with the corrected sign: the matrix form of the Born approximation, the exact renormalised masses, taken from the disorder-averaged Green's function of large periodic samples (160 × 160 sites, with no approximation), and the spin-resolved conductance of the same ribbons as in the paper. At weak disorder the corrected equations agree with the exact masses to \(10^{-3}\). The published ones move the masses in the opposite direction.

The renormalised masses of the two spin blocks against the coupling \(J_I\) of the impurities. Circles: exact. Dashed: the published Born equations. Solid: corrected. Left, the same-g coupling of the moments to the electrons and holes (the paper's "F" case); right, the opposite-g coupling ("AF"). A block is topological when its mass is negative.
With the right sign, the disorder pushes both masses towards the topological side, as in the topological Anderson insulator that our paper built on. In the same-g case, the spin-down mass never changes sign, so its block keeps its edge channel. The published lines inverted it.
What it changes

The Born lines over our published conductance maps, published on the left, corrected on the right. Top: opposite-g, \(n_I = 0.4\). Bottom: same-g, \(n_I = 0.2\). Light blue: one channel, \(G = e^2/h\); blue: two channels.
In the same-g case, the corrected lines predict one channel on 99.9 % of the points of the plateau, the published lines on 20 %. The corrected lines also predict one channel on part of the crossover before the plateau, so 35 % of the points where they predict it lie on the plateau, against 17 % for the published lines. The plateau begins where the spin-up band, shifted by the mean exchange field, reaches the Fermi level and the disorder localises its states.
In the opposite-g case, the spin-up mass changes sign at \(J_I \simeq 0.40\), where the published equations put it at 0.30. The published line seemed to match the map because the ribbons were 64 sites wide: close to the inversion, the edge states of the two sides overlap and the channel is lost before the mass changes sign. In wider ribbons the transition moves towards the corrected value: 0.32 at 64 sites, 0.355 at 128 and 0.39 at 256.
The numerical results of the paper (the conductance maps, the local currents and the densities of states) are unaffected, and so is its conclusion: a \(G = 1\) Chern-insulator phase carried by the spin-down edge state. What changes is the Born interpretation, which now agrees with the numerics. The full analysis is in a note in the repository.
6. What comes next
caroli's interface may still change. It is used as a Rust library (cargo add caroli) or through a command that reads a system and its calculations from a text file (cargo install caroli-cli), and its documentation covers the mathematics and the physics of each method, with the API reference beside it.
I did this work with Claude, Anthropic's AI model, as a working partner. It wrote the code, the tests and the documentation and drafted this article; I set the scope, chose between its proposals and checked every result against my thesis.
References
- C. Caroli, R. Combescot, P. Nozières and D. Saint-James, Direct calculation of the tunneling current, J. Phys. C: Solid State Phys. 4, 916 (1971).
- L. Raymond, A. D. Verga and A. Demion, Anomalous quantum Hall effect induced by disorder in topological insulators, Phys. Rev. B 92, 075101 (2015), arXiv:1505.07145.
- A. Demion, Transport électronique dans le graphène et les isolants topologiques 2D en présence de désordre magnétique, PhD thesis, Aix-Marseille Université (2015).
- J. Li, R.-L. Chu, J. K. Jain and S.-Q. Shen, Topological Anderson insulator, Phys. Rev. Lett. 102, 136806 (2009).
- C. W. Groth, M. Wimmer, A. R. Akhmerov, J. Tworzydło and C. W. J. Beenakker, Theory of the topological Anderson insulator, Phys. Rev. Lett. 103, 196805 (2009).
- C. W. Groth, M. Wimmer, A. R. Akhmerov and X. Waintal, Kwant: a software package for quantum transport, New J. Phys. 16, 063065 (2014).
- K. Sellapillay and A. D. Verga, Phys. Rev. E 103, 032123 (2021).