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

WIP: Concurrent loading of ensemble #77

Closed
wants to merge 24 commits into from
Closed
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f7abe42
Concurrent loading of ensemble
wouterjdb Dec 9, 2019
06910ed
Removed some spaces
wouterjdb Dec 10, 2019
37cbc42
Remove double code, changed camel case
wouterjdb Dec 10, 2019
eea4314
black
wouterjdb Dec 10, 2019
d16f525
Leaner writing of functional calls
wouterjdb Dec 10, 2019
24492f9
Small change in documentation
wouterjdb Dec 10, 2019
ac061e8
Added concurrent to load_file()
wouterjdb Dec 10, 2019
983e927
Fix static realidxregexp and autodiscovery
wouterjdb Dec 10, 2019
5010057
Added index, minor documentation change
wouterjdb Dec 10, 2019
f2565fb
Limit concurrent.futures import to ProcessPollExecutor
wouterjdb Dec 10, 2019
184cea7
Minor documentation changes
wouterjdb Dec 10, 2019
2b49f8b
Fixed missing positional argument names
wouterjdb Dec 10, 2019
58d55cf
Changed argument creation for concurrent
wouterjdb Dec 10, 2019
08fac79
Fix for concurrent not updating self
wouterjdb Dec 10, 2019
3904d21
Concurrent to load_smry
wouterjdb Dec 10, 2019
28e9870
Alternative way to test Python version
wouterjdb Dec 11, 2019
345ce26
removing caching for parallel
wouterjdb Dec 11, 2019
7ac23bb
Removed unused code, black
wouterjdb Dec 11, 2019
57a3ccb
Minor code fixes
wouterjdb Dec 11, 2019
cc8df36
Fix Python2.7 cach removal
wouterjdb Dec 11, 2019
32e9ec8
Added pylint disable W0212
wouterjdb Dec 11, 2019
8e76bfd
rm wrapper for ScratchRealization.__init__
berland Dec 11, 2019
e0ac3e7
Minor code fixes + black
wouterjdb Dec 12, 2019
5909079
Changed i to idx because of pylint complaining
wouterjdb Dec 12, 2019
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
61 changes: 48 additions & 13 deletions src/fmu/ensemble/ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
import os
import glob
from datetime import datetime
try:
import concurrent.futures
USE_CONCURRENT = True
except ImportError:
USE_CONCURRENT = False

import six
import pandas as pd
Expand Down Expand Up @@ -205,6 +210,20 @@ def _shortcut2path(keys, shortpath):
# calling function handle further errors.
return shortpath

def InitScratchRealization(self, realdir):
wouterjdb marked this conversation as resolved.
Show resolved Hide resolved
"""Wrapper function used for concurrent loading

Args:
realdir (string): directory to realization

Returns:
realization (ScratchRealization): Initialized ScratchRealization
"""
realization = ScratchRealization(
realdir, realidxregexp=None, autodiscovery=True
)
return realization

def add_realizations(self, paths, realidxregexp=None, autodiscovery=True):
"""Utility function to add realizations to the ensemble.

Expand Down Expand Up @@ -234,21 +253,37 @@ def add_realizations(self, paths, realidxregexp=None, autodiscovery=True):
globbedpaths = glob.glob(paths)

count = 0
for realdir in globbedpaths:
realization = ScratchRealization(
realdir, realidxregexp=realidxregexp, autodiscovery=autodiscovery
)
if realization.index is None:
logger.critical(
"Could not determine realization index " + "for path " + realdir
if USE_CONCURRENT:
with concurrent.futures.ProcessPoolExecutor() as executor:
for realization in executor.map(self.InitScratchRealization, globbedpaths):
wouterjdb marked this conversation as resolved.
Show resolved Hide resolved
if realization.index is None:
logger.critical(
"Could not determine realization index " + "for path " + realdir
)
if not realidxregexp:
logger.critical("Maybe you need to supply a regexp.")
else:
logger.critical("Your regular expression is maybe wrong.")
else:
count += 1
self._realizations[realization.index] = realization
else:
for realdir in globbedpaths:
realization = ScratchRealization(
realdir, realidxregexp=realidxregexp, autodiscovery=autodiscovery
)
if not realidxregexp:
logger.critical("Maybe you need to supply a regexp.")
if realization.index is None:
logger.critical(
"Could not determine realization index " + "for path " + realdir
)
if not realidxregexp:
logger.critical("Maybe you need to supply a regexp.")
else:
logger.critical("Your regular expression is maybe wrong.")
else:
logger.critical("Your regular expression is maybe wrong.")
else:
count += 1
self._realizations[realization.index] = realization
count += 1
self._realizations[realization.index] = realization

logger.info("add_realizations() found %d realizations", len(self._realizations))
return count

Expand Down