def startSimulationBatch(self, initialization_case_name, simulation_count): with self._session.lock: if not self.isRunning(): self._session.simulation_context = None self._session.init_case_name = initialization_case_name self.ert.addDataKW("<WPRO_RUN_COUNT>", str(self._session.batch_number)) self.ert.addDataKW("<ELCO_RUN_COUNT>", str(self._session.batch_number)) self._session.batch_number += 1 self._session.simulation_context = SimulationContext( self.ert, simulation_count, verbose=self._verbose_queue)
def startSimulationBatch(self, initialization_case_name, result_case_name, simulation_count): fs_manager = self.ert.getEnkfFsManager() init_fs = fs_manager.getFileSystem(initialization_case_name) result_fs = fs_manager.getFileSystem(result_case_name) mask = BoolVector( initial_size = simulation_count, default_value = True ) with self._session.lock: if not self.isRunning(): self._session.simulation_context = None self._session.geo_case = initialization_case_name self.ert.addDataKW("<WPRO_RUN_COUNT>", str(self._session.batch_number)) self.ert.addDataKW("<ELCO_RUN_COUNT>", str(self._session.batch_number)) self._session.simulation_context = SimulationContext(self.ert, result_fs, result_fs, mask , self._session.batch_number, verbose=self._verbose_queue) self._session.batch_number += 1
def test_runpath(self): with ErtTestContext("ert/server/rpc/simulation_context_runpath", self.config2) as test_context: ert = test_context.getErt() sys.stderr.write("cwd: %s \n" % os.getcwd()) size = 10 fs = ert.getEnkfFsManager().getCurrentFileSystem() parameters = ert.ensembleConfig().getKeylistFromVarType( EnkfVarType.PARAMETER) ert.getEnkfFsManager().initializeFromScratch( parameters, 0, size - 1) simulation_context = SimulationContext(ert, size) for iens in range(size): state = ert.getRealisation(iens) if iens % 2 == 0: state.addSubstKeyword("GEO_ID", "EVEN") else: state.addSubstKeyword("GEO_ID", "ODD") simulation_context.addSimulation(iens, fs) while simulation_context.isRunning(): time.sleep(1.0) for iens in range(size): if iens % 2 == 0: path = "simulations/EVEN/realisation-%d/iter-%d" % (iens, 0) self.assertTrue(os.path.isdir(path)) else: path = "simulations/ODD/realisation-%d/iter-%d" % (iens, 0) self.assertTrue(os.path.isdir(path)) pfx = 'SimulationContext(' self.assertEqual(pfx, repr(simulation_context)[:len(pfx)])
def test_simulation_context(self): config_file = self.createTestPath( "local/snake_oil_no_data/snake_oil.ert") with ErtTestContext("ert/server/rpc/simulation_context", config_file) as test_context: ert = test_context.getErt() size = 4 mask1 = BoolVector(initial_size=size) mask2 = BoolVector(initial_size=size) for iens_2 in range(size / 2): mask1[2 * iens_2] = True mask1[2 * iens_2 + 1] = False mask2[2 * iens_2] = False mask2[2 * iens_2 + 1] = True fs_manager = ert.getEnkfFsManager() first_half = fs_manager.getFileSystem("first_half") other_half = fs_manager.getFileSystem("other_half") simulation_context1 = SimulationContext(ert, first_half, mask1, 0) simulation_context2 = SimulationContext(ert, other_half, mask2, 0) ert.createRunpath(simulation_context1.get_run_context()) ert.createRunpath(simulation_context2.get_run_context()) geo_id = 0 for iens in range(size): if iens % 2 == 0: simulation_context1.addSimulation(iens, geo_id) self.assertFalse( simulation_context1.isRealizationFinished(iens)) else: simulation_context2.addSimulation(iens, geo_id) self.assertFalse( simulation_context2.isRealizationFinished(iens)) with self.assertRaises(UserWarning): simulation_context1.addSimulation(size, geo_id) with self.assertRaises(UserWarning): simulation_context1.addSimulation(0, geo_id) while simulation_context1.isRunning(): time.sleep(1.0) while simulation_context2.isRunning(): time.sleep(1.0) self.assertEqual(simulation_context1.getNumFailed(), 0) self.assertEqual(simulation_context1.getNumRunning(), 0) self.assertEqual(simulation_context1.getNumSuccess(), size / 2) self.assertEqual(simulation_context2.getNumFailed(), 0) self.assertEqual(simulation_context2.getNumRunning(), 0) self.assertEqual(simulation_context2.getNumSuccess(), size / 2) first_half_state_map = first_half.getStateMap() other_half_state_map = other_half.getStateMap() for iens in range(size): if iens % 2 == 0: self.assertTrue( simulation_context1.didRealizationSucceed(iens)) self.assertFalse( simulation_context1.didRealizationFail(iens)) self.assertTrue( simulation_context1.isRealizationFinished(iens)) self.assertEqual(first_half_state_map[iens], RealizationStateEnum.STATE_HAS_DATA) else: self.assertTrue( simulation_context2.didRealizationSucceed(iens)) self.assertFalse( simulation_context2.didRealizationFail(iens)) self.assertTrue( simulation_context2.isRealizationFinished(iens)) self.assertEqual(other_half_state_map[iens], RealizationStateEnum.STATE_HAS_DATA)
def test_simulation_context(self): with ErtTestContext("ert/server/rpc/simulation_context", self.config1) as test_context: ert = test_context.getErt() size = 4 first_half = initializeCase(ert, "first_half", size) other_half = initializeCase(ert, "other_half", size) simulation_context = SimulationContext(ert, size) for iens in range(size): if iens % 2 == 0: simulation_context.addSimulation(iens, first_half) else: simulation_context.addSimulation(iens, other_half) self.assertFalse( simulation_context.isRealizationFinished(iens)) with self.assertRaises(UserWarning): simulation_context.addSimulation(size, first_half) with self.assertRaises(UserWarning): simulation_context.addSimulation(0, first_half) while simulation_context.isRunning(): time.sleep(1.0) self.assertEqual(simulation_context.getNumFailed(), 0) self.assertEqual(simulation_context.getNumRunning(), 0) self.assertEqual(simulation_context.getNumSuccess(), size) first_half_state_map = first_half.getStateMap() other_half_state_map = other_half.getStateMap() for iens in range(size): self.assertTrue(simulation_context.didRealizationSucceed(iens)) self.assertFalse(simulation_context.didRealizationFail(iens)) self.assertTrue(simulation_context.isRealizationFinished(iens)) if iens % 2 == 0: self.assertEqual(first_half_state_map[iens], RealizationStateEnum.STATE_HAS_DATA) self.assertEqual(other_half_state_map[iens], RealizationStateEnum.STATE_INITIALIZED) else: self.assertEqual(first_half_state_map[iens], RealizationStateEnum.STATE_INITIALIZED) self.assertEqual(other_half_state_map[iens], RealizationStateEnum.STATE_HAS_DATA) pfx = 'SimulationContext(' self.assertEqual(pfx, repr(simulation_context)[:len(pfx)])