mdopt.optimiser package#

Submodules#

mdopt.optimiser.dephasing_dmrg module#

This module contains the DephasingDMRG and the EffectiveDensityOperator classes.

This algorithm’s main feature is that it restricts the target-state search to the computational basis states domain. In particular, we use it to find the main component of a Matrix Product Density Operator (MPDO), i.e., a computational basis state contributing the largest amplitude.

In our notation, MPDO for n sites denotes the following object:

     |      |               |       |
     |      |               |       |
----(0*)---(1*)--- ... ---(n-2*)--(n-1*)---
----(0)----(1)---- ... ---(n-2)---(n-1)----
     |      |               |       |
     |      |               |       |

An MPDO is formed by an MPS and its complex-conjugated version. The main idea is to find the main component of this object without performing the kronecker product explicitly.

class mdopt.optimiser.dephasing_dmrg.DephasingDMRG(mps: ExplicitMPS | CanonicalMPS, mps_target: ExplicitMPS | CanonicalMPS, chi_max: int = 10000, cut: float = 1e-17, mode: str = 'SA', silent: bool = False, copy: bool = True)#

Class holding the Dephasing Density Matrix Renormalisation Group algorithm with two-site updates for a finite-size system with open-boundary conditions.

mps#

MPS serving as a current approximation of the target state.

Type:

Union[ExplicitMPS, CanonicalMPS]

mps_target#

The target MPS in the right-canonical form. This MPS is used to construct the dephased MPDO.

Type:

Union[ExplicitMPS, CanonicalMPS]

chi_max#

The highest bond dimension of an MPS allowed.

Type:

int

mode#
The eigensolver mode. Available options:
LM : Largest (in magnitude) eigenvalues.
SM : Smallest (in magnitude) eigenvalues.
LA : Largest (algebraic) eigenvalues.
SA : Smallest (algebraic) eigenvalues.
Type:

str

cut#

The lower boundary of the spectrum, i.e., all the singular values smaller than that will be discarded.

Type:

float

silent#

Whether to show/hide the progress bar.

Type:

bool

run(num_iter: int = 1) None#

Run the algorithm for num_iter full sweeps.

sweep() None#

One full Dephasing DMRG sweep (left→right, then right→left).

update_bond(i: int) None#

Update the bond between sites i and i+1.

update_left_environment(i: int) None#

Compute left_environment left of site i+1 from left of site i.

update_right_environment(i: int) None#

Compute right_environment right of site i-1 from right of site i.

class mdopt.optimiser.dephasing_dmrg.EffectiveDensityOperator(*args, **kwargs)#

Bases: LinearOperator

Class to store an effective two-site density operator.

To take more advantage of the scipy.sparse.linalg module, we make a special class for local effective density operators extending the analogy from local effective operators. It allows us to compute eigenvectors more effeciently.

The diagram displaying the contraction can be found in the supplementary notes.

mdopt.optimiser.dmrg module#

This module contains the DMRG and the EffectiveOperator classes. The class structure is inspired by TenPy.

class mdopt.optimiser.dmrg.DMRG(mps: ExplicitMPS | CanonicalMPS, mpo: List[ndarray], chi_max: int = 10000, cut: float = 1e-17, mode: str = 'SA', silent: bool = False, copy: bool = True)#

Class holding the Density Matrix Renormalisation Group algorithm with two-site updates for a finite-size system with open-boundary conditions.

run(num_iter: int = 1) None#

Run the algorithm, i.e., run sweep for num_iter iterations.

sweep() None#

One full DMRG sweep (left→right, then right→left).

update_bond(i: int) None#

Update the bond between sites i and i+1.

update_left_environment(i: int) None#

Compute the left_environment left of site i+1 from the left_environment left of site i.

update_right_environment(i: int) None#

Compute the right_environment right of site i-1 from the right_environment right of site i.

class mdopt.optimiser.dmrg.EffectiveOperator(*args, **kwargs)#

Bases: LinearOperator

Class to store an effective two-site operator.

In order to take more advantage of the scipy.sparse.linalg module, we make a special class for local effective operators. It allows us to compute eigenvectors more efficiently.

Such effective operator is to be diagonalised in the update_bond method of the DMRG class:

---uL                    uR---
|        i          j        |
|  vL    |          |    vR  |
(L)----(mpo_l)----(mpo_r)----(R)
|        |          |        |
|        k          l        |
---dL                    dR---

