Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More IO Freeze Fixes #10411

Merged
merged 13 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ cmake-build-*
build-wheel/
dist/
energyplus.egg-info
wheelhouse/
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The auditwheel package puts patched up wheels into the wheelhouse directory, so I'm just adding that to the ignore list here.


# App-specific project files, for example, for Geany IDE:
*.geany
Expand Down
13 changes: 11 additions & 2 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@ version: 2

sphinx:
configuration: doc/readthedocs/sphinx/conf.py
builder: html

build:
os: ubuntu-22.04
tools:
python: "3.11"
apt_packages:
- doxygen

# read the docs image build already includes sphinx-rtd-theme, so this isn't needed
# however, keeping it here and running it on RTD is a near zero cost operation and makes sure the requirements are ok
python:
install:
- requirements: doc/readthedocs/requirements.txt

submodules:
exclude: all
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a bit of extra stuff to the read-the-docs config file so hopefully those docs build again.

2 changes: 2 additions & 0 deletions idd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ install(FILES "versions/V9-5-0-Energy+.idd" DESTINATION "PreProcess/IDFVersionUp
install(FILES "versions/V9-6-0-Energy+.idd" DESTINATION "PreProcess/IDFVersionUpdater")
install(FILES "versions/V22-1-0-Energy+.idd" DESTINATION "PreProcess/IDFVersionUpdater")
install(FILES "versions/V22-2-0-Energy+.idd" DESTINATION "PreProcess/IDFVersionUpdater")
install(FILES "versions/V23-1-0-Energy+.idd" DESTINATION "PreProcess/IDFVersionUpdater")
install(FILES "versions/V23-2-0-Energy+.idd" DESTINATION "PreProcess/IDFVersionUpdater")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was informed we were missing an IDD from the install, and I found both 23.1 and 23.2 were missing from this list. Apparently 23.2 is there from a different CMake command, but I'm putting them both here for completion.


# For fortran...
set(PREVIOUS_IDD "${CMAKE_CURRENT_SOURCE_DIR}/versions/V${PREV_RELEASE_MAJOR}-${PREV_RELEASE_MINOR}-${PREV_RELEASE_PATCH}-Energy+.idd")
Expand Down
104 changes: 104 additions & 0 deletions scripts/dev/api_debug_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env python3
# EnergyPlus, Copyright (c) 1996-2024, The Board of Trustees of the University
# of Illinois, The Regents of the University of California, through Lawrence
# Berkeley National Laboratory (subject to receipt of any required approvals
# from the U.S. Dept. of Energy), Oak Ridge National Laboratory, managed by UT-
# Battelle, Alliance for Sustainable Energy, LLC, and other contributors. All
# rights reserved.
#
# NOTICE: This Software was developed under funding from the U.S. Department of
# Energy and the U.S. Government consequently retains certain rights. As such,
# the U.S. Government has been granted for itself and others acting on its
# behalf a paid-up, nonexclusive, irrevocable, worldwide license in the
# Software to reproduce, distribute copies to the public, prepare derivative
# works, and perform publicly and display publicly, and to permit others to do
# so.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# (1) Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# (2) Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# (3) Neither the name of the University of California, Lawrence Berkeley
# National Laboratory, the University of Illinois, U.S. Dept. of Energy nor
# the names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# (4) Use of EnergyPlus(TM) Name. If Licensee (i) distributes the software in
# stand-alone form without changes from the version obtained under this
# License, or (ii) Licensee makes a reference solely to the software
# portion of its product, Licensee must refer to the software as
# "EnergyPlus version X" software, where "X" is the version number Licensee
# obtained under this License and may not use a different name for the
# software. Except as specifically required in this Section (4), Licensee
# shall not use in a company name, a product name, in advertising,
# publicity, or other promotional activities any name, trade name,
# trademark, logo, or other designation of "EnergyPlus", "E+", "e+" or
# confusingly similar designation, without the U.S. Department of Energy's
# prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

# This is just a small script that allows for easily running EnergyPlus for API calling debugging purposes
# It is currently set up for a Unix-ish environment, but could be adapted for all platforms
# To start debugging, follow these simple steps
# - You probably want to run from within a Python venv, so that you can quickly install custom dependencies.
# To do that, just run `python -m venv /path/to/venv`
# Then activate it with `. /path/to/venv/bin/activate`
# Then pip install whatever you want with `pip install something` or `pip install -r requirements.txt`
# - Next prepare this file, setting the build directory, products directory, and IDF to test
# - Next prepare the build folder, make sure cmake is set up and run and it builds OK already
# - Now run the debugger by simply passing the Python binary to it: `gdb /path/to/venv/bin/python`
# - Inside the debugger, you set the command line args to run this file with `set args /path/to/this/file.py`
# - You can try to immediately run and see what happens by entering `r`, it should run EnergyPlus straight through
# - You can add breakpoints at any time, like `break SimulationManager.cc:188`, though it may ask you to confirm
# - You can change the E+ code in this repo, kill the current Python run with `k`, and then re-run this script with `r`
# Because this script starts with a make command, it will then build the updated code before trying to call the API
# This allows for rapid debugging iteration

from os import cpu_count
from pathlib import Path
from subprocess import check_call
from sys import exit, path
from tempfile import mkdtemp

repo_root = Path(__file__).resolve().parent.parent.parent
build_dir = repo_root / 'builds' / 'r'
products_dir = build_dir / 'Products'
file_to_run = repo_root / 'testfiles' / 'PythonPluginCustomOutputVariable.idf'

# this will automatically build E+ each run, so you can quickly make changes and re-execute inside the debugger
check_call(['make', '-j', str(cpu_count() - 2), 'energyplus'], cwd=str(build_dir))

path.insert(0, str(products_dir))
from pyenergyplus.api import EnergyPlusAPI

api = EnergyPlusAPI()
state = api.state_manager.new_state()
run_dir = mkdtemp()
print(f"EnergyPlus starting with outputs in directory: {run_dir}")
return_value = api.runtime.run_energyplus(
state, [
'-d',
run_dir,
'-D',
str(file_to_run)
]
)
print(f"EnergyPlus finished with outputs in directory: {run_dir}")
exit(return_value)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a script that no one needs to worry about really. When I need to debug code that specifically calls into EnergyPlus from the API, this will be a very helpful little script to keep right in the repo. I doubt anyone else will ever use it...

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def get_current_wheel_details():
},
"Linux": {
"x86_64": {
"wheel": "linux_x86_64",
"wheel": "manylinux_2_17_x86_64",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we should be able to meet the constraints of the manylinux_2_17_x86_64 wheel, so that's nice.

"zip_tag": "Linux",
"build_tool": "Unix Makefiles",
"extension": "so",
Expand Down
9 changes: 7 additions & 2 deletions src/EnergyPlus/PluginManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ void initPython(EnergyPlusData &state, fs::path const &pathToPythonPackages)

// first pre-config Python so that it can speak UTF-8
PyPreConfig preConfig;
PyPreConfig_InitPythonConfig(&preConfig);
PyPreConfig_InitIsolatedConfig(&preConfig);
preConfig.utf8_mode = 1;
status = Py_PreInitialize(&preConfig);
if (PyStatus_Exception(status)) {
Expand Down Expand Up @@ -443,7 +443,12 @@ void initPython(EnergyPlusData &state, fs::path const &pathToPythonPackages)
PyMem_RawFree(wcharPath);
}

Py_InitializeFromConfig(&config);
// This was Py_InitializeFromConfig(&config), but was giving a seg fault when running inside
// another Python instance, for example as part of an API run. Per the example here:
// https://docs.python.org/3/c-api/init_config.html#preinitialize-python-with-pypreconfig
// It looks like we don't need to initialize from config again, it should be all set up with
// the init calls above, so just initialize and move on.
Py_Initialize();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment.

}
#endif // LINK_WITH_PYTHON

Expand Down
Loading