-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
173 lines (153 loc) · 5.36 KB
/
main.cpp
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include "components.hpp"
#include "core/specs/process_spec.hpp"
#include <algorithm>
#include <exception>
#include <experimental/filesystem>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <random>
#include <regex>
#include <string>
#include <string_view>
#include <thread>
#include <vector>
long ded::concepts::Substrate::substrate_id_ = 0;
int ded::concepts::Process::global_invocations_ = 0;
std::string ded::GLOBAL_PATH = "./";
std::map<std::string, ded::specs::SubstrateSpec> ded::ALL_SUBSTRATE_SPECS;
std::map<std::string, ded::specs::ProcessSpec> ded::ALL_PROCESS_SPECS;
std::map<std::string, ded::specs::PopulationSpec> ded::ALL_POPULATION_SPECS;
std::map<std::string, ded::specs::EncodingSpec> ded::ALL_ENCODING_SPECS;
std::map<std::string, ded::specs::ConverterSpec> ded::ALL_CONVERTER_SPECS;
struct CommandLineError
{
};
int
main(int argc, char **argv)
try
{
// check all things that aren't being checked statically,
// in particular the correct publication of components
ded::generateAllSpecs();
if (argc == 1)
{
std::cout << "ded: missing command line arguments. try -h or --help\n";
return 0;
}
std::string mode = argv[1];
if (argc == 2 && (mode == "-h" || mode == "--help"))
{
std::cout << R"~~(
Flags Arguments Description
----- --------- -----------
-l, --list : lists all components currently loaded
-s, --show <component-type>:<component-name>...
: show default configuration for each component
-sa, --show-all : show default configuration for all available components
-v, --verify <file-name> : verify simulations in file-name
-rl, --run-local <file-name> <N> : runs all simulations in file-name with N replicates (locally)
-rh, --run-hpc <file-name> <N> : runs all simulations in this file-name with N replicates (msu hpc)
-a, --analyse <file-name> <trace-name> : generate analysis for simulations in file-name
-f <bar-code> <N> : run a single simulation with REP ID N (should NOT be called manually)
)~~";
}
else if (argc == 2 && (mode == "-l" || mode == "--list"))
{
ded::config_manager::listAllConfigs(std::cout);
std::cout << std::endl;
}
else if (argc > 2 && (mode == "-s" || mode == "--show"))
{
for (auto i{ 2 }; i < argc; i++)
ded::config_manager::showConfig(std::cout, std::string(argv[i]));
std::cout << std::endl;
}
else if (argc == 2 && (mode == "-sa" || mode == "--show-all"))
{
ded::config_manager::saveAllConfigs();
}
else if (argc == 3 && (mode == "-v" || mode == "--verify"))
{
auto simulations = ded::experiments::parseAllSimulations(argv[2]);
for (auto sim : simulations)
std::cout << sim.prettyName() << "\n";
std::cout << "All simulations are valid - this experiment is correct\n";
}
else if (argc == 4 && (mode == "-rl" || mode == "--run-local"))
{
int replicate_count{};
std::stringstream ss{ argv[3] };
ss >> replicate_count;
if (ss.fail())
throw CommandLineError{};
ded::experiments::prepareSimulationsLocally(
ded::experiments::checkSimulations(
ded::experiments::parseAllSimulations(argv[2])),
replicate_count);
std::cout << "execute run.sh\n";
}
else if (argc == 4 && (mode == "-rh" || mode == "--run-hpc"))
{
int replicate_count{};
std::stringstream ss{ argv[3] };
ss >> replicate_count;
if (ss.fail())
throw CommandLineError{};
ded::experiments::prepareSimulationsMsuHpcc(
ded::experiments::checkSimulations(
ded::experiments::parseAllSimulations(argv[2])),
replicate_count);
std::cout << "execute run.sh\n";
}
else if (argc == 4 && (mode == "-a" || mode == "--analyse"))
{
ded::experiments::analyseAllSimulations(argv[2], argv[3]);
std::cout << "execute Rscript analysis.R\n";
}
else if (argc == 4 && mode == "-f")
{
if (!std::experimental::filesystem::exists("./data/" +
std::string{ argv[2] }))
{
std::cout
<< "Error: invalid manually specified simulation; does not exist\n";
std::exit(0);
}
auto [pop_spec, proc_spec] = ded::experiments::loadSimulation(argv[2]);
auto pop = ded::makePopulation(pop_spec);
auto proc = ded::makeProcess(proc_spec);
ded::GLOBAL_PATH = "./data/" + std::string{ argv[2] } + "/" + argv[3] + "/";
std::experimental::filesystem::create_directory(ded::GLOBAL_PATH);
std::srand(std::stoi(argv[3]));
pop = proc.evaluate(pop);
pop.flushUnpruned();
// should write success report to file
std::cout << "simulation " << argv[2] << " - Replicate # " << argv[3]
<< " successfully simulated\n";
}
else
{
throw CommandLineError{};
}
return 0;
}
catch (const CommandLineError &)
{
std::cout << "ded: unknown command line arguments. try -h or --help\n";
}
catch (const ded::language::ParserError &)
{
}
catch (const ded::specs::SpecError &)
{
}
catch (const ded::config_manager::ConfigError &)
{
}
catch (...)
{
std::cout << "\nFATAL: this is a core issue - please file a bug report\n";
}