Skip to content
Snippets Groups Projects
Commit f23f57e9 authored by Joseph Weston's avatar Joseph Weston
Browse files

correct test for shape errors

This test was previously incorrect, but because we didn't actually
check the number of orbitals on constant values on finalization
this was not caught.
parent 2087abbe
No related branches found
No related tags found
No related merge requests found
Pipeline #25460 passed
......@@ -75,19 +75,15 @@ def test_hamiltonian_submatrix(vectorize):
raises(ValueError, kwant.solvers.default.greens_function, syst3, 0.2)
# Test for shape errors.
syst[chain2(0), chain(2)] = np.array([[1, 2]])
syst2 = syst.finalized()
raises(ValueError, syst2.hamiltonian_submatrix)
raises(ValueError, syst2.hamiltonian_submatrix, sparse=True)
syst[chain2(0), chain(2)] = 1
syst2 = syst.finalized()
raises(ValueError, syst2.hamiltonian_submatrix)
raises(ValueError, syst2.hamiltonian_submatrix, sparse=True)
if vectorize: # non-vectorized systems don't check this at finalization
# Add another hopping of the same type but with a different
# (and still incompatible) shape.
syst[chain2(0), chain(1)] = np.array([[1, 2]])
raises(ValueError, syst.finalized)
for onsite in ([[1, 2]], 1):
syst[chain2(0), chain(2)] = onsite
if vectorize:
# non-vectorized systems don't check this at finalization
raises(ValueError, syst.finalized)
else:
syst2 = syst.finalized()
raises(ValueError, syst2.hamiltonian_submatrix)
raises(ValueError, syst2.hamiltonian_submatrix, sparse=True)
@pytest.mark.parametrize("vectorize", [False, True])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment