Attention une mise à jour du service Gitlab va être effectuée le mardi 30 novembre entre 17h30 et 18h00. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes. Cette mise à jour intermédiaire en version 14.0.12 nous permettra de rapidement pouvoir mettre à votre disposition une version plus récente.

Commit 1d4fdaa2 authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

Ability to dump tests results in json file; graph_isomorph_test() returns a...

Ability to dump tests results in json file; graph_isomorph_test() returns a check dict for easy integration in python scripts
parent ffc85832
...@@ -100,7 +100,8 @@ def model_comp(args): ...@@ -100,7 +100,8 @@ def model_comp(args):
params['model_file_1'], params['model_file_1'],
params['model_file_2'], params['model_file_2'],
params['output'], params['output'],
params['make_graphs'], params['graphs'],
params['json'],
) )
...@@ -246,7 +247,8 @@ def main(): ...@@ -246,7 +247,8 @@ def main():
parser_model_comparison.add_argument('model_file_1') parser_model_comparison.add_argument('model_file_1')
parser_model_comparison.add_argument('model_file_2') parser_model_comparison.add_argument('model_file_2')
# Export graphs for the 2 models; default: false # Export graphs for the 2 models; default: false
parser_model_comparison.add_argument('--make_graphs', action='store_true') parser_model_comparison.add_argument('--graphs', action='store_true')
parser_model_comparison.add_argument('--json', action='store_true')
parser_model_comparison.add_argument('--output', action=ReadableDir, parser_model_comparison.add_argument('--output', action=ReadableDir,
nargs='?', default='graphs/') nargs='?', default='graphs/')
parser_model_comparison.set_defaults(func=model_comp) parser_model_comparison.set_defaults(func=model_comp)
......
...@@ -31,6 +31,7 @@ import networkx as nx ...@@ -31,6 +31,7 @@ import networkx as nx
import itertools as it import itertools as it
import re import re
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import json
from logging import DEBUG from logging import DEBUG
# Library imports # Library imports
...@@ -801,7 +802,7 @@ def main(output_dir, model_file, solution_file): ...@@ -801,7 +802,7 @@ def main(output_dir, model_file, solution_file):
def graph_isomorph_test(model_file_1, model_file_2, def graph_isomorph_test(model_file_1, model_file_2,
output_dir, make_graphs=False): output_dir, make_graphs=False, make_json=False):
"""Entry point for model consistency checking. """Entry point for model consistency checking.
This functions checks if the 2 given models have the same topology, This functions checks if the 2 given models have the same topology,
...@@ -814,6 +815,9 @@ def graph_isomorph_test(model_file_1, model_file_2, ...@@ -814,6 +815,9 @@ def graph_isomorph_test(model_file_1, model_file_2,
:param arg2: File for the model 2. :param arg2: File for the model 2.
:type arg1: <str> :type arg1: <str>
:type arg2: <str> :type arg2: <str>
:return: Dictionary with the results of tests.
keys: 'topology', 'nodes', 'edges'; values: booleans
:rtype: <dict <str>: <boolean>>
""" """
import networkx.algorithms.isomorphism as iso import networkx.algorithms.isomorphism as iso
...@@ -837,20 +841,32 @@ def graph_isomorph_test(model_file_1, model_file_2, ...@@ -837,20 +841,32 @@ def graph_isomorph_test(model_file_1, model_file_2,
res_2 = build_graph(front_places_2, [transitions_2.keys()], transitions_2) res_2 = build_graph(front_places_2, [transitions_2.keys()], transitions_2)
G2 = res_2[0] G2 = res_2[0]
# Checking
nm = iso.categorical_node_match('color', 'grey')
em = iso.categorical_edge_match('color', '')
check_state = \
{
'topology': nx.is_isomorphic(G1, G2),
'nodes': nx.is_isomorphic(G1, G2, node_match=nm),
'edges': nx.is_isomorphic(G1, G2, edge_match=em),
}
LOGGER.info("Topology checking: " + str(check_state['topology']))
LOGGER.info("Nodes checking: " + str(check_state['nodes']))
LOGGER.info("Edges checking: " + str(check_state['edges']))
# Draw graph # Draw graph
if make_graphs: if make_graphs:
draw_graph(output_dir, front_places_1, "first", *res_1) draw_graph(output_dir, front_places_1, "first", *res_1)
draw_graph(output_dir, front_places_2, "second", *res_2) draw_graph(output_dir, front_places_2, "second", *res_2)
# Checking # Export to json file
LOGGER.info("Topology checking: " + if make_json:
str(nx.is_isomorphic(G1, G2))) with open(output_dir + "comp_results.json", 'a') as fd:
nm = iso.categorical_node_match('color', 'grey') fd.write(json.dumps(check_state) + '\n')
LOGGER.info("Nodes checking: " +
str(nx.is_isomorphic(G1, G2, node_match=nm))) return check_state
em = iso.categorical_edge_match('color', '')
LOGGER.info("Edges checking: " +
str(nx.is_isomorphic(G1, G2, edge_match=em)))
if __name__ == "__main__": if __name__ == "__main__":
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment