Skip to content

Commit 8209c25

Browse files
Merge branch 'hip-ra-monte-carlo' NREL#151
2 parents 53c098d + 0deb747 commit 8209c25

File tree

6 files changed

+26
-23
lines changed

6 files changed

+26
-23
lines changed

src/geophires_monte_carlo/MC_GeoPHIRES3.py

Lines changed: 2 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

@@ -528,7 +523,6 @@ def main(command_line_args=None):
528523
if '-9999.0' not in line and len(s) > 1:
529524
line = line.strip()
530525
if len(line) > 3:
531-
# FIXME TODO doesn't work for HIP RA results
532526
line, sep, tail = line.partition(', (') # strip off the Input Variable Values
533527
line = line.replace('(', '').replace(')', '') # strip off the ()
534528
results.append([float(y) for y in line.split(',')])
@@ -614,7 +608,6 @@ def main(command_line_args=None):
614608

615609

616610
if __name__ == '__main__':
617-
logger = _get_logger()
618611
logger.info(f'Init {__name__!s}')
619612

620613
main(command_line_args=sys.argv[1:])
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"Producible Heat": {"minimum": 4240000000000.0, "maximum": 15600000000000.0, "median": 9120000000000.0, "average": 9806000000000.0, "mean": 9806000000000.0, "standard deviation": 4394740492907.4023}, "Producible Electricity": {"minimum": 134.42, "maximum": 494.5, "median": 289.19, "average": 310.688, "mean": 310.688, "standard deviation": 139.11459756617924}}

src/geophires_monte_carlo/__init__.py

Lines changed: 11 additions & 3 deletions
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')
@@ -71,15 +73,21 @@ def __init__(self, request: MonteCarloRequest):
7173

7274
with open(self._request.input_file) as request_input_file, open(
7375
self._request.monte_carlo_settings_file
74-
) as mc_settings_file, open(self.json_output_file_path) as json_file:
76+
) as mc_settings_file:
7577
self._result: dict = {
7678
'input': {
7779
'input_file_content': request_input_file.read(),
7880
'monte_carlo_settings_file_content': mc_settings_file.read(),
7981
},
80-
'output': json.loads(json_file.read()),
82+
# 'output': json.loads(json_file.read()),
8183
}
8284

85+
try:
86+
with open(self.json_output_file_path) as json_file:
87+
self._result['output'] = json.loads(json_file.read())
88+
except FileNotFoundError:
89+
pass # FIXME WIP
90+
8391
@property
8492
def output_file_path(self) -> Path:
8593
return self._request.output_file

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, 5

tests/geophires_monte_carlo_tests/test_geophires_monte_carlo.py

Lines changed: 7 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,12 @@ 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+
self.assertLess(json_result['Producible Electricity']['median'], 1000)
132+
self.assertGreater(json_result['Producible Electricity']['median'], 50)
133+
128134
def _get_arg_file_path(self, arg_file):
129135
test_dir: Path = Path(os.path.abspath(__file__)).parent
130136
return Path(test_dir, arg_file).absolute()

0 commit comments

Comments
 (0)