Skip to content

Commit

Permalink
Merge pull request #321 from pablosanjose/copylat2
Browse files Browse the repository at this point in the history
Bugfix: ensure correct dealiasing of lattices in attach
  • Loading branch information
pablosanjose authored Nov 20, 2024
2 parents 437e522 + 3c39b75 commit 75fd834
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 11 deletions.
10 changes: 1 addition & 9 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1623,14 +1623,6 @@ Base.copy(h::Hamiltonian) = Hamiltonian(
copy_lattice(h::Hamiltonian) = Hamiltonian(
copy(lattice(h)), blockstructure(h), harmonics(h), bloch(h))

function copy_lattice(h1::Hamiltonian, h2::Hamiltonian)
@assert lattice(h1) === lattice(h2)
lat´ = copy(lattice(h1))
h1´ = Hamiltonian(lat´, blockstructure(h1), harmonics(h1), bloch(h1))
h2´ = Hamiltonian(lat´, blockstructure(h2), harmonics(h2), bloch(h2))
return h1´, h2´
end

copy_harmonics_shallow(h::Hamiltonian) = Hamiltonian(
lattice(h), blockstructure(h), copy(harmonics(h)), bloch(h))

Expand Down Expand Up @@ -1705,7 +1697,7 @@ LinearAlgebra.ishermitian(h::ParametricHamiltonian) =
argerror("`ishermitian(::ParametricHamiltonian)` not supported, as the result can depend on the values of parameters.")

copy_lattice(p::ParametricHamiltonian) = ParametricHamiltonian(
copy_lattice(p.hparent, p.h)..., p.modifiers, p.allptrs, p.allparams)
p.hparent, copy_lattice(p.h), p.modifiers, p.allptrs, p.allparams)

copy_harmonics_shallow(p::ParametricHamiltonian) = ParametricHamiltonian(
copy_harmonics_shallow(p.hparent), copy_harmonics_shallow(p.h), p.modifiers, p.allptrs, p.allparams)
Expand Down
2 changes: 1 addition & 1 deletion test/test_greenfunction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ end
@test typeof(ρ0sol) == typeof(ρsol)
end

@testset "aliasing" begin
@testset "greenfunction aliasing" begin
# Issue #267
g = LP.linear() |> hamiltonian(@hopping((; q = 1) -> q*I), orbitals = 2) |> greenfunction
= Quantica.minimal_callsafe_copy(g)
Expand Down
2 changes: 1 addition & 1 deletion test/test_hamiltonian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ end
@test h((1,2)) == h3((1,2))
h = LP.square() |> @hopping((; t=1) -> t) |> supercell((2,0), (0, 1))
= h |> transform(r -> SA[r[2], r[1]])
@test sites(lattice(h´)) == sites(h´.h.lattice) == sites(lattice(parent(h´)))
@test sites(lattice(h´)) == sites(h´.h.lattice) != sites(lattice(parent(h´)))
@test sites(lattice(h´)) == [SA[0,0], SA[0,1]]
h´´ = reverse(h´)
@test bravais_matrix(lattice(h´´)) == - bravais_matrix(lattice(h´))
Expand Down

0 comments on commit 75fd834

Please sign in to comment.