-
Notifications
You must be signed in to change notification settings - Fork 14
/
runner.py
157 lines (141 loc) · 4.54 KB
/
runner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import subprocess
import yaml
import os
import sys
from glob import glob
def execute_demo(exampledir, name='demo.py'):
"""Exectue a demo in a particular directory."""
nameall = name.split()
output = subprocess.run(['python3'] + nameall + ['--savefig'],
cwd=f'{exampledir}',
capture_output=True, text=True)
if output.stderr:
raise ValueError(f'Trouble executing {exampledir} + {name} \n {output.stderr}')
return output.stdout
mainreadme = 'readme.md'
toc = yaml.safe_load("""
Introduction:
- dir: 0_start_here
title: Overview
Blackbox Solver:
- dir: blackbox
Smoothed Aggregation AMG:
- dir: aggregation
title: Aggregation
- dir: one_dimension
title: One Dimensional Problem
- dir: visualizing_aggregation
title: Visualizing Aggregation
demo: demo1.py, demo2.py
- dir: solver_diagnostics
title: Solver Diagnostics
demo: demo.py --matrix 2
- dir: complex
title: Complex Arithmetic
demo: demo.py --solver 1
- dir: nonsymmetric
title: Nonsymmetric example
demo: demo.py --solver 1
Classical AMG:
- dir: coarse_fine_splitting
title: Coarse Fine Splitting
- dir: compatible_relaxation
title: Compatible Relaxation
- dir: strength_options
title: Stength of Connection
- dir: air
title: Approximate ideal restriction (AIR)
Rootnode AMG:
- dir: rootnode
title: Rootnode AMG
Finite Elements:
- dir: diffusion
title: Anisotropic Diffusion
- dir: linear_elasticity
title: Linear Elasticity
demo: demo.py --solver 2
Preconditioning:
- dir: preconditioning
title: Krylov Methods
demo: demo.py --solver 1
- dir: eigensolver
title: Eigenvalue Solvers
Other Applications:
- dir: mesh_partition
title: Graph Partitioning
- dir: helmholtz
title: Indefinite Helmholtz
demo: demo1d.py, demo2d.py
- dir: diffusion_dg
title: High-Order DG on Poisson
- dir: edge_amg
title: Edge-based AMG
Other:
- dir: profile_pyamg
title: Profiling Performance
- dir: performance
title: Scaling performance of AMG and FE assembly
""")
# generate table and header
header = \
"""This is a collection of short examples for [PyAMG](https://github.com/pyamg/pyamg).
The source code for these **(and more)** examples is available at
https://github.com/pyamg/pyamg-examples.
"""
tocmd = '### Table of Contents\n'
main = '\n'
dirs = None
if len(sys.argv) > 1:
dirs = sys.argv[1:]
for d in dirs:
found = False
for section in toc:
for demo in toc[section]:
if d == demo['dir']:
found = True
if not found or not os.path.isdir(d):
print('usage: runner.py')
print('usage: runner.py dir1 [dir2] ...')
exit()
for section in toc:
# add to the TOC
hrefid = section.replace(' ', '').lower()
tocmd += f'- **<a href="#{hrefid}">{section}</a>**\n'
main += f'<a name="{hrefid}"></a>\n'
main += f'### {section}\n\n'
if toc[section] is not None:
for demo in toc[section]:
print(f'Processing {demo["dir"]}.', end=' ')
title = demo.get('title', None)
if title:
hrefid = title.replace(' ', '').lower()
tocmd += f' - <a href="#{hrefid}">{title}</a>\n'
main += f'<a name="{hrefid}"></a>\n'
main += f'\n#### {title}\n\n'
demonames = [d.strip() for d in demo.get('demo', 'demo.py').split(',')]
for demoname in demonames:
main += f'[{demoname}](./{demo["dir"]}/{demoname.split()[0]})\n\n'
# get the readme
with open(os.path.join(f"{demo['dir']}",'readme.md'), 'r') as f:
readmeoutput = f.read()
main += readmeoutput
# get the demo output
runit = True
if dirs is not None:
if demo['dir'] not in dirs:
runit = False
print('')
if runit:
print('[--->rerunning]')
for demoname in demonames:
if runit:
output = execute_demo(demo['dir'], name=demoname)
if len(output) > 0:
main += '\n```\n' + output + '```\n'
# get the output figs
figs = glob(os.path.join(f'{demo["dir"]}', 'output') +'/*.png')
for fig in figs:
main += f'\n<img src="./{fig}" width="300"/>\n\n'
main += '\n***\n\n'
with open(mainreadme, 'w') as f:
f.write(header + tocmd + main)