Strategy#

class tn4ml.strategy.Sweeps[source][source]#

Bases: Strategy

The sweeping DMRG (Density Matrix Renormalization Group) technique is an algorithm used to efficiently find the ground state of large quantum systems. But in general in Machine Learning, it is used to optimize the parameters of a tensor network model. It works by iteratively optimizing the parameters, focusing on local regions and gradually improving the accuracy of the solution.

Sweeping Process:

  • Left-to-Right Sweep:

    Contract two tensors into one, find the gradient of the loss function with respect to that contracted tensor, update the parameter of concatenated tensor, and then split the tensor back into two. Swipe from first to last tensor in the tensor network.

  • Right-to-Left Sweep:

    Same process as left-to-right sweep but in the opposite direction.

Iterative Refinement:

Repeat the left-to-right and right-to-left sweeps multiple times. Each iteration (or sweep) improves the overall accuracy of the optimization.

Convergence:

The process continues until the changes in the parameters become negligible.

__init__(grouping=2, two_way=True, split_opts={'cutoff': 0.0}, **kwargs)[source][source]#

Constructor for Sweeps strategy.

grouping#

Number of tensors to group together. Default*=**2*.

Type:

int

two_way#

Flag indicating wheather sweeping happens two-way or one-way. Default*=**True* (two-way sweep).

Type:

bool

split_opts#

Additional args passed to model.split_tensor().

Type:

optional

kwargs#

Additional keyword arguments passed to inherited class.

Type:

optional

Raises:
  • ValueError – If grouping > 2.

  • ValueError – If grouping == 1.

Parameters:

grouping (int)

iterate_sites(model)[source][source]#

Function for iterating selected tensors.

Parameters:

sites (sequence of str) – List of tensors’ tags.

prehook(model, sites)[source][source]#

Contract tensors before computing gradients.

Parameters:
  • model (tn4ml.models.Model`) – Model

  • sites (sequence of int) – List of tensor ids.

Raises:

NotImplementedError – If grouping > 2.

posthook(model, sites)[source][source]#

Split tensors after computing gradients.

Parameters:
  • model (tn4ml.models.Model`) – Model

  • sites (sequence of str) – List of tensors’ tags.

Raises:

ValueError – If split function didn’t produce correct tensors.