annotate ebcsgen_generate_ts.py @ 0:9e58089710ea draft

planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
author sybila
date Fri, 09 Sep 2022 13:22:19 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
1 import argparse
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
2
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
3 from eBCSgen.Errors.ModelParsingError import ModelParsingError
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
4 from eBCSgen.Errors.UnspecifiedParsingError import UnspecifiedParsingError
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
5 from eBCSgen.Parsing.ParseBCSL import Parser
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
6
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
7 import numpy as np
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
8
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
9
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
10 args_parser = argparse.ArgumentParser(description='Transition system generating')
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
11
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
12 args_parser._action_groups.pop()
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
13 required = args_parser.add_argument_group('required arguments')
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
14 optional = args_parser.add_argument_group('optional arguments')
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
15
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
16 required.add_argument('--model', type=str, required=True)
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
17 required.add_argument('--output', type=str, required=True)
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
18 required.add_argument('--direct', required=True)
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
19
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
20 optional.add_argument('--max_time', type=float, default=np.inf)
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
21 optional.add_argument('--max_size', type=float, default=np.inf)
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
22 optional.add_argument('--bound', type=int, default=None)
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
23
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
24 args = args_parser.parse_args()
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
25
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
26 model_parser = Parser("model")
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
27 model_str = open(args.model, "r").read()
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
28
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
29 model = model_parser.parse(model_str)
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
30 if model.success:
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
31 if eval(args.direct):
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
32 ts = model.data.generate_direct_transition_system(args.max_time,
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
33 args.max_size,
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
34 args.bound)
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
35 ts.change_to_vector_backend()
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
36 else:
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
37 vm = model.data.to_vector_model(args.bound)
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
38 ts = vm.generate_transition_system(None, args.max_time, args.max_size)
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
39 ts.save_to_json(args.output, model.data.params)
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
40 else:
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
41 if "error" in model.data:
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
42 raise UnspecifiedParsingError(model.data["error"])
9e58089710ea planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
43 raise ModelParsingError(model.data, model_str)