Command Line Interface

This notebook illustrates the command line interface (CLI) of the larvaworld package

The CLI entry point / shell command is larvaworld and can be run on a terminal along with additional arguments.

Here we will run it from within the notebook using !.

The --help/-h flag displays a help message.

The -verbose flag controls the verbosity of the output

The --show_parser_args/-parsargs flag shows the parsed argument namespace

# Display the help message for larvaworld
!larvaworld -h
# Control the verbosity of the output
!larvaworld -verbose 0
# Show the parsed argument namespace
!larvaworld -parsargs

There is only a single required positional argument that defines the simulation mode.

This takes one of several predefined values (see help message above) and should be provided just after the command.

Once the simulation mode is defined the available arguments can be set. Some of them are common but others diverge among modes.

The help message can illustrate this :

# Display the help message for a given simulation mode
!larvaworld Exp -h
# Display the help message for a given simulation mode
!larvaworld Ga -h

Argument parser

What arguments are there available in CLI?

To answer this let’s have a look at what’s happening behind the scenes. The ParserArgumentDict class creates the available arguments for a specified input configuration class. Let’s see some examples :

from larvaworld.lib.param import RuntimeOps, SimOps
from larvaworld.cli.argparser import ParserArgumentDict
from larvaworld.lib.screen import ScreenOps
from larvaworld.lib import reg

# Available simulation arguments
sim_kws = ParserArgumentDict.from_param(d0=SimOps)
sim_kws.parsargs.keylist.sorted
# Available visualization arguments
screen_kws = ParserArgumentDict.from_param(d0=ScreenOps)
screen_kws.parsargs.keylist.sorted
# Available GA-mode arguments
GAselector = ParserArgumentDict.from_param(d0=reg.gen.GAselector)
GAevaluation = ParserArgumentDict.from_param(d0=reg.gen.GAevaluation)

print(GAselector.parsargs.keylist.sorted)
print(GAevaluation.parsargs.keylist.sorted)
# Available replay-mode arguments
Replay = ParserArgumentDict.from_param(d0=reg.gen.Replay)
Replay.parsargs.keylist.sorted

Now let’s see the overarching argument parser used in CLI

from larvaworld.cli.argparser import SimModeParser

# Initialize the parser
P = SimModeParser()

# The grouped arguments
print(P.parsers)

# The individual arguments
# print(P.__dict__)