diff --git a/lib/ast.ml b/lib/ast.ml
index c76d822149a233b8f7ec5ba0899093f62b20239f..913a9be2983a4da9492bcbf10277c9904190c059 100644
--- a/lib/ast.ml
+++ b/lib/ast.ml
@@ -295,15 +295,17 @@ end
 
 module G =  Graph.Imperative.Digraph.ConcreteLabeled(Node)(Edge)
 module Topological = Graph.Topological.Make(G)
-
+module D = Graph.Traverse.Dfs(G)
 
 type edge =
 | Nolab of (expr * expr)
 
+
 (**[graph_from_edges el] creates a graph from a list of edges [el] 
     @param edge [list]
     @return [G.t]*)
 let graph_from_edges (el : edge list)=
+
   let g = G.create () in
   let nolab = fun (x, y) -> 
     let vx = G.V.create x in 
@@ -315,7 +317,8 @@ let graph_from_edges (el : edge list)=
     | [] -> ()
     | (Nolab h)::t -> nolab h ; add_edge t
   in add_edge el;
-  g
+  if not(D.has_cycle g) then g else raise(Failure("Graph is cyclic"))
+
 
 (**[png_from_graph g name] generates a png file of the graph [g]
     @param g [G.t]
@@ -334,7 +337,7 @@ let png_from_graph g name=
   let oc = open_out ("./generate/"^name^"_measure.dot") in
   Printf.fprintf oc "%s\n" dot;
   close_out oc;
-  ignore (Sys.command ("dot -Tpng "^name^".dot -o ./generate/"^ name^"_measure.png"))
+  ignore (Sys.command ("dot -Tpng ./generate/"^name^"_measure.dot -o ./generate/"^ name^"_measure.png"))
 
 (**[assign_heigth g] returns the phase, phase weight association list. The phase weight is deduced from the order
                      topology of the phase