Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NPTAV2Maude
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
real-time maude
NPTAV2Maude
Commits
1d8b9fbd
Commit
1d8b9fbd
authored
1 year ago
by
Jaime Arias
Browse files
Options
Downloads
Patches
Plain Diff
fix analysis notebook
parent
ad260349
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
benchmarks/analysis.ipynb
+205
-90
205 additions, 90 deletions
benchmarks/analysis.ipynb
with
205 additions
and
90 deletions
benchmarks/analysis.ipynb
+
205
−
90
View file @
1d8b9fbd
...
...
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count":
1
,
"execution_count":
25
,
"metadata": {},
"outputs": [],
"source": [
...
...
@@ -14,10 +14,10 @@
"import plotly.io as pio\n",
"import plotly.graph_objects as go\n",
"\n",
"#pio.kaleido.scope.mathjax = None\n",
"#
pio.kaleido.scope.mathjax = None\n",
"\n",
"# models to analyse\n",
"models = [\"
accel-1000\", \"tgc\", \"Pipeline_KP12_2_3\", \"gear-1000\", \"coffee\", \"blowup-200\", \"RCP
\"]\n",
"models = [\"
tgc\", \"coffee\", \"fischer
\"]\n",
"\n",
"# csv with results\n",
"csv_filename = \"results.csv\"\n",
...
...
@@ -25,10 +25,17 @@
"# folder with tools results\n",
"log_folder = \"logs\"\n",
"\n",
"# folder with the mdoels\n",
"models_folder = \"models\"\n",
"\n",
"# filenames\n",
"imitator_file = \"{model}-EFwitness.imiprop.{location}.res\"\n",
"no_collapsing_maude_file = \"{model}.no-collapsing.maude.{location}.res\"\n",
"collapsing_maude_file = \"{model}.collapsing.maude.{location}.res\""
"maude_files = [\n",
" {\"name\": \"no_folding\", \"file\": \"{model}.no-folding.maude.{location}.res\"},\n",
" {\"name\": \"no_folding_FME\", \"file\": \"{model}.no-folding.maude.{location}.FEM.res\"},\n",
" {\"name\": \"folding\", \"file\": \"{model}.folding.maude.{location}.res\"},\n",
" {\"name\": \"folding_FME\", \"file\": \"{model}.folding.maude.{location}.FEM.res\"},\n",
"]\n"
]
},
{
...
...
@@ -40,7 +47,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 2
8
,
"metadata": {},
"outputs": [],
"source": [
...
...
@@ -48,89 +55,109 @@
" if unit == \"ms\":\n",
" return float(value)\n",
" elif unit == \"second\" or unit == \"seconds\":\n",
" return float(value)
*
1000\n",
" return float(value)
*
1000\n",
" else:\n",
" raise Exception(f\"Unit {unit} is not supported\")\n",
"\n",
"def generate_csv():\n",
"\n",
"def parse_imi_file(model, loc):\n",
" # regex\n",
" regex_imitator = re.compile(r\"Total computation time\\s*:\\s*(\\d+(?:\\.\\d+)?) (\\w+)\")\n",
" regex_maude = re.compile(r\"rewrites: (\\d+) in (\\d+)(\\w+) cpu \\((\\d+)(\\w+) real\\)\")\n",
" regex_clocks = re.compile(r\"Number of clocks\\s*:\\s*(\\d+)\")\n",
" regex_parameters = re.compile(r\"Number of parameters\\s*:\\s*(\\d+)\")\n",
" regex_actions = re.compile(r\"Number of actions\\s*:\\s*(\\d+)\")\n",
" regex_locations = re.compile(r\"Total number of locations\\s*:\\s*(\\d+)\")\n",
" regex_transitions = re.compile(r\"Total number of transitions\\s*:\\s*(\\d+)\")\n",
"\n",
" output = {}\n",
"\n",
" # search in imitator file\n",
" imi_filename = imitator_file.format(model=model, location=loc)\n",
" with open(os.path.join(log_folder, model, imi_filename), \"r\") as imi_file:\n",
" imi_content = imi_file.read()\n",
"\n",
" # get imitator times\n",
" imi_search = regex_imitator.search(imi_content)\n",
" imi_time, imi_unit = imi_search.groups()\n",
" output[\"time\"] = f\"{format_unit(imi_time, imi_unit)}\"\n",
"\n",
" # get model's information\n",
" output[\"nb_clocks\"] = regex_clocks.search(imi_content).group(1)\n",
" output[\"nb_parameters\"] = regex_parameters.search(imi_content).group(1)\n",
" output[\"nb_actions\"] = regex_actions.search(imi_content).group(1)\n",
" output[\"nb_locations\"] = regex_locations.search(imi_content).group(1)\n",
" output[\"nb_transitions\"] = regex_transitions.search(imi_content).group(1)\n",
"\n",
" return output\n",
"\n",
"\n",
"def parse_maude_file(filename_file, model, loc):\n",
" regex_maude = re.compile(r\"rewrites: (\\d+) in (\\d+)(\\w+) cpu \\((\\d+)(\\w+) real\\)\")\n",
" output = {}\n",
"\n",
" # search in maude file\n",
" maude_filename = filename_file.format(model=model, location=loc)\n",
" with open(os.path.join(log_folder, model, maude_filename), \"r\") as rl_file:\n",
" maude_content = regex_maude.search(rl_file.read())\n",
" (rewrites, cpu, cpu_unit, real, real_unit) = maude_content.groups()\n",
"\n",
" output[\"rewrites\"] = rewrites\n",
" output[\"cpu\"] = f\"{format_unit(cpu, cpu_unit)}\"\n",
" output[\"real\"] = f\"{format_unit(real, real_unit)}\"\n",
" return output\n",
"\n",
"\n",
"def generate_csv():\n",
" with open(csv_filename, \"w\") as csv_file:\n",
" fieldnames = ['model', 'clocks', 'parameters', 'actions', 'locations', 'transitions', 'location_reached', 'imitator_time(ms)', 'maude_rewrites', 'maude_cpu(ms)', 'maude_real(ms)', 'maude_collapsing_rewrites', 'maude_collapsing_cpu(ms)', 'maude_collapsing_real(ms)']\n",
" fieldnames = [\n",
" \"model\",\n",
" \"clocks\",\n",
" \"parameters\",\n",
" \"actions\",\n",
" \"locations\",\n",
" \"transitions\",\n",
" \"location_reached\",\n",
" \"imitator_time(ms)\",\n",
" ]\n",
" for f in maude_files:\n",
" prefix = f'maude_{f[\"name\"]}'\n",
" fieldnames.append(f\"{prefix}_rewrites\")\n",
" fieldnames.append(f\"{prefix}_cpu(ms)\")\n",
" fieldnames.append(f\"{prefix}_real(ms)\")\n",
"\n",
" writer = csv.DictWriter(csv_file, fieldnames=fieldnames)\n",
" writer.writeheader()\n",
"\n",
" for model in models:\n",
" with open(os.path.join(log_folder, model,\"locations.txt\")) as loc_file:\n",
" for location in loc_file:\n",
" loc = location.replace(\"\\n\",\"\")\n",
" imi_filename = imitator_file.format(model=model, location=loc)\n",
" maude_filename = no_collapsing_maude_file.format(model=model, location=loc)\n",
" collapsing_maude_filename = collapsing_maude_file.format(model=model, location=loc)\n",
"\n",
" imitator_time=\"\"\n",
" maude_rewrites=\"\"\n",
" maude_cpu=\"\"\n",
" maude_real=\"\"\n",
" c_maude_rewrites=\"\"\n",
" c_maude_cpu=\"\"\n",
" c_maude_real=\"\"\n",
"\n",
"\n",
" # search in imitator file\n",
" with open(os.path.join(log_folder, model, imi_filename), 'r') as imi_file:\n",
" imi_content = imi_file.read()\n",
" imi_search = regex_imitator.search(imi_content)\n",
" imi_time, imi_unit = imi_search.groups()\n",
" imitator_time=f\"{format_unit(imi_time, imi_unit)}\"\n",
" with open(os.path.join(models_folder, f\"{model}_loc.txt\")) as loc_file:\n",
" locations = [l.replace(\"\\n\", \"\").split(\" \")[1] for l in loc_file]\n",
" for loc in locations:\n",
" imitator_info = parse_imi_file(model, loc)\n",
" results = {\n",
" \"model\": model,\n",
" \"location_reached\": loc,\n",
" \"clocks\": imitator_info[\"nb_clocks\"],\n",
" \"parameters\": imitator_info[\"nb_parameters\"],\n",
" \"actions\": imitator_info[\"nb_actions\"],\n",
" \"locations\": imitator_info[\"nb_locations\"],\n",
" \"transitions\": imitator_info[\"nb_transitions\"],\n",
" \"imitator_time(ms)\": imitator_info[\"time\"],\n",
" }\n",
"\n",
" # get model's information\n",
" nb_clocks = regex_clocks.search(imi_content).group(1)\n",
" nb_parameters = regex_parameters.search(imi_content).group(1)\n",
" nb_actions = regex_actions.search(imi_content).group(1)\n",
" nb_locations = regex_locations.search(imi_content).group(1)\n",
" nb_transitions = regex_transitions.search(imi_content).group(1)\n",
" \n",
" # search in maude file\n",
" with open(os.path.join(log_folder, model, maude_filename), 'r') as rl_file:\n",
" maude_rewrites, _maude_cpu, maude_cpu_unit, _maude_real, maude_real_unit = regex_maude.search(rl_file.read()).groups()\n",
" maude_cpu=f\"{format_unit(_maude_cpu, maude_cpu_unit)}\"\n",
" maude_real=f\"{format_unit(_maude_real, maude_real_unit)}\"\n",
" \n",
" for f in maude_files:\n",
" maude_info = parse_maude_file(f[\"file\"], model, loc)\n",
" prefix = f'maude_{f[\"name\"]}'\n",
" results[f\"{prefix}_rewrites\"] = maude_info[\"rewrites\"]\n",
" results[f\"{prefix}_cpu(ms)\"] = maude_info[\"cpu\"]\n",
" results[f\"{prefix}_real(ms)\"] = maude_info[\"real\"]\n",
"\n",
" # search in collapsing maude file\n",
" with open(os.path.join(log_folder, model, collapsing_maude_filename), 'r') as collapsing_file:\n",
" c_maude_rewrites, _c_maude_cpu, c_maude_cpu_unit, _c_maude_real, c_maude_real_unit = regex_maude.search(collapsing_file.read()).groups()\n",
" c_maude_cpu=f\"{format_unit(_c_maude_cpu, c_maude_cpu_unit)}\"\n",
" c_maude_real=f\"{format_unit(_c_maude_real, c_maude_real_unit)}\"\n",
" \n",
" # save info\n",
" writer.writerow({\"model\":model,\n",
" \"location_reached\": loc,\n",
" \"clocks\": nb_clocks,\n",
" \"parameters\": nb_parameters,\n",
" \"actions\": nb_actions,\n",
" \"locations\": nb_locations,\n",
" \"transitions\": nb_transitions,\n",
" \"imitator_time(ms)\": imitator_time,\n",
" \"maude_rewrites\": maude_rewrites,\n",
" \"maude_cpu(ms)\": maude_cpu,\n",
" \"maude_real(ms)\": maude_real,\n",
" \"maude_collapsing_rewrites\": c_maude_rewrites,\n",
" \"maude_collapsing_cpu(ms)\": c_maude_cpu,\n",
" \"maude_collapsing_real(ms)\": c_maude_real})"
" writer.writerow(results)\n"
]
},
{
"cell_type": "code",
"execution_count":
3
,
"execution_count":
29
,
"metadata": {},
"outputs": [],
"source": [
...
...
@@ -152,27 +179,99 @@
"source": [
"def plot(df, model_name):\n",
" model = df.loc[[model_name]]\n",
" max_value_model = model.drop(axis=1, labels=[\"maude_rewrites\", \"maude_collapsing_rewrites\"]).max(numeric_only=True, axis=0).max()\n",
" max_value_model = (\n",
" model.drop(axis=1, labels=[\"maude_rewrites\", \"maude_collapsing_rewrites\"])\n",
" .max(numeric_only=True, axis=0)\n",
" .max()\n",
" )\n",
" axis_bound = math.ceil(math.log10(max_value_model))\n",
"\n",
" fig = go.Figure()\n",
" # no collapsing\n",
" fig.add_trace(go.Scatter(x=model[\"maude_real(ms)\"], y=model[\"imitator_time(ms)\"], text=model['location_reached'], mode='markers', marker_symbol=\"circle-open\", marker_color=\"red\", marker_size=12, name=\"no-collapsing\"))\n",
" fig.add_trace(\n",
" go.Scatter(\n",
" x=model[\"maude_real(ms)\"],\n",
" y=model[\"imitator_time(ms)\"],\n",
" text=model[\"location_reached\"],\n",
" mode=\"markers\",\n",
" marker_symbol=\"circle-open\",\n",
" marker_color=\"red\",\n",
" marker_size=12,\n",
" name=\"no-collapsing\",\n",
" )\n",
" )\n",
"\n",
" # collapsing\n",
" fig.add_trace(go.Scatter(x=model[\"maude_collapsing_real(ms)\"], y=model[\"imitator_time(ms)\"], text=model['location_reached'], mode='markers', marker_symbol=\"circle-open\", marker_color=\"blue\", marker_size=12, name=\"collapsing\"))\n",
" fig.add_trace(\n",
" go.Scatter(\n",
" x=model[\"maude_collapsing_real(ms)\"],\n",
" y=model[\"imitator_time(ms)\"],\n",
" text=model[\"location_reached\"],\n",
" mode=\"markers\",\n",
" marker_symbol=\"circle-open\",\n",
" marker_color=\"blue\",\n",
" marker_size=12,\n",
" name=\"collapsing\",\n",
" )\n",
" )\n",
"\n",
" # identity line\n",
" fig.add_trace(go.Scatter(x=[0, 10**axis_bound], y=[0, 10**axis_bound], mode='lines', line=dict(color= \"black\", width=1), showlegend=False))\n",
" fig.add_trace(\n",
" go.Scatter(\n",
" x=[0, 10**axis_bound],\n",
" y=[0, 10**axis_bound],\n",
" mode=\"lines\",\n",
" line=dict(color=\"black\", width=1),\n",
" showlegend=False,\n",
" )\n",
" )\n",
"\n",
" fig.update_xaxes(type=\"log\", showgrid=False, mirror=True, linewidth=1, linecolor='black', constrain=\"domain\", range=[-1, axis_bound], title=\"Maude (ms)\") \n",
" fig.update_yaxes(type=\"log\", showgrid=False, mirror=True, linewidth=1, linecolor='black', scaleanchor = \"x\", scaleratio = 1, range=[-1, axis_bound], title=\"Imitator (ms)\")\n",
" fig.update_xaxes(\n",
" type=\"log\",\n",
" showgrid=False,\n",
" mirror=True,\n",
" linewidth=1,\n",
" linecolor=\"black\",\n",
" constrain=\"domain\",\n",
" range=[-1, axis_bound],\n",
" title=\"Maude (ms)\",\n",
" )\n",
" fig.update_yaxes(\n",
" type=\"log\",\n",
" showgrid=False,\n",
" mirror=True,\n",
" linewidth=1,\n",
" linecolor=\"black\",\n",
" scaleanchor=\"x\",\n",
" scaleratio=1,\n",
" range=[-1, axis_bound],\n",
" title=\"Imitator (ms)\",\n",
" )\n",
"\n",
" legend_options=dict(yanchor=\"top\", y=0.99, xanchor=\"left\", x=0.05, bordercolor=\"Black\", borderwidth=1)\n",
" margin=margin=dict(l=20, r=20, t=20, b=20)\n",
" legend_options = dict(\n",
" yanchor=\"top\",\n",
" y=0.99,\n",
" xanchor=\"left\",\n",
" x=0.05,\n",
" bordercolor=\"Black\",\n",
" borderwidth=1,\n",
" )\n",
" margin = margin = dict(l=20, r=20, t=20, b=20)\n",
"\n",
" fig.update_layout(width=800, height=800, paper_bgcolor='white', plot_bgcolor='white', legend_title_text='Method', legend=legend_options, autosize=False, margin=margin, font=dict(size=28))\n",
" fig.update_traces(hovertemplate='<b>%{text}</b><br><br>Maude: %{x} ms <br>Imitator: %{y} ms<extra></extra>')\n",
" fig.update_layout(\n",
" width=800,\n",
" height=800,\n",
" paper_bgcolor=\"white\",\n",
" plot_bgcolor=\"white\",\n",
" legend_title_text=\"Method\",\n",
" legend=legend_options,\n",
" autosize=False,\n",
" margin=margin,\n",
" font=dict(size=28),\n",
" )\n",
" fig.update_traces(\n",
" hovertemplate=\"<b>%{text}</b><br><br>Maude: %{x} ms <br>Imitator: %{y} ms<extra></extra>\"\n",
" )\n",
"\n",
" return fig\n"
]
...
...
@@ -184,9 +283,9 @@
"outputs": [],
"source": [
"def export_to_latex(df):\n",
" styler =df.style\n",
" styler.hide(axis=
'
index
'
)\n",
" return styler.to_latex(hrules=True)"
" styler =
df.style\n",
" styler.hide(axis=
\"
index
\"
)\n",
" return styler.to_latex(hrules=True)
\n
"
]
},
{
...
...
@@ -353,7 +452,7 @@
"source": [
"df = pd.read_csv(csv_filename)\n",
"df = df.set_index(\"model\")\n",
"df"
"df
\n
"
]
},
{
...
...
@@ -415,10 +514,26 @@
}
],
"source": [
"df_model_info = df.drop_duplicates(subset=['clocks', 'parameters', 'actions', 'locations', 'transitions'], keep='last').reset_index()\n",
"df_model_info = df_model_info.drop(labels=[\"location_reached\", \"imitator_time(ms)\", \"maude_rewrites\", \"maude_cpu(ms)\", \"maude_real(ms)\", \"maude_collapsing_rewrites\", \"maude_collapsing_cpu(ms)\", \"maude_collapsing_real(ms)\"], axis=1)\n",
"df_model_info = df_model_info.sort_values(by=\"model\", key=lambda col: col.str.lower(), ignore_index=True)\n",
"df_model_info"
"df_model_info = df.drop_duplicates(\n",
" subset=[\"clocks\", \"parameters\", \"actions\", \"locations\", \"transitions\"], keep=\"last\"\n",
").reset_index()\n",
"df_model_info = df_model_info.drop(\n",
" labels=[\n",
" \"location_reached\",\n",
" \"imitator_time(ms)\",\n",
" \"maude_rewrites\",\n",
" \"maude_cpu(ms)\",\n",
" \"maude_real(ms)\",\n",
" \"maude_collapsing_rewrites\",\n",
" \"maude_collapsing_cpu(ms)\",\n",
" \"maude_collapsing_real(ms)\",\n",
" ],\n",
" axis=1,\n",
")\n",
"df_model_info = df_model_info.sort_values(\n",
" by=\"model\", key=lambda col: col.str.lower(), ignore_index=True\n",
")\n",
"df_model_info\n"
]
},
{
...
...
@@ -434,8 +549,8 @@
"metadata": {},
"outputs": [],
"source": [
"with open(\"images/table.tex\",
'w'
) as latex_file:\n",
" latex_file.write(export_to_latex(df_model_info))"
"with open(\"images/table.tex\",
\"w\"
) as latex_file:\n",
" latex_file.write(export_to_latex(df_model_info))
\n
"
]
},
{
...
...
@@ -456,9 +571,9 @@
"source": [
"for m in models:\n",
" fig = plot(df, m)\n",
" filename = m.replace(\"_\",\"-\")\n",
" filename = m.replace(\"_\",
\"-\")\n",
" fig.write_html(f\"images/{filename}.html\")\n",
" fig.write_image(f\"images/{filename}.pdf\", format=\"pdf\")"
" fig.write_image(f\"images/{filename}.pdf\", format=\"pdf\")
\n
"
]
},
{
...
...
@@ -1432,7 +1547,7 @@
],
"source": [
"# show a figure\n",
"plot(df, models[0])"
"plot(df, models[0])
\n
"
]
}
],
...
...
@@ -1452,7 +1567,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.
3
"
"version": "3.10.
6
"
},
"orig_nbformat": 4,
"vscode": {
...
...
%% Cell type:code id: tags:
```
python
import
os
import
re
import
csv
import
pandas
as
pd
import
math
import
plotly.io
as
pio
import
plotly.graph_objects
as
go
#pio.kaleido.scope.mathjax = None
#
pio.kaleido.scope.mathjax = None
# models to analyse
models
=
[
"
accel-1000
"
,
"
tgc
"
,
"
Pipeline_KP12_2_3
"
,
"
gear-1000
"
,
"
coffee
"
,
"
blowup-200
"
,
"
RCP
"
]
models
=
[
"
tgc
"
,
"
coffee
"
,
"
fischer
"
]
# csv with results
csv_filename
=
"
results.csv
"
# folder with tools results
log_folder
=
"
logs
"
# folder with the mdoels
models_folder
=
"
models
"
# filenames
imitator_file
=
"
{model}-EFwitness.imiprop.{location}.res
"
no_collapsing_maude_file
=
"
{model}.no-collapsing.maude.{location}.res
"
collapsing_maude_file
=
"
{model}.collapsing.maude.{location}.res
"
maude_files
=
[
{
"
name
"
:
"
no_folding
"
,
"
file
"
:
"
{model}.no-folding.maude.{location}.res
"
},
{
"
name
"
:
"
no_folding_FME
"
,
"
file
"
:
"
{model}.no-folding.maude.{location}.FEM.res
"
},
{
"
name
"
:
"
folding
"
,
"
file
"
:
"
{model}.folding.maude.{location}.res
"
},
{
"
name
"
:
"
folding_FME
"
,
"
file
"
:
"
{model}.folding.maude.{location}.FEM.res
"
},
]
```
%% Cell type:markdown id: tags:
# Generate CSV file with data
%% Cell type:code id: tags:
```
python
def
format_unit
(
value
,
unit
):
if
unit
==
"
ms
"
:
return
float
(
value
)
elif
unit
==
"
second
"
or
unit
==
"
seconds
"
:
return
float
(
value
)
*
1000
return
float
(
value
)
*
1000
else
:
raise
Exception
(
f
"
Unit
{
unit
}
is not supported
"
)
def
generate_csv
():
def
parse_imi_file
(
model
,
loc
):
# regex
regex_imitator
=
re
.
compile
(
r
"
Total computation time\s*:\s*(\d+(?:\.\d+)?) (\w+)
"
)
regex_maude
=
re
.
compile
(
r
"
rewrites: (\d+) in (\d+)(\w+) cpu \((\d+)(\w+) real\)
"
)
regex_clocks
=
re
.
compile
(
r
"
Number of clocks\s*:\s*(\d+)
"
)
regex_parameters
=
re
.
compile
(
r
"
Number of parameters\s*:\s*(\d+)
"
)
regex_actions
=
re
.
compile
(
r
"
Number of actions\s*:\s*(\d+)
"
)
regex_locations
=
re
.
compile
(
r
"
Total number of locations\s*:\s*(\d+)
"
)
regex_transitions
=
re
.
compile
(
r
"
Total number of transitions\s*:\s*(\d+)
"
)
output
=
{}
# search in imitator file
imi_filename
=
imitator_file
.
format
(
model
=
model
,
location
=
loc
)
with
open
(
os
.
path
.
join
(
log_folder
,
model
,
imi_filename
),
"
r
"
)
as
imi_file
:
imi_content
=
imi_file
.
read
()
# get imitator times
imi_search
=
regex_imitator
.
search
(
imi_content
)
imi_time
,
imi_unit
=
imi_search
.
groups
()
output
[
"
time
"
]
=
f
"
{
format_unit
(
imi_time
,
imi_unit
)
}
"
# get model's information
output
[
"
nb_clocks
"
]
=
regex_clocks
.
search
(
imi_content
).
group
(
1
)
output
[
"
nb_parameters
"
]
=
regex_parameters
.
search
(
imi_content
).
group
(
1
)
output
[
"
nb_actions
"
]
=
regex_actions
.
search
(
imi_content
).
group
(
1
)
output
[
"
nb_locations
"
]
=
regex_locations
.
search
(
imi_content
).
group
(
1
)
output
[
"
nb_transitions
"
]
=
regex_transitions
.
search
(
imi_content
).
group
(
1
)
return
output
def
parse_maude_file
(
filename_file
,
model
,
loc
):
regex_maude
=
re
.
compile
(
r
"
rewrites: (\d+) in (\d+)(\w+) cpu \((\d+)(\w+) real\)
"
)
output
=
{}
# search in maude file
maude_filename
=
filename_file
.
format
(
model
=
model
,
location
=
loc
)
with
open
(
os
.
path
.
join
(
log_folder
,
model
,
maude_filename
),
"
r
"
)
as
rl_file
:
maude_content
=
regex_maude
.
search
(
rl_file
.
read
())
(
rewrites
,
cpu
,
cpu_unit
,
real
,
real_unit
)
=
maude_content
.
groups
()
output
[
"
rewrites
"
]
=
rewrites
output
[
"
cpu
"
]
=
f
"
{
format_unit
(
cpu
,
cpu_unit
)
}
"
output
[
"
real
"
]
=
f
"
{
format_unit
(
real
,
real_unit
)
}
"
return
output
def
generate_csv
():
with
open
(
csv_filename
,
"
w
"
)
as
csv_file
:
fieldnames
=
[
'
model
'
,
'
clocks
'
,
'
parameters
'
,
'
actions
'
,
'
locations
'
,
'
transitions
'
,
'
location_reached
'
,
'
imitator_time(ms)
'
,
'
maude_rewrites
'
,
'
maude_cpu(ms)
'
,
'
maude_real(ms)
'
,
'
maude_collapsing_rewrites
'
,
'
maude_collapsing_cpu(ms)
'
,
'
maude_collapsing_real(ms)
'
]
fieldnames
=
[
"
model
"
,
"
clocks
"
,
"
parameters
"
,
"
actions
"
,
"
locations
"
,
"
transitions
"
,
"
location_reached
"
,
"
imitator_time(ms)
"
,
]
for
f
in
maude_files
:
prefix
=
f
'
maude_
{
f
[
"
name
"
]
}
'
fieldnames
.
append
(
f
"
{
prefix
}
_rewrites
"
)
fieldnames
.
append
(
f
"
{
prefix
}
_cpu(ms)
"
)
fieldnames
.
append
(
f
"
{
prefix
}
_real(ms)
"
)
writer
=
csv
.
DictWriter
(
csv_file
,
fieldnames
=
fieldnames
)
writer
.
writeheader
()
for
model
in
models
:
with
open
(
os
.
path
.
join
(
log_folder
,
model
,
"
locations.txt
"
))
as
loc_file
:
for
location
in
loc_file
:
loc
=
location
.
replace
(
"
\n
"
,
""
)
imi_filename
=
imitator_file
.
format
(
model
=
model
,
location
=
loc
)
maude_filename
=
no_collapsing_maude_file
.
format
(
model
=
model
,
location
=
loc
)
collapsing_maude_filename
=
collapsing_maude_file
.
format
(
model
=
model
,
location
=
loc
)
imitator_time
=
""
maude_rewrites
=
""
maude_cpu
=
""
maude_real
=
""
c_maude_rewrites
=
""
c_maude_cpu
=
""
c_maude_real
=
""
# search in imitator file
with
open
(
os
.
path
.
join
(
log_folder
,
model
,
imi_filename
),
'
r
'
)
as
imi_file
:
imi_content
=
imi_file
.
read
()
imi_search
=
regex_imitator
.
search
(
imi_content
)
imi_time
,
imi_unit
=
imi_search
.
groups
()
imitator_time
=
f
"
{
format_unit
(
imi_time
,
imi_unit
)
}
"
# get model's information
nb_clocks
=
regex_clocks
.
search
(
imi_content
).
group
(
1
)
nb_parameters
=
regex_parameters
.
search
(
imi_content
).
group
(
1
)
nb_actions
=
regex_actions
.
search
(
imi_content
).
group
(
1
)
nb_locations
=
regex_locations
.
search
(
imi_content
).
group
(
1
)
nb_transitions
=
regex_transitions
.
search
(
imi_content
).
group
(
1
)
# search in maude file
with
open
(
os
.
path
.
join
(
log_folder
,
model
,
maude_filename
),
'
r
'
)
as
rl_file
:
maude_rewrites
,
_maude_cpu
,
maude_cpu_unit
,
_maude_real
,
maude_real_unit
=
regex_maude
.
search
(
rl_file
.
read
()).
groups
()
maude_cpu
=
f
"
{
format_unit
(
_maude_cpu
,
maude_cpu_unit
)
}
"
maude_real
=
f
"
{
format_unit
(
_maude_real
,
maude_real_unit
)
}
"
# search in collapsing maude file
with
open
(
os
.
path
.
join
(
log_folder
,
model
,
collapsing_maude_filename
),
'
r
'
)
as
collapsing_file
:
c_maude_rewrites
,
_c_maude_cpu
,
c_maude_cpu_unit
,
_c_maude_real
,
c_maude_real_unit
=
regex_maude
.
search
(
collapsing_file
.
read
()).
groups
()
c_maude_cpu
=
f
"
{
format_unit
(
_c_maude_cpu
,
c_maude_cpu_unit
)
}
"
c_maude_real
=
f
"
{
format_unit
(
_c_maude_real
,
c_maude_real_unit
)
}
"
with
open
(
os
.
path
.
join
(
models_folder
,
f
"
{
model
}
_loc.txt
"
))
as
loc_file
:
locations
=
[
l
.
replace
(
"
\n
"
,
""
).
split
(
"
"
)[
1
]
for
l
in
loc_file
]
for
loc
in
locations
:
imitator_info
=
parse_imi_file
(
model
,
loc
)
results
=
{
"
model
"
:
model
,
"
location_reached
"
:
loc
,
"
clocks
"
:
imitator_info
[
"
nb_clocks
"
],
"
parameters
"
:
imitator_info
[
"
nb_parameters
"
],
"
actions
"
:
imitator_info
[
"
nb_actions
"
],
"
locations
"
:
imitator_info
[
"
nb_locations
"
],
"
transitions
"
:
imitator_info
[
"
nb_transitions
"
],
"
imitator_time(ms)
"
:
imitator_info
[
"
time
"
],
}
for
f
in
maude_files
:
maude_info
=
parse_maude_file
(
f
[
"
file
"
],
model
,
loc
)
prefix
=
f
'
maude_
{
f
[
"
name
"
]
}
'
results
[
f
"
{
prefix
}
_rewrites
"
]
=
maude_info
[
"
rewrites
"
]
results
[
f
"
{
prefix
}
_cpu(ms)
"
]
=
maude_info
[
"
cpu
"
]
results
[
f
"
{
prefix
}
_real(ms)
"
]
=
maude_info
[
"
real
"
]
# save info
writer
.
writerow
({
"
model
"
:
model
,
"
location_reached
"
:
loc
,
"
clocks
"
:
nb_clocks
,
"
parameters
"
:
nb_parameters
,
"
actions
"
:
nb_actions
,
"
locations
"
:
nb_locations
,
"
transitions
"
:
nb_transitions
,
"
imitator_time(ms)
"
:
imitator_time
,
"
maude_rewrites
"
:
maude_rewrites
,
"
maude_cpu(ms)
"
:
maude_cpu
,
"
maude_real(ms)
"
:
maude_real
,
"
maude_collapsing_rewrites
"
:
c_maude_rewrites
,
"
maude_collapsing_cpu(ms)
"
:
c_maude_cpu
,
"
maude_collapsing_real(ms)
"
:
c_maude_real
})
writer
.
writerow
(
results
)
```
%% Cell type:code id: tags:
```
python
generate_csv
()
```
%% Cell type:markdown id: tags:
# Analyse Data
%% Cell type:code id: tags:
```
python
def
plot
(
df
,
model_name
):
model
=
df
.
loc
[[
model_name
]]
max_value_model
=
model
.
drop
(
axis
=
1
,
labels
=
[
"
maude_rewrites
"
,
"
maude_collapsing_rewrites
"
]).
max
(
numeric_only
=
True
,
axis
=
0
).
max
()
max_value_model
=
(
model
.
drop
(
axis
=
1
,
labels
=
[
"
maude_rewrites
"
,
"
maude_collapsing_rewrites
"
])
.
max
(
numeric_only
=
True
,
axis
=
0
)
.
max
()
)
axis_bound
=
math
.
ceil
(
math
.
log10
(
max_value_model
))
fig
=
go
.
Figure
()
# no collapsing
fig
.
add_trace
(
go
.
Scatter
(
x
=
model
[
"
maude_real(ms)
"
],
y
=
model
[
"
imitator_time(ms)
"
],
text
=
model
[
'
location_reached
'
],
mode
=
'
markers
'
,
marker_symbol
=
"
circle-open
"
,
marker_color
=
"
red
"
,
marker_size
=
12
,
name
=
"
no-collapsing
"
))
fig
.
add_trace
(
go
.
Scatter
(
x
=
model
[
"
maude_real(ms)
"
],
y
=
model
[
"
imitator_time(ms)
"
],
text
=
model
[
"
location_reached
"
],
mode
=
"
markers
"
,
marker_symbol
=
"
circle-open
"
,
marker_color
=
"
red
"
,
marker_size
=
12
,
name
=
"
no-collapsing
"
,
)
)
# collapsing
fig
.
add_trace
(
go
.
Scatter
(
x
=
model
[
"
maude_collapsing_real(ms)
"
],
y
=
model
[
"
imitator_time(ms)
"
],
text
=
model
[
'
location_reached
'
],
mode
=
'
markers
'
,
marker_symbol
=
"
circle-open
"
,
marker_color
=
"
blue
"
,
marker_size
=
12
,
name
=
"
collapsing
"
))
fig
.
add_trace
(
go
.
Scatter
(
x
=
model
[
"
maude_collapsing_real(ms)
"
],
y
=
model
[
"
imitator_time(ms)
"
],
text
=
model
[
"
location_reached
"
],
mode
=
"
markers
"
,
marker_symbol
=
"
circle-open
"
,
marker_color
=
"
blue
"
,
marker_size
=
12
,
name
=
"
collapsing
"
,
)
)
# identity line
fig
.
add_trace
(
go
.
Scatter
(
x
=
[
0
,
10
**
axis_bound
],
y
=
[
0
,
10
**
axis_bound
],
mode
=
'
lines
'
,
line
=
dict
(
color
=
"
black
"
,
width
=
1
),
showlegend
=
False
))
fig
.
update_xaxes
(
type
=
"
log
"
,
showgrid
=
False
,
mirror
=
True
,
linewidth
=
1
,
linecolor
=
'
black
'
,
constrain
=
"
domain
"
,
range
=
[
-
1
,
axis_bound
],
title
=
"
Maude (ms)
"
)
fig
.
update_yaxes
(
type
=
"
log
"
,
showgrid
=
False
,
mirror
=
True
,
linewidth
=
1
,
linecolor
=
'
black
'
,
scaleanchor
=
"
x
"
,
scaleratio
=
1
,
range
=
[
-
1
,
axis_bound
],
title
=
"
Imitator (ms)
"
)
legend_options
=
dict
(
yanchor
=
"
top
"
,
y
=
0.99
,
xanchor
=
"
left
"
,
x
=
0.05
,
bordercolor
=
"
Black
"
,
borderwidth
=
1
)
margin
=
margin
=
dict
(
l
=
20
,
r
=
20
,
t
=
20
,
b
=
20
)
fig
.
update_layout
(
width
=
800
,
height
=
800
,
paper_bgcolor
=
'
white
'
,
plot_bgcolor
=
'
white
'
,
legend_title_text
=
'
Method
'
,
legend
=
legend_options
,
autosize
=
False
,
margin
=
margin
,
font
=
dict
(
size
=
28
))
fig
.
update_traces
(
hovertemplate
=
'
<b>%{text}</b><br><br>Maude: %{x} ms <br>Imitator: %{y} ms<extra></extra>
'
)
fig
.
add_trace
(
go
.
Scatter
(
x
=
[
0
,
10
**
axis_bound
],
y
=
[
0
,
10
**
axis_bound
],
mode
=
"
lines
"
,
line
=
dict
(
color
=
"
black
"
,
width
=
1
),
showlegend
=
False
,
)
)
fig
.
update_xaxes
(
type
=
"
log
"
,
showgrid
=
False
,
mirror
=
True
,
linewidth
=
1
,
linecolor
=
"
black
"
,
constrain
=
"
domain
"
,
range
=
[
-
1
,
axis_bound
],
title
=
"
Maude (ms)
"
,
)
fig
.
update_yaxes
(
type
=
"
log
"
,
showgrid
=
False
,
mirror
=
True
,
linewidth
=
1
,
linecolor
=
"
black
"
,
scaleanchor
=
"
x
"
,
scaleratio
=
1
,
range
=
[
-
1
,
axis_bound
],
title
=
"
Imitator (ms)
"
,
)
legend_options
=
dict
(
yanchor
=
"
top
"
,
y
=
0.99
,
xanchor
=
"
left
"
,
x
=
0.05
,
bordercolor
=
"
Black
"
,
borderwidth
=
1
,
)
margin
=
margin
=
dict
(
l
=
20
,
r
=
20
,
t
=
20
,
b
=
20
)
fig
.
update_layout
(
width
=
800
,
height
=
800
,
paper_bgcolor
=
"
white
"
,
plot_bgcolor
=
"
white
"
,
legend_title_text
=
"
Method
"
,
legend
=
legend_options
,
autosize
=
False
,
margin
=
margin
,
font
=
dict
(
size
=
28
),
)
fig
.
update_traces
(
hovertemplate
=
"
<b>%{text}</b><br><br>Maude: %{x} ms <br>Imitator: %{y} ms<extra></extra>
"
)
return
fig
```
%% Cell type:code id: tags:
```
python
def
export_to_latex
(
df
):
styler
=
df
.
style
styler
.
hide
(
axis
=
'
index
'
)
styler
=
df
.
style
styler
.
hide
(
axis
=
"
index
"
)
return
styler
.
to_latex
(
hrules
=
True
)
```
%% Cell type:code id: tags:
```
python
df
=
pd
.
read_csv
(
csv_filename
)
df
=
df
.
set_index
(
"
model
"
)
df
```
%% Output
clocks parameters actions locations transitions location_reached \
model
coffee 2 3 4 4 6 addsugar
coffee 2 3 4 4 6 cdone
coffee 2 3 4 4 6 idle
coffee 2 3 4 4 6 preparingcoffee
imitator_time(ms) maude_rewrites maude_cpu(ms) maude_real(ms) \
model
coffee 0.0 2 0.0 0.0
coffee 0.0 12 0.0 0.0
coffee 0.0 0 0.0 0.0
coffee 0.0 6 0.0 0.0
maude_collapsing_rewrites maude_collapsing_cpu(ms) \
model
coffee 85 4.0
coffee 373 8.0
coffee 801 12.0
coffee 182 8.0
maude_collapsing_real(ms)
model
coffee 5.0
coffee 7.0
coffee 15.0
coffee 6.0
%% Cell type:code id: tags:
```
python
df_model_info
=
df
.
drop_duplicates
(
subset
=
[
'
clocks
'
,
'
parameters
'
,
'
actions
'
,
'
locations
'
,
'
transitions
'
],
keep
=
'
last
'
).
reset_index
()
df_model_info
=
df_model_info
.
drop
(
labels
=
[
"
location_reached
"
,
"
imitator_time(ms)
"
,
"
maude_rewrites
"
,
"
maude_cpu(ms)
"
,
"
maude_real(ms)
"
,
"
maude_collapsing_rewrites
"
,
"
maude_collapsing_cpu(ms)
"
,
"
maude_collapsing_real(ms)
"
],
axis
=
1
)
df_model_info
=
df_model_info
.
sort_values
(
by
=
"
model
"
,
key
=
lambda
col
:
col
.
str
.
lower
(),
ignore_index
=
True
)
df_model_info
=
df
.
drop_duplicates
(
subset
=
[
"
clocks
"
,
"
parameters
"
,
"
actions
"
,
"
locations
"
,
"
transitions
"
],
keep
=
"
last
"
).
reset_index
()
df_model_info
=
df_model_info
.
drop
(
labels
=
[
"
location_reached
"
,
"
imitator_time(ms)
"
,
"
maude_rewrites
"
,
"
maude_cpu(ms)
"
,
"
maude_real(ms)
"
,
"
maude_collapsing_rewrites
"
,
"
maude_collapsing_cpu(ms)
"
,
"
maude_collapsing_real(ms)
"
,
],
axis
=
1
,
)
df_model_info
=
df_model_info
.
sort_values
(
by
=
"
model
"
,
key
=
lambda
col
:
col
.
str
.
lower
(),
ignore_index
=
True
)
df_model_info
```
%% Output
model clocks parameters actions locations transitions
0 coffee 2 3 4 4 6
%% Cell type:markdown id: tags:
# Plot
%% Cell type:code id: tags:
```
python
with
open
(
"
images/table.tex
"
,
'
w
'
)
as
latex_file
:
with
open
(
"
images/table.tex
"
,
"
w
"
)
as
latex_file
:
latex_file
.
write
(
export_to_latex
(
df_model_info
))
```
%% Cell type:code id: tags:
```
python
for
m
in
models
:
fig
=
plot
(
df
,
m
)
filename
=
m
.
replace
(
"
_
"
,
"
-
"
)
filename
=
m
.
replace
(
"
_
"
,
"
-
"
)
fig
.
write_html
(
f
"
images/
{
filename
}
.html
"
)
fig
.
write_image
(
f
"
images/
{
filename
}
.pdf
"
,
format
=
"
pdf
"
)
```
%% Output
../../sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.cc:**CRASHING**:seccomp-bpf failure in syscall 0230
../../sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.cc:**CRASHING**:seccomp-bpf failure in syscall 0230
../../sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.cc:**CRASHING**:seccomp-bpf failure in syscall 0230
%% Cell type:code id: tags:
```
python
# show a figure
plot
(
df
,
models
[
0
])
```
%% Output
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment