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

Fix #5164 - Unless --show-stdout, do not print any ExpandObjects / EnergyPlus messages #5169

Merged
merged 4 commits into from
May 2, 2024

Conversation

jmarrec
Copy link
Collaborator

@jmarrec jmarrec commented Apr 25, 2024

Pull request overview

Pull Request Author

  • Model API Changes / Additions
  • Any new or modified fields have been implemented in the EnergyPlus ForwardTranslator (and ReverseTranslator as appropriate)
  • Model API methods are tested (in src/model/test)
  • EnergyPlus ForwardTranslator Tests (in src/energyplus/Test)
  • If a new object or method, added a test in NREL/OpenStudio-resources: Add Link
  • If needed, added VersionTranslation rules for the objects (src/osversion/VersionTranslator.cpp)
  • Verified that C# bindings built fine on Windows, partial classes used as needed, etc.
  • All new and existing tests passes
  • If methods have been deprecated, update rest of code to use the new methods

Labels:

  • If change to an IDD file, add the label IDDChange
  • If breaking existing API, add the label APIChange
  • If deemed ready, add label Pull Request - Ready for CI so that CI builds your PR

Review Checklist

This will not be exhaustively relevant to every PR.

  • Perform a Code Review on GitHub
  • Code Style, strip trailing whitespace, etc.
  • All related changes have been implemented: model changes, model tests, FT changes, FT tests, VersionTranslation, OS App
  • Labeling is ok
  • If defect, verify by running develop branch and reproducing defect, then running PR and reproducing fix
  • If feature, test running new feature, try creative ways to break it
  • CI status: all green or justified

@jmarrec jmarrec added Enhancement Request component - CLI component - Workflow Pull Request - Ready for CI This pull request if finalized and is ready for continuous integration verification prior to merge. labels Apr 25, 2024
@jmarrec jmarrec requested a review from shorowit April 25, 2024 08:00
@jmarrec jmarrec self-assigned this Apr 25, 2024
Copy link
Collaborator Author

@jmarrec jmarrec left a comment

Choose a reason for hiding this comment

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

This is mimic'ing the way openstudio classic run -w workflow.osw would do it, completely silently.

IMHO this feels weird having zero output when it just works.

I'm thinking we should have --show-stdout (and maybe --style-stdout as being the default. and you could pass --no-show-stdout to shush it, but that's only my opinion. @kbenne FYI

@@ -154,14 +154,30 @@ void OSWorkflow::runEnergyPlus() {
// TODO: is this the right place /Do we want to do that if we chose epJSON?
detailedTimeBlock("Saving IDF", [this, &inIDF] { workspace_->save(inIDF, true); });

std::ofstream stdout_ofs(openstudio::toString(runDirPath / "stdout-energyplus"), std::ofstream::trunc);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Declare it higher, to trunc it first, because I'm going to pipe expand objects output to it as well.

Comment on lines +166 to +180
detailedTimeBlock("Running ExpandObjects", [this, /*&cmd,*/ &result, &runDirPath, &runDirResults, &stdout_ofs] {
// result = std::system(cmd.c_str());
namespace bp = boost::process;
bp::ipstream is;
std::string line;
bp::child c(runDirResults.expandObjectsExe, bp::std_out > is);
while (c.running() && std::getline(is, line)) {
stdout_ofs << openstudio::ascii_trim_right(line) << '\n'; // Fix for windows...
if (m_show_stdout) {
fmt::print("{}\n", line);
}
}
c.wait();
result = c.exit_code();
});
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Swallow the ExpandObjects stdout, otherwise you'll still get these

ExpandObjects Started.
No expanded file generated.
ExpandObjects Finished. Time:     0.021

std::string line;
// bp::child c(cmd, bp::std_out > is);
bp::child c(runDirResults.energyPlusExe, inIDF.filename(), bp::std_out > is);
bp::child c(runDirResults.energyPlusExe, inIDF.filename(), (bp::std_out & bp::std_err) > is);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Pipe both stdout and stderr for E+, because the final EnergyPlus Completed Successfully. is printed to stderr and we want to swallow it as well.

Comment on lines +261 to +272
if (m_show_stdout) {
if (m_style_stdout) {
fmt::print("RunEnergyPlus: {} with ", status);
fmt::print(fmt::fg(fmt::color::red), "{} Fatal Errors, ", errFile.fatalErrors().size());
fmt::print(fmt::fg(fmt::color::orange), "{} Severe Errors, ", errFile.severeErrors().size());
fmt::print(fmt::fg(fmt::color::yellow), "{} Warnings.", errFile.warnings().size());
fmt::print("\n");
} else {
fmt::print("RunEnergyPlus: {} with {} Fatal Errors, {} Severe Errors, {} Warnings.\n", status, errFile.fatalErrors().size(),
errFile.severeErrors().size(), errFile.warnings().size());
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unless --show-stdout is passed: do not print the numer of fatal/severe/warnings

And do not style it (colors) unless --style-stdout is passed.

Comment on lines +128 to +139
auto* const logLevelOpt = app
.add_option_function<LogLevel>(
"-l,--loglevel",
[](const LogLevel& level) {
const auto loglLevelStr = logLevelStrs[static_cast<size_t>(level) - static_cast<size_t>(LogLevel::Trace)];
openstudio::Logger::instance().standardOutLogger().setLogLevel(level);
LOG_FREE(Debug, "openstudio.CLI", "Setting Log Level to " << loglLevelStr << "(" << level << ")");
},
"LogLevel settings: One of {Trace, Debug, Info, Warn, Error, Fatal} [Default: Warn] Excludes: --verbose")
->excludes(verboseOpt)
->option_text("LEVEL")
->transform(CLI::CheckedTransformer(logLevelMap, CLI::ignore_case));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Don't print the "Setting Log Level to xx (n)" unless Debug or Trace.

@@ -140,7 +140,7 @@ openstudio::path XMLValidator::schematronToXslt(const openstudio::path& schemaPa
saveXmlDocToFile(xsltPath, compiled);

xmlFreeDoc(compiled);
LOG(Info, "Saved transformed XSLT Stylesheet at '" << toString(xsltPath) << "'.");
LOG(Trace, "Saved transformed XSLT Stylesheet at '" << toString(xsltPath) << "'.");
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

e7f46c8 is optional, but I'm sick and tired of seeing too much verbosity in XMLValidator (which I'm responsible for, mind you), so I downgraded every Debug/Info message to a Trace.

You shouldn't have to think about what it's doing, and if you do need to debug something, just use Trace

@ci-commercialbuildings
Copy link
Collaborator

ci-commercialbuildings commented Apr 25, 2024

CI Results for e7f46c8:

@jmarrec jmarrec force-pushed the 5164_shush_eplus branch 3 times, most recently from 9920ad1 to 6b23cad Compare April 25, 2024 12:58
@jmarrec jmarrec added this to the OpenStudio SDK 3.8.0 milestone Apr 29, 2024
@kbenne kbenne merged commit 7d0fedf into develop May 2, 2024
2 of 6 checks passed
@kbenne kbenne deleted the 5164_shush_eplus branch May 2, 2024 20:53
@shorowit
Copy link
Contributor

shorowit commented May 2, 2024

Thanks @jmarrec!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component - CLI component - Workflow Enhancement Request Pull Request - Ready for CI This pull request if finalized and is ready for continuous integration verification prior to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CLI: Allow disabling EnergyPlus result output
4 participants