@@ -195,34 +195,55 @@ def optimize_pulses(
195
195
"maxiter" : algorithm_kwargs .get ("max_iter" , 1000 ),
196
196
"gtol" : algorithm_kwargs .get ("min_grad" , 0.0 if alg == "CRAB" else 1e-8 ),
197
197
}
198
+
198
199
# Iterate over objectives and convert initial and target states based on the optimization type
199
200
for objective in objectives :
200
201
H_list = objective .H if isinstance (objective .H , list ) else [objective .H ]
201
202
if any (qt .issuper (H_i ) for H_i in H_list ):
202
203
if isinstance (optimization_type , str ) and optimization_type .lower () == "state_transfer" :
203
204
if qt .isket (objective .initial ):
205
+ dim = objective .initial .shape [0 ]
204
206
objective .initial = qt .operator_to_vector (qt .ket2dm (objective .initial ))
205
207
elif qt .isoper (objective .initial ):
208
+ dim = objective .initial .shape [0 ]
206
209
objective .initial = qt .operator_to_vector (objective .initial )
210
+
207
211
if qt .isket (objective .target ):
208
212
objective .target = qt .operator_to_vector (qt .ket2dm (objective .target ))
209
213
elif qt .isoper (objective .target ):
210
214
objective .target = qt .operator_to_vector (objective .target )
215
+
216
+ algorithm_kwargs .setdefault ("fid_params" , {})
217
+ algorithm_kwargs ["fid_params" ].setdefault ("scale_factor" , 1.0 / dim )
218
+
211
219
elif isinstance (optimization_type , str ) and optimization_type .lower () == "gate_synthesis" :
212
220
objective .initial = qt .to_super (objective .initial )
213
221
objective .target = qt .to_super (objective .target )
222
+
214
223
elif optimization_type is None :
224
+ is_state_transfer = False
215
225
if qt .isoper (objective .initial ) and qt .isoper (objective .target ):
216
- if np .isclose ((objective .initial ).tr (), 1 ) and np .isclose ((objective .target ).tr (), 1 ):
226
+ if np .isclose (objective .initial .tr (), 1 ) and np .isclose (objective .target .tr (), 1 ):
227
+ dim = objective .initial .shape [0 ]
217
228
objective .initial = qt .operator_to_vector (objective .initial )
218
229
objective .target = qt .operator_to_vector (objective .target )
230
+ is_state_transfer = True
219
231
else :
220
232
objective .initial = qt .to_super (objective .initial )
221
233
objective .target = qt .to_super (objective .target )
234
+
222
235
if qt .isket (objective .initial ):
236
+ dim = objective .initial .shape [0 ]
223
237
objective .initial = qt .operator_to_vector (qt .ket2dm (objective .initial ))
238
+ is_state_transfer = True
239
+
224
240
if qt .isket (objective .target ):
225
241
objective .target = qt .operator_to_vector (qt .ket2dm (objective .target ))
242
+ is_state_transfer = True
243
+
244
+ if is_state_transfer :
245
+ algorithm_kwargs .setdefault ("fid_params" , {})
246
+ algorithm_kwargs ["fid_params" ].setdefault ("scale_factor" , 1.0 / dim )
226
247
227
248
# prepare qtrl optimizers
228
249
qtrl_optimizers = []
0 commit comments