File tree 2 files changed +18
-1
lines changed 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change 13
13
from c3 .model import Model , Model_basis_change
14
14
import c3 .libraries .hamiltonians as hamiltonians
15
15
from c3 .parametermap import ParameterMap
16
+ from c3 .utils import tf_utils
16
17
17
18
qubit_lvls = 3
18
19
freq_q1 = 5e9
@@ -190,6 +191,22 @@ def test_model_init_state() -> None:
190
191
np .testing .assert_almost_equal (model .get_ground_state ()[0 ], 1 , decimal = 4 )
191
192
192
193
194
+ @pytest .mark .unit
195
+ def test_model_set_init_state () -> None :
196
+ """Test computation of initial state"""
197
+ model .set_lindbladian (False )
198
+ psi_init = [[0 ] * model .tot_dim ]
199
+ init_state_index = model .get_state_indeces ([(1 , 0 )])[0 ]
200
+ psi_init [0 ][init_state_index ] = 1
201
+ init_state = tf .transpose (tf .constant (psi_init , tf .complex128 ))
202
+ model .set_init_state (init_state )
203
+ np .testing .assert_allclose (model .init_state , init_state )
204
+
205
+ model .set_lindbladian (True )
206
+ model .set_init_state (init_state )
207
+ np .testing .assert_allclose (model .init_state , tf_utils .tf_state_to_dm (init_state ))
208
+
209
+
193
210
@pytest .mark .unit
194
211
def test_model_dressed_basis () -> None :
195
212
"""Test dressed basis"""
Original file line number Diff line number Diff line change @@ -112,7 +112,7 @@ def test_optim_ode_solver(get_OC_optimizer) -> None:
112
112
if opt .algorithm == algorithms .single_eval :
113
113
assert opt .current_best_goal < 0.5
114
114
else :
115
- assert opt .current_best_goal < 0.2
115
+ assert opt .current_best_goal < 0.3
116
116
117
117
maxiterKey = "maxiters" if opt .algorithm == algorithms .tf_sgd else "maxiter"
118
118
assert opt .evaluation == opt .options [maxiterKey ] - 1
You can’t perform that action at this time.
0 commit comments