Add command line interface
Besides Python API, a command line interface would be nice to have for things like:
- inspecting models ->
xsimlab inspect - automatically generating input files for a given model ->
xsimlab generate - running simulations ->
xsimlab run
As reference, see, e.g., the command line scripts implemented in distributed based on click: https://github.com/dask/distributed/tree/master/distributed/cli
See also how to add it in conda packages as entry points: https://github.com/conda-forge/distributed-feedstock/blob/master/recipe/meta.yaml
Hey!
nice presentation today at EGU. I would like to suggest the model-organization package for this issue.
Besides it's automated command line API (see the example in the docs), this module organizes experiments and makes the configuration accessible and clearly arranged. One simple implementation would be
from model_organization import ModelOrganizer
import xsimlab
class XSimlabOrganizer(ModelOrganizer):
commands = ModelOrganizer.commands[:]
commands.insert(commands.index('init') + 1, 'run')
def run(self, ...):
"""Run the model"""
in_ds = xsimlab.create_setup(model=..., ...)
out_ds = in_ds.xsimlab.run(model=...)
out_ds.to_netcdf(self.exp_dir + 'output.nc')
if you save this into a file named model.py, this could then be run via
python model.py run # ... any arguments
See the docs for more information about the model-organization framework.
Thanks for the suggestion @Chilipp ! I haven't really looked into existing solutions for automating cmd line interface yet but I'll look into your package.
Sure, just a hint 😉