From e1970fd50f270dba562f3ebfe96e0f1d4643bf73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20S=C3=A1nchez=20Ram=C3=ADrez?= Date: Sun, 3 Nov 2024 00:37:38 +0100 Subject: [PATCH] refactor `expect` to avoid calling `evolve!` --- src/Ansatz/Ansatz.jl | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Ansatz/Ansatz.jl b/src/Ansatz/Ansatz.jl index 7d1091f0..d8f68494 100644 --- a/src/Ansatz/Ansatz.jl +++ b/src/Ansatz/Ansatz.jl @@ -142,11 +142,7 @@ end overlap(a::AbstractAnsatz, b::AbstractAnsatz) = contract(merge(a, copy(b)')) -function expect(ψ::AbstractAnsatz, observable; bra=copy(ψ)) - ϕ = bra - evolve!(ϕ, observable) - return overlap(ϕ, ψ) -end +expect(ψ::AbstractAnsatz, observable; bra=copy(ψ)) = contract(merge(ψ, observable, bra')) function expect(ψ::AbstractAnsatz, observables::AbstractVecOrTuple; bra=copy(ψ)) sum(observables) do observable