DEM Audiocaroli Documentation
APIGitHub

Disorder


On this page

Disorder in caroli is a site-dependent term of the model, drawn from a reproducible random stream. The crate caroli-disorder provides the stream and the two disorders of the thesis, Anderson disorder and classical magnetic impurities, drawn in the order and with the formulas of the thesis codes, so that their configurations can be rebuilt bit for bit. Any other disorder (bond disorder, smooth potentials, vacancies) is a site-dependent term of one's own. One draw is a configuration: the transport, Keldysh, spectral and dynamical methods work on one configuration at a time, and the caller averages over many. The self-consistent Born approximation averages analytically, from the moments of the distributions given below.


Random streams

xoshiro256**

All the randomness of caroli comes from xoshiro256** (Blackman and Vigna), a generator with a fixed definition: the same seed gives the same stream on every platform and in every version of caroli, which a generator borrowed from a library that may change its algorithm would not guarantee. Its state is four 64-bit words \(s_0, \dots, s_3\), its period \(2^{256} - 1\). Each step returns

$$ x = \mathrm{rotl}(5 s_1, 7) \times 9 $$

and updates the state with \(t = s_1 \ll 17\), then, in this order, \(s_2 \leftarrow s_2 \oplus s_0\), \(s_3 \leftarrow s_3 \oplus s_1\), \(s_1 \leftarrow s_1 \oplus s_2\), \(s_0 \leftarrow s_0 \oplus s_3\), \(s_2 \leftarrow s_2 \oplus t\) and \(s_3 \leftarrow \mathrm{rotl}(s_3, 45)\), all in 64-bit arithmetic modulo \(2^{64}\) (\(\oplus\) is the bitwise exclusive or, \(\ll\) a left shift and \(\mathrm{rotl}\) a left rotation).

DrawFormula
next_u64()The 64 bits \(x\)
uniform()\(u = \lfloor x / 2^{11} \rfloor \cdot 2^{-53}\), uniform in \([0, 1)\) with 53 random bits, as gfortran's random_number for real(8)
uniforms(n)\(n\) uniforms in a row, as random_number on an array
integer(lo, hi)\(lo + \lfloor (hi - lo + 1)\, u \rfloor\), uniform in \(lo, \dots, hi\) (the thesis routine random_integer)

Seeding

Xoshiro256::seed_from_u64(seed) fills the state with four outputs of splitmix64, as the authors of xoshiro recommend:

$$ z \leftarrow z + \mathtt{9e3779b97f4a7c15} , \qquad y = \big(z \oplus (z \gg 30)\big) \times \mathtt{bf58476d1ce4e5b9} , \qquad y \leftarrow \big(y \oplus (y \gg 27)\big) \times \mathtt{94d049bb133111eb} , \qquad y \oplus (y \gg 31) , $$

starting from \(z = \mathrm{seed}\), with \(\gg\) a right shift. Neighbouring seeds give unrelated streams, so the seeds \(s, s + 1, s + 2, \dots\) of successive configurations are safe.

Xoshiro256::gfortran(seed) puts the generator in the state gfortran (version 9 and later, whose random_number is xoshiro256**) reaches after random_seed(put = [seed, seed, …]), which is what the thesis routine random_set(seed) calls. gfortran_put(put) takes the eight 32-bit integers of put in general. gfortran copies put(8), put(7), …, put(1) into consecutive 32-bit words of the state, low word first, and XORs the four 64-bit words with fixed keys (its scramble_seed):

$$ s_0 = \big(p_8 + 2^{32} p_7\big) \oplus \mathtt{bd0c5b6e50c2df49}, \quad s_1 = \big(p_6 + 2^{32} p_5\big) \oplus \mathtt{d46061cd46e1df38}, $$

$$ s_2 = \big(p_4 + 2^{32} p_3\big) \oplus \mathtt{bb4f4d4ed6103544}, \quad s_3 = \big(p_2 + 2^{32} p_1\big) \oplus \mathtt{114a583d0756ad39}, $$

each \(p_k\) read as an unsigned 32-bit integer. With it, and with the draw order of the thesis codes, caroli rebuilds the impurity configurations of the thesis exactly. This is why the golden cases with disorder (conductances with magnetic impurities, Keldysh currents, densities of states by the kernel polynomial method, the dynamics of graphene) are compared configuration by configuration, to rounding error, instead of in distribution (Validation and Benchmarks).

The stream is exact integer arithmetic. The uniforms, the Anderson energies and the positions of the impurities follow from it by correctly rounded floating-point operations, the same on every system. The moments also go through cos and sin, whose last bit may differ between the mathematical libraries of two systems.

Anderson disorder

Anderson disorder gives every site \(i\) a random on-site energy, the same on all its orbitals:

