def clientInteraction(): thread_success_state[iens] = False keywords = { "SNAKE_OIL_PARAM": [ 0.50, iens + 2, 1.750, 0.250, 0.990, 2 + client_count - iens, 1.770, 0.330, 0.550, 0.770 ] } client = ErtRPCClient("localhost", server.port) client.startSimulationBatch("default", client_count) self.assertTrue(client.isRunning()) self.assertTrue(client.isInitializationCaseAvailable()) client.addSimulation(target_case_name, 0, 0, iens, keywords) self.assertTrue( realizationIsInitialized(server.ert, target_case_name, iens)) while not client.isRealizationFinished(iens): time.sleep(0.5) self.assertTrue(client.didRealizationSucceed(iens)) result = client.getCustomKWResult(target_case_name, iens, "SNAKE_OIL_NPV") self.assertTrue("NPV" in result) self.assertTrue("RATING" in result) self.assertEqual(expected_ckw[iens]["RATING"], result["RATING"]) self.assertAlmostEqual(expected_ckw[iens]["NPV"], result["NPV"]) thread_success_state[iens] = True
def test_rpc_storage_with_simulation(self): config = self.createTestPath("local/snake_oil_no_data/snake_oil.ert") with RPCServiceContext("ert/server/rpc_storage/simulation_and_storage", config, store_area=True) as server: client = ErtRPCClient("localhost", server.port) realization_count = 2 client.prototypeStorage("SNAKEX", { "SNAKE_ID": float, "SNAKE_RUN": str }) batch_names = ["test_run_0", "test_run_1"] for batch_id, batch_name in enumerate(batch_names): self.runSimulation(client, realization_count, batch_id, batch_name) for (batch_id, batch_name), iens in product(enumerate(batch_names), range(realization_count)): result = client.getCustomKWResult(batch_name, iens, "SNAKEX") self.assertEqual(result["SNAKE_RUN"], "batch_%d" % batch_id) snake_id = realization_count * batch_id + iens self.assertEqual(result["SNAKE_ID"], snake_id)
def test_rpc_storage_with_simulation(self): config = self.createTestPath("local/snake_oil_no_data/snake_oil.ert") with RPCServiceContext("ert/server/rpc_storage/simulation_and_storage", config, store_area=True) as server: client = ErtRPCClient("localhost", server.port) realization_count = 2 client.prototypeStorage("SNAKEX", {"SNAKE_ID": float, "SNAKE_RUN": str}) batch_names = ["test_run_0", "test_run_1"] for batch_id, batch_name in enumerate(batch_names): self.runSimulation(client, realization_count, batch_id, batch_name) for (batch_id, batch_name), iens in product(enumerate(batch_names), range(realization_count)): result = client.getCustomKWResult(batch_name, iens, "SNAKEX") self.assertEqual(result["SNAKE_RUN"], "batch_%d" % batch_id) snake_id = realization_count * batch_id + iens self.assertEqual(result["SNAKE_ID"], snake_id)
def clientInteraction(): thread_success_state[iens] = False keywords = {"SNAKE_OIL_PARAM": [0.50, iens + 2, 1.750, 0.250, 0.990, 2 + client_count - iens, 1.770, 0.330, 0.550, 0.770]} client = ErtRPCClient("localhost", server.port) client.startSimulationBatch("default", client_count) self.assertTrue(client.isRunning()) self.assertTrue(client.isInitializationCaseAvailable()) client.addSimulation(target_case_name, 0, 0, iens, keywords) self.assertTrue(realizationIsInitialized(server.ert, target_case_name, iens)) while not client.isRealizationFinished(iens): time.sleep(0.5) self.assertTrue(client.didRealizationSucceed(iens)) result = client.getCustomKWResult(target_case_name, iens, "SNAKE_OIL_NPV") self.assertTrue("NPV" in result) self.assertTrue("RATING" in result) self.assertEqual(expected_ckw[iens]["RATING"], result["RATING"]) self.assertAlmostEqual(expected_ckw[iens]["NPV"], result["NPV"]) thread_success_state[iens] = True
def test_client_interaction(self): target_case_names = ["batch_1", ".batch_1", "batch_1", ".batch_1"] kw = [ {"SNAKE_OIL_PARAM": [0.50, 6, 1.750, 0.250, 0.990, 2, 1.770, 0.330, 0.550, 0.770]}, {"SNAKE_OIL_PARAM": [0.51, 7, 1.751, 0.251, 0.991, 3, 1.771, 0.331, 0.551, 0.771]}, {"SNAKE_OIL_PARAM": [0.52, 8, 1.752, 0.252, 0.992, 4, 1.772, 0.332, 0.552, 0.772]}, {"SNAKE_OIL_PARAM": [0.53, 9, 1.753, 0.253, 0.993, 5, 1.773, 0.333, 0.553, 0.773]} ] expected_state_map = { "batch_1": [RealizationStateEnum.STATE_HAS_DATA, RealizationStateEnum.STATE_UNDEFINED, RealizationStateEnum.STATE_HAS_DATA ], ".batch_1": [RealizationStateEnum.STATE_UNDEFINED, RealizationStateEnum.STATE_HAS_DATA, RealizationStateEnum.STATE_UNDEFINED, RealizationStateEnum.STATE_HAS_DATA ] } expected_custom_kw = [ {'RATING': 'EXCELLENT', 'NPV': 125692.534209}, {'RATING': 'AVERAGE', 'NPV': 87423.5773042}, {'RATING': 'GOOD', 'NPV': 113243.319848}, {'RATING': 'AVERAGE', 'NPV': 91781.8557083} ] with RPCServiceContext("ert/server/rpc/client", self.config) as server: client = ErtRPCClient("localhost", server.port) self.assertEqual(Version.currentVersion().versionTuple(), client.ertVersion()) realization_count = len(target_case_names) # with self.assertRaises(UserWarning): # client.startSimulationBatch("default", realization_count) # # initializeCase(server.ert, "default", 1) client.startSimulationBatch("default", realization_count) self.assertTrue(server.isInitializationCaseAvailable()) self.assertTrue(server.isRunning()) for iens in range(realization_count): client.addSimulation(target_case_names[iens], geo_id=0, pert_id=0, sim_id=iens, keywords=kw[iens]) self.assertTrue(realizationIsInitialized(server.ert, target_case_names[iens], iens)) while client.isRunning(): time.sleep(1) for case in expected_state_map: fs = server.ert.getEnkfFsManager().getFileSystem(case) state_map = fs.getStateMap() states = expected_state_map[case] for index, state in enumerate(states): self.assertEqual(state, state_map[index]) time_map = client.getTimeMap("batch_1") self.assertEqual(datetime.datetime(2010, 1, 1), time_map[0]) self.assertEqual(datetime.datetime(2015, 6, 13), time_map[199]) with self.assertRaises(KeyError): client.getGenDataResult(target_case_names[0], 0, 199, "UNKNOWN_KEYWORD") for iens, case in enumerate(target_case_names): self.assertTrue(client.isRealizationFinished(iens)) self.assertTrue(client.didRealizationSucceed(iens)) self.assertFalse(client.didRealizationFail(iens)) self.assertTrue(client.isCustomKWKey("SNAKE_OIL_NPV")) self.assertFalse(client.isGenDataKey("SNAKE_OIL_NPV")) self.assertTrue(client.isGenDataKey("SNAKE_OIL_OPR_DIFF")) result = client.getGenDataResult(case, iens, 199, "SNAKE_OIL_OPR_DIFF") self.assertEqual(len(result), 2000) result = client.getCustomKWResult(case, iens, "SNAKE_OIL_NPV") self.assertTrue("NPV" in result) self.assertTrue("RATING" in result) self.assertEqual(expected_custom_kw[iens]["RATING"], result["RATING"]) self.assertAlmostEqual(expected_custom_kw[iens]["NPV"], result["NPV"])