Skip to content

Commit d43efb9

Browse files
Merge pull request #31 from LegionAtol/rl_update
corrections in algorithm execution time
2 parents 138e3d8 + ec376e5 commit d43efb9

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/qutip_qoc/_rl.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def create_pulse_func(idx):
8989
self._result = Result(
9090
objectives=objectives,
9191
time_interval=time_interval,
92-
start_local_time=time.localtime(), # initial optimization time
92+
start_local_time=time.time(), # initial optimization time
9393
n_iters=0, # Number of iterations(episodes) until convergence
9494
iter_seconds=[], # list containing the time taken for each iteration(episode) of the optimization
9595
var_time=True, # Whether the optimization was performed with variable time
@@ -99,7 +99,7 @@ def create_pulse_func(idx):
9999
self._backup_result = Result( # used as a backup in case the algorithm with shorter_pulses does not find an episode with infid<target_infid
100100
objectives=objectives,
101101
time_interval=time_interval,
102-
start_local_time=time.localtime(),
102+
start_local_time=time.time(),
103103
n_iters=0,
104104
iter_seconds=[],
105105
var_time=True,
@@ -180,7 +180,7 @@ def _save_episode_info(self):
180180
"terminated": self.terminated,
181181
"truncated": self.truncated,
182182
"steps_used": self._current_step,
183-
"elapsed_time": time.mktime(time.localtime()),
183+
"elapsed_time": time.time(),
184184
}
185185
self._episode_info.append(episode_data)
186186

@@ -256,7 +256,7 @@ def reset(self, seed=None):
256256
time_diff = self._episode_info[-1]["elapsed_time"] - (
257257
self._episode_info[-2]["elapsed_time"]
258258
if len(self._episode_info) > 1
259-
else time.mktime(self._result.start_local_time)
259+
else self._result.start_local_time
260260
)
261261
self._result.iter_seconds.append(time_diff)
262262
self._current_step = 0 # Reset the step counter
@@ -281,7 +281,7 @@ def _save_result(self):
281281
self._backup_result._final_states = self._result._final_states.copy()
282282
self._backup_result.infidelity = self._result.infidelity
283283

284-
result_obj.end_local_time = time.localtime()
284+
result_obj.end_local_time = time.time()
285285
result_obj.n_iters = len(self._result.iter_seconds)
286286
result_obj.optimized_params = self._actions.copy() + [
287287
self._result.total_seconds
@@ -296,20 +296,20 @@ def result(self):
296296
"""
297297
if self._use_backup_result:
298298
self._backup_result.start_local_time = time.strftime(
299-
"%Y-%m-%d %H:%M:%S", self._backup_result.start_local_time
300-
) # Convert to a string
299+
"%Y-%m-%d %H:%M:%S", time.localtime(self._backup_result.start_local_time)
300+
)
301301
self._backup_result.end_local_time = time.strftime(
302-
"%Y-%m-%d %H:%M:%S", self._backup_result.end_local_time
303-
) # Convert to a string
302+
"%Y-%m-%d %H:%M:%S", time.localtime(self._backup_result.end_local_time)
303+
)
304304
return self._backup_result
305305
else:
306306
self._save_result()
307307
self._result.start_local_time = time.strftime(
308-
"%Y-%m-%d %H:%M:%S", self._result.start_local_time
309-
) # Convert to a string
308+
"%Y-%m-%d %H:%M:%S", time.localtime(self._result.start_local_time)
309+
)
310310
self._result.end_local_time = time.strftime(
311-
"%Y-%m-%d %H:%M:%S", self._result.end_local_time
312-
) # Convert to a string
311+
"%Y-%m-%d %H:%M:%S", time.localtime(self._result.end_local_time)
312+
)
313313
return self._result
314314

315315
def train(self):

0 commit comments

Comments
 (0)