Gekko Python: Memory allocation failed

Viewed 54

As a follow up to the question: How can I simplify a large scale NLP model in Gekko Python? I'm still trying to figure out why gekko gets me this error:

Memory allocation failed

Error: 'results.json' not found. Check above for additional error details

These are my constraints:

def contraintesPuissance(self):

    Pmin = self.df_donnees_techniques["Puissance min"].to_list()
    Pmax = self.df_donnees_techniques["Puissance max"].to_list()

    self.model.Equations(
    [
        [
            self.on_off_var[ idx + (heure*self.nb_actifs) ] \
                * Pmax[idx] / self.getRendement(idx,heure) \
                - self.variables[ idx + (heure*self.nb_actifs) ] >= 0,

            self.variables[ idx + (heure*self.nb_actifs) ] \
                - self.on_off_var[ idx + (heure*self.nb_actifs) ] \
                * Pmin[idx] / self.getRendement(idx,heure) >= 0
        ]
        for heure in range(self.nb_heure)
        for idx in range(self.nb_actifs)
    ]
    )

def contraintesBesoinsConsommation(self):
    self.model.Equations(
            [
                [
                    sum([self.variables[idx + (heure*self.nb_actifs)]*self.getRendement(idx,heure) for idx in range(self.nb_actifs)])  \
                        - self.Analyse_df['besoins_chaud'][heure] == 0
                ]
                for heure in range(self.nb_heure)
            ]
        )

def contraintesTxENR(self):
    intermed = [self.model.Intermediate(
                    self.variables[ idx + (heure*self.nb_actifs) ] * self.getRendement(idx,heure)
                ) for heure in range(self.nb_heure) for idx in range(self.nb_actifs)
                ]

    numerateur = self.model.sum(
        [intermed[idx + (heure*self.nb_actifs)] * self.getTaux(idx) for heure in range(self.nb_heure) for idx in range(self.nb_actifs)]
    )
    denominateur = self.model.sum(intermed)

    self.model.Equation( numerateur / denominateur - self.Tx_ENR_cible >= 0)

def contrainteEmissions(self):
    self.model.Equation( self.VLE_max_gaz - self.emissions("Gaz_1") >= 0 )
    # !! à arrêter 

And this is my objective function:

    def func_cout_NRJV2_gekko(self):

    somme = [
        sum([self.variables[ idx + (heure*self.nb_actifs) ] * self.donnees_prix_NRJ[self.actifs_instancies[idx]][heure] for idx in range(self.nb_actifs)])
    for heure in range(self.nb_heure)]      
    [self.model.Minimize(s) for s in somme]
    penalite = self.model.if3(self.Sum_NRJ("Bois") - self.take_or_pay_bois, self.penalite_bois, 0) # Penalité take or pay
    self.model.Minimize(penalite)  

If more info is needed, I can provide it, but the code is really big.

1 Answers

What OS are you using? The issue with Memory allocation failed may be that the problem is >4 GB. On Local solve: Linux / MacOS and Cloud solve: Linux it isn't a problem because the executables are 64-bit. For Windows, the local executable is still 32-bit so the RAM limitation may be reached. This will likely change in the near future, but it could be the limitation.

Here are a few things to try, even if you are on a 64-bit executable.

  1. Inspect the model by opening the local run folder with m.open_folder(). Open the gk0_model.apm file with a text editor. The variables will have different internal names. They can be changed by naming variables with the name argument such as x = m.Var(value=0,name='x') to make it more readable.

  2. Convert any Constants or Parameters to just regular Python numbers. This can greatly reduce the memory requirement because they are not added to the automatic differentiation.

  3. If there are summations that can be np.sum() instead of m.sum(), use that instead so parts of the model are pre-computed before giving it to the solver.

  4. Use m.options.REDUCE=3 to scan through the model 3 (or more) times to reduce the memory requirements. This eliminates equations such as x==1, y+x==1, and z+y+x==`` by replacing them with x=1, y=0, z=0` as a pre-solve.

  5. The if3() function creates a few extra variables and equations and can increase the size of the model. If some of the conditions are always greater than zero or less than zero with pre-processing, then try eliminating those.

Related