annotate ebcsgen_generate_ts.py @ 0:3bdec3b22152 draft default tip

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