Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question
4

Error in Running EnergyPlus in Python using API

asked 4 years ago

sajithwjay's avatar

updated 4 years ago

I am using the syntax below to run EnergyPlus from python using the EnergyPlus API. It gives me an error---> TypeError: run_energyplus() missing 1 required positional argument: 'command_line_args'.

If you could guide me as to what may be missing, Id be grateful.

import sys
sys.path.insert(0, 'C:\EnergyPlusV9-4-0') 

from pyenergyplus.api import EnergyPlusAPI

api = EnergyPlusAPI()

api.runtime.run_energyplus(['-d','C:/Users/Sajit/OneDrive/Documents/EnergyPlusExamplesForFMU/DirectPy','-w',
                            'C:/EnergyPlusV9-4-0/WeatherData/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw', 
                            'C:/Users/Sajit/OneDrive/Documents/EnergyPlusExamplesForFMU/EX1_9_4/TEST_NF_VFMU.idf'])
Preview: (hide)

1 Answer

Sort by » oldest newest most voted
3

answered 4 years ago

updated 4 years ago

You need to pass the state manager

import sys
from pyenergyplus.api import EnergyPlusAPI

def dummy_callback_function(state_argument):
    print("My argument is called state_argument to avoid duplicating the outer variable below called state")

api = EnergyPlusAPI()
state = api.state_manager.new_state()
api.runtime.callback_begin_new_environment(state, dummy_callback_function)
api.runtime.run_energyplus(state, 
    [
        '-d','C:/Users/Sajit/OneDrive/Documents/EnergyPlusExamplesForFMU/DirectPy',
        '-w', 'C:/EnergyPlusV9-4-0/WeatherData/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw',
        'C:/Users/Sajit/OneDrive/Documents/EnergyPlusExamplesForFMU/EX1_9_4/TEST_NF_VFMU.idf'
    ]
)
# If you need to call run_energyplus again, then reset the state first
api.state_manager.reset_state(state)
Preview: (hide)
link

Comments

1

Hi Julien, I have tried it and it works. Thank you for the pointers. I have a similar concern related to running energyplus as a PlugIn using Python. I will post it in another question. Regards.

sajithwjay's avatar sajithwjay  ( 4 years ago )

This works.. thanks..

prp92's avatar prp92  ( 3 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Training Workshops

Careers

Question Tools

3 followers

Stats

Asked: 4 years ago

Seen: 495 times

Last updated: Jan 04 '21