diff --git a/docs/src/examples/DMRG.md b/docs/src/examples/DMRG.md index 77c6e0a601..250ad474f0 100644 --- a/docs/src/examples/DMRG.md +++ b/docs/src/examples/DMRG.md @@ -308,10 +308,10 @@ let # os = OpSum() for j=1:N-1 - os += -4,"Sz",j,"Sz",j+1 + os -= 4,"Sz",j,"Sz",j+1 end for j=1:N - os += -2*h,"Sx",j; + os -= 2*h,"Sx",j; end H = MPO(os,sites) diff --git a/src/lib/ITensorMPS/examples/autodiff/circuit_optimization/vqe.jl b/src/lib/ITensorMPS/examples/autodiff/circuit_optimization/vqe.jl index 5ac27f66a5..edaeeaef8e 100644 --- a/src/lib/ITensorMPS/examples/autodiff/circuit_optimization/vqe.jl +++ b/src/lib/ITensorMPS/examples/autodiff/circuit_optimization/vqe.jl @@ -11,7 +11,7 @@ gradtol = 1e-4 # Tolerance for stopping gradient descent function ising_hamiltonian(nsites; h) ℋ = OpSum() for j in 1:(nsites - 1) - ℋ += -1, "Z", j, "Z", j + 1 + ℋ -= 1, "Z", j, "Z", j + 1 end for j in 1:nsites ℋ += h, "X", j diff --git a/src/lib/ITensorMPS/examples/autodiff/mps_autodiff.jl b/src/lib/ITensorMPS/examples/autodiff/mps_autodiff.jl index 5a9c123585..d1194e299f 100644 --- a/src/lib/ITensorMPS/examples/autodiff/mps_autodiff.jl +++ b/src/lib/ITensorMPS/examples/autodiff/mps_autodiff.jl @@ -5,10 +5,10 @@ using Zygote function ising(n; J, h) os = OpSum() for j in 1:(n - 1) - os += -J, "Z", j, "Z", j + 1 + os -= J, "Z", j, "Z", j + 1 end for j in 1:n - os += -h, "X", j + os -= h, "X", j end return os end diff --git a/src/lib/ITensorMPS/examples/dmrg/1d_hubbard_extended.jl b/src/lib/ITensorMPS/examples/dmrg/1d_hubbard_extended.jl index d4139bedb4..6e10091caa 100644 --- a/src/lib/ITensorMPS/examples/dmrg/1d_hubbard_extended.jl +++ b/src/lib/ITensorMPS/examples/dmrg/1d_hubbard_extended.jl @@ -17,17 +17,17 @@ let os = OpSum() for b in 1:(N - 1) - os += -t1, "Cdagup", b, "Cup", b + 1 - os += -t1, "Cdagup", b + 1, "Cup", b - os += -t1, "Cdagdn", b, "Cdn", b + 1 - os += -t1, "Cdagdn", b + 1, "Cdn", b + os -= t1, "Cdagup", b, "Cup", b + 1 + os -= t1, "Cdagup", b + 1, "Cup", b + os -= t1, "Cdagdn", b, "Cdn", b + 1 + os -= t1, "Cdagdn", b + 1, "Cdn", b os += V1, "Ntot", b, "Ntot", b + 1 end for b in 1:(N - 2) - os += -t2, "Cdagup", b, "Cup", b + 2 - os += -t2, "Cdagup", b + 2, "Cup", b - os += -t2, "Cdagdn", b, "Cdn", b + 2 - os += -t2, "Cdagdn", b + 2, "Cdn", b + os -= t2, "Cdagup", b, "Cup", b + 2 + os -= t2, "Cdagup", b + 2, "Cup", b + os -= t2, "Cdagdn", b, "Cdn", b + 2 + os -= t2, "Cdagdn", b + 2, "Cdn", b end for i in 1:N os += U, "Nupdn", i diff --git a/src/lib/ITensorMPS/examples/dmrg/1d_ising_with_observer.jl b/src/lib/ITensorMPS/examples/dmrg/1d_ising_with_observer.jl index d3dbd7c75b..76194be49e 100644 --- a/src/lib/ITensorMPS/examples/dmrg/1d_ising_with_observer.jl +++ b/src/lib/ITensorMPS/examples/dmrg/1d_ising_with_observer.jl @@ -11,7 +11,7 @@ function tfimMPO(sites, h::Float64) N = length(sites) os = OpSum() for j in 1:(N - 1) - os += -1, "Z", j, "Z", j + 1 + os -= 1, "Z", j, "Z", j + 1 end for j in 1:N os += h, "X", j diff --git a/src/lib/ITensorMPS/examples/dmrg/2d_hubbard_conserve_particles.jl b/src/lib/ITensorMPS/examples/dmrg/2d_hubbard_conserve_particles.jl index f1887341da..2c1b400608 100644 --- a/src/lib/ITensorMPS/examples/dmrg/2d_hubbard_conserve_particles.jl +++ b/src/lib/ITensorMPS/examples/dmrg/2d_hubbard_conserve_particles.jl @@ -14,10 +14,10 @@ function main(; Nx=6, Ny=3, U=4.0, t=1.0) os = OpSum() for b in lattice - os += -t, "Cdagup", b.s1, "Cup", b.s2 - os += -t, "Cdagup", b.s2, "Cup", b.s1 - os += -t, "Cdagdn", b.s1, "Cdn", b.s2 - os += -t, "Cdagdn", b.s2, "Cdn", b.s1 + os -= t, "Cdagup", b.s1, "Cup", b.s2 + os -= t, "Cdagup", b.s2, "Cup", b.s1 + os -= t, "Cdagdn", b.s1, "Cdn", b.s2 + os -= t, "Cdagdn", b.s2, "Cdn", b.s1 end for n in 1:N os += U, "Nupdn", n diff --git a/src/lib/ITensorMPS/test/base/test_autompo.jl b/src/lib/ITensorMPS/test/base/test_autompo.jl index 95156a3ba7..7451851f3d 100644 --- a/src/lib/ITensorMPS/test/base/test_autompo.jl +++ b/src/lib/ITensorMPS/test/base/test_autompo.jl @@ -905,7 +905,7 @@ end M1 = MPO(a1, s) a2 = OpSum() - a2 += -1, "C", 3, "Cdag", 1 + a2 -= 1, "C", 3, "Cdag", 1 M2 = MPO(a2, s) a3 = OpSum() @@ -938,7 +938,7 @@ end M1 = MPO(a1, s) a2 = OpSum() - a2 += -1, "Cdn", 3, "Cdagdn", 1 + a2 -= 1, "Cdn", 3, "Cdagdn", 1 M2 = MPO(a2, s) p0uu = MPS(s, [1, 2, 2, 1, 1]) @@ -1013,9 +1013,9 @@ end if m == i && n == j && p == l && q == k exact_val += V[i, j, l, k] elseif m == i && n == j && p == k && q == l - exact_val += -V[i, j, k, l] + exact_val -= V[i, j, k, l] elseif m == j && n == i && p == l && q == k - exact_val += -V[j, i, l, k] + exact_val -= V[j, i, l, k] elseif m == j && n == i && p == k && q == l exact_val += V[j, i, k, l] end @@ -1036,7 +1036,7 @@ end os = OpSum() for i in 1:(N - 1) os += +1im, "S+", i, "S-", i + 1 - os += -1im, "S-", i, "S+", i + 1 + os -= 1im, "S-", i, "S+", i + 1 end H = MPO(os, sites) psiud = MPS(sites, [1, 2, 1, 2]) @@ -1100,8 +1100,8 @@ end t = 1.0 os = OpSum() for n in 1:(N - 1) - os .+= -t, "Cdag", n, "C", n + 1 - os .+= -t, "Cdag", n + 1, "C", n + os .-= t, "Cdag", n, "C", n + 1 + os .-= t, "Cdag", n + 1, "C", n end s = siteinds("Fermion", N; conserve_qns=true) os_original = deepcopy(os) @@ -1138,8 +1138,8 @@ end os = OpSum() for j in 1:(N - 1) - os += -t, "Adag", j, "A", j + 1 - os += -t, "A", j, "Adag", j + 1 + os -= t, "Adag", j, "A", j + 1 + os -= t, "A", j, "Adag", j + 1 os += V1, "N", j, "N", j + 1 end for j in 1:(N - 2) diff --git a/src/lib/ITensorMPS/test/base/test_dmrg.jl b/src/lib/ITensorMPS/test/base/test_dmrg.jl index 648c19c147..f2b7f1a4db 100644 --- a/src/lib/ITensorMPS/test/base/test_dmrg.jl +++ b/src/lib/ITensorMPS/test/base/test_dmrg.jl @@ -283,10 +283,10 @@ using ITensors.ITensorMPS: nsite, set_nsite!, site_range os = OpSum() for j in 1:(N - 1) - os += -1, "Sz", j, "Sz", j + 1 + os -= 1, "Sz", j, "Sz", j + 1 end for j in 1:N - os += -0.2, "Sx", j + os -= 0.2, "Sx", j end H = MPO(os, sites) @@ -390,13 +390,13 @@ using ITensors.ITensorMPS: nsite, set_nsite!, site_range os = OpSum() for j in 1:(N - 1) - os += -t1, "Cdag", j, "C", j + 1 - os += -t1, "Cdag", j + 1, "C", j + os -= t1, "Cdag", j, "C", j + 1 + os -= t1, "Cdag", j + 1, "C", j os += V, "N", j, "N", j + 1 end for j in 1:(N - 2) - os += -t2, "Cdag", j, "C", j + 2 - os += -t2, "Cdag", j + 2, "C", j + os -= t2, "Cdag", j, "C", j + 2 + os -= t2, "Cdag", j + 2, "C", j end H = MPO(os, s) @@ -421,10 +421,10 @@ using ITensors.ITensorMPS: nsite, set_nsite!, site_range os += (U, "Nupdn", i) end for b in 1:(N - 1) - os += -t1, "Cdagup", b, "Cup", b + 1 - os += -t1, "Cdagup", b + 1, "Cup", b - os += -t1, "Cdagdn", b, "Cdn", b + 1 - os += -t1, "Cdagdn", b + 1, "Cdn", b + os -= t1, "Cdagup", b, "Cup", b + 1 + os -= t1, "Cdagup", b + 1, "Cup", b + os -= t1, "Cdagdn", b, "Cdn", b + 1 + os -= t1, "Cdagdn", b + 1, "Cdn", b os += V1, "Ntot", b, "Ntot", b + 1 end H = MPO(os, sites) diff --git a/src/lib/ITensorMPS/test/base/test_fermions.jl b/src/lib/ITensorMPS/test/base/test_fermions.jl index 0468f1997c..323a88e7bf 100644 --- a/src/lib/ITensorMPS/test/base/test_fermions.jl +++ b/src/lib/ITensorMPS/test/base/test_fermions.jl @@ -50,8 +50,8 @@ import ITensors: Out, In t1 = 1.0 os = OpSum() for b in 1:(N - 1) - os += -t1, "Cdag", b, "C", b + 1 - os += -t1, "Cdag", b + 1, "C", b + os -= t1, "Cdag", b, "C", b + 1 + os -= t1, "Cdag", b + 1, "C", b end H = MPO(os, sites) @@ -72,8 +72,8 @@ import ITensors: Out, In os = OpSum() for b in 1:(N - 1) - os += -t1, "Cdag", b, "C", b + 1 - os += -t1, "Cdag", b + 1, "C", b + os -= t1, "Cdag", b, "C", b + 1 + os -= t1, "Cdag", b + 1, "C", b os += V1, "N", b, "N", b + 1 end H = MPO(os, sites) @@ -110,12 +110,12 @@ import ITensors: Out, In s = siteinds("Fermion", N; conserve_qns=true) os = OpSum() for n in 1:(N - 1) - os += -t1, "Cdag", n, "C", n + 1 - os += -t1, "Cdag", n + 1, "C", n + os -= t1, "Cdag", n, "C", n + 1 + os -= t1, "Cdag", n + 1, "C", n end for n in 1:(N - 2) - os += -t2, "Cdag", n, "C", n + 2 - os += -t2, "Cdag", n + 2, "C", n + os -= t2, "Cdag", n, "C", n + 2 + os -= t2, "Cdag", n + 2, "C", n end H = MPO(os, s) @@ -173,8 +173,8 @@ import ITensors: Out, In ost = OpSum() osV = OpSum() for b in 1:(N - 1) - ost += -t1, "Cdag", b, "C", b + 1 - ost += -t1, "Cdag", b + 1, "C", b + ost -= t1, "Cdag", b, "C", b + 1 + ost -= t1, "Cdag", b + 1, "C", b osV += V1, "N", b, "N", b + 1 end Ht = MPO(ost, s) @@ -213,12 +213,12 @@ import ITensors: Out, In ost = OpSum() for b in 1:(N - 1) - ost += -t1, "Cdag", b, "C", b + 1 - ost += -t1, "Cdag", b + 1, "C", b + ost -= t1, "Cdag", b, "C", b + 1 + ost -= t1, "Cdag", b + 1, "C", b end for b in 1:(N - 2) - ost += -t2, "Cdag", b, "C", b + 2 - ost += -t2, "Cdag", b + 2, "C", b + ost -= t2, "Cdag", b, "C", b + 2 + ost -= t2, "Cdag", b + 2, "C", b end Ht = MPO(ost, s) diff --git a/src/lib/ITensorMPS/test/base/test_mps.jl b/src/lib/ITensorMPS/test/base/test_mps.jl index 8dce11c1e2..ad7989503a 100644 --- a/src/lib/ITensorMPS/test/base/test_mps.jl +++ b/src/lib/ITensorMPS/test/base/test_mps.jl @@ -1811,8 +1811,8 @@ end U = 1.0 opsum = OpSum() for b in 1:(N - 1) - opsum .+= -t, "Cdag", b, "C", b + 1 - opsum .+= -t, "Cdag", b + 1, "C", b + opsum .-= t, "Cdag", b, "C", b + 1 + opsum .-= t, "Cdag", b + 1, "C", b opsum .+= U, "N", b, "N", b + 1 end H = MPO(opsum, s) @@ -1897,10 +1897,10 @@ end U = 1.0 opsum = OpSum() for b in 1:(N - 1) - opsum .+= -t, "Cdagup", b, "Cup", b + 1 - opsum .+= -t, "Cdagup", b + 1, "Cup", b - opsum .+= -t, "Cdagdn", b, "Cdn", b + 1 - opsum .+= -t, "Cdagdn", b + 1, "Cdn", b + opsum .-= t, "Cdagup", b, "Cup", b + 1 + opsum .-= t, "Cdagup", b + 1, "Cup", b + opsum .-= t, "Cdagdn", b, "Cdn", b + 1 + opsum .-= t, "Cdagdn", b + 1, "Cdn", b end for n in 1:N opsum .+= U, "Nupdn", n diff --git a/src/lib/ITensorMPS/test/base/test_qnmpo.jl b/src/lib/ITensorMPS/test/base/test_qnmpo.jl index b44b96d47d..038f0812c0 100644 --- a/src/lib/ITensorMPS/test/base/test_qnmpo.jl +++ b/src/lib/ITensorMPS/test/base/test_qnmpo.jl @@ -250,7 +250,7 @@ end a = OpSum() h = 0.5 for j in 1:(N - 1) - a .+= -1, "Sx", j, "Sx", j + 1 + a .-= 1, "Sx", j, "Sx", j + 1 end for j in 1:N a .+= h, "Sz", j @@ -323,10 +323,10 @@ function make_hubbard_opsum( for dn in 1:NNN tj, Vj = t / dn, V / dn for n in 1:(N - dn) - os += -tj, "Cdagup", n, "Cup", n + dn - os += -tj, "Cdagup", n + dn, "Cup", n - os += -tj, "Cdagdn", n, "Cdn", n + dn - os += -tj, "Cdagdn", n + dn, "Cdn", n + os -= tj, "Cdagup", n, "Cup", n + dn + os -= tj, "Cdagup", n + dn, "Cup", n + os -= tj, "Cdagdn", n, "Cdn", n + dn + os -= tj, "Cdagdn", n + dn, "Cdn", n os += Vj, "Ntot", n, "Ntot", n + dn end end diff --git a/src/lib/ITensorMPS/test/base/test_threading.jl b/src/lib/ITensorMPS/test/base/test_threading.jl index e044ec1709..28e14085c7 100644 --- a/src/lib/ITensorMPS/test/base/test_threading.jl +++ b/src/lib/ITensorMPS/test/base/test_threading.jl @@ -33,10 +33,10 @@ end lattice = square_lattice(Nx, Ny; yperiodic=true) opsum = OpSum() for b in lattice - opsum .+= -t, "Cdagup", b.s1, "Cup", b.s2 - opsum .+= -t, "Cdagup", b.s2, "Cup", b.s1 - opsum .+= -t, "Cdagdn", b.s1, "Cdn", b.s2 - opsum .+= -t, "Cdagdn", b.s2, "Cdn", b.s1 + opsum .-= t, "Cdagup", b.s1, "Cup", b.s2 + opsum .-= t, "Cdagup", b.s2, "Cup", b.s1 + opsum .-= t, "Cdagdn", b.s1, "Cdn", b.s2 + opsum .-= t, "Cdagdn", b.s2, "Cdn", b.s1 end for n in 1:N opsum .+= U, "Nupdn", n diff --git a/src/lib/ITensorMPS/test/ext/ITensorMPSChainRulesCoreExt/test_chainrules.jl b/src/lib/ITensorMPS/test/ext/ITensorMPSChainRulesCoreExt/test_chainrules.jl index a6e9817c49..9b5e4937d1 100644 --- a/src/lib/ITensorMPS/test/ext/ITensorMPSChainRulesCoreExt/test_chainrules.jl +++ b/src/lib/ITensorMPS/test/ext/ITensorMPSChainRulesCoreExt/test_chainrules.jl @@ -148,10 +148,10 @@ Random.seed!(1234) function ising(n, h) os = OpSum() for j in 1:(n - 1) - os += -1, "Z", j, "Z", j + 1 - os += -h, "X", j + os -= 1, "Z", j, "Z", j + 1 + os -= h, "X", j end - os += -h, "X", n + os -= h, "X", n return os end H = MPO(ising(n, 1.0), s) diff --git a/src/lib/ITensorMPS/test/ext/ITensorMPSChainRulesCoreExt/test_optimization.jl b/src/lib/ITensorMPS/test/ext/ITensorMPSChainRulesCoreExt/test_optimization.jl index f5266065e5..3835f955b5 100644 --- a/src/lib/ITensorMPS/test/ext/ITensorMPSChainRulesCoreExt/test_optimization.jl +++ b/src/lib/ITensorMPS/test/ext/ITensorMPSChainRulesCoreExt/test_optimization.jl @@ -198,7 +198,7 @@ include(joinpath(@__DIR__, "utils", "circuit.jl")) function ising_hamiltonian(nsites; h) ℋ = OpSum() for j in 1:(nsites - 1) - ℋ += -1, "Z", j, "Z", j + 1 + ℋ -= 1, "Z", j, "Z", j + 1 end for j in 1:nsites ℋ += h, "X", j