From 2418ec64c1ae516747e5147b0bed58e65d128c0e Mon Sep 17 00:00:00 2001 From: wanqqq31 Date: Tue, 1 Oct 2024 11:10:39 +0900 Subject: [PATCH] remove exetime --- src/pfs_target_uploader/pn_app.py | 2 +- src/pfs_target_uploader/utils/ppp.py | 71 +++-------------- .../widgets/PppResultWidgets.py | 77 ++++++------------- 3 files changed, 37 insertions(+), 113 deletions(-) diff --git a/src/pfs_target_uploader/pn_app.py b/src/pfs_target_uploader/pn_app.py index 684ded7..1081b38 100644 --- a/src/pfs_target_uploader/pn_app.py +++ b/src/pfs_target_uploader/pn_app.py @@ -126,7 +126,7 @@ def target_uploader_app(use_panel_cli=False): panel_results = ValidationResultWidgets() panel_targets = TargetWidgets() - panel_ppp = PppResultWidgets(exetime=max_exetime, max_nppc=max_nppc) + panel_ppp = PppResultWidgets(max_nppc=max_nppc) panel_input.reset() panel_input.db_path = db_path diff --git a/src/pfs_target_uploader/utils/ppp.py b/src/pfs_target_uploader/utils/ppp.py index 8dffddb..eb1d4d0 100644 --- a/src/pfs_target_uploader/utils/ppp.py +++ b/src/pfs_target_uploader/utils/ppp.py @@ -50,7 +50,6 @@ def PPPrunStart( uS, uPPC, weight_para, - exetime: int, single_exptime: int = 900, max_nppc: int = 200, d_pfi=1.38, @@ -65,14 +64,8 @@ def PPPrunStart( if weight_para is None: weight_para = [2.02, 0.01, 0.01] - is_exetime = (exetime is not None) and (exetime > 0) is_nppc = (max_nppc is not None) and (max_nppc > 0) - if is_exetime: - logger.info(f"PPP iteration will be terminated after {exetime} seconds") - else: - logger.info("PPP calculation will be run until completion") - def count_N(sample): """calculate local count of targets @@ -366,7 +359,7 @@ def KDE(sample, multiProcesing): return X_, Y_, obj_dis_sig_, peak_x, peak_y - def PPP_centers(sample_f, ppc_f, mutiPro, weight_para, starttime, exetime: int): + def PPP_centers(sample_f, ppc_f, mutiPro, weight_para, starttime): """determine pointing centers Parameters @@ -402,24 +395,11 @@ def PPP_centers(sample_f, ppc_f, mutiPro, weight_para, starttime, exetime: int): logger.info("PPC determined from the user input [PPP_centers s1]") return sample_f, status - if is_exetime and ((time.time() - starttime) > exetime): - sample_f.meta["PPC"] = [] - status = 1 - logger.info("PPP stopped since the time is running out [PPP_centers s1]") - return sample_f, status - peak = [] for sample in target_clustering( sample_f, d_pfi, algorithm=clustering_algorithm ): - if is_exetime and ((time.time() - starttime) > exetime): - status = 1 - logger.info( - "PPP stopped since the time is running out [PPP_centers s2]" - ) - break - sample_s = sample[sample["exptime_PPP"] > 0] # targets not finished while any(sample_s["exptime_PPP"] > 0): @@ -427,13 +407,6 @@ def PPP_centers(sample_f, ppc_f, mutiPro, weight_para, starttime, exetime: int): if is_nppc and (len(peak) > max_nppc): break - if is_exetime and ((time.time() - starttime) > exetime): - status = 1 - logger.info( - "PPP stopped since the time is running out [PPP_centers s2_1]" - ) - break - # ------------------------------- # ### peak_xy from KDE peak with weights X_, Y_, obj_dis_sig_, peak_x, peak_y = KDE(sample_s, mutiPro) @@ -925,7 +898,7 @@ def complete_ppc(sample, point_l): sub_l, ) - def netflow_iter(uS, obj_allo, weight_para, starttime, exetime, status): + def netflow_iter(uS, obj_allo, weight_para, starttime, status): """iterate the total procedure to re-assign fibers to targets which have not been assigned in the previous/first iteration @@ -955,31 +928,17 @@ def netflow_iter(uS, obj_allo, weight_para, starttime, exetime, status): obj_allo.remove_rows(np.where(obj_allo["tel_fiber_usage_frac"] == 0)[0]) return obj_allo, status - elif is_exetime and ((time.time() - starttime) > exetime): - status = 1 - logger.info("PPP stopped since the time is running out [netflow_iter s1]") - return obj_allo, status - else: # select non-assigned targets --> PPC determination --> netflow --> if no fibre assigned: shift PPC iter_m2 = 0 while any(uS["exptime_assign"] < uS["exptime_PPP"]) and iter_m2 < 10: - if is_exetime and ((time.time() - starttime) > exetime): - status = 1 - logger.info( - "PPP stopped since the time is running out [netflow_iter s2]" - ) - break - uS_t1 = uS[uS["exptime_assign"] < uS["exptime_PPP"]] uS_t1["exptime_PPP"] = ( uS_t1["exptime_PPP"] - uS_t1["exptime_assign"] ) # remained exposure time - uS_t2, status = PPP_centers( - uS_t1, [], True, weight_para, starttime, exetime - ) + uS_t2, status = PPP_centers(uS_t1, [], True, weight_para, starttime) obj_allo_t = netflowRun(uS_t2) @@ -1026,15 +985,13 @@ def netflow_iter(uS, obj_allo, weight_para, starttime, exetime, status): out_obj_allo_M_fin = [] if len(uS_L) > 0 and len(uS_M) == 0: - uS_L_s2, status_ = PPP_centers( - uS_L, uPPC_L, True, weight_para, t_ppp_start, exetime - ) + uS_L_s2, status_ = PPP_centers(uS_L, uPPC_L, True, weight_para, t_ppp_start) obj_allo_L = netflowRun(uS_L_s2) if len(uPPC_L) == 0: uS_L2 = complete_ppc(uS_L_s2, obj_allo_L)[0] obj_allo_L_fin, status_ = netflow_iter( - uS_L2, obj_allo_L, weight_para, t_ppp_start, exetime, status_ + uS_L2, obj_allo_L, weight_para, t_ppp_start, status_ ) uS_L2, cR_L_fh, cR_L_fh_, cR_L_n, cR_L_n_, sub_l = complete_ppc( uS_L_s2, obj_allo_L_fin @@ -1053,15 +1010,13 @@ def netflow_iter(uS, obj_allo, weight_para, starttime, exetime, status): out_sub_l = sub_l if len(uS_M) > 0 and len(uS_L) == 0: - uS_M_s2, status_ = PPP_centers( - uS_M, uPPC_M, True, weight_para, t_ppp_start, exetime - ) + uS_M_s2, status_ = PPP_centers(uS_M, uPPC_M, True, weight_para, t_ppp_start) obj_allo_M = netflowRun(uS_M_s2) if len(uPPC_M) == 0: uS_M2 = complete_ppc(uS_M_s2, obj_allo_M)[0] obj_allo_M_fin, status_ = netflow_iter( - uS_M2, obj_allo_M, weight_para, t_ppp_start, exetime, status_ + uS_M2, obj_allo_M, weight_para, t_ppp_start, status_ ) uS_M2, cR_M_fh, cR_M_fh_, cR_M_n, cR_M_n_, sub_m = complete_ppc( uS_M_s2, obj_allo_M_fin @@ -1079,14 +1034,12 @@ def netflow_iter(uS, obj_allo, weight_para, starttime, exetime, status): out_sub_m = sub_m if len(uS_L) > 0 and len(uS_M) > 0: - uS_L_s2, status_ = PPP_centers( - uS_L, uPPC_L, True, weight_para, t_ppp_start, exetime - ) + uS_L_s2, status_ = PPP_centers(uS_L, uPPC_L, True, weight_para, t_ppp_start) obj_allo_L = netflowRun(uS_L_s2) if len(uPPC_L) == 0: uS_L2 = complete_ppc(uS_L_s2, obj_allo_L)[0] obj_allo_L_fin, status_ = netflow_iter( - uS_L2, obj_allo_L, weight_para, t_ppp_start, exetime, status_ + uS_L2, obj_allo_L, weight_para, t_ppp_start, status_ ) uS_L2, cR_L_fh, cR_L_fh_, cR_L_n, cR_L_n_, sub_l = complete_ppc( uS_L_s2, obj_allo_L_fin @@ -1098,14 +1051,12 @@ def netflow_iter(uS, obj_allo, weight_para, starttime, exetime, status): ) out_obj_allo_L_fin = obj_allo_L - uS_M_s2, status_ = PPP_centers( - uS_M, uPPC_M, True, weight_para, t_ppp_start, exetime - ) + uS_M_s2, status_ = PPP_centers(uS_M, uPPC_M, True, weight_para, t_ppp_start) obj_allo_M = netflowRun(uS_M_s2) if len(uPPC_M) == 0: uS_M2 = complete_ppc(uS_M_s2, obj_allo_M)[0] obj_allo_M_fin, status_ = netflow_iter( - uS_M2, obj_allo_M, weight_para, t_ppp_start, exetime, status_ + uS_M2, obj_allo_M, weight_para, t_ppp_start, status_ ) uS_M2, cR_M_fh, cR_M_fh_, cR_M_n, cR_M_n_, sub_m = complete_ppc( uS_M_s2, obj_allo_M_fin diff --git a/src/pfs_target_uploader/widgets/PppResultWidgets.py b/src/pfs_target_uploader/widgets/PppResultWidgets.py index 21e7c28..edc6b24 100644 --- a/src/pfs_target_uploader/widgets/PppResultWidgets.py +++ b/src/pfs_target_uploader/widgets/PppResultWidgets.py @@ -2,9 +2,9 @@ import sys +import multiprocessing as mp import numpy as np import panel as pn -import multiprocessing as mp from astropy import units as u from astropy.table import Table from loguru import logger @@ -21,7 +21,6 @@ class PppResultWidgets: def __init__( self, - exetime: int = 15 * 60, # [s] tentatively set to 15 min max_nppc: int = 200, # max number of PPCs ): # PPP status @@ -36,7 +35,6 @@ def __init__( self.origdata_ppc = None self.upload_time = None self.secret_token = None - self.exetime: int = exetime self.max_nppc = max_nppc self.status_ = 0 @@ -52,26 +50,17 @@ def __init__( "Note that targets observable in the input observing period are considered." ) - self.ppp_warning_text_2 = ( - "⚠️ **Warnings**\n\n" - f"Calculation stops because time ({int(self.exetime/60):d} min) is running out. " - "If you would get the complete outputs, please modify the input list or consult with the observatory. " - ) - - self.ppp_warning_text_3 = ( - "⚠️ **Warnings**\n\n" - f"1. The total requested time exceeds {int(self.max_reqtime_normal)} hours (maximum for a normal program). " - "Please make sure to adjust it to your requirement before proceeding to the submission. " - "Note that targets observable in the input observing period are considered." - f"\n 2. Calculation stops because time ({int(self.exetime/60):d} min) is running out." - "If you would get the complete outputs, please modify the input list or consult with the observatory. " - ) - self.ppp_error_text_1 = ( "⚠️ **Error**\n\n" "No fiber can be assigned. Please check the input pointing list, or the single exposure time." ) + self.ppp_error_text_2 = ( + "⚠️ **Error**\n\n" + f"Calculation stops because time is running out. " + "If you would get the complete outputs, please modify the input list or consult with the observatory. " + ) + self.ppp_success_text = ( "✅ **Success**\n\n" "The total requested time is reasonable for normal program. " @@ -117,12 +106,9 @@ def update_alert(df): if self.status_ == 999 and rot > self.max_reqtime_normal: text = self.ppp_warning_text_1 type = "warning" - elif self.status_ == 1 and rot > self.max_reqtime_normal: - text = self.ppp_warning_text_3 - type = "warning" - elif self.status_ == 1 and rot <= self.max_reqtime_normal: - text = self.ppp_warning_text_2 - type = "warning" + elif self.status_ == 1: + text = self.ppp_error_text_2 + type = "danger" elif self.status_ == 2 and df is None: text = self.ppp_error_text_1 type = "danger" @@ -315,7 +301,6 @@ def run_ppp( tb_visible, tb_ppc, weights, - self.exetime, self.single_exptime, self.max_nppc, 1.38, @@ -331,9 +316,10 @@ def run_ppp( ppp_run.join(max_exetime) if ppp_run.is_alive(): + # if ppp is still running after max_exetime, kill it logger.error("Pointing simulation failed (runout time)") pn.state.notifications.error( - f"Pointing simulation stops because time ({int(max_exetime):d} sec) is running out.", + f"Simulation stops because time ({int(max_exetime):d} sec) is running out.", duration=0, # ever ) @@ -355,7 +341,19 @@ def run_ppp( sub_m, obj_allo_M_fin, self.status_, - ) = (Table(), [], [], [], Table(), Table(), [], [], [], Table(), False) + ) = ( + Table(), + [], + [], + [], + Table(), + Table(), + [], + [], + [], + Table(), + 1, + ) # ppc_status=1 in case of runout time else: ( uS_L2, @@ -371,31 +369,6 @@ def run_ppp( self.status_, ) = ppp_run_results.get() - """ - ( - uS_L2, - cR_L, - cR_L_, - sub_l, - obj_allo_L_fin, - uS_M2, - cR_M, - cR_M_, - sub_m, - obj_allo_M_fin, - self.status_, - ) = PPPrunStart( - tb_visible, - tb_ppc, - weights, - self.exetime, - single_exptime=self.single_exptime, - max_nppc=self.max_nppc, - quiet=quiet, - clustering_algorithm=clustering_algorithm, - ) - #""" - ( self.nppc, self.p_result_fig,