Mercurial > repos > sybila > ebcsgen_pctl_parameter_synthesis
annotate ebcsgen_pctl_parameter_synthesis.py @ 2:3bb6c1e9252e draft default tip
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 4719a69f514aed27d90c7017f052463b0b43cbb0
author | sybila |
---|---|
date | Sat, 15 Oct 2022 09:23:30 +0000 |
parents | cf609f659b21 |
children |
rev | line source |
---|---|
0
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
1 import argparse |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
2 |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
3 from eBCSgen.Analysis.PCTL import PCTL |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
4 from eBCSgen.Errors.FormulaParsingError import FormulaParsingError |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
5 from eBCSgen.Errors.InvalidInputError import InvalidInputError |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
6 from eBCSgen.Parsing.ParseBCSL import load_TS_from_json |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
7 from eBCSgen.Parsing.ParsePCTLformula import PCTLparser |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
8 |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
9 |
2
3bb6c1e9252e
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 4719a69f514aed27d90c7017f052463b0b43cbb0
sybila
parents:
0
diff
changeset
|
10 class FakeFile: |
3bb6c1e9252e
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 4719a69f514aed27d90c7017f052463b0b43cbb0
sybila
parents:
0
diff
changeset
|
11 def __init__(self, content): |
3bb6c1e9252e
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 4719a69f514aed27d90c7017f052463b0b43cbb0
sybila
parents:
0
diff
changeset
|
12 self.content = content.decode("utf-8") |
3bb6c1e9252e
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 4719a69f514aed27d90c7017f052463b0b43cbb0
sybila
parents:
0
diff
changeset
|
13 |
3bb6c1e9252e
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 4719a69f514aed27d90c7017f052463b0b43cbb0
sybila
parents:
0
diff
changeset
|
14 def read(self): |
3bb6c1e9252e
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 4719a69f514aed27d90c7017f052463b0b43cbb0
sybila
parents:
0
diff
changeset
|
15 return self.content |
3bb6c1e9252e
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 4719a69f514aed27d90c7017f052463b0b43cbb0
sybila
parents:
0
diff
changeset
|
16 |
3bb6c1e9252e
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 4719a69f514aed27d90c7017f052463b0b43cbb0
sybila
parents:
0
diff
changeset
|
17 |
0
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
18 args_parser = argparse.ArgumentParser(description='Parameter synthesis') |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
19 |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
20 args_parser._action_groups.pop() |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
21 required = args_parser.add_argument_group('required arguments') |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
22 optional = args_parser.add_argument_group('optional arguments') |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
23 |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
24 required.add_argument('--transition_file', required=True) |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
25 required.add_argument('--output', type=str, required=True) |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
26 required.add_argument('--formula', type=str, required=True) |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
27 optional.add_argument('--region', type=str) |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
28 |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
29 args = args_parser.parse_args() |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
30 |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
31 if args.region: |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
32 region = args.region.replace("=", "<=") |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
33 else: |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
34 region = None |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
35 |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
36 ts = load_TS_from_json(args.transition_file) |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
37 |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
38 if len(ts.params) == 0: |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
39 raise InvalidInputError("Provided model is not parametrised - parameter synthesis cannot be executed.") |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
40 |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
41 if "?" not in args.formula: |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
42 if not region: |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
43 params = set() |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
44 else: |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
45 params = {param.split("<=")[1] for param in region.split(",")} |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
46 |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
47 undefined = set(ts.params) - params |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
48 if undefined: |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
49 raise InvalidInputError("Intervals undefined for parameters: {}.".format(", ".join(undefined))) |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
50 |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
51 formula = PCTLparser().parse(args.formula) |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
52 if formula.success: |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
53 result = PCTL.parameter_synthesis(ts, formula, region) |
2
3bb6c1e9252e
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 4719a69f514aed27d90c7017f052463b0b43cbb0
sybila
parents:
0
diff
changeset
|
54 if "?" not in args.formula: |
3bb6c1e9252e
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 4719a69f514aed27d90c7017f052463b0b43cbb0
sybila
parents:
0
diff
changeset
|
55 result = FakeFile(result) |
3bb6c1e9252e
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 4719a69f514aed27d90c7017f052463b0b43cbb0
sybila
parents:
0
diff
changeset
|
56 df = PCTL.process_output(result) |
3bb6c1e9252e
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 4719a69f514aed27d90c7017f052463b0b43cbb0
sybila
parents:
0
diff
changeset
|
57 df.to_csv(args.output, index=False) |
3bb6c1e9252e
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 4719a69f514aed27d90c7017f052463b0b43cbb0
sybila
parents:
0
diff
changeset
|
58 else: |
3bb6c1e9252e
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 4719a69f514aed27d90c7017f052463b0b43cbb0
sybila
parents:
0
diff
changeset
|
59 with open(args.output, "w") as f: |
3bb6c1e9252e
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit 4719a69f514aed27d90c7017f052463b0b43cbb0
sybila
parents:
0
diff
changeset
|
60 f.write(result.decode("utf-8")) |
0
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
61 else: |
cf609f659b21
planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit a7263af5f87e39dd0d3d29924e530c88d83a5ee6
sybila
parents:
diff
changeset
|
62 raise FormulaParsingError(formula.data, args.formula) |