tensorcircuit.fgs¶
Fermion Gaussian state simulator
- class tensorcircuit.fgs.FGSSimulator(L: int, filled: List[int] | None = None, alpha: Any | None = None, hc: Any | None = None, cmatrix: Any | None = None)[source]¶
Bases:
objectFermion Gaussian State (FGS) simulator for efficient simulation of non-interacting fermionic systems.
This simulator implements methods for: 1. State initialization and evolution 2. Correlation matrix calculations 3. Entanglement measures 4. Out-of-time-ordered correlators (OTOC) 5. Post-selection and measurements
Main references: - Gaussian formalism: https://arxiv.org/pdf/2306.16595.pdf - Quantum circuits: https://arxiv.org/abs/2209.06945 - Theory background: https://scipost.org/SciPostPhysLectNotes.54/pdf
Conventions: - Hamiltonian form: (c^dagger, c)H(c, c^dagger) - Correlation form: <(c, c^dagger)(c^dagger, c)> - Bogoliubov transformation: c’ = alpha^dagger (c, c^dagger)
- Example:
>>> import tensorcircuit as tc >>> # Initialize a 4-site system with sites 0 and 2 occupied >>> sim = tc.FGSSimulator(L=4, filled=[0, 2]) >>> # Apply hopping between sites 0 and 1 >>> sim.evol_hp(i=0, j=1, chi=1.0) >>> # Calculate entanglement entropy for first two sites >>> entropy = sim.entropy([2, 3])
- __init__(L: int, filled: List[int] | None = None, alpha: Any | None = None, hc: Any | None = None, cmatrix: Any | None = None)[source]¶
Initializes the Fermion Gaussian State (FGS) simulator.
The state can be initialized in one of four ways: 1. By specifying the system size L and a list of filled sites, creating a product state. 2. By providing a quadratic Hamiltonian hc, the ground state of which is used as the initial state. 3. By directly providing the alpha matrix, which defines the Bogoliubov transformation. 4. For debugging, by providing a pre-computed correlation matrix cmatrix.
- Parameters:
L (int) – The number of fermionic sites (system size).
filled (Optional[List[int]], optional) – A list of site indices that are occupied by fermions in the initial state. Defaults to None (no sites filled).
alpha (Optional[Tensor], optional) – The matrix defining the Bogoliubov transformation from the vacuum state, of shape (2L, L). If provided, it directly specifies the initial state. Defaults to None.
hc (Optional[Tensor], optional) – A quadratic Hamiltonian. The ground state of this Hamiltonian will be used as the initial state. Defaults to None.
cmatrix (Optional[Tensor], optional) – A pre-computed correlation matrix, primarily for debugging purposes. Defaults to None.
- charge_moment(alpha: Any, n: int, subsystems_to_trace_out: List[int]) Any[source]¶
Computes the charge moment of order n.
Ref: https://arxiv.org/abs/2302.03330
- Parameters:
alpha (Tensor) – The alpha parameter for the charge moment calculation.
n (int) – The order of the charge moment (Renyi-n).
subsystems_to_trace_out (List[int]) – A list of site indices to be traced out.
- Returns:
The charge moment.
- Return type:
Tensor
- static chemical_potential(chi: Any, i: int, L: int) Any[source]¶
Constructs the chemical potential Hamiltonian for a single site.
The chemical potential Hamiltonian is given by \(\chi c_i^\dagger c_i\).
- Parameters:
chi (Tensor) – The chemical potential strength.
i (int) – The index of the site.
L (int) – The number of fermionic sites.
- Returns:
The chemical potential Hamiltonian.
- Return type:
Tensor
- cond_measure(ind: int, status: float, with_prob: bool = False) Any[source]¶
Performs a conditional measurement on a specific site. The fermion Gaussian state is collapsed in the consistent way accordingly.
- Parameters:
ind (int) – The index of the site to measure.
status (float) – A random number between 0 and 1 to determine the measurement outcome.
with_prob (bool, optional) – If True, also return the probabilities of the measurement outcomes. Defaults to False.
- Returns:
The measurement outcome (0 or 1). If with_prob is True, a tuple containing the outcome and the probabilities is returned.
- Return type:
Tensor
- entropy(subsystems_to_trace_out: List[int] | None = None) Any[source]¶
Computes the von Neumann entropy of a subsystem.
- Parameters:
subsystems_to_trace_out (Optional[List[int]], optional) – A list of site indices to be traced out, defining the subsystem. If None, the entropy of the entire system is computed. Defaults to None.
- Returns:
The von Neumann entropy.
- Return type:
Tensor
- evol_cp(i: int, chi: Any | float = 0) None[source]¶
Evolves the state with a chemical potential Hamiltonian.
The evolution is governed by the Hamiltonian \(\chi c_i^\dagger c_i\).
This optimized implementation uses analytical phase factors reducing complexity from O(L³) to O(L).
- Parameters:
i (int) – The index of the site.
chi (Tensor, optional) – The chemical potential strength. Defaults to 0.
- evol_ghamiltonian(h: Any) None[source]¶
Evolves the state with a general non-Hermitian Hamiltonian.
The evolution is given by \(e^{-1/2 i \hat{h}}\).
- Parameters:
h (Tensor) – The non-Hermitian Hamiltonian for the evolution.
- evol_hamiltonian(h: Any) None[source]¶
Evolves the state with a given Hamiltonian.
The evolution is given by \(e^{-i/2 \hat{h}}\).
- Parameters:
h (Tensor) – The Hamiltonian for the evolution.
- evol_hp(i: int, j: int, chi: Any | float = 0) None[source]¶
Evolves the state with a hopping Hamiltonian.
The evolution is governed by the Hamiltonian \(\chi c_i^\dagger c_j + h.c.\).
This optimized implementation uses analytical 2x2 local unitaries reducing complexity from O(L³) to O(L).
- Parameters:
i (int) – The index of the first site.
j (int) – The index of the second site.
chi (Tensor, optional) – The hopping strength. Defaults to 0.
- evol_icp(i: int, chi: Any | float = 0) None[source]¶
Evolves the state with a chemical potential Hamiltonian using imaginary time evolution.
The evolution is governed by \(e^{-H/2}\) where \(H = \chi c_i^\dagger c_i\).
This optimized implementation uses analytical scaling factors reducing complexity from O(L³) to O(L).
- Parameters:
i (int) – The index of the site.
chi (Tensor, optional) – The chemical potential strength. Defaults to 0.
- evol_ihamiltonian(h: Any) None[source]¶
Evolves the state with a given Hamiltonian using imaginary time evolution.
The evolution is given by \(e^{-1/2 \hat{h}}\).
- Parameters:
h (Tensor) – The Hamiltonian for the evolution.
- evol_sp(i: int, j: int, chi: Any | float = 0) None[source]¶
Evolves the state with a superconducting pairing Hamiltonian.
The evolution is governed by the Hamiltonian \(\chi c_i^\dagger c_j^\dagger + h.c.\).
This optimized implementation uses analytical 4x4 local unitaries reducing complexity from O(L³) to O(L).
- Parameters:
i (int) – The index of the first site.
j (int) – The index of the second site.
chi (Tensor, optional) – The pairing strength. Defaults to 0.
- expectation_2body(i: int, j: int, now_i: bool = True, now_j: bool = True) Any[source]¶
Calculates the expectation value of a two-fermion term.
The convention for the operators is (c, c^dagger). For i >= L, the operator is c_{i-L}^dagger.
- Parameters:
i (int) – The index of the first fermion operator.
j (int) – The index of the second fermion operator.
now_i (bool, optional) – Whether to use the current state for the first operator. Defaults to True.
now_j (bool, optional) – Whether to use the current state for the second operator. Defaults to True.
- Returns:
The expectation value of the two-fermion term.
- Return type:
Tensor
- expectation_4body(i: int, j: int, k: int, l: int) Any[source]¶
Calculates the expectation value of a four-fermion term using Wick’s theorem.
The convention for the operators is (c, c^dagger). For an index m >= L, the operator is c_{m-L}^dagger.
- Parameters:
i (int) – The index of the first fermion operator.
j (int) – The index of the second fermion operator.
k (int) – The index of the third fermion operator.
l (int) – The index of the fourth fermion operator.
- Returns:
The expectation value of the four-fermion term.
- Return type:
Tensor
- classmethod fermion_diagonalization(hc: Any, L: int) Tuple[Any, Any, Any][source]¶
Diagonalizes a quadratic fermionic Hamiltonian.
This method computes the eigenvalues, eigenvectors, and the alpha matrix for a given quadratic Hamiltonian hc.
- Parameters:
hc (Tensor) – The quadratic Hamiltonian to be diagonalized.
L (int) – The number of fermionic sites.
- Returns:
A tuple containing the eigenvalues, eigenvectors, and the alpha matrix.
- Return type:
Tuple[Tensor, Tensor, Tensor]
- classmethod fermion_diagonalization_2(hc: Any, L: int) Tuple[Any, Any, Any][source]¶
Alternative method for diagonalizing a quadratic fermionic Hamiltonian.
This method uses a different approach based on the Schur decomposition to diagonalize the Hamiltonian.
- Parameters:
hc (Tensor) – The quadratic Hamiltonian to be diagonalized.
L (int) – The number of fermionic sites.
- Returns:
A tuple containing the eigenvalues, eigenvectors, and the alpha matrix.
- Return type:
Tuple[Tensor, Tensor, Tensor]
- get_alpha() Any[source]¶
Returns the current alpha matrix of the FGS.
- Returns:
The alpha matrix.
- Return type:
Tensor
- get_bogoliubov_uv() Tuple[Any, Any][source]¶
Returns the u and v matrices of the Bogoliubov transformation.
The Bogoliubov transformation is defined as: \(b_k = u_{k,i} a_i + v_{k,i} a_i^\dagger\)
where \(b_k\) are the new fermionic operators and \(a_i\) are the original ones.
- Returns:
A tuple containing the u and v matrices.
- Return type:
Tuple[Tensor, Tensor]
- get_cmatrix(now_i: bool = True, now_j: bool = True) Any[source]¶
Calculates the correlation matrix.
The correlation matrix is defined as \(C_{ij} = \langle c_i^\dagger c_j \rangle\). This method can also compute out-of-time-ordered correlators (OTOC) by specifying whether to use the current or initial state for the i and j indices.
- Parameters:
now_i (bool, optional) – If True, use the current state for the i index. Defaults to True.
now_j (bool, optional) – If True, use the current state for the j index. Defaults to True.
- Returns:
The correlation matrix.
- Return type:
Tensor
- get_cmatrix_majorana() Any[source]¶
Calculates the correlation matrix in the Majorana basis.
The Majorana operators are defined as: \(\gamma_{2i} = c_i + c_i^\dagger\) \(\gamma_{2i+1} = -i(c_i - c_i^\dagger)\)
- Returns:
The correlation matrix in the Majorana basis.
- Return type:
Tensor
- get_covariance_matrix() Any[source]¶
Calculates the covariance matrix.
The covariance matrix is defined from the Majorana correlation matrix.
- Returns:
The covariance matrix.
- Return type:
Tensor
- get_reduced_cmatrix(subsystems_to_trace_out: List[int]) Any[source]¶
Calculates the reduced correlation matrix by tracing out specified subsystems.
This optimized implementation first slices the alpha matrix, then computes the correlation matrix, reducing complexity from O(L³) to O(L·L_A²) where L_A is the size of the kept subsystem.
- Parameters:
subsystems_to_trace_out (List[int]) – A list of site indices to be traced out.
- Returns:
The reduced correlation matrix.
- Return type:
Tensor
- static hopping(chi: Any, i: int, j: int, L: int) Any[source]¶
Constructs the hopping Hamiltonian between two sites.
The hopping Hamiltonian is given by \(\chi c_i^\dagger c_j + h.c.\).
- Parameters:
chi (Tensor) – The hopping strength.
i (int) – The index of the first site.
j (int) – The index of the second site.
L (int) – The number of fermionic sites.
- Returns:
The hopping Hamiltonian.
- Return type:
Tensor
- static init_alpha(filled: List[int], L: int) Any[source]¶
Initializes the alpha matrix for a given set of filled sites.
- Parameters:
filled (List[int]) – A list of site indices that are occupied by fermions.
L (int) – The number of fermionic sites.
- Returns:
The initialized alpha matrix.
- Return type:
Tensor
- overlap(other: FGSSimulator) Any[source]¶
overlap upto a U(1) phase
- Parameters:
other (FGSSimulator) – _description_
- Returns:
_description_
- Return type:
_type_
- post_select(i: int, keep: int = 1) None[source]¶
Post-selects the state based on the occupation of a specific site.
This optimized implementation uses vectorized broadcasting operations instead of Python loops, improving JIT compilation performance.
- Parameters:
i (int) – The index of the site to post-select on.
keep (int, optional) – The desired occupation number (0 or 1). Defaults to 1.
- renyi_entanglement_asymmetry(n: int, subsystems_to_trace_out: List[int], batch: int = 100, status: Any | None = None, with_std: bool = False) Any[source]¶
Computes the Renyi entanglement asymmetry.
Ref: https://arxiv.org/abs/2302.03330
- Parameters:
n (int) – The order of the Renyi entanglement asymmetry.
subsystems_to_trace_out (List[int]) – A list of site indices to be traced out.
batch (int, optional) – The number of samples to use for the Monte Carlo estimation. Defaults to 100.
status (Optional[Tensor], optional) – A tensor of random numbers for the sampling. If None, it will be generated internally. Defaults to None.
with_std (bool, optional) – If True, also return the standard deviation of the estimation. Defaults to False.
- Returns:
The Renyi entanglement asymmetry. If with_std is True, a tuple containing the asymmetry and its standard deviation is returned.
- Return type:
Tensor
- renyi_entropy(n: int, subsystems_to_trace_out: List[int]) Any[source]¶
Computes the Renyi entropy of order n for a given subsystem.
- Parameters:
n (int) – The order of the Renyi entropy.
subsystems_to_trace_out (List[int]) – A list of site indices to be traced out, defining the subsystem.
- Returns:
The Renyi entropy of order n.
- Return type:
Tensor
- static sc_pairing(chi: Any, i: int, j: int, L: int) Any[source]¶
Constructs the superconducting pairing Hamiltonian between two sites.
The superconducting pairing Hamiltonian is given by \(\chi c_i^\dagger c_j^\dagger + h.c.\).
- Parameters:
chi (Tensor) – The pairing strength.
i (int) – The index of the first site.
j (int) – The index of the second site.
L (int) – The number of fermionic sites.
- Returns:
The superconducting pairing Hamiltonian.
- Return type:
Tensor
- class tensorcircuit.fgs.FGSTestSimulator(L: int, filled: List[int] | None = None, state: Any | None = None, hc: Any | None = None)[source]¶
Bases:
objectNever use, only for correctness testing stick to numpy backend and no jit/ad/vmap is available
- __init__(L: int, filled: List[int] | None = None, state: Any | None = None, hc: Any | None = None)[source]¶
- overlap(other: FGSTestSimulator) Any[source]¶
- product(other: FGSTestSimulator) Any[source]¶