aegis

This script is executed when AEGIS is imported (import aegis). Execute functions by running aegis.run_from_{}. AEGIS can be started in multiple ways; each of these functions starts AEGIS from a different context.

 1"""
 2This script is executed when AEGIS is imported (`import aegis`). Execute functions by running `aegis.run_from_{}`.
 3AEGIS can be started in multiple ways; each of these functions starts AEGIS from a different context.
 4"""
 5
 6import logging
 7import pathlib
 8import sys
 9
10import aegis_gui
11import aegis_sim
12from aegis.log import set_logging
13from aegis.parse import get_parser, validate_config_path
14
15
16def start_from_terminal():
17    parser = get_parser()
18    args = parser.parse_args()
19    set_logging(level=logging.DEBUG)
20    logging.getLogger("numba").setLevel(logging.ERROR)
21
22    if args.command == "sim":
23        config_path_str = validate_config_path(args.config_path)
24        config_path = pathlib.Path(config_path_str).absolute()
25
26        if args.extend is not None and not args.resume:
27            print("Error: --extend can only be used with --resume (-r).", file=sys.stderr)
28            sys.exit(1)
29
30        if args.resume:
31            # Resume mode — derive output dir from config path
32            odir = config_path.parent / config_path.stem
33            aegis_sim.run(
34                custom_config_path=config_path,
35                pickle_path=None,
36                overwrite=False,
37                custom_input_params={},
38                resume_path=odir,
39                extend_steps=args.extend,
40            )
41        else:
42            # Fresh or seed mode
43            pickle_path = pathlib.Path(args.pickle_path).absolute() if args.pickle_path else None
44            aegis_sim.run(
45                custom_config_path=config_path,
46                pickle_path=pickle_path,
47                overwrite=args.overwrite,
48                custom_input_params={},
49            )
50    elif args.command == "gui":
51        if args.server:
52            aegis_gui.run(environment="server", debug=False)
53        else:
54            aegis_gui.run(environment="local", debug=args.debug)
55    else:
56        parser.print_help()
def start_from_terminal():
17def start_from_terminal():
18    parser = get_parser()
19    args = parser.parse_args()
20    set_logging(level=logging.DEBUG)
21    logging.getLogger("numba").setLevel(logging.ERROR)
22
23    if args.command == "sim":
24        config_path_str = validate_config_path(args.config_path)
25        config_path = pathlib.Path(config_path_str).absolute()
26
27        if args.extend is not None and not args.resume:
28            print("Error: --extend can only be used with --resume (-r).", file=sys.stderr)
29            sys.exit(1)
30
31        if args.resume:
32            # Resume mode — derive output dir from config path
33            odir = config_path.parent / config_path.stem
34            aegis_sim.run(
35                custom_config_path=config_path,
36                pickle_path=None,
37                overwrite=False,
38                custom_input_params={},
39                resume_path=odir,
40                extend_steps=args.extend,
41            )
42        else:
43            # Fresh or seed mode
44            pickle_path = pathlib.Path(args.pickle_path).absolute() if args.pickle_path else None
45            aegis_sim.run(
46                custom_config_path=config_path,
47                pickle_path=pickle_path,
48                overwrite=args.overwrite,
49                custom_input_params={},
50            )
51    elif args.command == "gui":
52        if args.server:
53            aegis_gui.run(environment="server", debug=False)
54        else:
55            aegis_gui.run(environment="local", debug=args.debug)
56    else:
57        parser.print_help()