@@ -674,19 +674,25 @@ contract(ψ::MPS, A::MPO; kwargs...) = contract(A, ψ; kwargs...)
674674
675675# @doc (@doc contract(::MPO, ::MPS)) *(::MPO, ::MPS)
676676
677- function contract (:: Algorithm"densitymatrix" , A:: MPO , ψ:: MPS ; kwargs... ):: MPS
677+ function contract (
678+ :: Algorithm"densitymatrix" ,
679+ A:: MPO ,
680+ ψ:: MPS ;
681+ cutoff= 1e-13 ,
682+ maxdim= maxlinkdim (A) * maxlinkdim (ψ),
683+ mindim= 1 ,
684+ normalize= false ,
685+ kwargs... ,
686+ ):: MPS
678687 n = length (A)
679688 n != length (ψ) &&
680689 throw (DimensionMismatch (" lengths of MPO ($n ) and MPS ($(length (ψ)) ) do not match" ))
681690 if n == 1
682691 return MPS ([A[1 ] * ψ[1 ]])
683692 end
684-
693+ mindim = max (mindim, 1 )
694+ requested_maxdim = maxdim
685695 ψ_out = similar (ψ)
686- cutoff:: Float64 = get (kwargs, :cutoff , 1e-13 )
687- requested_maxdim:: Int = get (kwargs, :maxdim , maxlinkdim (A) * maxlinkdim (ψ))
688- mindim:: Int = max (get (kwargs, :mindim , 1 ), 1 )
689- normalize:: Bool = get (kwargs, :normalize , false )
690696
691697 any (i -> isempty (i), siteinds (commoninds, A, ψ)) &&
692698 error (" In `contract(A::MPO, x::MPS)`, `A` and `x` must share a set of site indices" )
@@ -719,7 +725,7 @@ function contract(::Algorithm"densitymatrix", A::MPO, ψ::MPS; kwargs...)::MPS
719725 ts = isnothing (l) ? " " : tags (l)
720726 Lis = siteinds (uniqueinds, A, ψ, n)
721727 Ris = siteinds (uniqueinds, simA_c, ψ_c, n)
722- F = eigen (ρ, Lis, Ris; ishermitian= true , tags= ts, kwargs... )
728+ F = eigen (ρ, Lis, Ris; ishermitian= true , tags= ts, cutoff, maxdim, mindim, kwargs... )
723729 D, U, Ut = F. D, F. V, F. Vt
724730 l_renorm, r_renorm = F. l, F. r
725731 ψ_out[n] = Ut
@@ -739,7 +745,7 @@ function contract(::Algorithm"densitymatrix", A::MPO, ψ::MPS; kwargs...)::MPS
739745 ts = isnothing (l) ? " " : tags (l)
740746 Lis = IndexSet (s... , l_renorm)
741747 Ris = IndexSet (s̃... , r_renorm)
742- F = eigen (ρ, Lis, Ris; ishermitian= true , maxdim = maxdim, tags = ts , kwargs... )
748+ F = eigen (ρ, Lis, Ris; ishermitian= true , tags = ts, cutoff, maxdim, mindim , kwargs... )
743749 D, U, Ut = F. D, F. V, F. Vt
744750 l_renorm, r_renorm = F. l, F. r
745751 ψ_out[j] = Ut
@@ -755,9 +761,7 @@ function contract(::Algorithm"densitymatrix", A::MPO, ψ::MPS; kwargs...)::MPS
755761 return ψ_out
756762end
757763
758- function _contract (:: Algorithm"naive" , A, ψ; kwargs... )
759- truncate = get (kwargs, :truncate , true )
760-
764+ function _contract (:: Algorithm"naive" , A, ψ; truncate= true , kwargs... )
761765 A = sim (linkinds, A)
762766 ψ = sim (linkinds, ψ)
763767
@@ -801,16 +805,20 @@ function contract(alg::Algorithm"naive", A::MPO, B::MPO; kwargs...)
801805 return _contract (alg, A, B; kwargs... )
802806end
803807
804- function contract (:: Algorithm"zipup" , A:: MPO , B:: MPO ; kwargs... )
808+ function contract (
809+ :: Algorithm"zipup" ,
810+ A:: MPO ,
811+ B:: MPO ;
812+ cutoff= 1e-14 ,
813+ maxdim= maxlinkdim (A) * maxlinkdim (B),
814+ mindim= 1 ,
815+ kwargs... ,
816+ )
805817 if hassameinds (siteinds, A, B)
806818 error (
807819 " In `contract(A::MPO, B::MPO)`, MPOs A and B have the same site indices. The indices of the MPOs in the contraction are taken literally, and therefore they should only share one site index per site so the contraction results in an MPO. You may want to use `replaceprime(contract(A', B), 2 => 1)` or `apply(A, B)` which automatically adjusts the prime levels assuming the input MPOs have pairs of primed and unprimed indices." ,
808820 )
809821 end
810- cutoff:: Float64 = get (kwargs, :cutoff , 1e-14 )
811- resp_degen:: Bool = get (kwargs, :respect_degenerate , true )
812- maxdim:: Int = get (kwargs, :maxdim , maxlinkdim (A) * maxlinkdim (B))
813- mindim:: Int = max (get (kwargs, :mindim , 1 ), 1 )
814822 N = length (A)
815823 N != length (B) &&
816824 throw (DimensionMismatch (" lengths of MPOs A ($N ) and B ($(length (B)) ) do not match" ))
@@ -832,9 +840,9 @@ function contract(::Algorithm"zipup", A::MPO, B::MPO; kwargs...)
832840 left_inds;
833841 ortho= " left" ,
834842 tags= commontags (linkinds (A, i)),
835- cutoff= cutoff ,
836- maxdim= maxdim ,
837- mindim= mindim ,
843+ cutoff,
844+ maxdim,
845+ mindim,
838846 kwargs... ,
839847 )
840848 lCᵢ = dag (commoninds (C[i], R))
@@ -847,9 +855,9 @@ function contract(::Algorithm"zipup", A::MPO, B::MPO; kwargs...)
847855 left_inds;
848856 ortho= " right" ,
849857 tags= commontags (linkinds (A, i)),
850- cutoff= cutoff ,
851- maxdim= maxdim ,
852- mindim= mindim ,
858+ cutoff,
859+ maxdim,
860+ mindim,
853861 kwargs... ,
854862 )
855863 truncate! (C; kwargs... )
0 commit comments