nera 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +9 -0
- data/lib/nera/nera_cui.rb +5 -5
- data/lib/nera/nera_job_layer_controller.rb +4 -3
- data/lib/nera/nera_parameter_layer_controller.rb +10 -6
- data/lib/nera/nera_run_layer_controller.rb +16 -5
- data/lib/nera/nera_simulator_layer_controller.rb +8 -0
- data/lib/nera.rb +1 -1
- data/test/test_nera_job_layer_controller.rb +4 -1
- data/test/test_nera_parameter_layer_controller.rb +4 -1
- data/test/test_nera_run_layer_controller.rb +16 -7
- data/test/test_nera_simulator_layer_controller.rb +10 -1
- metadata +9 -5
    
        data/History.txt
    CHANGED
    
    | @@ -1,3 +1,12 @@ | |
| 1 | 
            +
            == 0.1.2
         | 
| 2 | 
            +
            * 1 major enhancement:
         | 
| 3 | 
            +
              * constructor of ParamLayerController now accepts String type simulator name.
         | 
| 4 | 
            +
              * constructor of RunLayerController now accepts String type simulator name.
         | 
| 5 | 
            +
              * RunLayerController#cancel_jobs returns an array of cancelled job ids.
         | 
| 6 | 
            +
              * JobLayerController#cancel_jobs returns an array of cancelled job ids.
         | 
| 7 | 
            +
            * 2 bug fixes
         | 
| 8 | 
            +
              * require statements of NERA::Simulator classes become sooner.
         | 
| 9 | 
            +
             | 
| 1 10 | 
             
            == 0.1.1
         | 
| 2 11 | 
             
            * 1 major enhancement:
         | 
| 3 12 | 
             
            * 2 bug fixes
         | 
    
        data/lib/nera/nera_cui.rb
    CHANGED
    
    | @@ -88,7 +88,7 @@ HEADER | |
| 88 88 | 
             
                  elsif names[selected] == "exit"
         | 
| 89 89 | 
             
                    return :exit
         | 
| 90 90 | 
             
                  else
         | 
| 91 | 
            -
                    @simulator_class =  | 
| 91 | 
            +
                    @simulator_class = names[selected]
         | 
| 92 92 | 
             
                    return :parameter_layer
         | 
| 93 93 | 
             
                  end
         | 
| 94 94 | 
             
                end
         | 
| @@ -98,14 +98,14 @@ HEADER | |
| 98 98 |  | 
| 99 99 | 
             
                  plc = NERA::ParameterLayerController.new( @path_db_folder, @simulator_class)
         | 
| 100 100 | 
             
                  unless plc
         | 
