Skip to content

Commit ee97fdd

Browse files
authored
fix PR experiment additional arg parsing conflict (#1217)
This PR fix the problem when issuing `/gcbrun` command with additional args `-- additional_args`. The additional_args may flow to `web.py` or `run_all_experiment.py`, causing `web.py` to fail when the args are exclusively to `run_all_experiment.py`
1 parent 3383d79 commit ee97fdd

File tree

3 files changed

+61
-18
lines changed

3 files changed

+61
-18
lines changed

report/docker_run.py

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,22 @@ def _parse_args(cmd) -> argparse.Namespace:
138138
return args
139139

140140

141+
def _report_serve_exclusive_parse_arg(cmd):
142+
"""Parses additional args exclusively for report.web"""
143+
web_parser = argparse.ArgumentParser(add_help=False)
144+
web_parser.add_argument('--with-csv',
145+
'-csv',
146+
help='Will write a CSV file with the results.',
147+
action='store_true')
148+
web_parser.add_argument('--with-google-sheets',
149+
'-gs',
150+
help='Will write to Google Sheets.',
151+
action='store_true')
152+
153+
report_arg, all_exp_arg_list = web_parser.parse_known_args(cmd)
154+
return report_arg, all_exp_arg_list
155+
156+
141157
def _run_command(command: list[str], shell=False):
142158
"""Runs a command and return its exit code."""
143159
process = subprocess.run(command, shell=shell, check=False)
@@ -177,7 +193,8 @@ def main(cmd=None):
177193
"""Main entrypoint"""
178194
if os.path.isfile('/experiment/data-dir.zip'):
179195
subprocess.check_call(
180-
'apt-get install -y zip && zip -s0 data-dir.zip --out newd.zip && unzip newd.zip && rm ./data-dir.z*',
196+
'apt-get install -y zip && zip -s0 data-dir.zip --out newd.zip && '
197+
'unzip newd.zip && rm ./data-dir.z*',
181198
shell=True,
182199
cwd='/experiment')
183200
if os.path.isdir(DATA_DIR):
@@ -221,11 +238,23 @@ def run_on_data_from_scratch(cmd=None):
221238

222239
local_results_dir = 'results'
223240

224-
# Generate a report and upload it to GCS
225-
report_process = subprocess.Popen([
241+
# split additional args that are exclusive to upload_report.sh,
242+
# pass the rest to run_all_experiment.py
243+
report_arg, args.additional_args = _report_serve_exclusive_parse_arg(
244+
args.additional_args)
245+
246+
report_cmd = [
226247
"bash", "report/upload_report.sh", local_results_dir, gcs_report_dir,
227248
args.benchmark_set, args.model
228-
] + args.additional_args)
249+
]
250+
251+
if report_arg.with_csv:
252+
report_cmd.append('--with-csv')
253+
if report_arg.with_google_sheets:
254+
report_cmd.append('--with-google-sheets')
255+
256+
# Generate a report and upload it to GCS
257+
report_process = subprocess.Popen(report_cmd)
229258

230259
# Launch run_all_experiments.py
231260
# some notes:
@@ -377,11 +406,23 @@ def run_standard(cmd=None):
377406
# Trends report use a similarly named path.
378407
gcs_trend_report_path = f"{args.sub_dir}/{experiment_name}.json"
379408

380-
# Generate a report and upload it to GCS
381-
report_process = subprocess.Popen([
409+
# split additional args that are exclusive to upload_report.sh,
410+
# pass the rest to run_all_experiment.py
411+
report_arg, args.additional_args = _report_serve_exclusive_parse_arg(
412+
args.additional_args)
413+
414+
report_cmd = [
382415
"bash", "report/upload_report.sh", local_results_dir, gcs_report_dir,
383416
args.benchmark_set, args.model
384-
] + args.additional_args)
417+
]
418+
419+
if report_arg.with_csv:
420+
report_cmd.append('--with-csv')
421+
if report_arg.with_google_sheets:
422+
report_cmd.append('--with-google-sheets')
423+
424+
# Generate a report and upload it to GCS
425+
report_process = subprocess.Popen(report_cmd)
385426

386427
# Prepare the command to run experiments
387428
run_cmd = [

report/upload_report.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,16 @@ update_report() {
9696
rm -rf 'training_data'
9797
gsutil -q rm -r "gs://oss-fuzz-gcb-experiment-run-logs/Result-reports/${GCS_DIR:?}/training_data" || true
9898

99-
$PYTHON -m data_prep.parse_training_data \
100-
--experiment-dir "${RESULTS_DIR:?}" --save-dir 'training_data'
101-
$PYTHON -m data_prep.parse_training_data --group \
102-
--experiment-dir "${RESULTS_DIR:?}" --save-dir 'training_data'
103-
$PYTHON -m data_prep.parse_training_data --coverage \
104-
--experiment-dir "${RESULTS_DIR:?}" --save-dir 'training_data'
105-
$PYTHON -m data_prep.parse_training_data --coverage --group \
106-
--experiment-dir "${RESULTS_DIR:?}" --save-dir 'training_data'
107-
gsutil -q cp -r 'training_data' \
108-
"gs://oss-fuzz-gcb-experiment-run-logs/Result-reports/${GCS_DIR:?}"
99+
# $PYTHON -m data_prep.parse_training_data \
100+
# --experiment-dir "${RESULTS_DIR:?}" --save-dir 'training_data'
101+
#$PYTHON -m data_prep.parse_training_data --group \
102+
# --experiment-dir "${RESULTS_DIR:?}" --save-dir 'training_data'
103+
#$PYTHON -m data_prep.parse_training_data --coverage \
104+
# --experiment-dir "${RESULTS_DIR:?}" --save-dir 'training_data'
105+
#$PYTHON -m data_prep.parse_training_data --coverage --group \
106+
# --experiment-dir "${RESULTS_DIR:?}" --save-dir 'training_data'
107+
#gsutil -q cp -r 'training_data' \
108+
# "gs://oss-fuzz-gcb-experiment-run-logs/Result-reports/${GCS_DIR:?}"
109109
}
110110

111111
while [[ ! -f /experiment_ended ]]; do

report/web.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,9 @@ def _parse_arguments() -> argparse.Namespace:
746746
help='GCS directory for experiment.',
747747
default='')
748748

749-
return parser.parse_args()
749+
# Ignore unknown additional args that flows to run_all_experiment.py
750+
args, _ = parser.parse_known_args()
751+
return args
750752

751753

752754
def main():

0 commit comments

Comments
 (0)