class_docstr: Very simple model of a power system.
  Real life is more complicated!
  
  Parameters
  ----------
  num_dams: int
      number of dams to be managed
  depth: int
      number of layers in the neural networks
  width: int
      number of neurons per hidden layer
  year_to_day_ratio: float = 2.
      Ratio between std of consumption in the year and std of consumption in the day.
  constant_to_year_ratio: float
      Ratio between constant baseline consumption and std of consumption in the year.
  back_to_normal: float
      Part of the variability which is forgotten at each time step.
  consumption_noise: float
      Instantaneous variability.
  num_thermal_plants: int
      Number of thermal plants.
  num_years: float
      Number of years.
  failure_cost: float
      Cost of not satisfying the demand. Equivalent to an expensive infinite capacity thermal plant.
class_docstr_tok: ["Very","simple","model","of","a","power","system",".","Real","life","is","more","complicated","!","Parameters","--","--","--","--","--","num_dams",":","int","number","of","dams","to","be","managed","depth",":","int","number","of","layers","in","the","neural","networks","width",":","int","number","of","neurons","per","hidden","layer","year_to_day_ratio",":","float","=","2",".","Ratio","between","std","of","consumption","in","the","year","and","std","of","consumption","in","the","day",".","constant_to_year_ratio",":","float","Ratio","between","constant","baseline","consumption","and","std","of","consumption","in","the","year",".","back_to_normal",":","float","Part","of","the","variability","which","is","forgotten","at","each","time","step",".","consumption_noise",":","float","Instantaneous","variability",".","num_thermal_plants",":","int","Number","of","thermal","plants",".","num_years",":","float","Number","of","years",".","failure_cost",":","float","Cost","of","not","satisfying","the","demand",".","Equivalent","to","an","expensive","infinite","capacity","thermal","plant","."]
code: def make_plots(self, filename: str = "ps.png") -> None:
      losses = self.losses
      num_dams = self.num_dams
      consumption_per_ts = self.consumption_per_time_step
      hydro_prod_per_ts = self.hydro_prod_per_time_step
      total_hydro_prod_per_ts = [sum(h) for h in hydro_prod_per_ts]
  
      # Utility function for plotting per year or per day.
      def block(x: tp.List[float]) -> tp.List[float]:
          result: tp.List[float] = []
          step = int(np.sqrt(len(x)))
          for i in range(0, len(x), step):
              result += [sum(x[i : i + step]) / len(x[i : i + step])]
          return result
  
      def block24(x: tp.List[float]) -> tp.List[float]:
          result: tp.List[float] = []
          for i in range(0, len(x), 24):
              result += [sum(x[i : i + 24]) / len(x[i : i + 24])]
          if len(x) != len(result) * 24:
              print(len(x), len(result) * 24)
          return result
  
      def deblock24(x: tp.List[float]) -> tp.List[float]:
          result = [0.0] * 24
          for i, _ in enumerate(x):
              result[i % 24] += x[i] / 24.0
          return result
  
      plt.clf()
      # Plot the optimization run.
      ax = plt.subplot(2, 2, 1)
      ax.set_xlabel("iteration number")
      smoothed_losses = block(losses)
      ax.plot(np.linspace(0, 1, len(losses)), losses, label="losses")
      ax.plot(
          np.linspace(0, 1, len(smoothed_losses)),
          smoothed_losses,
          label="smoothed losses",
      )
      ax.legend(loc="best")
  
      # Plotting marginal costs.
      ax = plt.subplot(2, 2, 4)
      marginal_cost_per_hour = deblock24(self.marginal_costs)
      marginal_cost_per_day = block24(self.marginal_costs)
      ax.plot(
          np.linspace(0, 0.5, len(marginal_cost_per_hour)),
          marginal_cost_per_hour,
          label="marginal cost per hour",
      )
      ax.plot(
          np.linspace(0.5, 1, len(marginal_cost_per_day)),
          marginal_cost_per_day,
          label="marginal cost per day",
      )
      ax.legend(loc="best")
  
      # Plot consumption per day and decomposition of production.
      ax = plt.subplot(2, 2, 2)
      consumption_per_day = block24(consumption_per_ts)
      hydro_prod_per_day = block24(total_hydro_prod_per_ts)
      ax.plot(
          np.linspace(1, 365, len(consumption_per_day)),
          consumption_per_day,
          label="consumption",
      )
      ax.plot(
          np.linspace(1, 365, len(hydro_prod_per_day)),
          hydro_prod_per_day,
          label="hydro",
      )
      for i in range(min(num_dams, 3)):
          hydro_ts = [h[i] for h in hydro_prod_per_ts]
  
          hydro_day = block24(hydro_ts)
          ax.plot(
              np.linspace(1, 365, len(hydro_day)),
              hydro_day,
              label="dam " + str(i) + " prod",
          )
      ax.set_xlabel("time step")
      ax.set_ylabel("production per day")
      ax.legend(loc="best")
  
      # Plot consumption per hour of the day and decomposition of production.
      ax = plt.subplot(2, 2, 3)
      consumption_per_hour = deblock24(consumption_per_ts)
      hydro_prod_per_hour = deblock24(total_hydro_prod_per_ts)
      ax.plot(
          np.linspace(1, 24, len(consumption_per_hour)),
          consumption_per_hour,
          label="consumption",
      )
      ax.plot(
          np.linspace(1, 24, len(hydro_prod_per_hour)),
          hydro_prod_per_hour,
          label="hydro",
      )
      for i in range(min(num_dams, 3)):
          hydro_ts = [h[i] for h in hydro_prod_per_ts]
          hydro_hour = deblock24(hydro_ts)
          ax.plot(
              np.linspace(1, 24, len(hydro_hour)),
              hydro_hour,
              label="dam " + str(i) + " prod",
          )
      ax.set_xlabel("time step")
      ax.set_ylabel("production per hour")
      ax.legend(loc="best")
      plt.savefig(filename)
  
file_path: nevergrad/nevergrad/functions/powersystems/core.py
imports: import typing
  from math import pi, cos, sin
  import matplotlib.pyplot
  import numpy
  from nevergrad.parametrization import parameter
  from ..base import ExperimentFunction
label_desc: Use image node_id 4 for calling the PowerSystem obj's underlying member method code with example usage: obj.make_plots(filename) and returns: result, result, result