-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_AndersonGraph.py
More file actions
61 lines (53 loc) · 2.03 KB
/
test_AndersonGraph.py
File metadata and controls
61 lines (53 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import pytest
import numpy as np
import networkx as nx
from AndersonGraph import AndersonGraph
@pytest.fixture
def setup_anderson_graph():
# Create a simple graph for testing
graph = nx.path_graph(4)
psi_0 = np.array([1, 0, 0, 0], dtype=complex)
eps_range = (0, 1)
t_hop = 1.0
anderson_graph = AndersonGraph(graph, psi_0, eps_range, t_hop)
return anderson_graph
def test_initialization(setup_anderson_graph):
anderson_graph = setup_anderson_graph
assert anderson_graph.num_sites == 4
assert len(anderson_graph.psi_0) == 4
assert anderson_graph.t_hop == 1.0
assert anderson_graph.binding.shape == (4, 4)
def test_hamiltonian(setup_anderson_graph):
anderson_graph = setup_anderson_graph
hamiltonian = anderson_graph._hamiltonian()
assert hamiltonian.shape == (4, 4)
assert np.allclose(hamiltonian, hamiltonian.T.conj()) # Hamiltonian should be Hermitian
def test_time_evolution_operator(setup_anderson_graph):
anderson_graph = setup_anderson_graph
time = 1.0
U_t = anderson_graph._time_evolution_operator(time)
assert U_t.shape == (4, 4)
assert np.allclose(U_t @ U_t.T.conj(), np.eye(4)) # U_t should be unitary
def test_psi_at_t(setup_anderson_graph):
anderson_graph = setup_anderson_graph
time = 1.0
psi_t = anderson_graph.psi_at_t(time)
assert psi_t.shape == (4,)
assert np.isclose(np.linalg.norm(psi_t), 1.0) # Wavefunction should be normalized
def test_simulate(setup_anderson_graph):
anderson_graph = setup_anderson_graph
t_max = 10.0
nt = 100
history = anderson_graph.simulate(t_max, nt)
assert len(history) == nt
assert history[0].shape == (4,)
def test_calculate_entropy(setup_anderson_graph):
anderson_graph = setup_anderson_graph
state = np.array([1, 0, 0, 0], dtype=complex)
entropy = anderson_graph.calculate_entropy(state)
assert np.isclose(entropy, 0.0)
def test_entropy_times(setup_anderson_graph):
anderson_graph = setup_anderson_graph
t_max = 10.0
nt = 100
anderson_graph.entropy_times(t_max, nt)