Coverage for src/sparkle/CLI/help/argparse_custom.py: 100%
63 statements
« prev ^ index » next coverage.py v7.10.7, created at 2025-10-15 14:11 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2025-10-15 14:11 +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",
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={"action": "store_true", "help": "clean performance data from empty lines"},
115)
118ConfigurationArgument = ArgumentContainer(
119 names=["--configuration"],
120 kwargs={
121 "required": False,
122 "type": str,
123 "nargs": "+",
124 "help": "The indices of which configurations to use",
125 },
126)
128DefaultSolverConfigurationArgument = ArgumentContainer(
129 names=["--default-configuration"],
130 kwargs={
131 "action": "store_true",
132 "help": "use the default configurations for the command",
133 },
134)
136DeterministicArgument = ArgumentContainer(
137 names=["--deterministic"],
138 kwargs={
139 "action": "store_true",
140 "help": "Flag indicating the solver is deterministic",
141 },
142)
144DownloadExamplesArgument = ArgumentContainer(
145 names=["--download-examples"],
146 kwargs={
147 "action": "store_true",
148 "default": False,
149 "required": False,
150 "help": "Download the Examples into the directory.",
151 },
152)
154ExtractorPathArgument = ArgumentContainer(
155 names=["extractor_path"],
156 kwargs={
157 "metavar": "extractor-path",
158 "type": str,
159 "help": "path or nickname of the feature extractor",
160 },
161)
163GenerateJSONArgument = ArgumentContainer(
164 names=["--only-json"],
165 kwargs={
166 "required": False,
167 "default": False,
168 "type": bool,
169 "help": "if set to True, only generate machine readable output",
170 },
171)
173InstancePathOptional = ArgumentContainer(
174 names=["instance_path"],
175 kwargs={
176 "type": Path,
177 "nargs": "?",
178 "help": "Path to an instance to use for the command",
179 },
180)
182InstanceSetPathsArgument = ArgumentContainer(
183 names=[
184 "--instance-path",
185 "--instance-set-path",
186 "--instance",
187 "--instance-set",
188 "--instances",
189 "--instance-sets",
190 "--instance-paths",
191 "--instance-set-paths",
192 ],
193 kwargs={
194 "required": False,
195 "nargs": "+",
196 "type": Path,
197 "help": "Path to an instance (set)",
198 },
199)
201InstanceSetRequiredArgument = ArgumentContainer(
202 names=["--instance", "--instance-set"],
203 kwargs={"required": True, "type": Path, "help": "path to instance (set)"},
204)
206InstanceSetTestArgument = ArgumentContainer(
207 names=["--instance-set-test"],
208 kwargs={"required": False, "type": Path, "help": "path to test instance set"},
209)
211InstanceSetTrainArgument = ArgumentContainer(
212 names=["--instance-set-train"],
213 kwargs={"required": True, "type": Path, "help": "path to training instance set"},
214)
216InstanceSetTestAblationArgument = ArgumentContainer(
217 names=["--instance-set-test"],
218 kwargs={"required": False, "type": str, "help": "path to test instance set"},
219)
221InstanceSetTrainOptionalArgument = ArgumentContainer(
222 names=["--instance-set-train"],
223 kwargs={"required": False, "type": Path, "help": "path to training instance set"},
224)
226InstanceSetsReportArgument = ArgumentContainer(
227 names=["--instance-sets", "--instance-set"],
228 kwargs={
229 "required": False,
230 "nargs": "+",
231 "type": str,
232 "help": "Instance Set(s) to use for the report. If not "
233 "specified, all Instance Sets are used.",
234 },
235)
237InstancesPathArgument = ArgumentContainer(
238 names=["instances_path"],
239 kwargs={
240 "metavar": "instances-path",
241 "type": str,
242 "help": "path to the instance set",
243 },
244)
246InstancesPathRemoveArgument = ArgumentContainer(
247 names=["instances_path"],
248 kwargs={
249 "metavar": "instances-path",
250 "type": str,
251 "help": "path to or nickname of the instance set",
252 },
253)
255JobIDsArgument = ArgumentContainer(
256 names=["--job-ids"],
257 kwargs={
258 "required": False,
259 "nargs": "+",
260 "type": str,
261 "default": None,
262 "help": "job ID(s) to use for the command",
263 },
264)
266NicknameFeatureExtractorArgument = ArgumentContainer(
267 names=["--nickname"],
268 kwargs={"type": str, "help": "set a nickname for the feature extractor"},
269)
271NicknameInstanceSetArgument = ArgumentContainer(
272 names=["--nickname"],
273 kwargs={"type": str, "help": "set a nickname for the instance set"},
274)
276NicknamePortfolioArgument = ArgumentContainer(
277 names=["--portfolio-name"],
278 kwargs={
279 "type": Path,
280 "help": "Specify a name of the portfolio. "
281 "If none is given, one will be generated.",
282 },
283)
285NicknameSolverArgument = ArgumentContainer(
286 names=["--nickname"], kwargs={"type": str, "help": "set a nickname for the solver"}
287)
289NoCopyArgument = ArgumentContainer(
290 names=["--no-copy"],
291 kwargs={
292 "action": "store_true",
293 "required": False,
294 "help": "do not copy the source directory to "
295 "the platform directory, but create a"
296 " symbolic link instead",
297 },
298)
300NoSavePlatformArgument = ArgumentContainer(
301 names=["--no-save"],
302 kwargs={
303 "action": "store_false",
304 "default": True,
305 "required": False,
306 "help": "do not save the platform upon re-initialisation.",
307 },
308)
310RecomputeFeaturesArgument = ArgumentContainer(
311 names=["--recompute"],
312 kwargs={
313 "action": "store_true",
314 "help": "Re-run feature extractor for instances with "
315 "previously computed features",
316 },
317)
319RecomputePortfolioSelectorArgument = ArgumentContainer(
320 names=["--recompute-portfolio-selector"],
321 kwargs={
322 "action": "store_true",
323 "help": "force the construction of a new portfolio "
324 "selector even when it already exists for the current "
325 "feature and performance data.",
326 },
327)
329RecomputeRunSolversArgument = ArgumentContainer(
330 names=["--recompute"],
331 kwargs={
332 "action": "store_true",
333 "help": "recompute the performance of all solvers on all instances",
334 },
335)
337PerformanceDataJobsArgument = ArgumentContainer(
338 names=["--performance-data-jobs"],
339 kwargs={
340 "action": "store_true",
341 "help": "compute the remaining jobs in the Performance DataFrame",
342 },
343)
345RebuildRunsolverArgument = ArgumentContainer(
346 names=["--rebuild-runsolver"],
347 kwargs={
348 "action": "store_true",
349 "required": False,
350 "default": False,
351 "help": "Clean the RunSolver executable and rebuild it.",
352 },
353)
356SeedArgument = ArgumentContainer(
357 names=["--seed"], kwargs={"type": int, "help": "seed to use for the command"}
358)
360SelectionScenarioArgument = ArgumentContainer(
361 names=["--selection-scenario"],
362 kwargs={"required": True, "type": Path, "help": "the selection scenario to use"},
363)
365SelectorAblationArgument = ArgumentContainer(
366 names=["--solver-ablation"],
367 kwargs={
368 "required": False,
369 "action": "store_true",
370 "help": "construct a selector for each solver ablation combination",
371 },
372)
374SettingsFileArgument = ArgumentContainer(
375 names=["--settings-file"],
376 kwargs={
377 "type": Path,
378 "help": "Specify the settings file to use in case you want"
379 " supplement or override the default file.",
380 },
381)
383SkipChecksArgument = ArgumentContainer(
384 names=["--skip-checks"],
385 kwargs={
386 "dest": "run_checks",
387 "default": True,
388 "action": "store_false",
389 "help": "Checks the solver's functionality by testing it on an instance "
390 "and the pcs file, when applicable.",
391 },
392)
394SnapshotArgument = ArgumentContainer(
395 names=["snapshot_file_path"],
396 kwargs={
397 "metavar": "snapshot-file-path",
398 "type": str,
399 "help": "path to the snapshot file",
400 },
401)
403SnapshotNameArgument = ArgumentContainer(
404 names=["--name"],
405 kwargs={"required": False, "type": str, "help": "name of the snapshot"},
406)
408SolverArgument = ArgumentContainer(
409 names=["--solver"],
410 kwargs={"required": True, "type": Path, "help": "path to solver"},
411)
413SolversArgument = ArgumentContainer(
414 names=["--solvers", "--solver-paths", "--solver", "--solver-path"],
415 kwargs={
416 "required": False,
417 "nargs": "+",
418 "type": str,
419 "help": "Specify the list of solvers to be "
420 "used. If not specifed, all solvers "
421 "known in Sparkle will be used.",
422 },
423)
424SolverRemoveArgument = ArgumentContainer(
425 names=["solver"],
426 kwargs={
427 "metavar": "solver",
428 "type": str,
429 "help": "name, path to or nickname of the solver",
430 },
431)
433SolverPathArgument = ArgumentContainer(
434 names=["solver_path"],
435 kwargs={"metavar": "solver-path", "type": str, "help": "path to the solver"},
436)
438SolversReportArgument = ArgumentContainer(
439 names=["--solvers", "--solver"],
440 kwargs={
441 "nargs": "+",
442 "type": str,
443 "default": None,
444 "help": "Solver(s) to use for the report. If not specified, all solvers are "
445 "included.",
446 },
447)
449TestSetRunAllConfigurationArgument = ArgumentContainer(
450 names=["--test-set-run-all-configurations"],
451 kwargs={
452 "required": False,
453 "action": "store_true",
454 "help": "run all found configurations on the test set",
455 },
456)
458UseFeaturesArgument = ArgumentContainer(
459 names=["--use-features"],
460 kwargs={
461 "required": False,
462 "action": "store_true",
463 "help": "use the training set's features for configuration",
464 },
465)
467SolutionVerifierArgument = ArgumentContainer(
468 names=["--solution-verifier"],
469 kwargs={
470 "type": str,
471 "default": None,
472 "help": "the class name of the solution verifier to use "
473 "for the Solver. If it is a Path, will resolve as "
474 "a SolutionFileVerifier class with the specified "
475 "Path instead.",
476 },
477)
479ObjectiveArgument = ArgumentContainer(
480 names=["--objective"], kwargs={"type": str, "help": "the objective to use."}
481)