author | wenzelm |
Sat, 19 Jan 2019 20:18:26 +0100 | |
changeset 69693 | 06153e2e0cdb |
parent 67817 | 93faefc25fe7 |
child 69787 | 60b5a4731695 |
permissions | -rw-r--r-- |
66820 | 1 |
/* Title: Pure/Admin/afp.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Administrative support for the Archive of Formal Proofs. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
10 |
object AFP |
|
11 |
{ |
|
66854 | 12 |
val repos_source = "https://bitbucket.org/isa-afp/afp-devel" |
13 |
||
69693 | 14 |
val groups: Map[String, String] = |
15 |
Map("large" -> "full 64-bit memory model or word arithmetic required", |
|
16 |
"slow" -> "CPU time much higher than 60min (on mid-range hardware)", |
|
17 |
"very_slow" -> "elapsed time of many hours (on high-end hardware)") |
|
18 |
||
19 |
def groups_bulky: List[String] = List("large", "slow") |
|
20 |
||
66824 | 21 |
def init(options: Options, base_dir: Path = Path.explode("$AFP_BASE")): AFP = |
22 |
new AFP(options, base_dir) |
|
66820 | 23 |
|
66821 | 24 |
sealed case class Entry(name: String, sessions: List[String]) |
66820 | 25 |
} |
26 |
||
66824 | 27 |
class AFP private(options: Options, val base_dir: Path) |
66820 | 28 |
{ |
66821 | 29 |
override def toString: String = base_dir.expand.toString |
30 |
||
66820 | 31 |
val main_dir: Path = base_dir + Path.explode("thys") |
32 |
||
66821 | 33 |
|
34 |
/* entries and sessions */ |
|
35 |
||
66820 | 36 |
val entries: List[AFP.Entry] = |
66821 | 37 |
(for (name <- Sessions.parse_roots(main_dir + Sessions.ROOTS)) yield { |
66820 | 38 |
val sessions = |
39 |
Sessions.parse_root_entries(main_dir + Path.explode(name) + Sessions.ROOT).map(_.name) |
|
40 |
AFP.Entry(name, sessions) |
|
41 |
}).sortBy(_.name) |
|
42 |
||
66821 | 43 |
val sessions: List[String] = entries.flatMap(_.sessions) |
66824 | 44 |
|
67052 | 45 |
val sessions_structure: Sessions.Structure = |
67026 | 46 |
Sessions.load_structure(options, dirs = List(main_dir)). |
67025
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
66861
diff
changeset
|
47 |
selection(Sessions.Selection(sessions = sessions.toList)) |
66821 | 48 |
|
49 |
||
66824 | 50 |
/* dependency graph */ |
66821 | 51 |
|
66824 | 52 |
private def sessions_deps(entry: AFP.Entry): List[String] = |
53 |
entry.sessions.flatMap(sessions_structure.imports_graph.imm_preds(_)).distinct.sorted |
|
54 |
||
66852
d20a668b394e
entries_graph requires acyclic graph, but lazy val allows forming the AFP object nonetheless;
wenzelm
parents:
66832
diff
changeset
|
55 |
lazy val entries_graph: Graph[String, Unit] = |
66821 | 56 |
{ |
57 |
val session_entries = |
|
66831
29ea2b900a05
tuned: each session has at most one defining entry;
wenzelm
parents:
66824
diff
changeset
|
58 |
(Map.empty[String, String] /: entries) { |
29ea2b900a05
tuned: each session has at most one defining entry;
wenzelm
parents:
66824
diff
changeset
|
59 |
case (m1, e) => (m1 /: e.sessions) { case (m2, s) => m2 + (s -> e.name) } |
66821 | 60 |
} |
66831
29ea2b900a05
tuned: each session has at most one defining entry;
wenzelm
parents:
66824
diff
changeset
|
61 |
(Graph.empty[String, Unit] /: entries) { case (g, entry) => |
29ea2b900a05
tuned: each session has at most one defining entry;
wenzelm
parents:
66824
diff
changeset
|
62 |
val e1 = entry.name |
66832 | 63 |
(g.default_node(e1, ()) /: sessions_deps(entry)) { case (g1, s) => |
64 |
(g1 /: session_entries.get(s).filterNot(_ == e1)) { case (g2, e2) => |
|
66852
d20a668b394e
entries_graph requires acyclic graph, but lazy val allows forming the AFP object nonetheless;
wenzelm
parents:
66832
diff
changeset
|
65 |
try { g2.default_node(e2, ()).add_edge_acyclic(e2, e1) } |
d20a668b394e
entries_graph requires acyclic graph, but lazy val allows forming the AFP object nonetheless;
wenzelm
parents:
66832
diff
changeset
|
66 |
catch { |
d20a668b394e
entries_graph requires acyclic graph, but lazy val allows forming the AFP object nonetheless;
wenzelm
parents:
66832
diff
changeset
|
67 |
case exn: Graph.Cycles[_] => |
d20a668b394e
entries_graph requires acyclic graph, but lazy val allows forming the AFP object nonetheless;
wenzelm
parents:
66832
diff
changeset
|
68 |
error(cat_lines(exn.cycles.map(cycle => |
d20a668b394e
entries_graph requires acyclic graph, but lazy val allows forming the AFP object nonetheless;
wenzelm
parents:
66832
diff
changeset
|
69 |
"Cyclic dependency of " + cycle.map(c => quote(c.toString)).mkString(" via ") + |
d20a668b394e
entries_graph requires acyclic graph, but lazy val allows forming the AFP object nonetheless;
wenzelm
parents:
66832
diff
changeset
|
70 |
" due to session " + quote(s)))) |
66832 | 71 |
} |
66821 | 72 |
} |
73 |
} |
|
66824 | 74 |
} |
66821 | 75 |
} |
76 |
||
66824 | 77 |
def entries_graph_display: Graph_Display.Graph = |
78 |
Graph_Display.make_graph(entries_graph) |
|
66823 | 79 |
|
66824 | 80 |
def entries_json_text: String = |
81 |
(for (entry <- entries.iterator) yield { |
|
82 |
val distrib_deps = sessions_deps(entry).filterNot(sessions.contains(_)) |
|
83 |
val afp_deps = entries_graph.imm_preds(entry.name).toList |
|
84 |
""" |
|
66821 | 85 |
{""" + JSON.Format(entry.name) + """: |
86 |
{"distrib_deps": """ + JSON.Format(distrib_deps) + """, |
|
87 |
"afp_deps": """ + JSON.Format(afp_deps) + """ |
|
88 |
} |
|
89 |
}""" |
|
66824 | 90 |
}).mkString("[", ", ", "\n]\n") |
66861
f6676691ef8a
partition AFP sessions according to structure, which happens to cut it roughly into equal parts;
wenzelm
parents:
66854
diff
changeset
|
91 |
|
f6676691ef8a
partition AFP sessions according to structure, which happens to cut it roughly into equal parts;
wenzelm
parents:
66854
diff
changeset
|
92 |
|
f6676691ef8a
partition AFP sessions according to structure, which happens to cut it roughly into equal parts;
wenzelm
parents:
66854
diff
changeset
|
93 |
/* partition sessions */ |
f6676691ef8a
partition AFP sessions according to structure, which happens to cut it roughly into equal parts;
wenzelm
parents:
66854
diff
changeset
|
94 |
|
67817 | 95 |
val force_partition1: List[String] = List("Category3", "HOL-ODE") |
67776 | 96 |
|
66861
f6676691ef8a
partition AFP sessions according to structure, which happens to cut it roughly into equal parts;
wenzelm
parents:
66854
diff
changeset
|
97 |
def partition(n: Int): List[String] = |
f6676691ef8a
partition AFP sessions according to structure, which happens to cut it roughly into equal parts;
wenzelm
parents:
66854
diff
changeset
|
98 |
n match { |
f6676691ef8a
partition AFP sessions according to structure, which happens to cut it roughly into equal parts;
wenzelm
parents:
66854
diff
changeset
|
99 |
case 0 => Nil |
f6676691ef8a
partition AFP sessions according to structure, which happens to cut it roughly into equal parts;
wenzelm
parents:
66854
diff
changeset
|
100 |
case 1 | 2 => |
f6676691ef8a
partition AFP sessions according to structure, which happens to cut it roughly into equal parts;
wenzelm
parents:
66854
diff
changeset
|
101 |
val graph = sessions_structure.build_graph.restrict(sessions.toSet) |
67817 | 102 |
val force_part1 = |
103 |
graph.all_preds(graph.all_succs(force_partition1.filter(graph.defined(_)))).toSet |
|
104 |
val (part1, part2) = graph.keys.partition(a => force_part1(a) || graph.is_isolated(a)) |
|
105 |
if (n == 1) part1 else part2 |
|
66861
f6676691ef8a
partition AFP sessions according to structure, which happens to cut it roughly into equal parts;
wenzelm
parents:
66854
diff
changeset
|
106 |
case _ => error("Bad AFP partition: " + n + " (should be 0, 1, 2)") |
f6676691ef8a
partition AFP sessions according to structure, which happens to cut it roughly into equal parts;
wenzelm
parents:
66854
diff
changeset
|
107 |
} |
66820 | 108 |
} |