-
Notifications
You must be signed in to change notification settings - Fork 192
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
C++ CLI: Create results.json and handle analysis.json (create objectives.json) #5028
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6d2d0c6
WIP For #5019
jmarrec 7d528b1
Port rename_hash_keys from workflow gem util/post_process::run_extra…
jmarrec 8e6df5a
Start a pytest for running classic / labs in an analysis.json case
jmarrec d34d137
Use a measure that doesn't need a model/sql so testing goes much fast…
jmarrec 3fae861
Implement spitting out results.json and objectives.json when analysis…
jmarrec 6174aee
Add a script + a convenience target for updating the **build_dir** se…
jmarrec 44c2236
Making a test fail on purpose with TODO: Need to clarify which of the…
jmarrec 7ed29be
Fix build error
jmarrec 659cd67
Implement skip zip results in RunOptions. It's part of the osw schema…
jmarrec 5193679
Add data_point_out.json as requested
jmarrec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Just for convenience: having to VT the seb model which is at 1.11.5 | ||
# can be very time consuming, especially on debug builds | ||
|
||
require 'openstudio' | ||
|
||
model_path = File.join(__dir__, 'files/seb.osm') | ||
raise "#{model_path} not found" if !File.file?(model_path) | ||
|
||
# Starting at 3.7.0, no need to explicitly call vt, but still doing it | ||
# m = OpenStudio::Model::Model::load(model_path).get() | ||
vt = OpenStudio::OSVersion::VersionTranslator.new | ||
OpenStudio::Logger.instance.standardOutLogger.setLogLevel(OpenStudio::Debug) | ||
m = vt.loadModel(model_path).get() | ||
m.save(model_path, true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"analysis": { | ||
"display_name": "Test With Analysis JSON", | ||
"name": "analysis_json", | ||
"output_variables": [ | ||
{ | ||
"objective_function": true, | ||
"name": "FakeReport.net_site_energy", | ||
"objective_function_index": 0, | ||
"objective_function_target": 0, | ||
"objective_function_group": 1, | ||
"scaling_factor": 1.0, | ||
"display_name": "Net Site Energy, should be there", | ||
"display_name_short": "net_site_energy", | ||
"metadata_id": null, | ||
"visualize": true, | ||
"export": true, | ||
"variable_type": "double" | ||
}, | ||
{ | ||
"objective_function": false, | ||
"name": "FakeReport.net_site_energy", | ||
"objective_function_index": 1, | ||
"objective_function_target": 0, | ||
"objective_function_group": 1, | ||
"scaling_factor": 1.0, | ||
"display_name": "net_site_energy", | ||
"display_name_short": "net_site_energy", | ||
"metadata_id": null, | ||
"visualize": true, | ||
"export": true, | ||
"variable_type": "double" | ||
}, | ||
{ | ||
"objective_function": true, | ||
"name": "IsNonExisting.NonExisting", | ||
"objective_function_index": 2, | ||
"objective_function_target": 0, | ||
"objective_function_group": 1, | ||
"scaling_factor": 1.0, | ||
"display_name": "net_site_energy", | ||
"display_name_short": "net_site_energy", | ||
"metadata_id": null, | ||
"visualize": true, | ||
"export": true, | ||
"variable_type": "double" | ||
} | ||
] | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
resources/Examples/with_analysis/local/measures/FakeReport/measure.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require 'openstudio' | ||
|
||
class FakeReport < OpenStudio::Measure::ReportingMeasure | ||
|
||
def name | ||
return "Fake Report" | ||
end | ||
|
||
#define the arguments that the user will input | ||
def arguments(model = nil) | ||
args = OpenStudio::Measure::OSArgumentVector.new | ||
|
||
return args | ||
end #end the arguments method | ||
|
||
def outputs | ||
result = OpenStudio::Measure::OSOutputVector.new | ||
result << OpenStudio::Measure::OSOutput.makeDoubleOutput('net_site_energy', false) | ||
return result | ||
end | ||
|
||
#define what happens when the measure is run | ||
def run(runner, user_arguments) | ||
super(runner, user_arguments) | ||
|
||
#use the built-in error checking | ||
if not runner.validateUserArguments(arguments(), user_arguments) | ||
return false | ||
end | ||
|
||
# Register some constant values, so we can only do it during post | ||
# processing | ||
runner.registerValue("net_site_energy", "Net Site Energy", 167.1, "GJ") | ||
runner.registerValue("something!with.invalid_chars_", "Test Sanitizing", 1, "") | ||
runner.registerFinalCondition("Goodbye.") | ||
|
||
return true | ||
|
||
end | ||
|
||
end | ||
|
||
FakeReport.new.registerWithApplication |
57 changes: 57 additions & 0 deletions
57
resources/Examples/with_analysis/local/measures/FakeReport/measure.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version="1.0"?> | ||
<measure> | ||
<schema_version>3.1</schema_version> | ||
<name>fake_report</name> | ||
<uid>ca6ba362-ea57-4236-b803-17e37b0c0817</uid> | ||
<version_id>32617b1d-91b1-4325-9a3a-0708b9853d29</version_id> | ||
<version_modified>2023-11-13T17:08:41Z</version_modified> | ||
<xml_checksum>B2AD275E</xml_checksum> | ||
<class_name>FakeReport</class_name> | ||
<display_name>Fake Report</display_name> | ||
<description>Change me</description> | ||
<modeler_description>Change me</modeler_description> | ||
<arguments /> | ||
<outputs> | ||
<output> | ||
<name>net_site_energy</name> | ||
<display_name>net_site_energy</display_name> | ||
<short_name>net_site_energy</short_name> | ||
<type>Double</type> | ||
<model_dependent>false</model_dependent> | ||
</output> | ||
</outputs> | ||
<provenances /> | ||
<tags> | ||
<tag>Reporting.QAQC</tag> | ||
</tags> | ||
<attributes> | ||
<attribute> | ||
<name>Measure Type</name> | ||
<value>ReportingMeasure</value> | ||
<datatype>string</datatype> | ||
</attribute> | ||
<attribute> | ||
<name>Measure Language</name> | ||
<value>Ruby</value> | ||
<datatype>string</datatype> | ||
</attribute> | ||
<attribute> | ||
<name>Uses SketchUp API</name> | ||
<value>false</value> | ||
<datatype>boolean</datatype> | ||
</attribute> | ||
</attributes> | ||
<files> | ||
<file> | ||
<version> | ||
<software_program>OpenStudio</software_program> | ||
<identifier>1.1.2</identifier> | ||
<min_compatible>1.1.2</min_compatible> | ||
</version> | ||
<filename>measure.rb</filename> | ||
<filetype>rb</filetype> | ||
<usage_type>script</usage_type> | ||
<checksum>4CFB5158</checksum> | ||
</file> | ||
</files> | ||
</measure> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"steps": [ | ||
{ | ||
"measure_dir_name": "FakeReport", | ||
"arguments": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import json | ||
import subprocess | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"is_labs", | ||
[pytest.param(True, id="labs"), pytest.param(False, id="classic")], | ||
) | ||
def test_run_with_analysis(osclipath, is_labs: bool): | ||
base_osw_path = Path("with_analysis.osw").resolve() | ||
assert base_osw_path.is_file(), f"{base_osw_path=} is not found" | ||
|
||
osw = json.loads(base_osw_path.read_text()) | ||
suffix = "labs" if is_labs else "classic" | ||
osw_path = base_osw_path.parent / f"with_analysis_{suffix}.osw" | ||
runDir = base_osw_path.parent / f"run_{suffix}" | ||
osw["run_directory"] = str(runDir) | ||
runDir.mkdir(exist_ok=True) | ||
with open(osw_path, "w") as f: | ||
json.dump(osw, fp=f, indent=2, sort_keys=True) | ||
|
||
# Fake having an in.idf or it won't run in the "classic" subcommand, doing it for labs too so that it's less | ||
# confusing | ||
# if not is_labs: | ||
with open(runDir / "in.idf", "w") as f: | ||
f.write("Building,;") | ||
|
||
command = [str(osclipath)] | ||
if not is_labs: | ||
command.append("classic") | ||
command += ["run", "--postprocess_only", "-w", str(osw_path)] | ||
lines = subprocess.check_output(command, encoding="utf-8").splitlines() | ||
|
||
assert runDir.exists() | ||
measure_attributes_path = runDir / "measure_attributes.json" | ||
assert measure_attributes_path.is_file() | ||
results_path = runDir / "results.json" | ||
assert results_path.is_file() | ||
objectives_path = runDir / "objectives.json" | ||
assert objectives_path.is_file() | ||
|
||
measure_attributes = json.loads(measure_attributes_path.read_text()) | ||
assert measure_attributes == { | ||
"FakeReport": {"applicable": True, "net_site_energy": 167.1, "something_with_invalid_chars": 1} | ||
} | ||
|
||
results = json.loads(results_path.read_text()) | ||
assert results == {"FakeReport": {"applicable": True, "net_site_energy": 167.1, "something_with_invalid_chars": 1}} | ||
|
||
objectives = json.loads(objectives_path.read_text()) | ||
assert objectives == { | ||
"objective_function_1": 167.1, | ||
"objective_function_3": 1.7976931348623157e308, | ||
"objective_function_group_1": 1.0, | ||
"objective_function_group_3": None, | ||
"objective_function_target_1": 0.0, | ||
"objective_function_target_3": None, | ||
"scaling_factor_1": 1.0, | ||
"scaling_factor_3": None, | ||
} | ||
|
||
expected_files_in_run_dir = { | ||
"data_point.zip", | ||
"finished.job", | ||
"in.idf", | ||
"measure_attributes.json", | ||
"objectives.json", | ||
"results.json", | ||
"run.log", | ||
"started.job", | ||
# TODO: see below | ||
"data_point_out.json", | ||
} | ||
# TODO: I'm letting this test fail so it's obvious this needs to be addressed | ||
if True: # not is_labs: | ||
# We get the SAME exact info in measure_attributes.json, results.json and data_point_out.json... | ||
# measure_attributes.json is flushed after each apply measure Step (ModelMeasures, EnergyPlusMeasures, | ||
# ReportingMeasures), then at the end of ReportingMeasures it's done once again and results.json is spat out too | ||
# Do we really need the data_point_out.json in addition to this? | ||
# Seems like we could just run the output of results.json/data_point_out.json at the end of the workflow run | ||
# instead | ||
expected_files_in_run_dir.add("data_point_out.json") | ||
|
||
assert set([x.name for x in runDir.glob("*")]) == expected_files_in_run_dir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kbenne @brianlball Here is the TODO I want to adress (with a voluntarily failing tests so it doesn't slip by).
Do we really need all three of these json files? if so, when?