Command line
The command line: size a case, optimize a case, or read the interface of its black box.
Three commands, all taking a case file:
cdadt size <case>Converge the aircraft against its mission and print every response.
cdadt optimize <case>Converge a baseline, drive the design variables against the certification basis, and print the comparison and the traceability matrix.
cdadt inspect <case>Print what the case’s black box accepts and what it publishes, without running anything. This is the interface reference, generated rather than transcribed – which is the only kind that stays true.
Each command can write its results to JSON with --json, so a study is archivable without
re-running it, and --outputs <dir> additionally leaves the model diagram, the flown
trajectory and the printed report in one directory. See cdadt.artifacts.
The shape of this module. Every command is a Command subclass that declares its own
name, its own arguments and what it does, and CommandLineInterface composes whichever
set it is given. A fourth command is therefore a fourth subclass and one entry in
DEFAULT_COMMANDS; no existing command, and no dispatch table, is touched. That is the
same open/closed arrangement the disciplines use, and it is why there is no if command ==
anywhere here.
Nothing in this module computes anything. A command reads a case file, hands it to the classes that do the work, and turns what comes back into text and an exit status.
- cdadt.cli.DEFAULT_COMMANDS: tuple[type[Command], ...] = (<class 'cdadt.cli.SizeCommand'>, <class 'cdadt.cli.OptimizeCommand'>, <class 'cdadt.cli.InspectCommand'>)
The commands
cdadtoffers. A new one is a new class and one entry here.
- class cdadt.cli.Command[source]
Bases:
ABCOne subcommand of
cdadt.A subclass declares what it is called and what it does; the interface that composes it owns the parser and the dispatch, so a command never needs to know it has siblings.
- Variables:
name (str) – The word typed after
cdadt.help (str) – One line, shown in
cdadt --help.
- name: ClassVar[str]
- help: ClassVar[str]
- class cdadt.cli.CommandLineInterface(commands=(<class 'cdadt.cli.SizeCommand'>, <class 'cdadt.cli.OptimizeCommand'>, <class 'cdadt.cli.InspectCommand'>))[source]
Bases:
objectThe
cdadtcommand line: a parser, a set of commands, and the dispatch between them.- Parameters:
commands (sequence of type, optional) – Command classes to offer. Default
DEFAULT_COMMANDS. Passing a different set is how a study adds a command, and is what lets the dispatch be tested without running one.- Raises:
ValueError – If two commands claim the same name, which would otherwise mean one silently shadowed the other.
Examples
>>> CommandLineInterface().run(["--version"]) Traceback (most recent call last): SystemExit: 0
- class cdadt.cli.InspectCommand[source]
Bases:
CommandPrint the interface of a case’s black box without running it.
- name: ClassVar[str] = 'inspect'
- help: ClassVar[str] = "print the interface of the case's black box"
- HALVES: ClassVar[tuple[str, ...]] = ('inputs', 'outputs', 'both')
- class cdadt.cli.OptimizeCommand[source]
Bases:
StudyCommandOptimize a case against its certification basis.
- name: ClassVar[str] = 'optimize'
- help: ClassVar[str] = 'optimize a case against its certification basis'
- verbose_help: ClassVar[str] = 'print continuation and driver progress'
- class cdadt.cli.SizeCommand[source]
Bases:
StudyCommandConverge a case and print every response.
- name: ClassVar[str] = 'size'
- help: ClassVar[str] = 'converge a case and report every response'
- class cdadt.cli.StudyCommand[source]
Bases:
CommandA command that runs a study and leaves a complete record of it behind.
Both studies – sizing and optimizing – write the same files into the same place, so that behaviour lives here once. What differs is only what is run and what the archived payload contains, which is what the subclasses supply.
Every run writes its outputs. Not on request: a study whose files depend on a flag is a study whose record depends on remembering the flag. The run directory is
RunDirectory, which is OpenMDAO’s own mechanism, so the driver’s log and OpenMDAO’s reports land beside cdadt’s files rather than in the working directory.- verbose_help: ClassVar[str] = 'print each continuation step'
- configure(parser)[source]
Declare the case file, where runs go, and the verbosity flag.
- Parameters:
parser (ArgumentParser)
- Return type:
None
- static run_directory(arguments)[source]
Return the run directory this invocation writes into.
Named for the case and the moment it was run, so repeated runs of one case accumulate instead of overwriting each other. The clock is read here, at the edge, and the stamp is passed in as data – everything below this point is reproducible given the same stamp.
- Parameters:
arguments (Namespace)
- Return type:
- archive(arguments, analysis, report, payload)[source]
Write the report, the numbers and the three figures into the run directory.
- Parameters:
arguments (Namespace)
analysis (SizingAnalysis)
report (str)
payload (dict[str, Any])
- Return type:
None
- cdadt.cli.main(argv=None)[source]
Run the command line.
The console-script entry point, and nothing more: the work is
CommandLineInterface, which is what a test or another tool should use.- Parameters:
argv (sequence of str, optional) – Arguments, defaulting to
sys.argv[1:].- Returns:
int – Process exit status. Non-zero when an optimization did not succeed, or when the case could not be run at all.
- Return type:
int