@@ -15,6 +15,21 @@ def get_manybody_op(i, L, op):
15
15
return reduce (np .kron , [op if j == i else Ident for j in range (L )])
16
16
17
17
18
+ def project_to_subspace (operator , configurations ):
19
+ from scipy .sparse import csr_matrix
20
+
21
+ proj_shape = (configurations .size , operator .shape [0 ])
22
+ data = np .ones_like (configurations )
23
+ rows = np .arange (configurations .size )
24
+ cols = configurations
25
+ proj = csr_matrix ((data , (rows , cols )), shape = proj_shape )
26
+
27
+ if operator .ndim == 1 :
28
+ return proj @ operator
29
+ else :
30
+ return proj @ operator @ proj .T
31
+
32
+
18
33
@pytest .mark .parametrize ("L" , [1 , 2 , 3 , 4 , 5 , 6 ])
19
34
def test_2_level_uniform (L ):
20
35
circuit = (
@@ -34,6 +49,15 @@ def test_2_level_uniform(L):
34
49
assert np .all (hamiltonian .rabi_ops [0 ].op .tocsr ().toarray () == rabi )
35
50
assert np .all (hamiltonian .detuning_ops [0 ].diagonal == detuning )
36
51
52
+ emu_prog = EmulatorProgramCodeGen (blockade_radius = 6.2 ).emit (circuit )
53
+ hamiltonian = RydbergHamiltonianCodeGen ().emit (emu_prog )
54
+
55
+ rabi_op_proj = project_to_subspace (rabi , hamiltonian .space .configurations )
56
+ detuning_op_proj = project_to_subspace (detuning , hamiltonian .space .configurations )
57
+
58
+ assert np .all (hamiltonian .rabi_ops [0 ].op .tocsr ().toarray () == rabi_op_proj )
59
+ assert np .all (hamiltonian .detuning_ops [0 ].diagonal == detuning_op_proj )
60
+
37
61
38
62
@pytest .mark .parametrize ("L" , [1 , 2 , 3 , 4 ])
39
63
def test_3_level_uniform (L ):
@@ -54,3 +78,12 @@ def test_3_level_uniform(L):
54
78
55
79
assert np .all (hamiltonian .rabi_ops [0 ].op .tocsr ().toarray () == rabi )
56
80
assert np .all (hamiltonian .detuning_ops [0 ].diagonal == detuning )
81
+
82
+ emu_prog = EmulatorProgramCodeGen (blockade_radius = 6.2 ).emit (circuit )
83
+ hamiltonian = RydbergHamiltonianCodeGen ().emit (emu_prog )
84
+
85
+ rabi_op_proj = project_to_subspace (rabi , hamiltonian .space .configurations )
86
+ detuning_op_proj = project_to_subspace (detuning , hamiltonian .space .configurations )
87
+
88
+ assert np .all (hamiltonian .rabi_ops [0 ].op .tocsr ().toarray () == rabi_op_proj )
89
+ assert np .all (hamiltonian .detuning_ops [0 ].diagonal == detuning_op_proj )
0 commit comments