def test_name_invariant(self): """ Test that the crhonics are loaded in whatever format, but the order returned is consistent with the one of the backend. :return: """ path = os.path.join(PATH_CHRONICS, "chronics_reorder") chron_handl = ChronicsHandler(chronicsClass=GridStateFromFile, path=path) chron_handl.initialize(self.order_backend_loads, self.order_backend_prods, self.order_backend_lines, self.order_backend_subs, self.names_chronics_to_backend) _, res = chron_handl.next_time_step() # should load the first time stamp vect = np.array([18.8, 86.5, 44.5, 7.1, 10.4, 27.6, 8.1, 3.2, 5.6, 11.9, 13.6]) vect = vect[self.id_chron_to_back_load] assert self.compare_vect(res["injection"]['load_p'], vect) for i in range(287): _, res = chron_handl.next_time_step() # should load the first time stamp vect = np.array([19.0, 87.9, 44.4, 7.2, 10.4, 27.5, 8.4, 3.2, 5.7, 12.2, 13.6]) vect = vect[self.id_chron_to_back_load] assert self.compare_vect(res["injection"]['load_p'], vect) try: _, res = chron_handl.next_time_step() # should load the first time stamp raise RuntimeError("This should have thrown a StopIteration exception") except StopIteration: pass
def test_chronicsloading_secondtimestep(self): chron_handl = ChronicsHandler(chronicsClass=GridStateFromFile, path=self.path) chron_handl.initialize(self.order_backend_loads, self.order_backend_prods, self.order_backend_lines, self.order_backend_subs) _ = chron_handl.next_time_step() # should load the first time stamp _, res = chron_handl.next_time_step() # should load the first time stamp vect = [18.8, 85.1, 44.3, 7.1, 10.2, 27.1, 8.2, 3.2, 5.7, 11.8, 13.8] assert self.compare_vect(res["injection"]['load_p'], vect)
def test_stopiteration(self): chron_handl = ChronicsHandler(chronicsClass=GridStateFromFile, path=self.path) chron_handl.initialize(self.order_backend_loads, self.order_backend_prods, self.order_backend_lines, self.order_backend_subs) for i in range(288): _, res = chron_handl.next_time_step() # should load the first time stamp vect = [19.0, 87.9, 44.4, 7.2, 10.4, 27.5, 8.4, 3.2, 5.7, 12.2, 13.6] assert self.compare_vect(res["injection"]['load_p'], vect) try: res = chron_handl.next_time_step() # should load the first time stamp raise RuntimeError("This should have thrown a StopIteration exception") except StopIteration: pass
def test_chronicsloading_chunk(self): chron_handl = ChronicsHandler(chronicsClass=GridStateFromFile, path=self.path, chunk_size=5) chron_handl.initialize(self.order_backend_loads, self.order_backend_prods, self.order_backend_lines, self.order_backend_subs) _, res, *_ = chron_handl.next_time_step() # should load the first time stamp vect = [18.8, 86.5, 44.5, 7.1, 10.4, 27.6, 8.1, 3.2, 5.6, 11.9, 13.6] assert self.compare_vect(res["injection"]['load_p'], vect)
def test_stopiteration(self): chron_handl = ChronicsHandler(chronicsClass=Multifolder, path=self.path, gridvalueClass=GridStateFromFileWithForecasts, max_iter=self.max_iter) chron_handl.initialize(self.order_backend_loads, self.order_backend_prods, self.order_backend_lines, self.order_backend_subs, self.names_chronics_to_backend) _, res, *_ = chron_handl.next_time_step() # should load the first time stamp for i in range(self.max_iter): _, res, *_ = chron_handl.next_time_step() # should load the first time stamp try: _, res, *_ = chron_handl.next_time_step() # should load the first time stamp raise RuntimeError("This should have thrown a StopIteration exception") except StopIteration: pass
def test_done(self): chron_handl = ChronicsHandler(chronicsClass=GridStateFromFile, path=self.path) chron_handl.initialize(self.order_backend_loads, self.order_backend_prods, self.order_backend_lines, self.order_backend_subs) for i in range(288): _, res = chron_handl.next_time_step() # should load the first time stamp vect = [19.0, 87.9, 44.4, 7.2, 10.4, 27.5, 8.4, 3.2, 5.7, 12.2, 13.6] assert self.compare_vect(res["injection"]['load_p'], vect) assert chron_handl.done()
def test_chronicsloading(self): chron_handl = ChronicsHandler(chronicsClass=GridStateFromFile, path=self.path) chron_handl.initialize(self.order_backend_loads, self.order_backend_prods, self.order_backend_lines, self.order_backend_subs, self.names_chronics_to_backend) _, res = chron_handl.next_time_step() # should load the first time stamp vect = np.array([18.8, 86.5, 44.5, 7.1, 10.4, 27.6, 8.1, 3.2, 5.6, 11.9, 13.6]) # what is written on the file backend_th = vect[self.id_chron_to_back_load] # what should be in backend assert self.compare_vect(res["injection"]['load_p'], backend_th)
def test_done_chunk_size(self): chron_handl = ChronicsHandler(chronicsClass=GridStateFromFile, path=self.path, chunk_size=1) chron_handl.initialize(self.order_backend_loads, self.order_backend_prods, self.order_backend_lines, self.order_backend_subs, self.names_chronics_to_backend) for i in range(288): _, res, *_ = chron_handl.next_time_step() # should load the first time stamp vect = np.array([19.0, 87.9, 44.4, 7.2, 10.4, 27.5, 8.4, 3.2, 5.7, 12.2, 13.6]) vect = vect[self.id_chron_to_back_load] assert self.compare_vect(res["injection"]['load_p'], vect) assert chron_handl.done()
def test_loadchornics_hazard_ok(self): chron_handl = ChronicsHandler(chronicsClass=GridStateFromFile, path=self.path_hazard) chron_handl.initialize(self.order_backend_loads, self.order_backend_prods, self.order_backend_lines, self.order_backend_subs) current_datetime, dict_, maintenance_time, maintenance_duration, hazard_duration, prod_v = chron_handl.next_time_step() assert np.all(hazard_duration == 0) for i in range(12): current_datetime, dict_, maintenance_time, maintenance_duration, hazard_duration, prod_v = chron_handl.next_time_step() assert np.sum(hazard_duration == 0) == 19 assert hazard_duration[17] == 12-i, "error at iteration {}".format(i) current_datetime, dict_, maintenance_time, maintenance_duration, hazard_duration, prod_v = chron_handl.next_time_step() assert np.all(hazard_duration == 0)
def test_loadchornics_maintenance_ok(self): chron_handl = ChronicsHandler(chronicsClass=GridStateFromFile, path=self.path_maintenance) chron_handl.initialize(self.order_backend_loads, self.order_backend_prods, self.order_backend_lines, self.order_backend_subs) current_datetime, dict_, maintenance_time, maintenance_duration, hazard_duration, prod_v = chron_handl.next_time_step() assert np.sum(maintenance_duration == 0) == 18 assert maintenance_duration[17] == 12, "incorrect duration of maintenance on powerline 17" assert maintenance_duration[19] == 12, "incorrect duration of maintenance on powerline 19" assert np.sum(maintenance_time == -1) == 18 assert maintenance_time[17] == 1, "incorrect time for next maintenance on powerline 17" assert maintenance_time[19] == 276, "incorrect time for next maintenance on powerline 19" for i in range(12): current_datetime, dict_, maintenance_time, maintenance_duration, hazard_duration, prod_v = chron_handl.next_time_step() assert np.sum(maintenance_duration == 0) == 18 assert int(maintenance_duration[17]) == int(12-i), "incorrect duration of maintenance on powerline 17 at iteration {}: it is {} and should be {}".format(i, maintenance_duration[17], int(12-i)) assert maintenance_duration[19] == 12, "incorrect duration of maintenance on powerline 19 at iteration {}".format(i) assert np.sum(maintenance_time == -1) == 18 assert maintenance_time[17] == 0, "incorrect time for next maintenance on powerline 17 at iteration {}".format(i) assert maintenance_time[19] == 275-i, "incorrect time for next maintenance on powerline 19 at iteration {}".format(i) current_datetime, dict_, maintenance_time, maintenance_duration, hazard_duration, prod_v = chron_handl.next_time_step() assert np.sum(maintenance_duration == 0) == 19 assert maintenance_duration[19] == 12, "incorrect duration of maintenance on powerline 19 at finish" assert np.sum(maintenance_time == -1) == 19 assert maintenance_time[19] == 263, "incorrect time for next maintenance on powerline 19 at finish"