coniii.enumerate module

Exact enumeration of Ising models and code generation.

This module computes, symbolically, the partition function and observables for an Ising system of fixed size N, and writes them out as importable Python modules under coniii.ising_eqn (see write_ising_files.sh). It backs coniii.solvers.Enumerate.

Run as a script to (re)generate an equation file:

python -m coniii.enumerate N [sym] [order] [-hp=true]

where sym selects the {-1,+1} basis, order adds higher-order interactions, and -hp=true writes arbitrary-precision equations using mpmath.

Key functions

pairwise(), triplet()

Generate equation files for pairwise / triplet models.

fast_logsumexp(), mp_fast_logsumexp()

Lightweight logsumexp used inside the generated equation files (faster than scipy’s for this purpose).

coniii.enumerate.write_eqns(n, sym, corrTermsIx, suffix='', high_prec=False)[source]

Create strings for writing out the equations and then write them to file.

TODO: This code needs some cleanup.

Parameters:
  • n (int) – number of spins

  • sym (int) – value of 1 will use {-1,1} formulation, 0 means {0,1}

  • corrTermsIx (list of ndarrays) – Allows specification of arbitrary correlations to constrain using an index based structure. These should be index arrays as would be returned by np.where that specify which correlations to write down. Each consecutive array should specify a matrix of sequentially increasing dimension. [Nx1, NxN, NxNxN, …]

  • suffix (str, '')

  • high_prec (bool, False)

coniii.enumerate.write_py(n, sym, contraintTermsIx, signs, expterms, Z, extra='', suffix='', high_prec=False)[source]

Write out Ising equations for Python.

Parameters:
  • n (int) – System size.

  • contraintTermsIx (list of str)

  • signs (list of ndarray) – Sign for each term in the numerator when computing correlations.

  • expterms (list of str) – Every single energy term.

  • Z (str) – Energies for all states that will be put into partition function.

  • extra (str, '') – any extra lines to add at the end

  • suffix (str, '')

  • high_prec (bool, False) – If True, write version that uses mpmath for high precision calculations.

coniii.enumerate.get_terms11(subix, prefix, binstate, br, ix0)[source]

Specific to {-1,1}.

coniii.enumerate.get_terms01(subix, prefix, binstate, br, ix0)[source]

Specific to {0,1}.

coniii.enumerate.get_terms(subix, prefix, binstate, br, ix0)[source]

Spins are put in explicitly

coniii.enumerate.get_3idx(n)[source]

Get binary 3D matrix with truth values where index values correspond to the index of all possible ijk parameters. We can do this by recognizing that the pattern along each plane in the third dimension is like the upper triangle pattern that just moves up and over by one block each cut lower into the box.

coniii.enumerate.get_nidx(k, n)[source]

Get the kth order indices corresponding to all the states in which k elements are firing up out of n spins. The ordering correspond to that returned by bin_states().

One can check this code for correctness by comparing with get_3idx()

print where(exact.get_3idx(4)) print where(exact.get_nidx(3,4)) <<<<<

coniii.enumerate.pairwise(n, sym=0, **kwargs)[source]

Wrapper for writing pairwise maxent model (Ising) files.

Parameters:
  • n (int) – System size.

  • sym (int, 0) – Can be 0 or 1.

  • **kwargs

Return type:

None

coniii.enumerate.triplet(n, sym=0, **kwargs)[source]

Wrapper for writing triplet-order maxent model.

Parameters:
  • n (int) – System size.

  • sym (int, 0) – Can be 0 or 1.

  • **kwargs

Return type:

None

coniii.enumerate.fast_logsumexp(X, coeffs=None)[source]

Simplified version of logsumexp to do correlation calculation in Ising equation files. Scipy’s logsumexp can be around 10x slower in comparison.

Parameters:
  • X (ndarray) – Terms inside logs.

  • coeffs (ndarray) – Factors in front of exponentials.

Returns:

  • float – Value of magnitude of quantity inside log (the sum of exponentials).

  • float – Sign.

coniii.enumerate.mp_fast_logsumexp(X, coeffs=None)[source]

fast_logsumexp for high precision numbers using mpmath.

Parameters:
  • X (ndarray) – Terms inside logs.

  • coeffs (ndarray) – Factors in front of exponentials.

Returns:

  • float – Value of magnitude of quantity inside log (the sum of exponentials).

  • float – Sign.