7
7
import pytest
8
8
from numpy .testing import assert_array_almost_equal as almost_equal
9
9
import c3 .libraries .algorithms as algorithms
10
+ from c3 .libraries .fidelities import state_transfer_from_states
10
11
11
12
# Libs and helpers
12
13
from c3 .libraries .propagation import rk4_unitary
14
+ import tensorflow as tf
13
15
14
16
with open ("test/two_qubit_data.pickle" , "rb" ) as filename :
15
17
test_data = pickle .load (filename )
@@ -82,6 +84,64 @@ def test_optim(get_OC_optimizer) -> None:
82
84
assert opt .evaluation == opt .options [maxiterKey ] - 1
83
85
84
86
87
+ @pytest .mark .slow
88
+ @pytest .mark .tensorflow
89
+ @pytest .mark .optimizers
90
+ @pytest .mark .integration
91
+ def test_optim_ode_solver (get_OC_optimizer ) -> None :
92
+ """
93
+ check if optimization result is below 1e-1
94
+ """
95
+ opt = get_OC_optimizer
96
+ opt .fid_func = state_transfer_from_states
97
+ opt .set_goal_function (ode_solver = "rk4" , ode_step_function = "schrodinger" )
98
+
99
+ model = opt .exp .pmap .model
100
+ psi_init = [[0 ] * model .tot_dim ]
101
+ psi_init [0 ][0 ] = 1 / np .sqrt (2 )
102
+ index = model .get_state_indeces ([(1 , 0 )])[0 ]
103
+ psi_init [0 ][index ] = 1 / np .sqrt (2 )
104
+ target_state = tf .transpose (tf .constant (psi_init , tf .complex128 ))
105
+ params = {"target" : target_state }
106
+ opt .fid_func_kwargs = {"params" : params }
107
+
108
+ assert opt .evaluation == 0
109
+ opt .optimize_controls ()
110
+ assert opt .current_best_goal < 0.5 # TODO - Make it 0.1
111
+ maxiterKey = "maxiters" if opt .algorithm == algorithms .tf_sgd else "maxiter"
112
+ assert opt .evaluation == opt .options [maxiterKey ] - 1
113
+
114
+
115
+ @pytest .mark .slow
116
+ @pytest .mark .tensorflow
117
+ @pytest .mark .optimizers
118
+ @pytest .mark .integration
119
+ def test_optim_ode_solver_final (get_OC_optimizer ) -> None :
120
+ """
121
+ check if optimization result is below 1e-1
122
+ """
123
+ opt = get_OC_optimizer
124
+ opt .fid_func = state_transfer_from_states
125
+ opt .set_goal_function (
126
+ ode_solver = "rk4" , ode_step_function = "schrodinger" , only_final_state = True
127
+ )
128
+
129
+ model = opt .exp .pmap .model
130
+ psi_init = [[0 ] * model .tot_dim ]
131
+ psi_init [0 ][0 ] = 1 / np .sqrt (2 )
132
+ index = model .get_state_indeces ([(1 , 0 )])[0 ]
133
+ psi_init [0 ][index ] = 1 / np .sqrt (2 )
134
+ target_state = tf .transpose (tf .constant (psi_init , tf .complex128 ))
135
+ params = {"target" : target_state }
136
+ opt .fid_func_kwargs = {"params" : params }
137
+
138
+ assert opt .evaluation == 0
139
+ opt .optimize_controls ()
140
+ assert opt .current_best_goal < 0.5 # TODO - Make it 0.1
141
+ maxiterKey = "maxiters" if opt .algorithm == algorithms .tf_sgd else "maxiter"
142
+ assert opt .evaluation == opt .options [maxiterKey ] - 1
143
+
144
+
85
145
@pytest .mark .tensorflow
86
146
@pytest .mark .integration
87
147
def test_rk4_unitary (get_two_qubit_chip ) -> None :
@@ -101,3 +161,6 @@ def test_ode_solver(get_two_qubit_chip) -> None:
101
161
exp .compute_states (solver = "rk4" )
102
162
exp .compute_states (solver = "rk5" )
103
163
exp .compute_states (solver = "Tsit5" )
164
+ exp .compute_states (solver = "rk4" , step_function = "vonNeumann" )
165
+ exp .compute_states (solver = "rk5" , step_function = "vonNeumann" )
166
+ exp .compute_states (solver = "Tsit5" , step_function = "vonNeumann" )
0 commit comments