def check_validity(self, backend): at_least_one = False if self.load_p is not None: if self.load_p.shape[1] != backend.n_load: msg_err = "for the active part. It should be {} but is in fact {}" raise IncorrectNumberOfLoads( msg_err.format(backend.n_load, self.load_p.shape[1])) at_least_one = True if self.load_q is not None: if self.load_q.shape[1] != backend.n_load: msg_err = "for the reactive part. It should be {} but is in fact {}" raise IncorrectNumberOfLoads( msg_err.format(backend.n_load, self.load_q.shape[1])) at_least_one = True if self.prod_p is not None: if self.prod_p.shape[1] != backend.n_gen: msg_err = "for the active part. It should be {} but is in fact {}" raise IncorrectNumberOfGenerators( msg_err.format(backend.n_gen, self.prod_p.shape[1])) at_least_one = True if self.prod_v is not None: if self.prod_v.shape[1] != backend.n_gen: msg_err = "for the voltage part. It should be {} but is in fact {}" raise IncorrectNumberOfGenerators( msg_err.format(backend.n_gen, self.prod_v.shape[1])) at_least_one = True if self.hazards is not None: if self.hazards.shape[1] != backend.n_line: msg_err = "for the outage. It should be {} but is in fact {}" raise IncorrectNumberOfLines( msg_err.format(backend.n_line, self.hazards.shape[1])) at_least_one = True if self.maintenance is not None: if self.maintenance.shape[1] != backend.n_line: msg_err = "for the maintenance. It should be {} but is in fact {}" raise IncorrectNumberOfLines( msg_err.format(backend.n_line, self.maintenance.shape[1])) at_least_one = True if self.maintenance_time is not None: if self.maintenance_time.shape[1] != backend.n_line: msg_err = "for the maintenance times. It should be {} but is in fact {}" raise IncorrectNumberOfLines( msg_err.format(backend.n_line, self.maintenance_time.shape[1])) at_least_one = True if self.maintenance_duration is not None: if self.maintenance_duration.shape[1] != backend.n_line: msg_err = "for the maintenance durations. It should be {} but is in fact {}" raise IncorrectNumberOfLines( msg_err.format(backend.n_line, self.maintenance_duration.shape[1])) at_least_one = True if self.hazard_duration is not None: if self.hazard_duration.shape[1] != backend.n_line: msg_err = "for the hazard durations. It should be {} but is in fact {}" raise IncorrectNumberOfLines( msg_err.format(backend.n_line, self.hazard_duration.shape[1])) at_least_one = True if not at_least_one: raise ChronicsError( "No files are found in directory \"{}\". If you don't want to load any chronics, use " "\"ChangeNothing\" and not \"{}\" to load chronics." "".format(self.path, type(self))) for name_arr, arr in zip([ "load_q", "load_p", "prod_v", "prod_p", "maintenance", "hazards", "maintenance time", "maintenance duration", "hazard duration" ], [ self.load_q, self.load_p, self.prod_v, self.prod_p, self.maintenance, self.hazards, self.maintenance_time, self.maintenance_duration, self.hazard_duration ]): if arr is not None: if self.chunk_size is None: if arr.shape[0] != self.n_: msg_err = "Array {} has not the same number of rows than the maintenance. " \ "The chronics cannot be loaded properly." raise EnvError(msg_err.format(name_arr)) if self.max_iter > 0: if self.max_iter > self.n_: msg_err = "Files count {} rows and you ask this episode to last at {} timestep." raise InsufficientData(msg_err.format(self.n_, self.max_iter))
def check_validity(self, backend): """ A call to this method ensure that the action that will be sent to the current :class:`grid2op.Environment` can be properly implemented by its :class:`grid2op.Backend`. This specific method check that the dimension of all vectors are consistent Parameters ---------- backend: :class:`grid2op.Backend.Backend` The backend used by the :class:`grid2op.Environment.Environment` Returns ------- ``None`` """ at_least_one = False if self.load_p is not None: if self.load_p.shape[1] != backend.n_load: msg_err = "for the active part. It should be {} but is in fact {}" raise IncorrectNumberOfLoads( msg_err.format(backend.n_load, self.load_p.shape[1])) at_least_one = True if self.load_q is not None: if self.load_q.shape[1] != backend.n_load: msg_err = "for the reactive part. It should be {} but is in fact {}" raise IncorrectNumberOfLoads( msg_err.format(backend.n_load, self.load_q.shape[1])) at_least_one = True if self.prod_p is not None: if self.prod_p.shape[1] != backend.n_gen: msg_err = "for the active part. It should be {} but is in fact {}" raise IncorrectNumberOfGenerators( msg_err.format(backend.n_gen, self.prod_p.shape[1])) at_least_one = True if self.prod_v is not None: if self.prod_v.shape[1] != backend.n_gen: msg_err = "for the voltage part. It should be {} but is in fact {}" raise IncorrectNumberOfGenerators( msg_err.format(backend.n_gen, self.prod_v.shape[1])) at_least_one = True if self.hazards is not None: if self.hazards.shape[1] != backend.n_line: msg_err = "for the outage. It should be {} but is in fact {}" raise IncorrectNumberOfLines( msg_err.format(backend.n_line, self.hazards.shape[1])) at_least_one = True if self.maintenance is not None: if self.maintenance.shape[1] != backend.n_line: msg_err = "for the maintenance. It should be {} but is in fact {}" raise IncorrectNumberOfLines( msg_err.format(backend.n_line, self.maintenance.shape[1])) at_least_one = True if self.maintenance_time is not None: if self.maintenance_time.shape[1] != backend.n_line: msg_err = "for the maintenance times. It should be {} but is in fact {}" raise IncorrectNumberOfLines( msg_err.format(backend.n_line, self.maintenance_time.shape[1])) at_least_one = True if self.maintenance_duration is not None: if self.maintenance_duration.shape[1] != backend.n_line: msg_err = "for the maintenance durations. It should be {} but is in fact {}" raise IncorrectNumberOfLines( msg_err.format(backend.n_line, self.maintenance_duration.shape[1])) at_least_one = True if self.hazard_duration is not None: if self.hazard_duration.shape[1] != backend.n_line: msg_err = "for the hazard durations. It should be {} but is in fact {}" raise IncorrectNumberOfLines( msg_err.format(backend.n_line, self.hazard_duration.shape[1])) at_least_one = True if not at_least_one: raise ChronicsError( "No files are found in directory \"{}\". If you don't want to load any chronics, use " "\"ChangeNothing\" and not \"{}\" to load chronics." "".format(self.path, type(self))) for name_arr, arr in zip([ "load_q", "load_p", "prod_v", "prod_p", "maintenance", "hazards", "maintenance time", "maintenance duration", "hazard duration" ], [ self.load_q, self.load_p, self.prod_v, self.prod_p, self.maintenance, self.hazards, self.maintenance_time, self.maintenance_duration, self.hazard_duration ]): if arr is not None: if self.chunk_size is None: if arr.shape[0] != self.n_: msg_err = "Array {} has not the same number of rows of load_p. The chronics cannot be loaded properly." raise EnvError(msg_err.format(name_arr)) if self.max_iter > 0: if self.max_iter > self.n_: msg_err = "Files count {} rows and you ask this episode to last at {} timestep." raise InsufficientData(msg_err.format(self.n_, self.max_iter))