@@ -603,95 +603,98 @@ def get_task(self, get_statement=True) -> Task | None:
603603 else :
604604 evaluation_param = "diff"
605605
606- # Detect subtasks by checking GEN
607- gen_filename = os .path .join (self .path , 'gen' , 'GEN' )
608- try :
609- with open (gen_filename , "rt" , encoding = "utf-8" ) as gen_file :
610- subtasks = []
611- testcases = 0
612- points = None
613- for line in gen_file :
614- line = line .strip ()
615- splitted = line .split ('#' , 1 )
616-
617- if len (splitted ) == 1 :
618- # This line represents a testcase, otherwise
619- # it's just a blank
620- if splitted [0 ] != '' :
621- testcases += 1
622-
623- else :
624- testcase , comment = splitted
625- testcase = testcase .strip ()
626- comment = comment .strip ()
627- testcase_detected = len (testcase ) > 0
628- copy_testcase_detected = comment .startswith ("COPY:" )
629- subtask_detected = comment .startswith ('ST:' )
630-
631- flags = [testcase_detected ,
632- copy_testcase_detected ,
633- subtask_detected ]
634- if len ([x for x in flags if x ]) > 1 :
635- raise Exception ("No testcase and command in"
636- " the same line allowed" )
637-
638- # This line represents a testcase and contains a
639- # comment, but the comment doesn't start a new
640- # subtask
641- if testcase_detected or copy_testcase_detected :
642- testcases += 1
643-
644- # This line starts a new subtask
645- if subtask_detected :
646- # Close the previous subtask
647- if points is None :
648- assert testcases == 0
649- else :
650- subtasks .append ([points , testcases ])
651- # Open the new one
652- testcases = 0
653- points = int (comment [3 :].strip ())
654-
655- # Close last subtask (if no subtasks were defined, just
656- # fallback to Sum)
657- if points is None :
658- args ["score_type" ] = "Sum"
659- total_value = float (conf .get ("total_value" , 100.0 ))
660- input_value = 0.0
661- n_input = testcases
662- if n_input != 0 :
663- input_value = total_value / n_input
664- args ["score_type_parameters" ] = input_value
665- else :
666- subtasks .append ([points , testcases ])
667- assert 100 == sum ([int (st [0 ]) for st in subtasks ])
668- n_input = sum ([int (st [1 ]) for st in subtasks ])
669- args ["score_type" ] = "GroupMin"
670- args ["score_type_parameters" ] = subtasks
671-
672- if "n_input" in conf :
673- assert int (conf ['n_input' ]) == n_input
674-
675- # If gen/GEN doesn't exist, just fallback to Sum
676- except OSError :
677- args ["score_type" ] = "Sum"
678- total_value = float (conf .get ("total_value" , 100.0 ))
679- input_value = 0.0
680- n_input = int (conf ['n_input' ])
681- if n_input != 0 :
682- input_value = total_value / n_input
683- args ["score_type_parameters" ] = input_value
684-
685606 # Override score_type if explicitly specified
686- if "score_type" in conf and "score_type_parameters" in conf :
607+ if "score_type" in conf and "score_type_parameters" in conf and "n_input" in conf :
687608 logger .info ("Overriding 'score_type' and 'score_type_parameters' "
688609 "as per task.yaml" )
610+ n_input = conf ["n_input" ]
689611 load (conf , args , "score_type" )
690612 load (conf , args , "score_type_parameters" )
691- elif "score_type" in conf or "score_type_parameters" in conf :
692- logger .warning ("To override score type data, task.yaml must "
693- "specify both 'score_type' and "
694- "'score_type_parameters'." )
613+ else :
614+ if "score_type" in conf or "score_type_parameters" in conf or "n_input" in conf :
615+ logger .warning ("To override score type data, task.yaml must "
616+ "specify all 'score_type', "
617+ "'score_type_parameters' and"
618+ "'n_input'." )
619+
620+ # Detect subtasks by checking GEN
621+ gen_filename = os .path .join (self .path , 'gen' , 'GEN' )
622+ try :
623+ with open (gen_filename , "rt" , encoding = "utf-8" ) as gen_file :
624+ subtasks = []
625+ testcases = 0
626+ points = None
627+ for line in gen_file :
628+ line = line .strip ()
629+ splitted = line .split ('#' , 1 )
630+
631+ if len (splitted ) == 1 :
632+ # This line represents a testcase, otherwise
633+ # it's just a blank
634+ if splitted [0 ] != '' :
635+ testcases += 1
636+
637+ else :
638+ testcase , comment = splitted
639+ testcase = testcase .strip ()
640+ comment = comment .strip ()
641+ testcase_detected = len (testcase ) > 0
642+ copy_testcase_detected = comment .startswith ("COPY:" )
643+ subtask_detected = comment .startswith ('ST:' )
644+
645+ flags = [testcase_detected ,
646+ copy_testcase_detected ,
647+ subtask_detected ]
648+ if len ([x for x in flags if x ]) > 1 :
649+ raise Exception ("No testcase and command in"
650+ " the same line allowed" )
651+
652+ # This line represents a testcase and contains a
653+ # comment, but the comment doesn't start a new
654+ # subtask
655+ if testcase_detected or copy_testcase_detected :
656+ testcases += 1
657+
658+ # This line starts a new subtask
659+ if subtask_detected :
660+ # Close the previous subtask
661+ if points is None :
662+ assert testcases == 0
663+ else :
664+ subtasks .append ([points , testcases ])
665+ # Open the new one
666+ testcases = 0
667+ points = int (comment [3 :].strip ())
668+
669+ # Close last subtask (if no subtasks were defined, just
670+ # fallback to Sum)
671+ if points is None :
672+ args ["score_type" ] = "Sum"
673+ total_value = float (conf .get ("total_value" , 100.0 ))
674+ input_value = 0.0
675+ n_input = testcases
676+ if n_input != 0 :
677+ input_value = total_value / n_input
678+ args ["score_type_parameters" ] = input_value
679+ else :
680+ subtasks .append ([points , testcases ])
681+ assert 100 == sum ([int (st [0 ]) for st in subtasks ])
682+ n_input = sum ([int (st [1 ]) for st in subtasks ])
683+ args ["score_type" ] = "GroupMin"
684+ args ["score_type_parameters" ] = subtasks
685+
686+ if "n_input" in conf :
687+ assert int (conf ['n_input' ]) == n_input
688+
689+ # If gen/GEN doesn't exist, just fallback to Sum
690+ except OSError :
691+ args ["score_type" ] = "Sum"
692+ total_value = float (conf .get ("total_value" , 100.0 ))
693+ input_value = 0.0
694+ n_input = int (conf ['n_input' ])
695+ if n_input != 0 :
696+ input_value = total_value / n_input
697+ args ["score_type_parameters" ] = input_value
695698
696699 # If output_only is set, then the task type is OutputOnly
697700 if conf .get ('output_only' , False ):
0 commit comments