nera 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/History.txt +4 -0
  2. data/Manifest.txt +37 -0
  3. data/README.rdoc +47 -0
  4. data/Rakefile +27 -0
  5. data/bin/nera +29 -0
  6. data/bin/nera_addsim +30 -0
  7. data/lib/nera/nera_cui.rb +417 -0
  8. data/lib/nera/nera_database.rb +281 -0
  9. data/lib/nera/nera_db_folders.rb +226 -0
  10. data/lib/nera/nera_dialog.rb +205 -0
  11. data/lib/nera/nera_job_layer_controller.rb +237 -0
  12. data/lib/nera/nera_job_records.rb +111 -0
  13. data/lib/nera/nera_job_script.rb +202 -0
  14. data/lib/nera/nera_parameter_layer_controller.rb +157 -0
  15. data/lib/nera/nera_parameter_records.rb +186 -0
  16. data/lib/nera/nera_run_layer_controller.rb +192 -0
  17. data/lib/nera/nera_run_records.rb +184 -0
  18. data/lib/nera/nera_simulator.rb +26 -0
  19. data/lib/nera/nera_simulator_layer_controller.rb +66 -0
  20. data/lib/nera/nera_simulator_records.rb +84 -0
  21. data/lib/nera.rb +25 -0
  22. data/lib/nera_addsim/make_simulator.rb +307 -0
  23. data/scripts/make_manifest.rb +21 -0
  24. data/test/runner.rb +3 -0
  25. data/test/test_helper.rb +52 -0
  26. data/test/test_nera_database.rb +221 -0
  27. data/test/test_nera_db_folders.rb +209 -0
  28. data/test/test_nera_dialog.rb +134 -0
  29. data/test/test_nera_job_layer_controller.rb +132 -0
  30. data/test/test_nera_job_records.rb +260 -0
  31. data/test/test_nera_parameter_layer_controller.rb +188 -0
  32. data/test/test_nera_parameter_records.rb +285 -0
  33. data/test/test_nera_run_layer_controller.rb +171 -0
  34. data/test/test_nera_run_records.rb +290 -0
  35. data/test/test_nera_simulator.rb +26 -0
  36. data/test/test_nera_simulator_layer_controller.rb +54 -0
  37. data/test/test_nera_simulator_records.rb +140 -0
  38. metadata +125 -0
