Skip to content

Commit 215a372

Browse files
Merge pull request NREL#178 from softwareengineerprogrammer/main
Fix MC HIP-RA test
2 parents b207b55 + 3cf0cea commit 215a372

File tree

6 files changed

+27
-21
lines changed

6 files changed

+27
-21
lines changed

src/geophires_monte_carlo/MC_GeoPHIRES3.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
from hip_ra import HipRaResult
3636
from hip_ra_x import HipRaXClient
3737

38+
logger = _get_logger()
39+
3840

3941
def Write_HTML_Output(
4042
html_path: str,
@@ -311,12 +313,6 @@ def work_package(pass_list: list):
311313
HipRaInputParameters(from_file_path=Path(tmp_input_file))
312314
)
313315
shutil.copyfile(result.output_file_path, tmp_output_file)
314-
elif args.Code_File.endswith('HIP_RA_x.py'):
315-
hip_ra_x_client: HipRaXClient = HipRaXClient()
316-
result: HipRaResult = hip_ra_x_client.get_hip_ra_result(
317-
HipRaInputParameters(from_file_path=Path(tmp_input_file))
318-
)
319-
shutil.copyfile(result.output_file_path, tmp_output_file)
320316
else:
321317
log.warning(
322318
f'Code file from args ({args.Code_File}) is not a known program, '
@@ -449,7 +445,6 @@ def main(command_line_args=None):
449445
if 'MC_OUTPUT_FILE' in args and args.MC_OUTPUT_FILE is not None
450446
else str(Path(Path(args.Input_file).parent, 'MC_Result.txt').absolute())
451447
)
452-
args.MC_OUTPUT_FILE = output_file
453448
python_path = 'python'
454449
html_path = ''
455450

@@ -464,6 +459,8 @@ def main(command_line_args=None):
464459
elif pair[0].startswith('ITERATIONS'):
465460
iterations = int(pair[1])
466461
elif pair[0].startswith('MC_OUTPUT_FILE'):
462+
# FIXME accepting relative paths here is likely to break MC, consolidate/align setting output file with
463+
# pattern in geophires_monte_carlo.MonteCarloRequest
467464
output_file = pair[1]
468465
elif pair[0].startswith('PYTHON_PATH'):
469466
python_path = pair[1]
@@ -528,7 +525,6 @@ def main(command_line_args=None):
528525
if '-9999.0' not in line and len(s) > 1:
529526
line = line.strip()
530527
if len(line) > 3:
531-
# FIXME TODO doesn't work for HIP RA results
532528
line, sep, tail = line.partition(', (') # strip off the Input Variable Values
533529
line = line.replace('(', '').replace(')', '') # strip off the ()
534530
results.append([float(y) for y in line.split(',')])
@@ -614,7 +610,6 @@ def main(command_line_args=None):
614610

615611

616612
if __name__ == '__main__':
617-
logger = _get_logger()
618613
logger.info(f'Init {__name__!s}')
619614

620615
main(command_line_args=sys.argv[1:])

src/geophires_monte_carlo/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ def __init__(
5151
self.output_file: Path = output_file
5252
else:
5353
self._temp_output_dir: TemporaryDirectory = TemporaryDirectory(prefix='geophires_monte_carlo-')
54-
self.output_file: Path = Path(self._temp_output_dir.name, 'MC_GEOPHIRES_Result.txt').absolute()
54+
self.output_file: Path = Path(
55+
self._temp_output_dir.name, f'MC_{self._simulation_program.name}_Result.txt'
56+
).absolute()
5557

5658
if not self.output_file.is_absolute():
5759
raise ValueError(f'Output file path ({output_file}) must be absolute')

src/geophires_x/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ Examples\Test2.json
124124
/References/Garg and Combs A REEXAMINATION OF USGS VOLUMETRIC “HEAT IN PLACE” METHOD.pdf
125125
/HIP.out
126126
/MC_HIP_Result.txt
127+
/MC_HIP_Result.json
127128
/MC_HIP_Settings_file.txt
128129
/MC_Result_10.txt
129130
/MC_Result_100.txt

tests/.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
HIP.out
22
*.log
3-
MC_Result.json
4-
MC_Result.txt
3+
MC_*Result.json
4+
MC_*Result.txt
55
*.png

tests/geophires_monte_carlo_tests/MC_HIP_Settings_file.txt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ INPUT, Reservoir Area, uniform, 50.0, 120.0
33
INPUT, Reservoir Thickness, uniform, 0.122, 0.299
44
INPUT, Reservoir Temperature, uniform, 130, 170
55
INPUT, Rejection Temperature, uniform, 20, 33
6-
OUTPUT, Producible Heat (reservoir)
7-
OUTPUT, Producible Heat/Unit Area (reservoir)
8-
OUTPUT, Producible Heat/Unit Volume (reservoir)
9-
OUTPUT, Producible Electricity (reservoir)
10-
OUTPUT, Producible Electricity/Unit Area (reservoir)
11-
OUTPUT, Producible Electricity/Unit Volume (reservoir)
12-
ITERATIONS, 25
13-
MC_OUTPUT_FILE, MC_HIP_Result.txt
6+
OUTPUT, Producible Heat
7+
OUTPUT, Producible Electricity
8+
ITERATIONS, 10

tests/geophires_monte_carlo_tests/test_geophires_monte_carlo.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ def test_monte_carlo_result_ordering(self):
107107

108108
self.assertDictEqual(result_json_obj, result.result['output'])
109109

110-
@unittest.skip(reason='FIXME: MC HIP result parsing is broken')
111110
def test_hip_ra_monte_carlo(self):
112111
client = GeophiresMonteCarloClient()
113112

@@ -116,6 +115,7 @@ def test_hip_ra_monte_carlo(self):
116115
SimulationProgram.HIP_RA,
117116
self._get_arg_file_path('HIP-example1.txt'),
118117
self._get_arg_file_path('MC_HIP_Settings_file.txt'),
118+
self._get_arg_file_path('MC_HIP_Result.txt'),
119119
)
120120
)
121121
self.assertIsNotNone(result)
@@ -125,6 +125,19 @@ def test_hip_ra_monte_carlo(self):
125125
result_content = '\n'.join(f.readlines())
126126
self.assertIn('Electricity', result_content)
127127

128+
with open(result.json_output_file_path) as f:
129+
json_result = json.loads(f.read())
130+
self.assertIn('Producible Electricity', json_result)
131+
132+
# Note: it is possible, though unlikely, for the test to incorrectly fail (i.e. a false negative)
133+
# if the random values generated happen to give valid results that are outside this range.
134+
# If you experience intermittent test failures from the below lines (that are unrelated to HIP-RA code
135+
# changes), then it probably means the expected range or settings file need to be adjusted to 'guarantee'
136+
# the results can be confidently asserted. (Such as in
137+
# https://github.com/NREL/GEOPHIRES-X/pull/178/commits/ec4db42fca5a90715ceb5143e18315d5f3d782b7)
138+
self.assertLess(json_result['Producible Electricity']['median'], 1000)
139+
self.assertGreater(json_result['Producible Electricity']['median'], 20)
140+
128141
def _get_arg_file_path(self, arg_file):
129142
test_dir: Path = Path(os.path.abspath(__file__)).parent
130143
return Path(test_dir, arg_file).absolute()

0 commit comments

Comments
 (0)