@@ -195,34 +195,55 @@ def optimize_pulses(
195195 "maxiter" : algorithm_kwargs .get ("max_iter" , 1000 ),
196196 "gtol" : algorithm_kwargs .get ("min_grad" , 0.0 if alg == "CRAB" else 1e-8 ),
197197 }
198+
198199 # Iterate over objectives and convert initial and target states based on the optimization type
199200 for objective in objectives :
200201 H_list = objective .H if isinstance (objective .H , list ) else [objective .H ]
201202 if any (qt .issuper (H_i ) for H_i in H_list ):
202203 if isinstance (optimization_type , str ) and optimization_type .lower () == "state_transfer" :
203204 if qt .isket (objective .initial ):
205+ dim = objective .initial .shape [0 ]
204206 objective .initial = qt .operator_to_vector (qt .ket2dm (objective .initial ))
205207 elif qt .isoper (objective .initial ):
208+ dim = objective .initial .shape [0 ]
206209 objective .initial = qt .operator_to_vector (objective .initial )
210+
207211 if qt .isket (objective .target ):
208212 objective .target = qt .operator_to_vector (qt .ket2dm (objective .target ))
209213 elif qt .isoper (objective .target ):
210214 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+
211219 elif isinstance (optimization_type , str ) and optimization_type .lower () == "gate_synthesis" :
212220 objective .initial = qt .to_super (objective .initial )
213221 objective .target = qt .to_super (objective .target )
222+
214223 elif optimization_type is None :
224+ is_state_transfer = False
215225 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 ]
217228 objective .initial = qt .operator_to_vector (objective .initial )
218229 objective .target = qt .operator_to_vector (objective .target )
230+ is_state_transfer = True
219231 else :
220232 objective .initial = qt .to_super (objective .initial )
221233 objective .target = qt .to_super (objective .target )
234+
222235 if qt .isket (objective .initial ):
236+ dim = objective .initial .shape [0 ]
223237 objective .initial = qt .operator_to_vector (qt .ket2dm (objective .initial ))
238+ is_state_transfer = True
239+
224240 if qt .isket (objective .target ):
225241 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 )
226247
227248 # prepare qtrl optimizers
228249 qtrl_optimizers = []
0 commit comments