santoshphilip / eppy

scripting language for E+, Energyplus
MIT License
151 stars 67 forks source link

Energyplus terminated and the program iteration stopped #433

Open Split031 opened 8 months ago

Split031 commented 8 months ago

Hi, I tried to run idf files using eppy for building envelope parameters optimization, combined EnergyPlus with Genetic Algorithm. Each parameter has its own boundary. GA program generates different parameter combinations within the boundary and uses them to run idf files with eppy.

During the iteration, the GA program often terminated because EnergyPlus detected the error and terminated. And that stopped the whole iteration. I can't fix this problem by changing the parameters' boundary.

My question is: Can I just jump over the wrong idf file running ( after EnergyPlus detects the error ) and let the Python program iteration keep going to do the other idf running?

I would appreciate it if you could help me solve this problem. Thank you!

The code is: `import os import pandas as pd from eppy.modeleditor import IDF

def eppy_cal(para): iddfile = "D:/EnergyPlus/EnergyPlusV8-7-0/Energy+.idd" IDF.setiddname(iddfile) idfname = "./SH.S.WWR0.3.3F.idf" epwfile = "./CHN_Shanghai.Shanghai.583620_CSWD.epw" idf = IDF(idfname, epwfile)

idf.run(output_directory='./', readvars=True, output_prefix='Result', output_suffix='C')

files = os.listdir(os.getcwd())
extensions_not_to_delete = ['.idf', '.epw', '.py', '.csv', '.png', '__pycache__']
for file in files:
    if not any(file.endswith(ext) for ext in extensions_not_to_delete):
        file_path = os.path.join(os.getcwd(), file)
        os.remove(file_path)

df = pd.read_csv("./Result.csv")
selected_data = df.iloc[:, [32, 33]]
energy_consumption = selected_data.sum().sum()

return energy_consumption`
santoshphilip commented 8 months ago

@Split031 ,

Here is my reframing of your issue:

I'll start to look into this. idf.run() is a tricky part of the code. So this is going to take a little attendion from me.

santoshphilip commented 8 months ago

for clarity, I have reformatted your function:

import os
import pandas as pd
from eppy.modeleditor import IDF

def eppy_cal(para):
    iddfile = "D:/EnergyPlus/EnergyPlusV8-7-0/Energy+.idd"
    IDF.setiddname(iddfile)
    idfname = "./SH.S.WWR0.3.3F.idf"
    epwfile = "./CHN_Shanghai.Shanghai.583620_CSWD.epw"
    idf = IDF(idfname, epwfile)

idf.run(output_directory='./', readvars=True, output_prefix='Result', output_suffix='C')

Let me know if I got it wrong.

santoshphilip commented 8 months ago

I made a branch i433_run

take a look at script i433.py run the script. It will run from directory eppy

Is this a solution for your issue ?

santoshphilip commented 8 months ago

The code in i433.py:

import eppy
from eppy.runner.run_functions import EnergyPlusRunError

goodfile = "goodfile.idf"
badfile = "badfile.idf"
wfile = "USA_CA_San.Francisco.Intl.AP.724940_TMY3.epw"
goodidf = eppy.openidf(goodfile, epw=wfile)
badidf = eppy.openidf(badfile, epw=wfile)

idfs = [badidf, goodidf]
for an_idf in idfs:
    try:    
        an_idf.run(verbose='s')
        print(f"sucessfully ran {an_idf.idfname}")
    except EnergyPlusRunError as e:
        print(f"error in running {an_idf.idfname}")        

This will run without the script stopping even though it has a bad file that E+ cannot simulate