Skip to content
Snippets Groups Projects
Unverified Commit c0a1add4 authored by Andrea Franchini's avatar Andrea Franchini
Browse files

Add stats viewer

parent 59307cbd
Branches
Tags
No related merge requests found
......@@ -17,6 +17,7 @@ from mc_openapi.doml_mc.imc import RequirementStore
from mc_openapi.doml_mc.intermediate_model.metamodel import MetaModelDocs
from mc_openapi.doml_mc.mc import ModelChecker
from mc_openapi.doml_mc.mc_result import MCResult
from mc_openapi.doml_mc.stats import STATS
from mc_openapi.doml_mc.xmi_parser.doml_model import get_pyecore_model
parser = argparse.ArgumentParser()
......@@ -26,6 +27,7 @@ parser.add_argument("-V", "--doml-version", dest="doml_version", help="(optional
parser.add_argument("-r", "--requirements", dest="requirements", help="the user-specified requirements file to check")
parser.add_argument("-p", "--port", dest="port", type=int, default=8080, help="the port exposing the model checker REST API (default: 8080)")
parser.add_argument("-v", "--verbose", dest="verbose", action='store_true', help="print a detailed human-readable output of everything going on. Helpful for debugging.")
parser.add_argument("-z", "--stats", dest="stats", action='store_true', help="print stats of Z3 solver")
# Model Checker
parser.add_argument("-c", "--check-consistency", dest="consistency", action='store_true', help="check on additional built-in consistency requirements")
parser.add_argument("-S", "--skip-common-checks", dest="skip_common", action='store_true', help="skip check on common built-in requirements")
......@@ -134,14 +136,19 @@ else:
res, msg = results.summarize()
print("[RESULT]")
if res == MCResult.sat:
print("sat")
else:
print(res.name)
print("[ERRORS]")
print("\033[91m{}\033[00m".format(msg))
except RequirementException as e:
print(e.message)
if args.stats:
STATS.print()
else: # Synthesis
printv("Running synthesis...")
......
......@@ -5,6 +5,8 @@ from typing import Literal
from z3 import (Context, DatatypeSortRef, ExprRef, FuncDeclRef, Solver,
SortRef, sat)
from mc_openapi.doml_mc.stats import STATS
from .intermediate_model.doml_element import IntermediateModel
from .mc_result import MCResult, MCResults
from .z3encoding.im_encoding import (assert_im_associations,
......@@ -170,4 +172,6 @@ class IntermediateModelChecker:
))
self.solver.pop()
stats = self.solver.statistics()
STATS.add(stats)
return MCResults(results)
# Singleton: use this for stats caching/logging like behaviour
import pandas as pd
class Stats:
def __init__(self) -> None:
self.df = pd.DataFrame(columns=['memory', 'conflicts', 'quant instantiations'])
def add(self, stats):
keys = ['memory', 'conflicts', 'quant instantiations'] # set(self.df.columns) & set(stats.keys())
stats = dict(zip(keys, [stats.get_key_value(x) for x in keys]))
df2 = pd.DataFrame.from_records(stats, index=[0])
self.df = pd.concat([self.df, df2])
def print(self):
print("[STATS]")
print(self.df.to_csv(index=False))
STATS = Stats()
\ No newline at end of file
......@@ -17,6 +17,8 @@ def parse_iface_address(addrport: str) -> Attributes:
addr, _, port = addrport.rpartition(":")
if addr == "":
addr = port
if addr == "":
raise Exception(f"Interface address with value '{addrport}' is not valid. It should be 'x.x.x.x/cidr'.")
return {"endPoint": [int(ip_address(addr))]}
......@@ -66,6 +68,12 @@ def init_special_parsers():
("infrastructure_ComputingNode", "memory_mb"): parse_memory_mb,
("commons_FProperty", "value"): parse_fproperty,
},
DOMLVersion.V2_2_1: {
("infrastructure_Network", "addressRange"): parse_cidr,
("infrastructure_NetworkInterface", "endPoint"): parse_iface_address,
("infrastructure_ComputingNode", "memory_mb"): parse_memory_mb,
("commons_FProperty", "value"): parse_fproperty,
},
}
for ver in DOMLVersion:
SpecialParsers[ver] = SpecialParser(MetaModels[ver], attribute_parsers[ver])
%% Cell type:code id: tags:
``` python
PROJ_PATH = '/home/andrea/Projects/piacere-model-checker'
TESTS_PATH = PROJ_PATH + '/tests/doml/CaseStudies/*.domlx'
```
%% Cell type:code id: tags:
``` python
from glob import glob
```
%% Cell type:code id: tags:
``` python
domlx_files = glob(TESTS_PATH)
domlx_files
```
%% Output
['/home/andrea/Projects/piacere-model-checker/tests/doml/CaseStudies/SIMPA_Validation_v2.domlx',
'/home/andrea/Projects/piacere-model-checker/tests/doml/CaseStudies/nio3_test_exec_env.domlx',
'/home/andrea/Projects/piacere-model-checker/tests/doml/CaseStudies/posidonia.domlx',
'/home/andrea/Projects/piacere-model-checker/tests/doml/CaseStudies/posidonia_IOP.domlx',
'/home/andrea/Projects/piacere-model-checker/tests/doml/CaseStudies/uc3-openstack_v2.domlx']
%% Cell type:code id: tags:
``` python
import subprocess
import os
from time import time
import pandas as pd
os.chdir(PROJ_PATH)
print(os.getcwd())
test_cmd = lambda file: f"python -m mc_openapi -z -d {file}"
df = pd.DataFrame(columns=['filename', 'time', 'doml_ver', 'result', '#error', 'memory', 'conflicts', 'quant inst'])
for file in domlx_files:
filename = file.split("/")[-1]
# I know that using time is inaccurate, but it's simple and it works for generating simple benchmarks
start_time = time()
out = subprocess.run(test_cmd(file), shell=True, capture_output=True)
run_time = time() - start_time
r = out.stdout.decode('utf-8')
print(r)
doml_ver, _, r = r.rpartition("[RESULT]")
result, _, r = r.rpartition("[ERRORS]")
errors, _, stats = r.rpartition("[STATS]")
_, _, doml_ver = doml_ver.rpartition("v")
doml_ver = doml_ver.replace("\n", "")
result = result.replace("\n", "")
error_num = len(errors.split("\n")) - 1
stats = stats.split("\n")[2].split(",")[-3:]
df2 = pd.DataFrame([[filename, run_time, doml_ver, result, error_num, *stats]], columns=df.columns)
df = pd.concat([df, df2])
df
```
%% Output
/home/andrea/Projects/piacere-model-checker
Using DOML v2.2.1
[RESULT]
unsat
[ERRORS]
[Built-in]
Software component 'nio3_git' is not deployed to any abstract infrastructure node.
[STATS]
memory,conflicts,quant instantiations
40.38,1273,1253
Using DOML v2.2.1
[RESULT]
sat
[STATS]
memory,conflicts,quant instantiations
43.29,2592,2614
Using DOML v2.2.1
[RESULT]
unsat
[ERRORS]
[Built-in]
Virtual machine gestaut_vm is connected to no network interface.
Software components 'Database' and 'Gestaut' are supposed to communicate through interface 'dbAccess', but they are deployed to nodes that cannot communicate through a common network.
Abstract infrastructure element 'gestaut_vm' has not been mapped to any element in the active concretization.
Security group 'sg' is not associated with any network interface.
[STATS]
memory,conflicts,quant instantiations
91.13,1875,2794
Using DOML v2.2.1
[RESULT]
unsat
[ERRORS]
[Built-in]
Virtual machine gestaut_vm is connected to no network interface.
Software components 'Database' and 'Gestaut' are supposed to communicate through interface 'dbAccess', but they are deployed to nodes that cannot communicate through a common network.
Abstract infrastructure element 'gestaut_vm' has not been mapped to any element in the active concretization.
Security group 'sg' is not associated with any network interface.
[STATS]
memory,conflicts,quant instantiations
91.45,1417,2263
Using DOML v2.2.1
[RESULT]
unsat
[ERRORS]
[Built-in]
Security group 'sg' is not associated with any network interface.
[STATS]
memory,conflicts,quant instantiations
91.29,7649,8422
filename time doml_ver result #error memory \
0 SIMPA_Validation_v2.domlx 1.344904 2.2.1 unsat 3 40.38
0 nio3_test_exec_env.domlx 1.602703 2.2.1 2 43.29
0 posidonia.domlx 16.781076 2.2.1 unsat 6 91.13
0 posidonia_IOP.domlx 16.956536 2.2.1 unsat 6 91.45
0 uc3-openstack_v2.domlx 10.553367 2.2.1 unsat 3 91.29
conflicts quant inst
0 1273 1253
0 2592 2614
0 1875 2794
0 1417 2263
0 7649 8422
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment