Skip to content
This repository has been archived by the owner on Jul 7, 2024. It is now read-only.

Commit

Permalink
Implement normalize! for Product ansatz
Browse files Browse the repository at this point in the history
  • Loading branch information
mofeing committed Jan 22, 2024
1 parent 65cb2c6 commit 284d68f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Quantum/Product.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,15 @@ function LinearAlgebra.norm(ψ::Product{State}, p::Real = 2)
mapreduce(Base.Fix2(^, p), +, parent(tensor))
end^(1 // p)
end

function LinearAlgebra.normalize!::Product{State}, p::Real = 2; insert::Union{Nothing,Int} = nothing)
norm = LinearAlgebra.norm(ψ, p)

n = length(tensors(ψ))
norm ^= 1 / n
for tensor in tensors(ψ)
tensor ./= norm
end

ψ
end

0 comments on commit 284d68f

Please sign in to comment.