Skip to content
Snippets Groups Projects
Commit ebe6e6e4 authored by Lionel GUEZ's avatar Lionel GUEZ
Browse files

Add timings for script `trajectories.py`

parent 699ecbf0
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,7 @@
"command": [
"$src_dir/Trajectories/trajectories.py",
"$PWD/Perf_cost_function/segments_cost_functions.gt"
]
}
],
"exclude_cmp": ["timings.txt"]
}
}
......@@ -18,6 +18,7 @@ import json
import sys
import report_graph
import numpy as np
import time
def new_traj(ind_traj, traj_prop, n, traj_vert_ind):
"""Assign new trajectory to vertex index n."""
......@@ -27,6 +28,8 @@ def new_traj(ind_traj, traj_prop, n, traj_vert_ind):
traj_vert_ind.append([n])
return ind_traj
t0 = time.perf_counter()
timings_file = open("timings.txt", "w")
if len(sys.argv) != 2: sys.exit("Required argument: input-graph")
g = graph_tool.load_graph(sys.argv[1])
print("Input graph:")
......@@ -34,6 +37,9 @@ print("Number of vertices:", g.num_vertices())
print("Number of edges:", g.num_edges())
print("Internal properties:")
g.list_properties()
t1 = time.perf_counter()
timings_file.write(f'Loading done in {t1 - t0:.0f} s\n')
t0 = t1
if "cost_function" in g.edge_properties:
closest_succ = g.new_vertex_property('int')
......@@ -55,6 +61,9 @@ else:
# This happens if there are only isolated segments.
print("No cost values in the input file.")
t1 = time.perf_counter()
timings_file.write(f'closest_succ defined in {t1 - t0:.0f} s\n')
t0 = t1
traj_prop = g.new_vertex_property('int', val = - 1)
# Trajectory index to which a segment belongs. - 1 means the segment
# does not belong yet to any trajectory. The trajectory index is also
......@@ -144,6 +153,9 @@ for n in topology.topological_sort(g):
# traj_prop[n] != - 1
t1 = time.perf_counter()
timings_file.write(f'traj_prop defined in {t1 - t0:.0f} s\n')
t0 = t1
print("Number of trajectories: ", len(traj_vert_ind))
# We have trajectories as lists of vertex indices. Now construct
......@@ -173,6 +185,10 @@ for t in traj_vert_ind:
traj_segm.append(list_segm)
expanded_traj.append(list_eddies_traj)
t1 = time.perf_counter()
timings_file.write(f'traj_segm and expanded_traj defined in {t1 - t0:.0f} s\n')
t0 = t1
# Save:
with open("traj_segm.json", "w") as outfile:
......@@ -185,4 +201,6 @@ with open("expanded_traj.json", "w") as outfile:
outfile, separators = (',', ':'))
print("Created expanded_traj.json.")
t1 = time.perf_counter()
timings_file.write(f'Saving done in {t1 - t0:.0f} s\n')
print('Done')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment