SimControl 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +11 -11
- data/lib/SimControl.rb +1 -0
- data/lib/SimControl/controller.rb +7 -2
- data/lib/SimControl/environments/python.rb +1 -1
- data/lib/SimControl/scenario.rb +24 -0
- data/lib/SimControl/version.rb +1 -1
- data/spec/controller_spec.rb +17 -5
- data/spec/environments/python_environment_spec.rb +3 -7
- data/spec/scenario_spec.rb +18 -0
- metadata +5 -2
data/README.md
CHANGED
@@ -79,20 +79,20 @@ Usage Example
|
|
79
79
|
|
80
80
|
* Next, we consider the execution of the simulation on one of the hosts specified in the Controlfile by running `bundle exec simulate myScenario`. First, all scenarios, i.e. calls to simulate, are enumerated. Then, they are assigned to the hosts specified via the host call, were each host is considered multiple times if multiple cores are specified. In our example, the 3 of the 10 scenarios will be assigned to hostname and the first core of another-hostname, while 2 scenarios will be assigned the remaining cores of another-hostname. Then, simcontrol obtains the local hostname and the assigned scenarios and one scenario group is started per core. The command to simulate a scenario is obtained as follows:
|
81
81
|
|
82
|
-
The class and options hash passed to the simulation method in Controlfile are used to construct a `PythonEnvironment` instance, which is able to start the simulation environment. Note, that the simulation method merges the options hash with computed options, e.g. the path to the scenarios results directory and the seed to use for the stimulation. The full set of parameters used to invoke the simulation are obtained from the parameters of the simulate method in myScenario.rb, were each of the options passed to the simulation as unix-style long parameters (i.e. foo: 4 is converted to --foo 4).
|
82
|
+
The class and options hash passed to the simulation method in Controlfile are used to construct a `PythonEnvironment` instance, which is able to start the simulation environment. Note, that the simulation method merges the options hash with computed options, e.g. the path to the scenarios results directory and the seed to use for the stimulation. The full set of parameters used to invoke the simulation are obtained from the parameters of the simulate method in myScenario.rb, were each of the (hash) options passed to the simulation as unix-style long parameters (i.e. foo: 4 is converted to --foo 4) and the first parameter is passed as a command.
|
83
83
|
|
84
84
|
In our example this results in the following simulation scenarios. Note, that in our example each of the scenarios is executed with varying parameter values for SEED (seed generation is discussed later).
|
85
85
|
|
86
86
|
| Host | Core | Command |
|
87
87
|
|--------------|------|---------|
|
88
|
-
| host | % | /home/simpy/simpy-env/bin/pypy /home/simpy/simulation/simulation.py --numberOfServers 1 --duration 90000 --transientPhaseDuration 3600 --seed SEED --results /home/simpy/control/results/myScenario/ |
|
89
|
-
| host | % | /home/simpy/simpy-env/bin/pypy /home/simpy/simulation/simulation.py --numberOfServers 11 --duration 90000 --transientPhaseDuration 3600 --seed SEED --results /home/simpy/control/results/myScenario |
|
90
|
-
| host | % | /home/simpy/simpy-env/bin/pypy /home/simpy/simulation/simulation.py --numberOfServers 21 --duration 90000 --transientPhaseDuration 3600 --seed SEED --results /home/simpy/control/results/myScenario |
|
91
|
-
| another-host | 1 | /home/simpy/simpy-env/bin/pypy /home/simpy/simulation/simulation.py --numberOfServers 1 --duration 90000 --transientPhaseDuration 3600 --seed SEED --results /home/simpy/control/results/myScenario |
|
92
|
-
| another-host | 1 | /home/simpy/simpy-env/bin/pypy /home/simpy/simulation/simulation.py --numberOfServers 11 --duration 90000 --transientPhaseDuration 3600 --seed SEED --results /home/simpy/control/results/myScenario |
|
93
|
-
| another-host | 1 | /home/simpy/simpy-env/bin/pypy /home/simpy/simulation/simulation.py --numberOfServers 21 --duration 90000 --transientPhaseDuration 3600 --seed SEED --results /home/simpy/control/results/myScenario |
|
94
|
-
| another-host | 2 | /home/simpy/simpy-env/bin/pypy /home/simpy/simulation/simulation.py --numberOfServers 1 --duration 90000 --transientPhaseDuration 3600 --seed SEED --results /home/simpy/control/results/myScenario |
|
95
|
-
| another-host | 2 | /home/simpy/simpy-env/bin/pypy /home/simpy/simulation/simulation.py --numberOfServers 11 --duration 90000 --transientPhaseDuration 3600 --seed SEED --results /home/simpy/control/results/myScenario |
|
96
|
-
| another-host | 3 | /home/simpy/simpy-env/bin/pypy /home/simpy/simulation/simulation.py --numberOfServers 1 --duration 90000 --transientPhaseDuration 3600 --seed SEED --results /home/simpy/control/results/myScenario |
|
97
|
-
| another-host | 3 | /home/simpy/simpy-env/bin/pypy /home/simpy/simulation/simulation.py --numberOfServers 11 --duration 90000 --transientPhaseDuration 3600 --seed SEED --results /home/simpy/control/results/myScenario |
|
88
|
+
| host | % | /home/simpy/simpy-env/bin/pypy /home/simpy/simulation/simulation.py command --numberOfServers 1 --duration 90000 --transientPhaseDuration 3600 --seed SEED --results /home/simpy/control/results/myScenario/ |
|
89
|
+
| host | % | /home/simpy/simpy-env/bin/pypy /home/simpy/simulation/simulation.py command --numberOfServers 11 --duration 90000 --transientPhaseDuration 3600 --seed SEED --results /home/simpy/control/results/myScenario |
|
90
|
+
| host | % | /home/simpy/simpy-env/bin/pypy /home/simpy/simulation/simulation.py command --numberOfServers 21 --duration 90000 --transientPhaseDuration 3600 --seed SEED --results /home/simpy/control/results/myScenario |
|
91
|
+
| another-host | 1 | /home/simpy/simpy-env/bin/pypy /home/simpy/simulation/simulation.py command --numberOfServers 1 --duration 90000 --transientPhaseDuration 3600 --seed SEED --results /home/simpy/control/results/myScenario |
|
92
|
+
| another-host | 1 | /home/simpy/simpy-env/bin/pypy /home/simpy/simulation/simulation.py command --numberOfServers 11 --duration 90000 --transientPhaseDuration 3600 --seed SEED --results /home/simpy/control/results/myScenario |
|
93
|
+
| another-host | 1 | /home/simpy/simpy-env/bin/pypy /home/simpy/simulation/simulation.py command --numberOfServers 21 --duration 90000 --transientPhaseDuration 3600 --seed SEED --results /home/simpy/control/results/myScenario |
|
94
|
+
| another-host | 2 | /home/simpy/simpy-env/bin/pypy /home/simpy/simulation/simulation.py command --numberOfServers 1 --duration 90000 --transientPhaseDuration 3600 --seed SEED --results /home/simpy/control/results/myScenario |
|
95
|
+
| another-host | 2 | /home/simpy/simpy-env/bin/pypy /home/simpy/simulation/simulation.py command --numberOfServers 11 --duration 90000 --transientPhaseDuration 3600 --seed SEED --results /home/simpy/control/results/myScenario |
|
96
|
+
| another-host | 3 | /home/simpy/simpy-env/bin/pypy /home/simpy/simulation/simulation.py command --numberOfServers 1 --duration 90000 --transientPhaseDuration 3600 --seed SEED --results /home/simpy/control/results/myScenario |
|
97
|
+
| another-host | 3 | /home/simpy/simpy-env/bin/pypy /home/simpy/simulation/simulation.py command --numberOfServers 11 --duration 90000 --transientPhaseDuration 3600 --seed SEED --results /home/simpy/control/results/myScenario |
|
98
98
|
|
data/lib/SimControl.rb
CHANGED
@@ -4,6 +4,7 @@ module SimControl
|
|
4
4
|
|
5
5
|
def initialize(hostname, simulation_description, scenario_description, results_directory, args = {})
|
6
6
|
@hosts = args.delete(:hosts) || SimControl::Hosts.new
|
7
|
+
@scenario_klass = args.delete(:scenario_klass) || SimControl::Scenario
|
7
8
|
|
8
9
|
@hostname = hostname
|
9
10
|
@simulation_description = simulation_description
|
@@ -16,6 +17,10 @@ module SimControl
|
|
16
17
|
@max_seed = 2**(32 - 1) - 1
|
17
18
|
end
|
18
19
|
|
20
|
+
def create_scenario(*args)
|
21
|
+
@scenario_klass.new(*args)
|
22
|
+
end
|
23
|
+
|
19
24
|
def run
|
20
25
|
instance_eval(@simulation_description)
|
21
26
|
instance_eval(@scenario_description)
|
@@ -53,8 +58,8 @@ module SimControl
|
|
53
58
|
(1..@number_of_repetitions).map { @rng.rand(@max_seed) }
|
54
59
|
end
|
55
60
|
|
56
|
-
def simulate(scenario)
|
57
|
-
@scenarios << scenario
|
61
|
+
def simulate(*scenario)
|
62
|
+
@scenarios << (create_scenario *scenario)
|
58
63
|
end
|
59
64
|
|
60
65
|
def all_scenarios
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module SimControl
|
2
|
+
class Scenario
|
3
|
+
def initialize(*args)
|
4
|
+
options = Hash.try_convert(args.last)
|
5
|
+
if options
|
6
|
+
args.pop
|
7
|
+
end
|
8
|
+
@commands = args
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def options
|
13
|
+
@options.map { |k, v| "--#{ k } #{ v }" }.join " "
|
14
|
+
end
|
15
|
+
|
16
|
+
def commands
|
17
|
+
@commands.join(" ").strip
|
18
|
+
end
|
19
|
+
|
20
|
+
def args
|
21
|
+
[commands, options].join " "
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/SimControl/version.rb
CHANGED
data/spec/controller_spec.rb
CHANGED
@@ -72,13 +72,25 @@ scenario
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
+
describe "#create_scenario" do
|
76
|
+
it "passes the parameters to Scenario.new and returns the new scenario instance" do
|
77
|
+
scenario_klass = double("Scenario")
|
78
|
+
a_scenario = double("ScenarioInstance")
|
79
|
+
instance = SimControl::Controller.new("", "", "", "", scenario_klass: scenario_klass)
|
80
|
+
scenario_klass.should_receive(:new).with("a-command", a_hash: 1).and_return(a_scenario)
|
81
|
+
expect(instance.create_scenario("a-command", a_hash: 1)).to eq(a_scenario)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
75
85
|
describe "#scenario" do
|
76
86
|
it "stores all provided scenarios in all_scenarios" do
|
77
|
-
scenario_a =
|
78
|
-
scenario_b =
|
87
|
+
scenario_a = double("Scenario")
|
88
|
+
scenario_b = double("Scenario")
|
79
89
|
instance = SimControl::Controller.new("", "", "", "")
|
80
|
-
instance.
|
81
|
-
instance.
|
90
|
+
instance.stub(:create_scenario).with("a-command", a_hash: 1).and_return(scenario_a)
|
91
|
+
instance.stub(:create_scenario).with("b-command", b_hash: 2).and_return(scenario_b)
|
92
|
+
instance.simulate "a-command", a_hash: 1
|
93
|
+
instance.simulate "b-command", b_hash: 2
|
82
94
|
expect(instance.all_scenarios).to include(scenario_a)
|
83
95
|
expect(instance.all_scenarios).to include(scenario_b)
|
84
96
|
end
|
@@ -91,7 +103,7 @@ scenario
|
|
91
103
|
let(:seeds) { [1, 2] }
|
92
104
|
let(:simulation_instance) { double("simulation_instance") }
|
93
105
|
let(:hosts) { double("Hosts") }
|
94
|
-
|
106
|
+
subject { SimControl::Controller.new(hostname, "", "", "", hosts: hosts).tap do |c|
|
95
107
|
c.stub(:seeds).and_return(seeds)
|
96
108
|
c.stub(:current_simulation).and_return(simulation_instance)
|
97
109
|
end
|
@@ -23,11 +23,6 @@ describe SimControl::PythonEnvironment do
|
|
23
23
|
expect(simulation.script).to eq("a-script")
|
24
24
|
end
|
25
25
|
|
26
|
-
it "passes args to the script in -- syntax" do
|
27
|
-
simulation = SimControl::PythonEnvironment.new script
|
28
|
-
expect(simulation.args({foo: "bar", baz: 1})).to eq("--foo bar --baz 1")
|
29
|
-
end
|
30
|
-
|
31
26
|
it "uses a given interpreter" do
|
32
27
|
simulation = SimControl::PythonEnvironment.new script, interpreter: "pypy"
|
33
28
|
expect(simulation.interpreter).to eq("pypy")
|
@@ -40,9 +35,10 @@ describe SimControl::PythonEnvironment do
|
|
40
35
|
|
41
36
|
it "composes the command" do
|
42
37
|
simulation = SimControl::PythonEnvironment.new script
|
43
|
-
|
38
|
+
scenario = double("scenario")
|
39
|
+
scenario.should_receive(:args).and_return("--args 1")
|
44
40
|
simulation.stub(:interpreter).and_return "/foo/jpython"
|
45
|
-
expect(simulation.command(
|
41
|
+
expect(simulation.command(scenario)).to eq("/foo/jpython a-script --args 1")
|
46
42
|
end
|
47
43
|
|
48
44
|
it "raised an exception is a virtualenv is passed but no interpreter" do
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe SimControl::Scenario do
|
4
|
+
it "generates options in -- syntax" do
|
5
|
+
scenario = SimControl::Scenario.new foo: "bar", baz: 1
|
6
|
+
expect(scenario.options).to eq("--foo bar --baz 1")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "generates commands by concatenating" do
|
10
|
+
scenario = SimControl::Scenario.new "foo", "bar"
|
11
|
+
expect(scenario.commands).to eq("foo bar")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "generates the complete arguments string" do
|
15
|
+
scenario = SimControl::Scenario.new "foo", "bar", baz: "1", qux: 2
|
16
|
+
expect(scenario.args).to eq("foo bar --baz 1 --qux 2")
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: SimControl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
@@ -163,6 +163,7 @@ files:
|
|
163
163
|
- lib/SimControl/environments/base.rb
|
164
164
|
- lib/SimControl/environments/python.rb
|
165
165
|
- lib/SimControl/hosts.rb
|
166
|
+
- lib/SimControl/scenario.rb
|
166
167
|
- lib/SimControl/version.rb
|
167
168
|
- spec/acceptance/init_spec.rb
|
168
169
|
- spec/acceptance/scenario_spec.rb
|
@@ -171,6 +172,7 @@ files:
|
|
171
172
|
- spec/environments/base_environment_spec.rb
|
172
173
|
- spec/environments/python_environment_spec.rb
|
173
174
|
- spec/hosts_spec.rb
|
175
|
+
- spec/scenario_spec.rb
|
174
176
|
- spec/spec_helper.rb
|
175
177
|
- templates/scaffolding/Controlfile
|
176
178
|
- templates/scenario/scenario.rb
|
@@ -207,4 +209,5 @@ test_files:
|
|
207
209
|
- spec/environments/base_environment_spec.rb
|
208
210
|
- spec/environments/python_environment_spec.rb
|
209
211
|
- spec/hosts_spec.rb
|
212
|
+
- spec/scenario_spec.rb
|
210
213
|
- spec/spec_helper.rb
|