annotate ebcsgen_generate_ts.py @ 1:6ef168733c4d draft

planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 81dbe4922abcbd544c1dd9830d05daf661a29658
author sybila
date Tue, 04 Oct 2022 09:54:28 +0000
parents f13bdc5f4409
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f13bdc5f4409 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
1 import argparse
f13bdc5f4409 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
2
f13bdc5f4409 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
f13bdc5f4409 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
f13bdc5f4409 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
f13bdc5f4409 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
6
f13bdc5f4409 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
7 import numpy as np
f13bdc5f4409 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
8
f13bdc5f4409 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
9
f13bdc5f4409 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')
f13bdc5f4409 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
11
f13bdc5f4409 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()
f13bdc5f4409 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')
f13bdc5f4409 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')
f13bdc5f4409 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
15
f13bdc5f4409 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)
f13bdc5f4409 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)
f13bdc5f4409 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)
f13bdc5f4409 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
19
f13bdc5f4409 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)
f13bdc5f4409 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)
f13bdc5f4409 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)
f13bdc5f4409 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
23
f13bdc5f4409 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()
f13bdc5f4409 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
25
f13bdc5f4409 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
26 model_parser = Parser("model")
f13bdc5f4409 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()
f13bdc5f4409 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
28
f13bdc5f4409 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)
f13bdc5f4409 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
30 if model.success:
f13bdc5f4409 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
31 if eval(args.direct):
f13bdc5f4409 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,
f13bdc5f4409 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
33 args.max_size,
f13bdc5f4409 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
34 args.bound)
f13bdc5f4409 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()
f13bdc5f4409 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
36 else:
f13bdc5f4409 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)
f13bdc5f4409 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)
f13bdc5f4409 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)
f13bdc5f4409 planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit e26adecc1caf5c8fe966a5c891cc7941324d73bb
sybila
parents:
diff changeset
40 else:
f13bdc5f4409 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:
f13bdc5f4409 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"])
f13bdc5f4409 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)