@@ -0,0 +1,285 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+
4
+ class TC_NERA_PARAM_RECS < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @testdir = 'test_sim_recs'
8
+ FileUtils.mkdir(@testdir)
9
+ FileUtils.chdir(@testdir)
10
+ @path_to_db = 'sim_recs_table.marshal'
11
+ NERA::ParameterRecords.create_table( @path_to_db, Ising)
12
+ @db = NERA::ParameterRecords.new( @path_to_db, Ising)
13
+ end
14
+
15
+ def teardown
16
+ FileUtils.chdir('..')
17
+ FileUtils.rm_r( @testdir)
18
+ end
19
+
20
+ def test_initialize
21
+ assert_raise( RuntimeError) {
22
+ NERA::ParameterRecords.new('unknown_file', Ising)
23
+ }
24
+ assert_raise( ArgumentError) {
25
+ NERA::ParameterRecords.new( @path_to_db, XY)
26
+ }
27
+ assert_raise( ArgumentError) {
28
+ NERA::ParameterRecords.new(@path_to_db, Temp)
29
+ }
30
+ end
31
+
32
+ def test_create_table
33
+ f = NERA::ParameterRecords.create_table( @path_to_db, Ising)
34
+ assert_nil( f)
35
+
36
+ assert_raise( ArgumentError) {
37
+ NERA::ParameterRecords.create_table( @path_to_db, XY)
38
+ }
39
+
40
+ assert_raise( ArgumentError) {
41
+ NERA::ParameterRecords.create_table( @path_to_db, Temp)
42
+ }
43
+ end
44
+
45
+ def test_keys
46
+ assert_equal( [:id,:created_at,:updated_at,:in_trashbox?,:L,:K,:tmax], @db.keys)
47
+ end
48
+
49
+ def test_add
50
+ param1 = { :L => 32, :K => 0.22, :tmax => 512 }
51
+ f = @db.add( param1)
52
+ d = DateTime.now
53
+ assert_equal( 1, f)
54
+ l_all = @db.list_all
55
+ r1 = l_all[0]
56
+ assert_equal( 1, l_all.size)
57
+ assert_equal( 1, r1[:id] )
58
+ assert_equal( d.year, r1[:created_at].year)
59
+ assert_equal( d.month, r1[:created_at].month)
60
+ assert_equal( d.day, r1[:created_at].day)
61
+ assert_equal( d.hour, r1[:created_at].hour)
62
+ assert_equal( d.min, r1[:created_at].min)
63
+ assert_equal( r1[:created_at], r1[:updated_at])
64
+ assert_equal( :active, r1[:in_trashbox?] )
65
+ assert_equal( param1[:L], r1[:L] )
66
+ assert_equal( param1[:K], r1[:K] )
67
+ assert_equal( param1[:tmax], r1[:tmax] )
68
+
69
+ param2 = { :L => 96, :K => 0.32, :tmax => 512 }
70
+ f = @db.add( param2)
71
+ assert_equal( 2, f)
72
+ l_all = @db.list_all
73
+ assert_equal( 2, l_all.size)
74
+ r2 = l_all[1]
75
+ assert_equal( 2, r2[:id] )
76
+ assert_equal( d.year, r2[:created_at].year)
77
+ assert_equal( d.month, r2[:created_at].month)
78
+ assert_equal( d.day, r2[:created_at].day)
79
+ assert_equal( d.hour, r2[:created_at].hour)
80
+ assert_equal( d.min, r2[:created_at].min)
81
+ assert_equal( r2[:created_at], r2[:updated_at])
82
+ assert_equal( :active, r2[:in_trashbox?] )
83
+ assert_equal( param2[:L], r2[:L] )
84
+ assert_equal( param2[:K], r2[:K] )
85
+ assert_equal( param2[:tmax], r2[:tmax] )
86
+
87
+ param3 = { :L => 32, :K => 0.22, :tmax => 512 }
88
+ f = @db.add( param3)
89
+ assert_nil( f)
90
+ l_all2 = @db.list_all
91
+ assert_equal( 2, l_all2.size)
92
+ assert_equal( l_all, l_all2)
93
+
94
+ param4 = { :L => 128, :tmax => 512 }
95
+ f = @db.add( param4)
96
+ assert_equal( 3, f)
97
+ l_all = @db.list_all
98
+ assert_equal( 3, l_all.size)
99
+ r2 = l_all[2]
100
+ assert_equal( 3, r2[:id] )
101
+ assert_equal( d.year, r2[:created_at].year)
102
+ assert_equal( d.month, r2[:created_at].month)
103
+ assert_equal( d.day, r2[:created_at].day)
104
+ assert_equal( d.hour, r2[:created_at].hour)
105
+ assert_equal( d.min, r2[:created_at].min)
106
+ assert_equal( r2[:created_at], r2[:updated_at])
107
+ assert_equal( :active, r2[:in_trashbox?] )
108
+ assert_equal( param4[:L], r2[:L] )
109
+ assert_nil( r2[:K] )
110
+ assert_equal( param4[:tmax], r2[:tmax] )
111
+
112
+
113
+ param5 = [32,0.22,64]
114
+ assert_raise( ArgumentError) {
115
+ f = @db.add( param5)
116
+ }
117
+ param6 = { :Lx => 32, :K => 0.22, :tmax => 512 }
118
+ assert_raise( ArgumentError) {
119
+ f = @db.add( param6)
120
+ }
121
+
122
+ end
123
+
124
+ def add_three
125
+ p1 = { :L => 32, :K => 0.22, :tmax => 512 }
126
+ p2 = { :L => 64, :K => 0.22, :tmax => 512 }
127
+ p3 = { :L => 32, :K => 0.32, :tmax => 128 }
128
+ @db.add(p1)
129
+ @db.add(p2)
130
+ @db.add(p3)
131
+ end
132
+
133
+ def test_list
134
+ assert_equal( 0, @db.list_all.size)
135
+ assert_equal( 0, @db.list_active.size)
136
+ assert_equal( 0, @db.list_trashbox.size)
137
+ add_three
138
+ l_all = @db.list_all
139
+ assert_equal( 3, l_all.size)
140
+ assert( l_all.is_a?(Array) )
141
+ l_active = @db.list_active
142
+ assert_equal( 3, l_active.size)
143
+ assert( l_active.is_a?(Array) )
144
+ assert_equal( l_all, l_active)
145
+ l_trashbox = @db.list_trashbox
146
+ assert( l_trashbox.is_a?(Array) )
147
+ assert_equal( 0, l_trashbox.size)
148
+ end
149
+
150
+ def test_find
151
+ add_three
152
+ l = @db.list_all
153
+ r1 = @db.find_by_id(1)
154
+ assert_equal( l[0], r1)
155
+ assert_equal( 1, r1[:id])
156
+ r3 = @db.find_by_id(3)
157
+ assert_equal( l[2], r3)
158
+ assert_equal( 3, r3[:id])
159
+
160
+ r23 = @db.find_by_id(2..5)
161
+ assert( r23.is_a?(Array) )
162
+ assert_equal( 2, r23.size)
163
+ assert_equal( 2, r23[0][:id])
164
+ assert_equal( 3, r23[1][:id])
165
+
166
+ r254 = @db.find_by_id( [2,5,4])
167
+ assert( r254.is_a?(Array) )
168
+ assert_equal( 3, r254.size)
169
+ assert_equal( 2, r254[0][:id])
170
+ assert_nil( r254[1])
171
+ assert_nil( r254[2])
172
+
173
+ assert_nil( @db.find_by_id(500) )
174
+ assert_nil( @db.find_by_id( 100..500) )
175
+
176
+ assert_raise( ArgumentError) {
177
+ @db.find_by_id("3")
178
+ }
179
+ end
180
+
181
+ def test_update_state
182
+ add_three
183
+ r1 = @db.find_by_id(1)
184
+ r1[:in_trashbox?] = :trashbox
185
+ f = @db.update_to_state_trashbox(1)
186
+ updated = @db.find_by_id(1)
187
+ assert_equal( true, f)
188
+ assert_equal( r1, updated)
189
+ assert_equal( :trashbox, updated[:in_trashbox?] )
190
+
191
+ assert_equal( 3, @db.list_all.size )
192
+ assert_equal( 2, @db.list_active.size )
193
+ assert_equal( 1, @db.list_trashbox.size )
194
+
195
+ f = @db.update_to_state_trashbox(3)
196
+ assert_equal( true, f)
197
+ assert_equal( :trashbox, @db.find_by_id(3)[:in_trashbox?] )
198
+ assert_equal( 3, @db.list_all.size )
199
+ assert_equal( 1, @db.list_active.size )
200
+ assert_equal( 2, @db.list_trashbox.size )
201
+
202
+ f = @db.update_to_state_trashbox(3)
203
+ assert_nil( f)
204
+ assert_equal( 3, @db.list_all.size )
205
+ assert_equal( 1, @db.list_active.size )
206
+ assert_equal( 2, @db.list_trashbox.size )
207
+
208
+ f = @db.update_to_state_trashbox(500)
209
+ assert_nil( f)
210
+
211
+ f = @db.update_to_state_active(1)
212
+ updated2 = @db.find_by_id(1)
213
+ updated[:in_trashbox?] = :active
214
+ updated[:updated_at] = updated2[:updated_at]
215
+ assert_equal( updated, updated2)
216
+ assert_equal( :active, updated2[:in_trashbox?] )
217
+ assert_equal( 3, @db.list_all.size )
218
+ assert_equal( 2, @db.list_active.size )
219
+ assert_equal( 1, @db.list_trashbox.size )
220
+
221
+ f = @db.update_to_state_active(1)
222
+ assert_nil( f)
223
+
224
+ assert_raise( ArgumentError) {
225
+ @db.update_to_state_active( "3")
226
+ }
227
+ assert_raise( ArgumentError) {
228
+ @db.update_to_state_trashbox( [3,4])
229
+ }
230
+ end
231
+
232
+ def test_touch
233
+ add_three
234
+ a = @db.find_by_id(1)
235
+ sleep 3
236
+ f = @db.touch( 1)
237
+ assert_equal(true, f)
238
+ b = @db.find_by_id(1)
239
+ assert( a[:updated_at] < b[:updated_at] )
240
+ b[:updated_at] = a[:updated_at]
241
+ assert_equal( a, b)
242
+
243
+ f = @db.touch(500)
244
+ assert_nil( f)
245
+ end
246
+
247
+ def test_destroy
248
+ add_three
249
+ @db.update_to_state_trashbox(3)
250
+ r3 = @db.find_by_id(3)
251
+ f = @db.destroy(3)
252
+ assert_equal( r3, f)
253
+ assert_equal( 2, @db.list_all.size )
254
+ assert_equal( 2, @db.list_active.size )
255
+ assert_equal( 0, @db.list_trashbox.size )
256
+
257
+ f = @db.destroy(3)
258
+ assert_nil(f)
259
+ f = @db.destroy(1)
260
+ assert_nil(f)
261
+ end
262
+
263
+ def test_transaction
264
+ add_three
265
+
266
+ assert_raise(RuntimeError) {
267
+ @db.transaction {
268
+ @db.update_to_state_trashbox(3)
269
+ raise
270
+ }
271
+ }
272
+ assert_equal( 3, @db.list_active.size)
273
+
274
+ assert_raise(RuntimeError) {
275
+ @db.transaction {
276
+ @db.update_to_state_trashbox(1)
277
+ @db.destroy(1)
278
+ assert_equal(2,@db.list_all.size)
279
+ raise
280
+ }
281
+ }
282
+ assert_equal( 3, @db.list_all.size)
283
+ end
284
+
285
+ end
@@ -0,0 +1,171 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+
4
+ class TC_NERA_RUN_LAYER_CONTROLLER < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @testdir = 'test_sim_controller'
8
+ FileUtils.mkdir(@testdir)
9
+ FileUtils.chdir(@testdir)
10
+ @db_folder = "nera_db"
11
+ NERA::DbFolders.create_db( @db_folder)
12
+ @dbf = NERA::DbFolders.new( @db_folder)
13
+ @slc = NERA::SimulatorLayerController.new( @db_folder)
14
+ @plc = NERA::ParameterLayerController.new( @db_folder, Ising)
15
+ pid = @plc.create_a_new_parameter_set({:L => 32, :K => 0.01, :tmax => 1})
16
+ @rlc = NERA::RunLayerController.new( @db_folder, Ising, pid)
17
+ end
18
+
19
+ def teardown
20
+ FileUtils.chdir('..')
21
+ FileUtils.rm_r(@testdir)
22
+ end
23
+
24
+ def test_constructor
25
+ assert_raise(ArgumentError) {
26
+ NERA::RunLayerController.new( @dbf,1, 1)
27
+ }
28
+ assert_raise( ArgumentError) {
29
+ NERA::RunLayerController.new( Temp,1, 1)
30
+ }
31
+ assert_raise( ArgumentError) {
32
+ x = NERA::RunLayerController.new( @db_folder, 1, "1")
33
+ }
34
+ assert_raise( ArgumentError) {
35
+ x = NERA::RunLayerController.new( @db_folder, "1", 1)
36
+ }
37
+ end
38
+
39
+ def test_path_to_run_layer
40
+ assert_equal( @rlc.path_to_run_layer, @dbf.path_to_run_layer(Ising,1) )
41
+ end
42
+
43
+ def test_all_runs_list_in_csv
44
+ header, list = @rlc.all_runs_list_in_csv
45
+ str = "id, state, created_at, job_id, seed, start_at, finish_at, included_at, real_time, user_time, host_name, omp_threads, mpi_processes"
46
+ assert_equal( str, header)
47
+ assert_equal( [], list)
48
+
49
+ #create_jobs
50
+ @rlc.create_jobs( 2, 3)
51
+ header, list = @rlc.all_runs_list_in_csv
52
+ assert_equal( str, header)
53
+ assert_equal( 6, list.size)
54
+ dstr = DateTime.now.to_s.split('T')[0]
55
+ 6.times do |i|
56
+ rid = i+1
57
+ jid = i/3 + 1
58
+ a = list[i].split(',')
59
+ assert( a.delete_at(4).to_i > 0 )
60
+ s = a.join(',')
61
+ assert_equal( "#{rid}, not_finished, #{dstr}, #{jid}, , , , , , , 1, 1", s)
62
+ end
63
+
64
+ ##################################################
65
+ # test for completed jobs ########################
66
+ ##################################################
67
+ end
68
+
69
+ def test_create_jobs
70
+ jid = @rlc.create_jobs(1)
71
+ header, list = @rlc.all_runs_list_in_csv
72
+ assert_equal( 1, list.size)
73
+ assert_equal( [1], jid)
74
+ assert( list[0].split(', ')[3].to_i > 0) # check job id
75
+
76
+ jobs_table = NERA::JobRecords.new( @dbf.path_to_jobs_table)
77
+ l = jobs_table.list_all
78
+ assert_equal( 1, l.size)
79
+
80
+ assert( File.exist?( @dbf.path_to_job_script( 1)) )
81
+
82
+ # -------------------------------------
83
+ jid = @rlc.create_jobs(3)
84
+ header, list = @rlc.all_runs_list_in_csv
85
+ assert_equal( 4, list.size)
86
+ assert_equal( [2,3,4], jid)
87
+ assert( list[1].split(', ')[3].to_i > 0) # check job id
88
+ assert( list[2].split(', ')[3].to_i > 0) # check job id
89
+ assert( list[3].split(', ')[3].to_i > 0) # check job id
90
+
91
+ jobs_table = NERA::JobRecords.new( @dbf.path_to_jobs_table)
92
+ l = jobs_table.list_all
93
+ assert_equal( 4, l.size)
94
+
95
+ assert( File.exist?( @dbf.path_to_job_script( 2)) )
96
+ assert( File.exist?( @dbf.path_to_job_script( 3)) )
97
+ assert( File.exist?( @dbf.path_to_job_script( 4)) )
98
+
99
+ # -------------------------------------
100
+ jid = @rlc.create_jobs(2, 2)
101
+ header, list = @rlc.all_runs_list_in_csv
102
+ assert_equal( 8, list.size)
103
+ assert_equal( [5,6], jid)
104
+
105
+ jobs_table = NERA::JobRecords.new( @dbf.path_to_jobs_table)
106
+ l = jobs_table.list_all
107
+ assert_equal( 6, l.size)
108
+
109
+ assert( File.exist?( @dbf.path_to_job_script( 5)) )
110
+ assert( File.exist?( @dbf.path_to_job_script( 6)) )
111
+ end
112
+
113
+ def test_not_finished_jobs_list_in_csv
114
+ header, list = @rlc.not_finished_jobs_list_in_csv
115
+ str = "job_id, created_at, run_id, num_runs, omp_threads, mpi_processes"
116
+ assert_equal( str, header)
117
+ assert_equal( [], list)
118
+
119
+ @rlc.create_jobs(1)
120
+ header, list = @rlc.not_finished_jobs_list_in_csv
121
+ assert_equal( str, header)
122
+ assert_equal( 1, list.size)
123
+ dstr = DateTime.now.to_s.split('T')[0]
124
+ assert_match( /^1, #{dstr}, 1, [0-9]+,/, list[0])
125
+
126
+ @rlc.create_jobs(3,3)
127
+ header, list = @rlc.not_finished_jobs_list_in_csv
128
+ assert_equal( str, header)
129
+ assert_equal( 4, list.size)
130
+
131
+ end
132
+
133
+ def test_cancel_jobs
134
+ jids = @rlc.create_jobs(3)
135
+ p jids
136
+ @rlc.cancel_jobs( jids)
137
+ h, l = @rlc.all_runs_list_in_csv
138
+ assert_equal( 0, l.size)
139
+
140
+ l = NERA::JobRecords.new( @dbf.path_to_jobs_table).list_all
141
+ assert_equal( 0, l.size)
142
+
143
+ jids.each do |i|
144
+ jpath = @dbf.path_to_job_script(i)
145
+ assert_equal( false, FileTest.exist?( jpath))
146
+ end
147
+
148
+ # -----------------------------
149
+ jids = @rlc.create_jobs(3)
150
+ jids.delete(4)
151
+ @rlc.cancel_jobs( jids)
152
+ h, l = @rlc.all_runs_list_in_csv
153
+ assert_equal( 1, l.size)
154
+ l = NERA::JobRecords.new( @dbf.path_to_jobs_table).list_all
155
+ assert_equal( 1, l.size)
156
+ end
157
+
158
+ def test_analyze
159
+ @rlc.analyze( "analyze_test1")
160
+ assert( FileTest.exist?( @dbf.path_to_run_layer(Ising,1) + "test1") )
161
+
162
+ assert_nil( @rlc.analyze( "hoge") )
163
+ end
164
+
165
+ def test_analyze_all
166
+ @rlc.analyze_all
167
+ assert( FileTest.exist?( @dbf.path_to_run_layer(Ising,1) + "test1") )
168
+ assert( FileTest.exist?( @dbf.path_to_run_layer(Ising,1) + "test2") )
169
+ end
170
+
171
+ end