Closed HugoStrand closed 5 years ago
Dear all,
There is a silent but dangerous bug in the copy behavior of MeshBrillouinZone (or any object having such a mesh) in python. When making a copy using copy.deepcopy the BrillouinZone unit-vectors are not copied and instead set to the unit matrix...
MeshBrillouinZone
copy.deepcopy
BrillouinZone
Below is a test for the problem.
Best, Hugo
import copy import numpy as np from pytriqs.gf import MeshBrillouinZone from pytriqs.lattice import BrillouinZone, BravaisLattice cell = [ [1., 0., 2.], [0.5, 2.5, 1.], [1., 2., 0.]] bl = BravaisLattice(cell) bz = BrillouinZone(bl) periodization_matrix = 32 * np.eye(3, dtype=np.int32) bzmesh = MeshBrillouinZone(bz, periodization_matrix) bzmesh_ref = copy.deepcopy(bzmesh) # BREAKS units = bzmesh.domain.units() units_ref = bzmesh_ref.domain.units() np.testing.assert_array_almost_equal(units, units_ref)
This gives the output
AssertionError: Arrays are not almost equal to 6 decimals (mismatch 88.8888888889%) x: array([[ 2.513274, -1.256637, 1.884956], [-5.026548, 2.513274, 2.513274], [ 6.283185, -0. , -3.141593]]) y: array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])
Fixed in unstable
PS : upgrade cpp2py !!
Dear all,
There is a silent but dangerous bug in the copy behavior of
MeshBrillouinZone
(or any object having such a mesh) in python. When making a copy usingcopy.deepcopy
theBrillouinZone
unit-vectors are not copied and instead set to the unit matrix...Below is a test for the problem.
Best, Hugo
This gives the output