annotate ebcsgen_ctl_model_checking.py @ 0:213df1fd884f draft

planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
author sybila
date Thu, 06 Oct 2022 14:39:48 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
1 import argparse
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
2
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
3 from eBCSgen.Analysis.CTL import CTL
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
4 from eBCSgen.Errors.FormulaParsingError import FormulaParsingError
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
5 from eBCSgen.Errors.InvalidInputError import InvalidInputError
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
6 from eBCSgen.Parsing.ParseBCSL import load_TS_from_json
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
7 from eBCSgen.Parsing.ParseCTLformula import CTLparser
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
8
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
9 args_parser = argparse.ArgumentParser(description='Model checking')
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
10
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
11 args_parser._action_groups.pop()
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
12 required = args_parser.add_argument_group('required arguments')
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
13
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
14 required.add_argument('--transition_file', required=True)
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
15 required.add_argument('--output', type=str, required=True)
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
16 required.add_argument('--formula', type=str, required=True)
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
17
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
18 args = args_parser.parse_args()
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
19
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
20 ts = load_TS_from_json(args.transition_file)
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
21
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
22 if len(ts.params) != 0:
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
23 raise InvalidInputError("Provided transition system is parametrised - model checking cannot be executed.")
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
24
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
25 formula = CTLparser().parse(args.formula)
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
26 if formula.success:
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
27 result, states = CTL.model_checking(ts, formula)
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
28 output = 'Result: {}\nNumber of satisfying states: {}'.format(result, len(states))
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
29 f = open(args.output, "w")
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
30 f.write(output)
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
31 f.close()
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
32 else:
213df1fd884f planemo upload for repository https://github.com/sybila/galaxytools/tree/master/tools/ebcsgen commit ab45353a4e518f67057a1789aa527fb3bf1e74d5
sybila
parents:
diff changeset
33 raise FormulaParsingError(formula.data, args.formula)