In our convention, the legs of left/right environments (tensors L/R in the cartoon) are ordered as follows: (uL/uR, vL/vR, dL/dR) which means “(up, virtual, down)”.

mdopt.optimiser.utils module#

This module contains different combinatorial optimisation utilities.

First, we define the tensors which represent logical operation. We use the following tensors: IDENTITY, COPY, XOR, SWAP.

According to our convention, each tensor has legs (vL, vR, pU, pD), where v stands for “virtual”, p – for “physical”, and L, R, U, D stand for “left”, “right”, “up”, “down”.

class mdopt.optimiser.utils.ConstraintString(constraints: List[ndarray], sites: List[List[int]])#

Class for storing a string of logical constraints in the Matrix Product Operator format. Logical constraints are to be passed in the form of 4-dimensional MPO tensors.

constraints#

A list of logical constraints of which the string consists.

Type:

List[np.ndarray]

sites#

Each list inside corresponds to a constraint from the constraints list, and contains the sites to which each constraint is applied. For example, [[3, 5], [2, 4, 6], …] means applying constraints[0] to sites 3 and 5, constraints[1] to sites 2, 4, 6 etc.

Type:

List[List[int]]

Raises:

ValueError

  • Empty list of constraints. - Empty list of sites. - The sites list is longer than the constraints list. - Non-unique sites in the sites list. - The list of sites has gaps, indicating breaks in the constraints string.

flat(sort: bool = False) List[int]#

Returns a flattened list of sites.

mpo() List[ndarray]#

Returns an MPO list aligned to the span of this constraint string.

span() int#

Returns the span (length) of the constraint string.

mdopt.optimiser.utils.apply_constraints(mps: CanonicalMPS, strings: List[List[int]], logical_tensors: List[ndarray], chi_max: int = 10000, cut: float = 1e-17, renormalise: bool = True, strategy: str = 'Naive', silent: bool = False, dense: bool = False, return_entropies_and_bond_dims: bool = False) CanonicalMPS | ndarray#

This function applies logical constraints to an MPS.

Parameters:
  • mps (CanonicalMPS) – The MPS to which the logical constraints are being applied.

  • strings (List[List[int]]) – The list of arguments for ConstraintString.

  • logical_tensors (List[np.ndarray]) – List of logical tensors for ConstraintString.

  • chi_max (int) – Maximum bond dimension to keep in the contractor.

  • cut (float) – The lower boundary of the spectrum in the contractor. All singular values below this value are truncated.

  • renormalise (bool) – Whether to renormalise the orthogonality centre after each constraint application.

  • result_to_explicit (bool) – Whether to transform the resulting MPS into the Explicit form.

  • strategy (str) – The contractor strategy. Available options are “Optimised” and “Naive”.

  • silent (bool) – Whether to show the progress bar or not.

  • return_entropies_and_bond_dims (bool) – Whether to return the entanglement entropies and bond dimensions at each bond.

  • dense (bool) – Whether to perform the calculations in the dense form. To be used only for small systems (<= 20 sites).

Returns:

  • mps (CanonicalMPS) – The resulting MPS.

  • entropies, bond_dims (List[float], List[int]) – The list of entanglement entropies at each bond. Returned only if return_entropies_and_bond_dims is set to True.

mdopt.optimiser.utils.parity(bitstring: str, indices: list[int]) int#

Returns the parity of the bits at the given indices in the bitstring.

mdopt.optimiser.utils.random_constraints(num_bits: int, constraint_size: int, rng: Generator) dict#

Generate random XOR and SWAP site constraints for a bitstring.

Parameters:
  • num_bits (int) – The total number of bits in the bitstring. Must be at least 3.

  • constraint_size (int) – The maximum possible length of the constraint, i.e., the number of XOR sites.

  • rng (numpy.random.Generator) – A NumPy random number generator instance for reproducibility.

Returns:

A dictionary containing the following keys:

  • ’xor_left_sites’: list of int

    List with one index selected as the left XOR site.

  • ’xor_bulk_sites’: list of int

    List of indices selected as bulk XOR sites, between left and right.

  • ’xor_right_sites’: list of int

    List with one index selected as the right XOR site.

  • ’swap_sites’: list of int

    List of indices between left and right XOR sites, excluding the bulk XOR sites.

  • ’all_constrained_bits’: list of int

    Sorted list of all selected XOR site indices (left, bulk, right).

Return type:

dict

Raises:

ValueError – If num_bits is less than 3.

Module contents#