@@ -693,20 +693,8 @@ def __run_simulation_worker(
693
693
go_read_results [i ].release ()
694
694
695
695
# update user on progress
696
- average_time = (
697
- time () - sim_counter .get_intial_time ()
698
- ) / sim_counter .get_count ()
699
- estimated_time = int (
700
- (sim_counter .get_n_simulations () - sim_counter .get_count ())
701
- * average_time
702
- )
703
-
704
- msg = f"Current iteration: { sim_idx :06d} "
705
- msg += f" | Average Time per Iteration: { average_time :.3f} s"
706
- msg += f" | Estimated time left: { estimated_time } s"
707
-
708
696
sim_counter .reprint (
709
- msg ,
697
+ sim_idx ,
710
698
end = "\n " ,
711
699
flush = False ,
712
700
)
@@ -1628,6 +1616,7 @@ def __init__(self):
1628
1616
1629
1617
class SimCounter :
1630
1618
def __init__ (self , initial_count , n_simulations , parallel_start ):
1619
+ self .initial_count = initial_count
1631
1620
self .count = initial_count
1632
1621
self .n_simulations = n_simulations
1633
1622
self ._last_print_len = 0 # used to print on the same line
@@ -1649,7 +1638,7 @@ def get_n_simulations(self):
1649
1638
def get_intial_time (self ):
1650
1639
return self .initial_time
1651
1640
1652
- def reprint (self , msg , end = "\n " , flush = False ):
1641
+ def reprint (self , sim_idx , end = "\n " , flush = False ):
1653
1642
"""Prints a message on the same line as the previous one and replaces
1654
1643
the previous message with the new one, deleting the extra characters
1655
1644
from the previous message.
@@ -1667,11 +1656,19 @@ def reprint(self, msg, end="\n", flush=False):
1667
1656
-------
1668
1657
None
1669
1658
"""
1659
+ average_time = (time () - self .initial_time ) / (self .count - self .initial_count )
1660
+ estimated_time = int (
1661
+ (self .n_simulations - (self .count - self .initial_count )) * average_time
1662
+ )
1663
+
1664
+ msg = f"Current iteration: { sim_idx :06d} "
1665
+ msg += f" | Average Time per Iteration: { average_time :.3f} s"
1666
+ msg += f" | Estimated time left: { estimated_time } s"
1670
1667
1671
- # len_msg = len(msg)
1672
- # if len_msg < self._last_print_len:
1673
- # msg += " " * (self._last_print_len - len_msg)
1674
- # else:
1675
- # self._last_print_len = len_msg
1668
+ len_msg = len (msg )
1669
+ if len_msg < self ._last_print_len :
1670
+ msg += " " * (self ._last_print_len - len_msg )
1671
+ else :
1672
+ self ._last_print_len = len_msg
1676
1673
1677
1674
print (msg , end = end , flush = flush )
0 commit comments