Coverage for src / sparkle / CLI / help / argparse_custom.py: 100%
69 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-21 15:31 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-21 15:31 +0000
1"""Custom helper class and functions to process CLI arguments with argparse."""
3from __future__ import annotations
4from pathlib import Path
5from typing import Any
8class ArgumentContainer:
9 """Helper class for more convenient argument packaging and access."""
11 def __init__(
12 self: ArgumentContainer, names: list[str], kwargs: dict[str, Any]
13 ) -> None:
14 """Create an ArgumentContainer.
16 Args:
17 names: List of names for the contained argument. For positional arguments
18 this will typically contain two, the first one starting with '-' and the
19 second one starting with '--'.
20 kwargs: Keyword arguments needed by the method parser.add_argument which adds
21 the contained argument to a parser.
22 """
23 self.names = names
24 self.kwargs = kwargs
27AllJobsArgument = ArgumentContainer(
28 names=["--all"],
29 kwargs={"action": "store_true", "help": "use all known job ID(s) for the command"},
30)
32AllSolverConfigurationArgument = ArgumentContainer(
33 names=["--all-configurations"],
34 kwargs={
35 "action": "store_true",
36 "help": "use all known configurations for the command",
37 },
38)
40AllConfigurationArgument = ArgumentContainer(
41 names=["--all-configurations"],
42 kwargs={"action": "store_true", "help": "use all known Solver configurations"},
43)
45BestConfigurationArgument = ArgumentContainer(
46 names=["--best-configuration"],
47 kwargs={
48 "required": False,
49 "nargs": "?",
50 "type": Path,
51 "const": True,
52 "default": False,
53 "help": "Paths to instance(s) or instanceset(s) over "
54 "which to determine the best configuration. If "
55 "empty, all known instances are used.",
56 },
57)
59BestSolverConfigurationArgument = ArgumentContainer(
60 names=["--best-configuration"],
61 kwargs={
62 "action": "store_true",
63 "help": "use the best configurations for the command",
64 },
65)
67CancelJobsArgument = ArgumentContainer(
68 names=["--cancel"],
69 kwargs={"action": "store_true", "help": "cancel the job(s) with the given ID(s)"},
70)
72CheckTypeArgument = ArgumentContainer(
73 names=["type"],
74 kwargs={
75 # "choices": [
76 # "extractor",
77 # "feature-extractor",
78 # "solver",
79 # "instance-set",
80 # "ExtractorFeature-Extractor",
81 # "Instance-Set",
82 # "Solver",
83 # "FeatureExtractor",
84 # "InstanceSet",
85 # ],
86 "help": "type of the object to check (Solver, Extractor, InstanceSet)",
87 },
88)
90CheckPathArgument = ArgumentContainer(
91 names=["path"], kwargs={"type": Path, "help": "path to the object to check"}
92)
94CleanupArgumentAll = ArgumentContainer(
95 names=["--all"], kwargs={"action": "store_true", "help": "clean all output files"}
96)
98CleanupArgumentRemove = ArgumentContainer(
99 names=["--remove"],
100 kwargs={
101 "action": "store_true",
102 "help": "remove all files in the platform, including "
103 "user data such as InstanceSets and Solvers",
104 },
105)
107CleanupArgumentLogs = ArgumentContainer(
108 names=["--logs", "--log"],
109 kwargs={"action": "store_true", "help": "Clean log files from the platform"},
110)
112CleanUpPerformanceDataArgument = ArgumentContainer(
113 names=["--performance-data"],
114 kwargs={
115 "action": "store_true",
116 "help": "clean performance data from errorneous lines",
117 },
118)
120CleanUpFeatureDataArgument = ArgumentContainer(
121 names=["--feature-data"],
122 kwargs={"action": "store_true", "help": "clean feature data from errorneous lines"},
123)
125ConfigurationArgument = ArgumentContainer(
126 names=["--configuration"],
127 kwargs={
128 "required": False,
129 "type": str,
130 "nargs": "+",
131 "help": "The indices of which configurations to use",
132 },
133)
135DefaultSolverConfigurationArgument = ArgumentContainer(
136 names=["--default-configuration"],
137 kwargs={
138 "action": "store_true",
139 "help": "use the default configurations for the command",
140 },
141)
143DeterministicArgument = ArgumentContainer(
144 names=["--deterministic"],
145 kwargs={
146 "action": "store_true",
147 "help": "Flag indicating the solver is deterministic",
148 },
149)
151DownloadExamplesArgument = ArgumentContainer(
152 names=["--download-examples"],
153 kwargs={
154 "action": "store_true",
155 "default": False,
156 "required": False,
157 "help": "Download the Examples into the directory.",
158 },
159)
161ExtractorsArgument = ArgumentContainer(
162 names=["--extractors", "--extractor_paths", "--extractor", "--extractor_path"],
163 kwargs={
164 "required": False,
165 "metavar": "extractor",
166 "type": str,
167 "nargs": "+",
168 "help": "path or nickname of the feature extractor(s)",
169 },
170)
172ExtractorPathArgument = ArgumentContainer(
173 names=["extractor_path"],
174 kwargs={
175 "metavar": "extractor-path",
176 "type": str,
177 "help": "path or nickname of the feature extractor",
178 },
179)
181GenerateJSONArgument = ArgumentContainer(
182 names=["--only-json"],
183 kwargs={
184 "required": False,
185 "default": False,
186 "type": bool,
187 "help": "if set to True, only generate machine readable output",
188 },
189)
191InstancePathOptional = ArgumentContainer(
192 names=["instance_path"],
193 kwargs={
194 "type": Path,
195 "nargs": "?",
196 "help": "Path to an instance to use for the command",
197 },
198)
200InstanceSetPathsArgument = ArgumentContainer(
201 names=[
202 "--instance-path",
203 "--instance-set-path",
204 "--instance",
205 "--instance-set",
206 "--instances",
207 "--instance-sets",
208 "--instance-paths",
209 "--instance-set-paths",
210 ],
211 kwargs={
212 "required": False,
213 "nargs": "+",
214 "type": Path,
215 "help": "Path to an instance (set)",
216 },
217)
219InstanceSetRequiredArgument = ArgumentContainer(
220 names=["--instance", "--instance-set"],
221 kwargs={"required": True, "type": Path, "help": "path to instance (set)"},
222)
224InstanceSetTestArgument = ArgumentContainer(
225 names=["--instance-set-test"],
226 kwargs={"required": False, "type": Path, "help": "path to test instance set"},
227)
229InstanceSetTrainArgument = ArgumentContainer(
230 names=["--instance-set-train"],
231 kwargs={"required": True, "type": Path, "help": "path to training instance set"},
232)
234InstanceSetTestAblationArgument = ArgumentContainer(
235 names=["--instance-set-test"],
236 kwargs={"required": False, "type": str, "help": "path to test instance set"},
237)
239InstanceSetTrainOptionalArgument = ArgumentContainer(
240 names=["--instance-set-train"],
241 kwargs={"required": False, "type": Path, "help": "path to training instance set"},
242)
244InstanceSetsReportArgument = ArgumentContainer(
245 names=["--instance-sets", "--instance-set"],
246 kwargs={
247 "required": False,
248 "nargs": "+",
249 "type": str,
250 "help": "Instance Set(s) to use for the report. If not "
251 "specified, all Instance Sets are used.",
252 },
253)
255InstancesPathArgument = ArgumentContainer(
256 names=["instances_path"],
257 kwargs={
258 "metavar": "instances-path",
259 "type": str,
260 "help": "path to the instance set",
261 },
262)
264InstancesPathRemoveArgument = ArgumentContainer(
265 names=["instances_path"],
266 kwargs={
267 "metavar": "instances-path",
268 "type": str,
269 "help": "path to or nickname of the instance set",
270 },
271)
273JobIDsArgument = ArgumentContainer(
274 names=["--job-ids"],
275 kwargs={
276 "required": False,
277 "nargs": "+",
278 "type": str,
279 "default": None,
280 "help": "job ID(s) to use for the command",
281 },
282)
284NicknameFeatureExtractorArgument = ArgumentContainer(
285 names=["--nickname"],
286 kwargs={"type": str, "help": "set a nickname for the feature extractor"},
287)
289NicknameInstanceSetArgument = ArgumentContainer(
290 names=["--nickname"],
291 kwargs={"type": str, "help": "set a nickname for the instance set"},
292)
294NicknamePortfolioArgument = ArgumentContainer(
295 names=["--portfolio-name"],
296 kwargs={
297 "type": Path,
298 "help": "Specify a name of the portfolio. "
299 "If none is given, one will be generated.",
300 },
301)
303NicknameSolverArgument = ArgumentContainer(
304 names=["--nickname"], kwargs={"type": str, "help": "set a nickname for the solver"}
305)
307NoCopyArgument = ArgumentContainer(
308 names=["--no-copy"],
309 kwargs={
310 "action": "store_true",
311 "required": False,
312 "help": "do not copy the source directory to "
313 "the platform directory, but create a"
314 " symbolic link instead",
315 },
316)
318NoSavePlatformArgument = ArgumentContainer(
319 names=["--no-save"],
320 kwargs={
321 "action": "store_false",
322 "default": True,
323 "required": False,
324 "help": "do not save the platform upon re-initialisation.",
325 },
326)
328ObjectiveArgument = ArgumentContainer(
329 names=["--objective"], kwargs={"type": str, "help": "the objective to use."}
330)
332RecomputeFeaturesArgument = ArgumentContainer(
333 names=["--recompute"],
334 kwargs={
335 "action": "store_true",
336 "help": "Re-run feature extractor for instances with "
337 "previously computed features",
338 },
339)
341RecomputePortfolioSelectorArgument = ArgumentContainer(
342 names=["--recompute-portfolio-selector"],
343 kwargs={
344 "action": "store_true",
345 "help": "force the construction of a new portfolio "
346 "selector even when it already exists for the current "
347 "feature and performance data.",
348 },
349)
351RecomputeRunSolversArgument = ArgumentContainer(
352 names=["--recompute"],
353 kwargs={
354 "action": "store_true",
355 "help": "recompute the performance of all solvers on all instances",
356 },
357)
359PerformanceDataJobsArgument = ArgumentContainer(
360 names=["--performance-data-jobs"],
361 kwargs={
362 "action": "store_true",
363 "help": "compute the remaining jobs in the Performance DataFrame",
364 },
365)
367RebuildRunsolverArgument = ArgumentContainer(
368 names=["--rebuild-runsolver"],
369 kwargs={
370 "action": "store_true",
371 "required": False,
372 "default": False,
373 "help": "Clean the RunSolver executable and rebuild it.",
374 },
375)
378SeedArgument = ArgumentContainer(
379 names=["--seed"], kwargs={"type": int, "help": "seed to use for the command"}
380)
382SelectionScenarioArgument = ArgumentContainer(
383 names=["--selection-scenario"],
384 kwargs={"required": True, "type": Path, "help": "the selection scenario to use"},
385)
387SelectorAblationArgument = ArgumentContainer(
388 names=["--solver-ablation"],
389 kwargs={
390 "required": False,
391 "action": "store_true",
392 "help": "construct a selector for each solver ablation combination",
393 },
394)
396SettingsFileArgument = ArgumentContainer(
397 names=["--settings-file"],
398 kwargs={
399 "type": Path,
400 "help": "Specify the settings file to use in case you want"
401 " supplement or override the default file.",
402 },
403)
405SkipChecksArgument = ArgumentContainer(
406 names=["--skip-checks"],
407 kwargs={
408 "dest": "run_checks",
409 "default": True,
410 "action": "store_false",
411 "help": "Checks the solver's functionality by testing it on an instance "
412 "and the pcs file, when applicable.",
413 },
414)
416SnapshotArgument = ArgumentContainer(
417 names=["snapshot_file_path"],
418 kwargs={
419 "metavar": "snapshot-file-path",
420 "type": str,
421 "help": "path to the snapshot file",
422 },
423)
425SnapshotNameArgument = ArgumentContainer(
426 names=["--name"],
427 kwargs={"required": False, "type": str, "help": "name of the snapshot"},
428)
430SolverArgument = ArgumentContainer(
431 names=["--solver"],
432 kwargs={"required": True, "type": Path, "help": "path to solver"},
433)
435SolversArgument = ArgumentContainer(
436 names=["--solvers", "--solver-paths", "--solver", "--solver-path"],
437 kwargs={
438 "required": False,
439 "nargs": "+",
440 "type": str,
441 "help": "Specify the list of solvers to be "
442 "used. If not specifed, all solvers "
443 "known in Sparkle will be used.",
444 },
445)
446SolverRemoveArgument = ArgumentContainer(
447 names=["solver"],
448 kwargs={
449 "metavar": "solver",
450 "type": str,
451 "help": "name, path to or nickname of the solver",
452 },
453)
455SolverPathArgument = ArgumentContainer(
456 names=["solver_path"],
457 kwargs={"metavar": "solver-path", "type": str, "help": "path to the solver"},
458)
460SolversReportArgument = ArgumentContainer(
461 names=["--solvers", "--solver"],
462 kwargs={
463 "nargs": "+",
464 "type": str,
465 "default": None,
466 "help": "Solver(s) to use for the report. If not specified, all solvers are "
467 "included.",
468 },
469)
471TestSetRunAllConfigurationArgument = ArgumentContainer(
472 names=["--test-set-run-all-configurations"],
473 kwargs={
474 "required": False,
475 "action": "store_true",
476 "help": "run all found configurations on the test set",
477 },
478)
480UseFeaturesArgument = ArgumentContainer(
481 names=["--use-features"],
482 kwargs={
483 "required": False,
484 "action": "store_true",
485 "help": "use the training set's features for configuration",
486 },
487)
489SolutionVerifierArgument = ArgumentContainer(
490 names=["--solution-verifier"],
491 kwargs={
492 "type": str,
493 "default": None,
494 "help": "the class name of the solution verifier to use "
495 "for the Solver. If it is a Path, will resolve as "
496 "a SolutionFileVerifier class with the specified "
497 "Path instead.",
498 },
499)
501WrapPathArgument = ArgumentContainer(
502 names=["path"], kwargs={"type": Path, "help": "path to the directory to wrap"}
503)
505WrapTargetArgument = ArgumentContainer(
506 names=["target"],
507 kwargs={"type": Path, "help": "relative path to the target executable"},
508)
510WrapTypeArgument = ArgumentContainer(
511 names=["type"],
512 kwargs={
513 "type": str,
514 "help": "type of the target to wrap (Solver or Extractor)",
515 },
516)
518WrapGeneratePCSArgument = ArgumentContainer(
519 names=["--generate-pcs"],
520 kwargs={
521 "required": False,
522 "action": "store_true",
523 "help": "generate a Solver Parameter Configuration Space (PCS) file for the target",
524 },
525)