| 101 | 
            -
                    Dialog::message("Specified simulator does not exist #{@path_db_folder}/#{@simulator_class | 
| 101 | 
            +
                    Dialog::message("Specified simulator does not exist #{@path_db_folder}/#{@simulator_class}")
         | 
| 102 102 | 
             
                    return :simulator_layer
         | 
| 103 103 | 
             
                  end
         | 
| 104 104 |  | 
| 105 105 | 
             
                  $stdout.puts <<"HEADER"
         | 
| 106 106 | 
             
            ===============================================
         | 
| 107 107 | 
             
            --- in parameter layer ------------------------
         | 
| 108 | 
            -
              #{@path_db_folder} / #{@simulator_class | 
| 108 | 
            +
              #{@path_db_folder} / #{@simulator_class}
         | 
| 109 109 | 
             
            ===============================================
         | 
| 110 110 | 
             
            HEADER
         | 
| 111 111 |  | 
| @@ -212,14 +212,14 @@ HEADER | |
| 212 212 |  | 
| 213 213 | 
             
                  rlc = NERA::RunLayerController.new( @path_db_folder, @simulator_class, @parameter_id)
         | 
| 214 214 | 
             
                  unless rlc
         | 
| 215 | 
            -
                    Dialog::message("Table #{@path_db_folder}/#{@simulator_class | 
| 215 | 
            +
                    Dialog::message("Table #{@path_db_folder}/#{@simulator_class}/#{@parameter_id} is not found.")
         | 
| 216 216 | 
             
                    return :parameter_layer
         | 
| 217 217 | 
             
                  end
         | 
| 218 218 |  | 
| 219 219 | 
             
                  $stdout.puts <<"HEADER"
         | 
| 220 220 | 
             
            ===============================================
         | 
| 221 221 | 
             
            --- in run layer ------------------------------
         | 
| 222 | 
            -
              #{@path_db_folder} / #{@simulator_class | 
| 222 | 
            +
              #{@path_db_folder} / #{@simulator_class} / #{@parameter_id}
         | 
| 223 223 | 
             
            ===============================================
         | 
| 224 224 | 
             
            HEADER
         | 
| 225 225 |  | 
| @@ -57,7 +57,7 @@ module NERA | |
| 57 57 | 
             
                    raise ArgumentError, "each element of job_ids must be an Integer" unless x.is_a?(Integer)
         | 
| 58 58 | 
             
                  end
         | 
| 59 59 |  | 
| 60 | 
            -
                   | 
| 60 | 
            +
                  destroyed_jobids = []
         | 
| 61 61 | 
             
                  @job_records.transaction {
         | 
| 62 62 | 
             
                    job_ids.each do |jid|
         | 
| 63 63 | 
             
                      d = @job_records.destroy( jid)
         | 
| @@ -75,11 +75,12 @@ module NERA | |
| 75 75 | 
             
                        YAML.dump( run_records.list_all, io)
         | 
| 76 76 | 
             
                        io.flush
         | 
| 77 77 | 
             
                      end
         | 
| 78 | 
            -
                       | 
| 78 | 
            +
                      destroyed_jobids << jid
         | 
| 79 79 | 
             
                    end
         | 
| 80 80 | 
             
                  }
         | 
| 81 81 | 
             
                  dump_in_yaml
         | 
| 82 | 
            -
                   | 
| 82 | 
            +
                  destroyed_jobids = nil if destroyed_jobids.size == 0
         | 
| 83 | 
            +
                  return destroyed_jobids
         | 
| 83 84 | 
             
                end
         | 
| 84 85 |  | 
| 85 86 | 
             
                def include_list
         | 
| @@ -16,15 +16,19 @@ module NERA | |
| 16 16 | 
             
                # instance of NERA::ParameterRecords
         | 
| 17 17 | 
             
                @param_records
         | 
| 18 18 |  | 
| 19 | 
            -
                def initialize( path_db_folder,  | 
| 19 | 
            +
                def initialize( path_db_folder, sim_name)
         | 
| 20 20 | 
             
                  raise ArgumentError unless path_db_folder.is_a?(String)
         | 
| 21 | 
            -
                  unless sim_class.is_a?(Class) and sim_class.superclass == NERA::Simulator
         | 
| 22 | 
            -
                    raise ArgumentError, "#{sim_class} is not a subclass of NERA::Simulator"
         | 
| 23 | 
            -
                  end
         | 
| 24 | 
            -
                  
         | 
| 25 21 | 
             
                  @db_folders = NERA::DbFolders.new( path_db_folder)
         | 
| 26 22 | 
             
                  sim_records = NERA::SimulatorRecords.new( @db_folders.path_to_simulators_table)
         | 
| 27 | 
            -
                   | 
| 23 | 
            +
                  found = sim_records.list.find do |rec|
         | 
| 24 | 
            +
                    rec[:name] == sim_name.to_s
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
                  raise "No such simulator." unless found
         | 
| 27 | 
            +
                  @sim_class = NERA::Simulator.inherited_simulators.find do |sim|
         | 
| 28 | 
            +
                    sim.to_s == sim_name.to_s
         | 
| 29 | 
            +
                  end
         | 
| 30 | 
            +
                  raise "No such simulator." unless @sim_class
         | 
| 31 | 
            +
                  
         | 
| 28 32 | 
             
                  p_tab_path = @db_folders.path_to_parameters_table( @sim_class)
         | 
| 29 33 | 
             
                  @param_records = NERA::ParameterRecords.new( p_tab_path, @sim_class)
         | 
| 30 34 | 
             
                end
         | 
| @@ -20,17 +20,25 @@ module NERA | |
| 20 20 | 
             
                # instance of NERA::RunRecords
         | 
| 21 21 | 
             
                @run_records
         | 
| 22 22 |  | 
| 23 | 
            -
                def initialize( path_db_folder,  | 
| 23 | 
            +
                def initialize( path_db_folder, sim_name, param_id)
         | 
| 24 24 | 
             
                  raise ArgumentError unless path_db_folder.is_a?(String)
         | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 25 | 
            +
             | 
| 26 | 
            +
                  @db_folders = NERA::DbFolders.new( path_db_folder)
         | 
| 27 | 
            +
                  sim_records = NERA::SimulatorRecords.new( @db_folders.path_to_simulators_table)
         | 
| 28 | 
            +
                  found = sim_records.list.find do |rec|
         | 
| 29 | 
            +
                    rec[:name] == sim_name.to_s
         | 
| 27 30 | 
             
                  end
         | 
| 31 | 
            +
                  raise "No such simulator : #{sim_name.to_s}" unless found
         | 
| 32 | 
            +
                  sim_class = NERA::Simulator.inherited_simulators.find do |sim|
         | 
| 33 | 
            +
                    sim.to_s == sim_name.to_s
         | 
| 34 | 
            +
                  end
         | 
| 35 | 
            +
                  raise "No such simulator : #{sim_name.to_s}" unless sim_class
         | 
| 28 36 |  | 
| 29 | 
            -
                  @db_folders = NERA::DbFolders.new( path_db_folder)
         | 
| 30 37 | 
             
                  @sim_instance = sim_class.new
         | 
| 31 38 | 
             
                  @param_id = param_id
         | 
| 32 39 | 
             
                  param_records = NERA::ParameterRecords.new( @db_folders.path_to_parameters_table( sim_class), sim_class)
         | 
| 33 40 | 
             
                  found = param_records.find_by_id( @param_id)
         | 
| 41 | 
            +
                  raise "No such parameter : #{param_id}." unless found
         | 
| 34 42 | 
             
                  @sim_instance.class::Parameters.each do |pa|
         | 
| 35 43 | 
             
                    key = pa[0]
         | 
| 36 44 | 
             
                    if found[key]
         | 
| @@ -124,6 +132,7 @@ module NERA | |
| 124 132 | 
             
                  end
         | 
| 125 133 |  | 
| 126 134 | 
             
                  job_recs = NERA::JobRecords.new( @db_folders.path_to_jobs_table)
         | 
| 135 | 
            +
                  destroyed_jobids = []
         | 
| 127 136 | 
             
                  job_recs.transaction {
         | 
| 128 137 | 
             
                    @run_records.transaction {
         | 
| 129 138 | 
             
                      job_ids.each do |jid|
         | 
| @@ -132,11 +141,13 @@ module NERA | |
| 132 141 | 
             
                        a = @run_records.destroy_job_id( jid)
         | 
| 133 142 | 
             
                        raise "must not happen" unless a
         | 
| 134 143 | 
             
                        FileUtils.rm( @db_folders.path_to_job_script(jid) )
         | 
| 144 | 
            +
                        destroyed_jobids << jid
         | 
| 135 145 | 
             
                      end
         | 
| 136 146 | 
             
                    }
         | 
| 137 147 | 
             
                  }
         | 
| 138 148 | 
             
                  dump_in_yaml( job_recs)
         | 
| 139 | 
            -
                   | 
| 149 | 
            +
                  destroyed_jobids = nil if destroyed_jobids.size == 0
         | 
| 150 | 
            +
                  return destroyed_jobids
         | 
| 140 151 | 
             
                end
         | 
| 141 152 |  | 
| 142 153 | 
             
                def analysis_methods
         | 
| @@ -35,6 +35,14 @@ module NERA | |
| 35 35 | 
             
                def path_to_sim_layer
         | 
| 36 36 | 
             
                  @db_folders.path_to_simulator_layer
         | 
| 37 37 | 
             
                end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                def get_class_by_name( sim_name)
         | 
| 40 | 
            +
                  raise ArgumentError unless sim_name.is_a?(String)
         | 
| 41 | 
            +
                  found = NERA::Simulator.inherited_simulators.find do |sim|
         | 
| 42 | 
            +
                    sim.to_s == sim_name
         | 
| 43 | 
            +
                  end
         | 
| 44 | 
            +
                  return found
         | 
| 45 | 
            +
                end
         | 
| 38 46 |  | 
| 39 47 | 
             
                private
         | 
| 40 48 | 
             
                def register_a_simulator( sim_klass)
         | 
    
        data/lib/nera.rb
    CHANGED
    
    
| @@ -56,7 +56,7 @@ class TC_NERA_JOB_LAYER_CONTROLLER < Test::Unit::TestCase | |
| 56 56 | 
             
                }
         | 
| 57 57 |  | 
| 58 58 | 
             
                f = @jlc.cancel_jobs( [1,2] )
         | 
| 59 | 
            -
                 | 
| 59 | 
            +
                assert_equal([1,2], f)
         | 
| 60 60 | 
             
                h, l = @jlc.not_finished_list_in_csv
         | 
| 61 61 | 
             
                assert_equal( 1, l.size)
         | 
| 62 62 | 
             
                assert_equal( 3, l[0].split(',')[0].to_i)
         | 
| @@ -71,6 +71,9 @@ class TC_NERA_JOB_LAYER_CONTROLLER < Test::Unit::TestCase | |
| 71 71 |  | 
| 72 72 | 
             
                f = @jlc.cancel_jobs( [1000] )
         | 
| 73 73 | 
             
                assert_nil( f)
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                f = @jlc.cancel_jobs( [2,3] )
         | 
| 76 | 
            +
                assert_equal( [3], f)
         | 
| 74 77 | 
             
              end
         | 
| 75 78 |  | 
| 76 79 | 
             
              def test_include_list
         | 
| @@ -11,7 +11,7 @@ class TC_NERA_PARAM_LAYER_CONTROLLER < Test::Unit::TestCase | |
| 11 11 | 
             
                NERA::DbFolders.create_db( @db_folder)
         | 
| 12 12 | 
             
                @dbf = NERA::DbFolders.new( @db_folder)
         | 
| 13 13 | 
             
                @slc = NERA::SimulatorLayerController.new( @db_folder)
         | 
| 14 | 
            -
                @plc = NERA::ParameterLayerController.new( @db_folder, Ising)
         | 
| 14 | 
            +
                @plc = NERA::ParameterLayerController.new( @db_folder, "Ising")
         | 
| 15 15 | 
             
              end
         | 
| 16 16 |  | 
| 17 17 | 
             
              def teardown
         | 
| @@ -29,6 +29,9 @@ class TC_NERA_PARAM_LAYER_CONTROLLER < Test::Unit::TestCase | |
| 29 29 | 
             
                assert_raise( ArgumentError) {
         | 
| 30 30 | 
             
                  x = NERA::ParameterLayerController.new( @dbf, "1")
         | 
| 31 31 | 
             
                }
         | 
| 32 | 
            +
                assert_raise( RuntimeError) {
         | 
| 33 | 
            +
                  x = NERA::ParameterLayerController.new( @db_folder, "Unknown")
         | 
| 34 | 
            +
                }
         | 
| 32 35 | 
             
              end
         | 
| 33 36 |  | 
| 34 37 | 
             
              def test_parameters_list_in_csv
         | 
| @@ -11,9 +11,9 @@ class TC_NERA_RUN_LAYER_CONTROLLER < Test::Unit::TestCase | |
| 11 11 | 
             
                NERA::DbFolders.create_db( @db_folder)
         | 
| 12 12 | 
             
                @dbf = NERA::DbFolders.new( @db_folder)
         | 
| 13 13 | 
             
                @slc = NERA::SimulatorLayerController.new( @db_folder)
         | 
| 14 | 
            -
                @plc = NERA::ParameterLayerController.new( @db_folder, Ising)
         | 
| 14 | 
            +
                @plc = NERA::ParameterLayerController.new( @db_folder, "Ising")
         | 
| 15 15 | 
             
                pid = @plc.create_a_new_parameter_set({:L => 32, :K => 0.01, :tmax => 1})
         | 
| 16 | 
            -
                @rlc = NERA::RunLayerController.new( @db_folder, Ising, pid)
         | 
| 16 | 
            +
                @rlc = NERA::RunLayerController.new( @db_folder, "Ising", pid)
         | 
| 17 17 | 
             
              end
         | 
| 18 18 |  | 
| 19 19 | 
             
              def teardown
         | 
| @@ -28,12 +28,18 @@ class TC_NERA_RUN_LAYER_CONTROLLER < Test::Unit::TestCase | |
| 28 28 | 
             
                assert_raise( ArgumentError) {
         | 
| 29 29 | 
             
                  NERA::RunLayerController.new( Temp,1, 1)
         | 
| 30 30 | 
             
                }
         | 
| 31 | 
            -
                assert_raise(  | 
| 31 | 
            +
                assert_raise( RuntimeError) {
         | 
| 32 32 | 
             
                  x = NERA::RunLayerController.new( @db_folder, 1, "1")
         | 
| 33 33 | 
             
                }
         | 
| 34 | 
            -
                assert_raise(  | 
| 34 | 
            +
                assert_raise( RuntimeError) {
         | 
| 35 35 | 
             
                  x = NERA::RunLayerController.new( @db_folder, "1", 1)
         | 
| 36 36 | 
             
                }
         | 
| 37 | 
            +
                assert_raise( RuntimeError) {
         | 
| 38 | 
            +
                  x = NERA::RunLayerController.new( @db_folder, "Unknown", 1)
         | 
| 39 | 
            +
                }
         | 
| 40 | 
            +
                assert_raise( RuntimeError) {
         | 
| 41 | 
            +
                  x = NERA::RunLayerController.new( @db_folder, "Ising", 2)
         | 
| 42 | 
            +
                }
         | 
| 37 43 | 
             
              end
         | 
| 38 44 |  | 
| 39 45 | 
             
              def test_path_to_run_layer
         | 
| @@ -133,7 +139,8 @@ class TC_NERA_RUN_LAYER_CONTROLLER < Test::Unit::TestCase | |
| 133 139 | 
             
              def test_cancel_jobs
         | 
| 134 140 | 
             
                jids = @rlc.create_jobs(3)
         | 
| 135 141 | 
             
                p jids
         | 
| 136 | 
            -
                @rlc.cancel_jobs( jids)
         | 
| 142 | 
            +
                canceled = @rlc.cancel_jobs( jids)
         | 
| 143 | 
            +
                assert_equal( jids, canceled)
         | 
| 137 144 | 
             
                h, l = @rlc.all_runs_list_in_csv
         | 
| 138 145 | 
             
                assert_equal( 0, l.size)
         | 
| 139 146 |  | 
| @@ -147,8 +154,10 @@ class TC_NERA_RUN_LAYER_CONTROLLER < Test::Unit::TestCase | |
| 147 154 |  | 
| 148 155 | 
             
                # -----------------------------
         | 
| 149 156 | 
             
                jids = @rlc.create_jobs(3)
         | 
| 150 | 
            -
                jids.delete(4)
         | 
| 151 | 
            -
                @rlc.cancel_jobs( jids)
         | 
| 157 | 
            +
                canceled = jids.delete(4)
         | 
| 158 | 
            +
                canceled = @rlc.cancel_jobs( jids)
         | 
| 159 | 
            +
                assert_equal( [5,6], canceled)
         | 
| 160 | 
            +
                assert_nil( @rlc.cancel_jobs( [5,6]) )
         | 
| 152 161 | 
             
                h, l = @rlc.all_runs_list_in_csv
         | 
| 153 162 | 
             
                assert_equal( 1, l.size)
         | 
| 154 163 | 
             
                l = NERA::JobRecords.new( @dbf.path_to_jobs_table).list_all
         | 
| @@ -49,6 +49,15 @@ class TC_NERA_SIM_LAYER_CONTROLLER < Test::Unit::TestCase | |
| 49 49 | 
             
                p = @slc.path_to_sim_layer
         | 
| 50 50 | 
             
                assert_equal( @db_folder+'/', p)
         | 
| 51 51 | 
             
              end
         | 
| 52 | 
            -
             | 
| 52 | 
            +
             | 
| 53 | 
            +
              def test_get_class_by_name
         | 
| 54 | 
            +
                found = @slc.get_class_by_name('Ising')
         | 
| 55 | 
            +
                assert_equal( found, Ising)
         | 
| 56 | 
            +
                assert_raise(ArgumentError) {
         | 
| 57 | 
            +
                  found = @slc.get_class_by_name(1)
         | 
| 58 | 
            +
                }
         | 
| 59 | 
            +
                found = @slc.get_class_by_name('Unknown_simulator')
         | 
| 60 | 
            +
                assert_nil(found)
         | 
| 61 | 
            +
              end
         | 
| 53 62 |  | 
| 54 63 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: nera
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors: 
         | 
| 7 7 | 
             
            - Yohsuke Murase
         | 
| @@ -9,7 +9,7 @@ autorequire: | |
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 11 |  | 
| 12 | 
            -
            date: 2009-05- | 
| 12 | 
            +
            date: 2009-05-18 00:00:00 +09:00
         | 
| 13 13 | 
             
            default_executable: 
         | 
| 14 14 | 
             
            dependencies: 
         | 
| 15 15 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| @@ -52,7 +52,9 @@ dependencies: | |
| 52 52 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 53 53 | 
             
                    version: 1.8.0
         | 
| 54 54 | 
             
                version: 
         | 
| 55 | 
            -
            description:  | 
| 55 | 
            +
            description: |-
         | 
| 56 | 
            +
              This is an application which helps you to manage a database for the Monte Carlo simulations. 
         | 
| 57 | 
            +
              For the dtailed usage, see http://nera.rubyforge.com
         | 
| 56 58 | 
             
            email: 
         | 
| 57 59 | 
             
            - murase@serow.t.u-tokyo.ac.jp
         | 
| 58 60 | 
             
            executables: 
         | 
| @@ -112,6 +114,8 @@ files: | |
| 112 114 | 
             
            - test/test_nera_simulator_records.rb
         | 
| 113 115 | 
             
            has_rdoc: true
         | 
| 114 116 | 
             
            homepage: http://nera.rubyforge.com
         | 
| 117 | 
            +
            licenses: []
         | 
| 118 | 
            +
             | 
| 115 119 | 
             
            post_install_message: 
         | 
| 116 120 | 
             
            rdoc_options: 
         | 
| 117 121 | 
             
            - --main
         | 
| @@ -133,9 +137,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 133 137 | 
             
            requirements: []
         | 
| 134 138 |  | 
| 135 139 | 
             
            rubyforge_project: nera
         | 
| 136 | 
            -
            rubygems_version: 1. | 
| 140 | 
            +
            rubygems_version: 1.3.3
         | 
| 137 141 | 
             
            signing_key: 
         | 
| 138 | 
            -
            specification_version:  | 
| 142 | 
            +
            specification_version: 3
         | 
| 139 143 | 
             
            summary: This is an application which helps you to manage a database for the Monte Carlo simulations
         | 
| 140 144 | 
             
            test_files: 
         | 
| 141 145 | 
             
            - test/test_helper.rb
         |