$$ V_i = \varepsilon_i\, \mathbb 1 , \qquad \varepsilon_i = W \big(u_i - \tfrac12\big) \in \big[-W/2, W/2\big) , $$

one uniform \(u_i\) per site, drawn in the order of the sites given. The strength \(W\) is the full width of the distribution (conventions); the energies are independent from site to site, with

$$ \langle \varepsilon_i \rangle = 0 , \qquad \langle \varepsilon_i\, \varepsilon_j \rangle = \frac{W^2}{12}\, \delta_{ij} . $$

For weak disorder the Born approximation gives the local self-energy \(\Sigma = (W^2/12)\, G_0\), with \(G_0\) the local Green's function of the clean crystal (Self-Consistent Born Approximation). Anderson::generate(rng, sites, W) draws the energies, and onsite(orbitals) turns them into an on-site term.

Classical magnetic impurities

A magnetic impurity is a classical unit moment \(\mathbf n_i\) on a site, coupled to the electrons by the exchange \(J\, \mathbf n_i \cdot \mathbf S\). A configuration is a set of distinct sites and their moments.

Positions

choose_sites(rng, candidates, n) draws \(n\) distinct sites among the \(L\) candidates by a partial Fisher–Yates shuffle, as the thesis routine impurities_set: with a table of the indices \(0, \dots, L - 1\), for \(i = 0, \dots, n - 1\) it swaps entry \(i\) with entry \(r\), \(r\) drawn uniformly in \(i, \dots, L - 1\) (integer(i + 1, L) − 1), and keeps the first \(n\) entries. Every subset of \(n\) sites is equally likely; the concentration is \(n_I = n/L\). The order of the candidates matters for reproducibility: the thesis lists the region of the impurities with \(x\) varying fastest, while Region::cuboid lists \(x\) slowest, so the validation builds the thesis's list to rebuild its configurations.

Moments

