API Reference
This page contains the complete API reference for the Free Fermion Library.
Core Module (ff_lib)
Free Fermion Library - Basic Functions For Handling Fermions
This module contains the core quantum physics and linear algebra functions for free fermion systems, including Jordan-Wigner transformations, symplectic diagonalization, Gaussian state constructions, and correlation matrix computations.
- Key functionality:
Jordan-Wigner fermionic operators (Dirac and Majorana)
Symplectic free-fermion diagonalization
Gaussian state generation and manipulation
Fermionic correlation matrix computations
Block matrix construction for coefficient matrices
Wick’s theorem implementation
Copyright 2025 James.D.Whitfield@dartmouth.edu
- ff.ff_lib.permutation_to_matrix(permutation)[source]
Transform a permutation (list) into a permutation matrix using NumPy.
- Parameters:
permutation – A list representing a permutation
- Returns:
A NumPy array representing the permutation matrix. Returns None if the input is invalid.
- ff.ff_lib.jordan_wigner_lowering(n_sites)[source]
Define annihilation operators using the Jordan-Wigner transform.
- Parameters:
n_sites – The number of lattice sites
- Returns:
A list of the annihilation operators
- ff.ff_lib.jordan_wigner_alphas(n_sites)[source]
Define raising and lowering operators using the Jordan-Wigner transform. With alphas = raising + lowering
- Parameters:
n_sites – The number of lattice sites
- Returns:
A list of the [raising, lowering] operators
- ff.ff_lib.jordan_wigner_majoranas(n_sites)[source]
Generate a set of Majorana operators under Jordan-Wigner.
\[ \begin{align}\begin{aligned}\gamma_j = (a_j + a_j^\dagger)/\sqrt{2}, \qquad j < n_{sites}\\\gamma_k = i(a_k - a_k^\dagger)/\sqrt{2},\qquad k < 2n_{sites}\end{aligned}\end{align} \]- Parameters:
n_sites – The number of lattice sites
- Returns:
A list of the Majorana operators
- ff.ff_lib.rotate_operators(C, alphas, Left=False, verbose=False)[source]
Transform set of operators using a matrix C per:
\[\beta_j = \sum_i C_{ji} \alpha_i\]Use Left=True if instead you want
\[\beta_j = \sum_i \alpha_i C_{ij}^*\]- Parameters:
C – A [len(alpha) x len(alpha)] coefficient matrix
alphas – A list of operators (NumPy matrices)
Left – Do the transformation left-handed per above (default=False)
verbose – Print more information (default=False)
- Returns:
The list of rotated operators
- ff.ff_lib.build_V(n_sites, A, Z=None)[source]
Build the generator V matrix of dimension 2*N for N sites.
\[\begin{split}V=\begin{bmatrix} -Z^* & A \\ -A^* & Z \end{bmatrix}\end{split}\]- Parameters:
n_sites – The number of sites
A – The A coefficient matrix, [N x N]
Z – The Z coefficient matrix, [N x N] (optional)
- Returns:
A 2*N x 2*N numpy array representing a generator matrix
- ff.ff_lib.build_H(n_sites, A, B=None)[source]
Build the H block coefficient matrix of dimension 2*N for N sites.
\[\begin{split}H=\begin{bmatrix} -A^* & B \\ -B^* & A \end{bmatrix}\end{split}\]If A = A.conj().T and B = -B.T then the output is compatible with alphas = jordan_wigner_alphas(n_sites)
- Parameters:
n_sites – The number of sites, N
A – The A coefficient matrix, [N x N]
B – The B coefficient matrix, [N x N] (optional)
- Returns:
A [2*N x 2*N] numpy array representing the H matrix
- ff.ff_lib.random_FF_state(n_sites, fixedN=False, seed=None, returnH=False)[source]
Generate a random free fermion state using a random Hamiltonian. :param n_sites: The number of sites :param fixedN: If True, generator commutes with N_op (default: False) :param seed: Random seed for reproducibility (optional) :param returnH: If True, return the generator matrix along with
rho (default: False)
- Returns:
A normalized free fermion state, rho. If returnH is True, also returns the generator matrix H.
- ff.ff_lib.random_H_generator(n_sites, fixedN=False, seed=None)[source]
Generate a random generator matrix for free fermions. Entries are drawn from a standard normal distribution for both real and imaginary parts.
- Parameters:
n_sites – The number of sites
fixedN – If True, generator will preserve N (default: False)
seed – Random seed for reproducibility (optional)
- Returns:
A random generator matrix of dimension 2*N for N sites
- ff.ff_lib.build_Omega(N)[source]
Build the Omega matrix of dimension 2*N for N sites.
\[\begin{split}\Omega = \frac{1}{\sqrt{2}} \begin{bmatrix} \mathbf{1} & \mathbf{1} \\ i \mathbf{1} & -i \mathbf{1} \end{bmatrix}\end{split}\]- Parameters:
N – The number of sites
- Returns:
A 2*N x 2*N numpy array representing the Omega matrix
- ff.ff_lib.build_reordering_xx_to_xp(n_sites)[source]
A permutation matrix that transforms ordering [x_1, x_2… p_1, p_2…] to [x_1, p_1, x_2, p_2, …]
- Parameters:
n_sites – Number of sites
- Returns:
Permutation matrix for reordering
- ff.ff_lib.build_K(n_sites)[source]
Build the symplectic transform from standard to canonical eigenstruct
- ff.ff_lib.is_symp(U)[source]
Function checks if U is symplectic
U is symplectic if U S U^T = S
A known canonical form is:
\[\begin{split}U = \begin{bmatrix} s & t^* \\ t & s^* \end{bmatrix}\end{split}\]where s and t are square matrices of dimension N.
- Parameters:
U – Matrix to check for symplectic property
- Returns:
True if U is symplectic, False otherwise
- ff.ff_lib.check_canonical_form(L)[source]
Check if a matrix is in standard block diagonal form.
- Parameters:
L – A NumPy array representing the matrix
- Returns:
True if the matrix is in standard block diagonal form, False otherwise
- ff.ff_lib.generate_gaussian_state(n_sites, H, alphas=None)[source]
Generate a Gaussian state using Hamiltonian H.
- Parameters:
n_sites – The number of orbitals
H – Quadratic parent Hamiltonian ([2n x 2n] or [2**n x 2**n])
alphas – The list of 2n fermionic operators (optional)
- Returns:
The [2**n x 2**n] free fermion state
- ff.ff_lib.build_op(n_sites, R, alphas, verbose=None, direct=False)[source]
Build the N-body lift of a quadratic coefficient matrix
R̂ = Σ_ij R_ij α_i† α_j
- Parameters:
n_sites – The number of sites
R – Coefficient matrix [2N x 2N]
alphas – A list of 2N fermionic operators
verbose – Increases output if set to True or an integer (default: None)
direct – Do R_ij α_i α_j (no adjoint) (default: False)
- Returns:
The N-body Hamiltonian operator as a matrix
- ff.ff_lib.compute_cov_matrix(rho, n_sites=None, alphas=None)[source]
Calculate the fermionic covariance matrix of rho
K_ij = Tr[rho α_i α_j] - Tr[rho α_j α_i]
- Parameters:
rho – should be a [2**n_sites x 2**n_sites] matrix
n_sites – number of sites
alphas – a set of 2 n_sites of fermionic operators (optional)
- Returns:
An [2 n_sites x 2 n_sites] covariance matrix
- ff.ff_lib.correlation_matrix(rho)[source]
Calculates the following two-point correlation matrix
Γ = ⟨vec α vec α^t⟩ Γ_ij = Tr[rho α_i α_j]
for JW fermionic operators in the [a^+ a] ordering
- Parameters:
rho – should be a [2**n_sites x 2**n_sites] matrix
- Returns:
An [2 n_sites x 2 n_sites] correlation matrix
- ff.ff_lib.compute_2corr_matrix(rho, n_sites, alphas=None, conjugation=None)[source]
Calculate the two-point correlation matrix
Γ = ⟨vec α vec α^t⟩ Γ_{ij} = Tr[rho α_i α_j]
By changing the input conjugation parameter, this function also computes P = ⟨vec α vec α†⟩ (conjugation == T) η = ⟨vec α† vec α^t⟩ (conjugation < 0)
By default the operators are not conjugated but if conjugation is True or positive:
P_ij = Tr[ρ α_i α_j†]
- And if conjugation is negative:
η_ij = Tr[ρ α_i† α_j]
- Parameters:
rho – should be a [2**n_sites x 2**n_sites] matrix
n_sites – number of sites
alphas – a set of 2 n_sites of fermionic operators (optional)
conjugation – Indicates if the operators should be conjugated (optional)
- Returns:
An [2 n_sites x 2 n_sites] correlation matrix
- ff.ff_lib.compute_algebra_S(alphas, verbose=False)[source]
Given operators α_i, compute the S matrix
α_i α_j = S_ij 𝟙 - α_j α_i
- Parameters:
alphas – A list of 2N operators
verbose – Output more information (default: False)
- Returns:
The algebraic S matrix
- Return type:
S
- ff.ff_lib.is_matchgate(M, verbose=False)[source]
Check the matchgate condition for 4x4 input matrices.
A 4x4 matrix satisfies the matchgate condition if the determinant of its inner 2x2 submatrix equals the determinant of its corner 2x2 submatrix.
- Parameters:
M – 4x4 numpy array to test
verbose – Print detailed information (default: False)
- Returns:
True if M satisfies the matchgate condition, False otherwise
- ff.ff_lib.eigh_sp(H)[source]
Return the eigenvectors in symplectic form and the eigenvalues of a complex Hermitian (conjugate symmetric) FF coefficient array.
Returns two objects, a 1-D array containing the eigenvalues of H and a 2-D array containing a symplectic unitary that diagonalizes H.
This routine transforms to Majorana forms, gets the canonicalizing orthogonal matrix for skew-symmetric real matrices. This is transformed to symplectic form using
\[U_{symp} = \Omega^\dagger O \Omega\]Then a symplectic transformation is constructed to transform from canonical eigenstructure
\[\begin{split}L_{canonical} = \oplus_k \begin{pmatrix} 0 & -\lambda_k\\ \lambda_k & 0 \end{pmatrix}\end{split}\]to standard eigenstructure
\[\begin{split}L_{standard} = \begin{pmatrix} -\Sigma & 0\\ 0 & \Sigma \end{pmatrix}\end{split}\]- Parameters:
H –
(2N, 2N) array Should be of the form
- [[-A.conj(), B],
[-B.conj(), A]]
with \(A = A^\dagger\) and \(B = -B^T\)
- Returns:
A tuple with eigenvalues: (2N) ndarray eigenvectors: (2N,2N) ndarray
Ortho-normal eigenvectors arranged in the form \(\begin{pmatrix} s & t\\t^* & s^* \end{pmatrix}\)
- ff.ff_lib.eigv_sp(V)[source]
Returns the left eigenvectors in symplectic form and eigenvalues in Y-form
\[\begin{split}L_{Y} = \begin{pmatrix} 0 & -\Sigma\\ \Sigma & 0 \end{pmatrix}\end{split}\]of the coefficient matrix in V-form whereby \(\hat V = \hat V^\dagger = \sum V_{ij}\alpha_i \alpha_j\)
Returns two objects, a 1-D array containing the eigenvalues of V in Y-form and a 2-D array containing a symplectic unitary that diagonalizes V.
\[\begin{split}L_{standard} = \begin{pmatrix} -\Sigma & 0\\ 0 & \Sigma \end{pmatrix}\end{split}\]- Parameters:
V – (2N, 2N) array Should be of the form \(V = \begin{pmatrix}-B^* & A\\ -A^* & B\end{pmatrix}\) with A = A† and B = -B^T
- Returns:
A tuple with eigenvalues: (2N) ndarray in \(L_Y\) form eigenvectors: (2N,2N) ndarray
Ortho-normal eigenvectors arranged in the form \(U = \begin{pmatrix} s & t\\ t^* & s^* \end{pmatrix}\) such that U.T @ V @ U = L_Y
- ff.ff_lib.eigm_sp_can(G)[source]
Returns the orthogonal eigenvectors and the eigenvalues in direct sum canonical form for the Majorana coefficient matrix G.
G should be of form .. math:
G = i\begin{bmatrix}Im(A+Z) & Re(A+Z)\\ Re(Z-A)& Im(A-Z) \end{bmatrix}
where Z = -Z^T and A = A^dagger.
Returns two objects, the eigenvalues of G in canonical form and the sympletic orthogonal matrix that transforms G to canonical eigenstructure form .. math:
L_{canonical} = \oplus_k \begin{matrix} 0 & -\lambda_k\\ \lambda_k & 0 \end{matrix}
- Parameters:
G (( 2N, 2N ) array properly formatted)
- Returns:
A tuple with
eigenvalues ((2N) ndarray) –
- Lc = oplus_k [[ 0 , -ev_k ],
[ ev_k , 0 ]]
eigenvectors ((2N,2N) ndarray) – Ortho-normal eigenvectors arranged in the form U = [[ s , t ]
[ t^* , s^* ]]
- ff.ff_lib.eigm_sp(G)[source]
Returns the orthogonal eigenvectors and the eigenvalues in L_Y form for the Majorana coefficient matrix G. G should be of form
\[\begin{split}G = i\begin{bmatrix}Im(A+Z) & Re(A+Z)\\ Re(Z-A)& Im(A-Z) \end{bmatrix}\end{split}\]where \(Z = -Z^T\) and \(A = A^\dagger\).
Returns two objects, the eigenvalues of G in canonical form and the sympletic orthogonal matrix that transforms G to the Y eigenstructure form
\[\begin{split}L_{Y} = \begin{pmatrix} 0 & -\Sigma\\ \Sigma & 0 \end{pmatrix}\end{split}\]- Parameters:
G (( 2N, 2N ) array properly formatted)
- Returns:
A tuple with
eigenvalues (( 2N ) ndarray) – i*L in L_Y form
eigenvectors (( 2N, 2N ) ndarray) – Orthogonal matrix such that O^T O = Id
Combinatorics Module (ff_combinatorics)
Free Fermion Combinatorial Functions Module
Core combinatorial matrix functions including determinants, pfaffians, permanents, and hafnians.
Copyright 2025 James.D.Whitfield@dartmouth.edu Licensed under MIT License.
- ff.ff_combinatorics.sgn(permutation)[source]
Computes the sign of a permutation by counting inversions.
- Parameters:
permutation – List or array representing a permutation
- Returns:
1 if even number of inversions, -1 if odd
- ff.ff_combinatorics.pf(A)[source]
Computes pfaffian via combinatorial formula:
Given \(A\) of dimension \(N = 2 n_e\) we have the pfaffian as:
\[pf(A)= \sum_{\sigma\in S_N}^{N!} sgn(\sigma) W_\sigma(A)/(2^{n_e} n_e!)\]Where the weight of matching \(\sigma\) is given by
\[W_\sigma(A) = \prod_{i=0}^{n_e} A_{\sigma(2i), \sigma(2i+1)}\]- Parameters:
A – Square matrix (numpy array or array-like)
- Returns:
Pfaffian value (complex or real)
- ff.ff_combinatorics.hf(A)[source]
Computes hafian via combinatorial formula.
Given \(A\) of even dimension \(N = 2 n_e\) we have the hafian as:
\[hf(A) = \sum_{\sigma\in S_N}^{N!} W_\sigma(A)/(2^{n_e} n_e!)\]Where the weight of matching \(\sigma\) is given by
\[W_\sigma(A) = \prod_{i=0}^{n_e} A_{\sigma(2i), \sigma(2i+1)}\]- Parameters:
A – Square matrix (numpy array or array-like)
- Returns:
Hafnian value (complex or real)
- ff.ff_combinatorics.pt(A)[source]
Computes permanent via combinatorial formula.
Given \(A\) of dimension \(N\) we have the permanent as:
\[pt(A) = \sum_{\sigma\in S_N}^{N!} B_\sigma(A)\]Where the bipartite matching of \(\sigma\) is given by
\[B_\sigma(A) = \prod_{i=1}^N A_{i,\sigma(i)}\]- Parameters:
A – Square matrix (numpy array or array-like)
- Returns:
Permanent value (complex or real)
- ff.ff_combinatorics.dt(A)[source]
Computes determinant via combinatorial formula.
Given \(A\) of dimension \(N\) we have the determinant as:
\[dt(A) = \sum_{\sigma\in S_N}^{N!} sgn(\sigma) B_\sigma(A)\]Where the bipartite matching of \(\sigma\) is given by
\[B_\sigma(A) = \prod_{i=1}^N A_{i,\sigma(i)}\]- Parameters:
A – Square matrix (numpy array or array-like)
- Returns:
Determinant value (complex or real)
- ff.ff_combinatorics.dt_eigen(A)[source]
Computes the determinant of a matrix using eigenvalue decomposition.
\[dt(A) = \prod_{i=0}^{n-1} \lambda_i\]with \(\lambda_i\) the eigenvalues of \(A\).
- Parameters:
A – A NumPy array representing the square matrix.
- Returns:
The determinant of the matrix. Returns None if the input is not a square matrix or if eigenvalue decomposition fails.
Graph Theory Module (ff_graph_theory)
Graph Theory and Visualization Functions for Free Fermion Library
This module contains graph theory algorithms and visualization functions, particularly focused on planar graphs and the Pfaffian ordering algorithm (FKT algorithm).
Key algorithms: - Pfaffian ordering algorithm (FKT algorithm) for planar graphs - Graph visualization and plotting functions - Perfect matching algorithms - Dual graph construction for planar embeddings
Copyright 2025 James.D.Whitfield@dartmouth.edu
- ff.ff_graph_theory.plot_graph_with_edge_weights(A, matching=None, title=None)[source]
Plot the graph associated with adjacency matrix A with edge weights.
Given a real [n x n] matrix A, interpret the entries as directed edge weights, then plot the graph with the edge weights.
- Parameters:
A – A NumPy array representing the square matrix or NetworkX graph
matching – List of edges to highlight in red (optional)
title – Title for the plot (optional)
- Returns:
NetworkX graph object with edge weights
- ff.ff_graph_theory.generate_random_planar_graph(n, seed=None)[source]
Generate a random planar graph with n nodes.
- Parameters:
n – The number of nodes in the graph
seed – Random seed for reproducibility (optional)
- Returns:
A NetworkX graph object representing the planar graph. Returns None if a planar graph with n nodes cannot be generated within a reasonable number of attempts.
- ff.ff_graph_theory.plot_planar_embedding(G, pfo=None, title=None)[source]
Plot the planar embedding of a graph with oriented faces.
- Parameters:
G – The original NetworkX graph
pfo – Pfaffian ordering matrix (optional)
title – Title for the plot (optional)
- ff.ff_graph_theory.dual_graph_H(G, F, T)[source]
Create the dual graph according to the PFO algorithm (Vazirani 1987).
“Construct a new graph H having one vertex corresponding to each face (including the infinite face) of G. Two vertices u and v of H are connected by an edge iff the corresponding faces share an edge not in T. Let r be the vertex in H corresponding to the infinite face of G. Root H at r.”
- Parameters:
G – Original planar graph
F – List of faces from planar embedding
T – Spanning tree of G
- Returns:
NetworkX graph H representing the dual graph
- ff.ff_graph_theory.faces(graph, emb=None)[source]
Return the faces of an embedded graph using the networkx embedding scheme.
ADAPTED HEAVILY FROM SAGE: https://github.com/sagemath/sage/blob/develop/src/sage/graphs/generic_graph.py#L6815
- Parameters:
graph – NetworkX graph object
emb – Planar embedding from NetworkX
- Returns:
List of faces, where each face is a list of edges
- ff.ff_graph_theory.complete_face(pfo, edges, verbose=False)[source]
Update one edge while maintaining the PFO condition.
- Parameters:
pfo – Pfaffian ordering matrix
edges – List of edges in the face
verbose – Print debug information (optional)
- Returns:
Updated PFO matrix
- ff.ff_graph_theory.count_perfect_matchings(graph)[source]
Find all perfect matchings in a graph.
If planar, this method uses a pfo, otherwise it is computed via brute force
- Parameters:
graph – A NetworkX graph
- Returns:
The number of weighted matching for the given graph.
- ff.ff_graph_theory.count_perfect_matchings_planar(graph)[source]
Find all perfect matchings in a planar graph using the PFO algorithm.
- Parameters:
graph – A NetworkX graph
- Returns:
The number of weighted matching for the given graph
- ff.ff_graph_theory.find_perfect_matchings_brute(graph)[source]
Find all perfect matchings in a graph using a brute force enumeration.
- Parameters:
graph – A NetworkX graph
- Returns:
A list of tuples, where each tuple represents a perfect matching
- ff.ff_graph_theory.pfo_algorithm(graph, verbose=False)[source]
Pfaffian ordering algorithm for planar graphs (FKT algorithm).
This algorithm is due to Kasteleyn 1967 by way of Vazirani 1987.
The algorithm constructs a pfaffian ordering of the edges of a planar graph such that the pfaffian of the resulting skew-symmetric matrix equals the number of perfect matchings in the graph.
- Parameters:
graph – NetworkX planar graph
verbose – Print debug information and plots (optional)
- Returns:
NumPy array representing the pfaffian ordering matrix
Utilities Module (ff_utils)
Free Fermion Utilities Module
Common utility functions for the free fermion codebase.
Copyright 2025 James.D.Whitfield@dartmouth.edu Licensed under MIT License.
- ff.ff_utils.print_custom(obj, k=9)[source]
Custom print function with small number suppression
- Parameters:
obj – Any object to be printed
k – The number of decimal places to print
- Returns:
None
- ff.ff_utils.clean(obj, threshold=1e-06)[source]
Clean small numerical values from arrays or matrices.
- Parameters:
obj – array, scalar, NumPy array or matrix
threshold – Values below this threshold are set to zero
Note: if threshold is an integer, it will be converted to 10^-threshold
- Returns:
Cleaned obj with rounded values and small values set to zero.
- ff.ff_utils.formatted_output(obj, precision=6)[source]
Format numerical output with specified precision.
- Parameters:
obj – Object to format
precision – Number of decimal places
- Returns:
Formatted string representation
- ff.ff_utils.generate_random_bitstring(n, k)[source]
Generates a random bit string of length n with Hamming weight k.
Based on np.random.choice
- Parameters:
n – The length of the bit string.
k – The Hamming weight (number of 1s).
- Returns:
A NumPy array representing the bit string, or None if k is invalid.
Function Index
Core Quantum Physics Functions
Jordan-Wigner Transformations
|
Define annihilation operators using the Jordan-Wigner transform. |
|
Define raising and lowering operators using the Jordan-Wigner transform. |
|
Generate a set of Majorana operators under Jordan-Wigner. |
|
Transform set of operators using a matrix C per: |
|
Helper function to perform the actual rotation of operators. |
Matrix Construction
|
Build the generator V matrix of dimension 2*N for N sites. |
|
Build the H block coefficient matrix of dimension 2*N for N sites. |
Build the Omega matrix of dimension 2*N for N sites. |
|
|
Build the symplectic transform from standard to canonical eigenstruct |
|
A permutation matrix that transforms ordering [x_1, x_2. |
|
Transform a permutation (list) into a permutation matrix using NumPy. |
Define the Pauli matrices as numpy arrays. |
|
|
Build the N-body lift of a quadratic coefficient matrix |
Gaussian States and Correlation Matrices
|
Generate a Gaussian state using Hamiltonian H. |
|
Calculate the fermionic covariance matrix of rho |
|
Calculate the two-point correlation matrix |
|
Given operators α_i, compute the S matrix |
Calculates the following two-point correlation matrix |
|
|
Generate a random free fermion state using a random Hamiltonian. :param n_sites: The number of sites :param fixedN: If True, generator commutes with N_op (default: False) :param seed: Random seed for reproducibility (optional) :param returnH: If True, return the generator matrix along with rho (default: False). |
|
Generate a random generator matrix for free fermions. |
|
Create Kitaev chain Hamiltonian. |
Symplectic Operations
Return the eigenvectors in symplectic form and the eigenvalues of a complex Hermitian (conjugate symmetric) FF coefficient array. |
|
Returns the left eigenvectors in symplectic form and eigenvalues in Y-form |
|
Returns the orthogonal eigenvectors and the eigenvalues in direct sum canonical form for the Majorana coefficient matrix G. |
|
Returns the orthogonal eigenvectors and the eigenvalues in L_Y form for the Majorana coefficient matrix G. |
|
Function checks if U is symplectic |
|
Check if a matrix is in standard block diagonal form. |
Quantum Physics Analysis Functions
|
Check the matchgate condition for 4x4 input matrices. |
Combinatorial Functions
|
Computes the sign of a permutation by counting inversions. |
Computes pfaffian via combinatorial formula: |
|
Computes hafian via combinatorial formula. |
|
Computes permanent via combinatorial formula. |
|
Computes determinant via combinatorial formula. |
|
Computes the determinant of a matrix using eigenvalue decomposition. |
Graph Theory Functions
|
Pfaffian ordering algorithm for planar graphs (FKT algorithm). |
Plot the graph associated with adjacency matrix A with edge weights. |
|
Generate a random planar graph with n nodes. |
|
Plot the planar embedding of a graph with oriented faces. |
|
|
Create the dual graph according to the PFO algorithm (Vazirani 1987). |
|
Return the faces of an embedded graph using the networkx embedding scheme. |
|
Update one edge while maintaining the PFO condition. |
Graph Visualization Functions
|
Draw a labeled multigraph with curved edges for multiple connections. |
|
Draw a labeled graph using positions (if given). |
Perfect Matching Functions
Find all perfect matchings in a graph. |
|
Find all perfect matchings in a planar graph using the PFO algorithm. |
|
Find all perfect matchings in a graph using a brute force enumeration. |
Tree Analysis Functions
Compute the depth of a tree graph. |
Utility Functions
|
Printing with small number suppression (using numpy printoptions) |
|
Clean small numerical values from arrays or matrices. |
|
Format numerical output with specified precision. |
Generates a random bit string of length n with Hamming weight k. |
|
|
Computes the direct sum of two matrices |