-
Notifications
You must be signed in to change notification settings - Fork 2
/
run.py
117 lines (102 loc) · 3.2 KB
/
run.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
from pathlib import Path
from subprocess import run
import sys
import shutil
scripts_path = Path('scripts')
settings_path = Path('settings')
def get_script(script_filename: str) -> str:
return str(scripts_path / script_filename)
settings_paths = sorted([*settings_path.iterdir()], key=lambda x: x.stem)
settings = {
str(setting_id): setting_path
for setting_id, setting_path in enumerate(settings_paths, start=1)
}
print(
'The following settings are available:\n'
+ '\n'.join([
f'{setting_id}: {setting_path.stem}'
for setting_id, setting_path in settings.items()
])
)
# Get the user's chosen setting.
while True:
setting_id = input('\n\nWhich setting would you like? ')
if setting_id in settings:
break
print(
'The selected setting did not match an available setting. '
f'Selected setting: {setting_id}'
)
# Copy the chosen settings to the scripts directory for usage by the tasks.
settings_output_path = scripts_path / '_settings.py'
if settings_output_path.exists():
raise FileExistsError(
'A settings file already exists in the scripts directory. Please '
f'remove {settings_output_path} then try again.'
)
shutil.copy(settings[setting_id], settings_output_path)
# Describe the available tasks.
tasks = {
'3.1': {
'description': 'Estimate parameters.',
'script': 'estimate.py',
},
'3.2': {
'description': 'Plot: fit, waterfall, parameters.',
'script': 'estimate_plot.py',
},
'4.1': {
'description': 'Assess estimate fit.',
'script': 'estimate_assess_fit.py',
},
'5.1_sample': {
'description': 'Sample from posterior.',
'script': 'uncertainty_sample.py',
},
'5.1_plot_sample': {
'description': 'Plot: sample trace, marginals, credibility intervals.',
'script': 'uncertainty_sample_plot.py',
},
'5.1_profile': {
'description': 'Profile likelihood.',
'script': 'uncertainty_profile.py',
},
'5.1_plot_profile': {
'description': 'Plot: likelihood profile.',
'script': 'uncertainty_profile_plot.py',
},
'6.1': {
'description': 'Compute states and observables of samples.',
'script': 'uncertainty_sample_predict.py',
},
'6.1_plot': {
'description': 'Plot: state and observable prediction uncertainties.',
'script': 'uncertainty_sample_predict_plot.py',
},
}
print(
'The following tasks are available to run:\n'
+ '\n'.join([
f'{task_id}: {task["description"]}'
for task_id, task in tasks.items()
])
)
# Get the user's chosen task.
while True:
task_id = input('\n\nWhich task would you like to run? ')
if task_id in tasks:
break
print(
'The selected task did not match an available task. '
f'Selected task: {task_id}'
)
task = tasks[task_id]
# Run the chosen task.
print(
f'Starting task {task_id}: {task["description"]}\n'
f'Now running "{task["script"]}"'
)
run(['python3', get_script(task['script'])])
print(f'Completed task {task_id}: {task["description"]}\n')
# Remove the custom settings that were copied to the scripts directory.
settings_output_path.unlink()