The moments are drawn axisymmetric about \(z\): \(n_z\) is an affine function of a uniform \(u\), the azimuth \(\varphi = 2\pi u'\) is uniform, and

$$ \mathbf n = \big(\sqrt{1 - n_z^2}\, \cos\varphi,\; \sqrt{1 - n_z^2}\, \sin\varphi,\; n_z\big) . $$

Moments::draw(rng, n) draws the \(n\) values of \(n_z\) first, then the \(n\) azimuths, in the order of the thesis codes. Three distributions are available:

Moments\(n_z\)Uniform inThesis codes
Isotropic\(2u - 1\)\([-1, 1]\)spin = 0
Cone { theta0 }\(1 - (1 - \cos\theta_0)\, u\)\([\cos\theta_0, 1]\)spin ≠ 0, theta_0
Polarized { mz }\((2M_z - 1) + 2 (1 - M_z)\, u\)\([2M_z - 1, 1]\)The 2015 codes, Mz

Since the area of a spherical zone is proportional to its height (Archimedes), \(n_z\) uniform in \([z_0, 1]\) with a uniform azimuth is the uniform distribution on the cap \(n_z \ge z_0\) of the unit sphere: the isotropic moments are uniform on the sphere, the cone puts them uniformly within the half-angle \(\theta_0\) of \(+z\), and the polarised moments are the cone with \(\cos\theta_0 = 2M_z - 1\). The cone and the polarised forms describe the same family; they map a given \(u\) to mirror values (\(u \to 1 - u\)), and each reproduces the codes of its year. \(\theta_0 = 0\) and \(M_z = 1\) put every moment along \(+z\); \(\theta_0 = \pi\) and \(M_z = 0\) are isotropic. A polarisation outside \([0, 1]\) panics.

For \(n_z\) uniform in \([z_0, 1]\), the moments of the distribution are

$$ \langle n_z \rangle = \frac{1 + z_0}{2} , \qquad \langle n_z^2 \rangle = \frac{1 + z_0 + z_0^2}{3} , \qquad \langle n_x^2 \rangle = \langle n_y^2 \rangle = \frac{1 - \langle n_z^2 \rangle}{2} , $$

and \(\langle n_x \rangle = \langle n_y \rangle = \langle n_a n_b \rangle_{a \ne b} = 0\):

Distribution\(M_z = \langle n_z \rangle\)\(\langle n_z^2 \rangle\)
Isotropic01/3
Cone of half-angle \(\theta_0\)\((1 + \cos\theta_0)/2\)\((1 + \cos\theta_0 + \cos^2\theta_0)/3\)
Polarised\(M_z\)\(M_z^2 + (1 - M_z)^2/3\)

MagneticImpurities::magnetisation() gives the mean moment of one configuration.

Exchange coupling

MagneticImpurities::generate(rng, candidates, n, moments) draws the sites, then the moments; exchange(J, &S) turns them into the on-site term \(V_i = J\, (n_{i,x} S_x + n_{i,y} S_y + n_{i,z} S_z)\) of every impurity site, for the spin matrices \(\mathbf S\) of the model: the Pauli matrices for a spinful site of two orbitals, and for BHZ the matrices of the same-g or opposite-g coupling,

Coupling\(g\)-factors\(\mathbf S\)
Same-g\(g_E = g_H\)\((s_x, s_y, s_z)\)
Opposite-g\(g_E = -g_H\)\((s_x \tau_z, s_y \tau_z, s_z \tau_z)\)

Moments along \(z\) (\(\theta_0 = 0\), \(M_z = 1\)) conserve \(s_z\) in both couplings: the two spin blocks of BHZ stay apart, each a model of two orbitals with its own disorder.

Mean field and second moments

With the occupation \(p_i \in \{0, 1\}\) of a site, of mean \(n_I\), the exchange on site \(i\) is \(V_i = p_i J\, \mathbf n_i \cdot \mathbf S\). Its average over positions and moments is a uniform term, the mean field,

$$ \langle V \rangle = n_I J\, \langle \mathbf n \rangle \cdot \mathbf S = n_I J M_z\, S_z . $$

For same-g it is the Zeeman-like \(n_I J M_z\, s_z\), which shifts the two spin blocks by \(\pm n_I J M_z\) in energy; the golden case ti-ribbon-bands is a BHZ ribbon with such a uniform exchange, \(J_s s_z\) on every site (Spectra and Bands). For opposite-g it is \(n_I J M_z\, s_z \tau_z\), which changes the masses of the two blocks in opposite directions, \(M_{\uparrow, \downarrow} = M \pm n_I J M_z\). In the inverted regime (\(M \lt 0\), \(B \lt 0\)), once \(\lvert n_I J M_z \rvert \gt \lvert M \rvert\) the mean field alone makes one block a normal insulator (spin up for \(J M_z \gt 0\)) while the other stays inverted: the quantum anomalous Hall state, with one chiral edge channel.

The fluctuations around the mean field are given by the second cumulant,

$$ \langle V_a V_b \rangle - \langle V_a \rangle \langle V_b \rangle = n_I J^2 \big[ \langle n_a n_b \rangle - n_I \langle n_a \rangle \langle n_b \rangle \big] , $$

for the components along \(S_a\) and \(S_b\): \(n_I J^2 (\langle n_z^2 \rangle - n_I M_z^2)\) on \(S_z \otimes S_z\), and \(n_I J^2 (1 - \langle n_z^2 \rangle)/2\) on each of \(S_x \otimes S_x\) and \(S_y \otimes S_y\). The Born approximation renormalises the masses and the chemical potentials of the spin blocks with these vertices: caroli_born::Disorder::magnetic takes the same Moments and computes \(M_z\) and \(\langle n_z^2 \rangle\) from the table above (Self-Consistent Born Approximation). A configuration of MagneticImpurities has exactly \(n\) impurities, while the Born approximation treats the occupations as independent; the two agree for large samples.

Bond disorder and other terms

Any other disorder is an on-site term (Model::with_onsite_term) or a hopping term (Model::with_hopping_term) of one's own (Tight-Binding Models). OnSiteMap holds site-dependent matrices in a hash map, adds the matrices given twice to the same site, and serves as an on-site term: Anderson disorder and impurities are returned in this form, and several of them on one model add up.

A hopping term receives the two sites in the orientation of the stored hopping, whichever end the builder starts from, and the reverse block is its conjugate: a value drawn for the pair of sites applies to the bond in both directions, and the Hamiltonian stays Hermitian. To draw bond disorder from a reproducible stream, draw one value per bond of the region in a fixed order (that of Model::bonds, keeping one direction of each bond), store them in a map keyed by the pair of sites, and look them up in the term. A test of caroli-model multiplies every bond of a square lattice by \(1 + 0.4\,(u - \tfrac12)\), with \(u\) a hash of the two sites, and checks that the Hamiltonian stays Hermitian to \(10^{-15}\), the same in its dense and sparse forms.

Configurations and seeds

A disordered device is a new model: the clean model with the disorder terms added. The leads are always built from the clean model, so a disorder average reuses the lead self-energies of each energy for every configuration (Green's Functions and the Caroli Formula). In the library, configuration \(c\) is drawn with a generator of one's own, for instance Xoshiro256::seed_from_u64(seed + c).

The caroli command draws each [[disorder]] table on its own stream. Configuration \(c\) of table \(k\) uses seed_from_u64(s_k + c), with \(s_k\) the table's seed, \(1 + 1000 k\) by default. The candidates are the sites of the sample inside the table's cells windows and on its sublattices, in the order of the sample (the cuboid order). Anderson disorder draws one energy per candidate; magnetic disorder places \(\lfloor n_I L \rfloor\) impurities among the \(L\) candidates, with the spin matrices pauli, same-g, opposite-g or three matrices of one's own (The caroli Command).

Accuracy and tests

TestWhat it checks
reproduces_gfortran (rng)Six uniforms printed by gfortran 16 after random_seed(put = [12345, …]), one after [1237, …] and one after [1, 2, …, 8]: equal bit for bit
seeds_differ (rng)Different seeds give different streams in \([0, 1)\)
distinct_sites30 impurities among 50 sites are distinct
moment_distributionsMoments of unit norm to \(10^{-12}\) for the three distributions; \(M_z = 1\) puts every moment exactly along \(+z\); the mean \(n_z\) of 1000 moments with \(M_z = 0.6\) within 0.05
moments_of_the_magnetic_distributions (caroli-born)The mean field and the \(S_z\) vertex of Disorder::magnetic against 200 000 draws of each distribution, to 0.01

The golden cases of the thesis with disorder are reproduced with the thesis's own configurations (Validation and Benchmarks); the largest differences below were measured on 28 November 2026 (cargo test -p caroli-validation):

Golden caseDisorderLargest difference
ti-cond2t-same-g, -isotropic, -opposite-g24 magnetic impurities in a 16 × 10 BHZ ribbon (seed 12345), moments along \(z\) or isotropic\(6.4 \times 10^{-14}\) on the conductance, with the thesis's formula (its broadenings truncated to their real part); the exact transmission differs from it by up to 0.22
ti-lcur-same-g, -opposite-g51 magnetic impuritiesBond currents \(1.3 \times 10^{-17}\) (of \(10^{-3}\)), occupied densities \(1.4 \times 10^{-14}\)
ti-lcur-andersonAnderson disorder, 128 sitesBond currents \(1.7 \times 10^{-17}\), occupied densities \(1.6 \times 10^{-14}\)
ti-cond-ldos-currentAnderson disorderRelative \(1.3 \times 10^{-14}\) on the conductance, \(2.9 \times 10^{-14}\) on the local densities of states
ti-cond4t-andersonAnderson disorder in a four-terminal cross\(2.6 \times 10^{-5}\) with the thesis's formula, which puts \(E + i\eta\) on one slice
ti-dos-kpm-same-g, -opposite-gMagnetic impurities on a BHZ torus, the same random vectors\(3.3 \times 10^{-16}\) on densities of states up to 0.83
graphene-dos-kpmImpurities on a graphene torus\(4.6 \times 10^{-15}\) on densities of states up to 4.65
graphene-current-af, -paraOrdered and isotropic impurities on graphene tori under a field\(4.8 \times 10^{-16}\) on currents up to \(1.2 \times 10^{-2}\), \(1.5 \times 10^{-16}\) on the pair counts

In the code

Crate caroli-disorder (re-exported as caroli::disorder; Xoshiro256, Anderson, MagneticImpurities and Moments are in caroli::prelude):

ItemRole
Xoshiro256The generator: seed_from_u64, gfortran, gfortran_put, next_u64, uniform, uniforms, integer
Andersongenerate, onsite
MagneticImpuritiesgenerate, exchange, magnetisation
MomentsIsotropic, Cone, Polarized; draw
choose_sitesDistinct sites by a partial Fisher–Yates shuffle
OnSiteMapSite-dependent matrices as an on-site term
bhz_spin, GFactorsThe spin matrices of the same-g and opposite-g couplings (caroli-model)
caroli_born::DisorderThe mean field and the cumulant vertices of the same disorders, for the Born approximation

References

  • D. Blackman and S. Vigna, Scrambled linear pseudorandom number generators, ACM Trans. Math. Softw. 47, 36 (2021), arXiv:1805.01407 (2018): xoshiro256** and the seeding by splitmix64.
  • G. L. Steele, D. Lea and C. H. Flood, Fast splittable pseudorandom number generators, Proc. OOPSLA 2014, ACM SIGPLAN Notices 49 (10), 453 (2014): splitmix64.
  • D. E. Knuth, The Art of Computer Programming, vol. 2, Seminumerical Algorithms, 3rd ed., Addison-Wesley (1997), § 3.4.2: random sampling and shuffling.
  • P. W. Anderson, Absence of diffusion in certain random lattices, Phys. Rev. 109, 1492 (1958).
  • L. Raymond, A. D. Verga and A. Demion, Anomalous quantum Hall effect induced by disorder in topological insulators, arXiv:1505.07145 (2015): magnetic impurities in the BHZ model, the same-g and opposite-g couplings.
  • A. Demion and A. D. Verga, Nonlinear electric transport in graphene with magnetic disorder, Phys. Rev. B 90, 085412 (2014).
  • 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).