コード例 #1
0
def test_gauge_match_minimizes(backend, dtype, chi, d):
    """
  Gauge matching decreases the values of ||A_C - A_L C ||
  and ||A_C - C A_R||.
  """
    A_L, C, A_R, _ = random_hermitian_system(backend, dtype, chi, d)
    A_C = tn.randn((chi, d, chi), dtype=dtype, backend=backend)
    epsL = tn.linalg.linalg.norm(A_C - ct.rightmult(A_L, C))
    epsR = tn.linalg.linalg.norm(A_C - ct.leftmult(C, A_R))
    A_L2, A_R2 = vumps.gauge_match(A_C, C, True)
    epsL2 = tn.linalg.linalg.norm(A_C - ct.rightmult(A_L2, C))
    epsR2 = tn.linalg.linalg.norm(A_C - ct.leftmult(C, A_R2))
    assert epsL2 < epsL
    assert epsR2 < epsR
コード例 #2
0
def test_leftmult(backend, dtype, chi, d):
  lam = tn.randn((chi, chi), dtype=dtype, backend=backend, seed=10)
  gam = tn.randn((chi, d, chi), dtype=dtype, backend=backend, seed=10)
  result = ct.leftmult(lam, gam)
  compare = tn.linalg.operations.ncon([lam, gam], [[-1, 1],
                                                   [1, -2, -3]])
  np.testing.assert_allclose(result.array, compare.array)
コード例 #3
0
def vumps_delta(mps: ThreeTensors, A_C: tn.Tensor, oldA_L: tn.Tensor,
                mode: Text):
    """
  Estimate the current vuMPS error.
  Args:
    mps: The MPS.
    A_C: Current A_C.
    oldA_L: A_L from the last iteration.
    mode: gradient_estimate_mode in vumps_params. See that docstring for
      details.
  """
    if mode == "gauge mismatch":
        A_L, C, A_R = mps
        eL = tn.norm(A_C - ct.rightmult(A_L, C))
        eR = tn.norm(A_C - ct.leftmult(C, A_R))
        delta = max(eL, eR)
    elif mode == "null space":
        A_Ldag = tn.pivot(oldA_L, pivot_axis=2).H
        N_Ldag = tn_vumps.polar.null_space(A_Ldag)
        N_L = N_Ldag.H
        A_Cmat = tn.pivot(A_C, pivot_axis=2)
        B = N_L @ A_Cmat
        delta = tn.norm(B)
    else:
        raise ValueError("Invalid mode {mode}.")
    return delta
コード例 #4
0
def gauge_match(A_C: tn.Tensor,
                C: tn.Tensor,
                mode: Text = "svd") -> TwoTensors:
    """
  Return approximately gauge-matched A_L and A_R from A_C and C
  using a polar decomposition.

  A_L and A_R are chosen to minimize ||A_C - A_L C|| and ||A_C - C A_R||.
  The respective solutions are the isometric factors in the
  polar decompositions of A_C @ C.H and C.H @ A_C.

  Args:
    A_C: Current estimate of A_C.
    C: C from the MPS.
    mode: Chooses the algorithm for the polar decomposition. See the docstring
     of vumps_params in params.py.

  Returns:
    A_L, A_R: Such that A_L C A_R minimizes ||A_C - A_L C|| and ||A_C - C A_R||,
      with A_L (A_R) left (right) isometric.
  """
    UC = tn_vumps.polar.polarU(C, mode=mode)  # unitary
    UAc_l = tn_vumps.polar.polarU(A_C, mode=mode)  # left isometric
    A_L = ct.rightmult(UAc_l, UC.H)
    UAc_r = tn_vumps.polar.polarU(A_C, pivot_axis=1, mode=mode)  # right iso
    A_R = ct.leftmult(UC.H, UAc_r)
    return A_L, A_R
コード例 #5
0
def test_gauge_match_right(backend, dtype, chi, d):
    """
  Gauge matching is a null op on a system gauge matched on the RHS.
  """
    _, C, A_R, _ = random_hermitian_system(backend, dtype, chi, d)
    A_C = ct.leftmult(C, A_R)
    _, A_R2 = vumps.gauge_match(A_C, C, True)
    rtol = 2 * A_R.size * C.size * A_C.size * np.finfo(dtype).eps
    np.testing.assert_allclose(A_R.array, A_R2.array, rtol=rtol)
    I = tn.eye(chi, backend=backend, dtype=dtype)
    XAR2 = ct.XopR(A_R2, I)
    np.testing.assert_allclose(XAR2.array, I.array, atol=rtol)
コード例 #6
0
def test_minimize_HAc(backend, dtype, chi, d):
    """
  The result of minimize_HAc solves the eigenproblem for HAc.
  """
    A_L, C, A_R, H = random_hermitian_system(backend, dtype, chi, d)
    A_C = ct.leftmult(C, A_R)
    LH = tn.randn((chi, chi), dtype=dtype, backend=backend)
    LH = 0.5 * (LH + LH.H)
    RH = tn.randn((chi, chi), dtype=dtype, backend=backend)
    RH = 0.5 * (RH + RH.H)
    params = tn_vumps.params.krylov_params(n_krylov=chi * chi, max_restarts=20)
    ev, newAC = tn_vumps.vumps.minimize_HAc([A_L, C, A_R], A_C, [H, LH, RH],
                                            1E-5, params)
    AC_prime = ct.apply_HAc(newAC, A_L, A_R, H, LH, RH)
    EAC = ev * newAC
    np.testing.assert_allclose(AC_prime.array, EAC.array, rtol=1E-4, atol=1E-4)