-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Share ensemble smry datasets in memory between plugins (#569)
Share ensemble smry datasets in memory between plugins
- Loading branch information
Showing
13 changed files
with
184 additions
and
97 deletions.
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
41 changes: 41 additions & 0 deletions
41
webviz_subsurface/_models/caching_ensemble_set_model_factory.py
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,41 @@ | ||
import json | ||
from typing import Union, Optional, Dict | ||
import threading | ||
|
||
from .ensemble_set_model import EnsembleSetModel | ||
|
||
|
||
# Module level globals | ||
# Do we actually need to consider locking here or will this access always be single threaded? | ||
_cache_lock = threading.Lock() | ||
_ensemble_set_model_cache: Dict[str, EnsembleSetModel] = {} | ||
|
||
|
||
def get_or_create_model( | ||
ensemble_paths: dict, | ||
time_index: Optional[Union[list, str]] = None, | ||
column_keys: Optional[list] = None, | ||
) -> EnsembleSetModel: | ||
|
||
modelkey = json.dumps( | ||
{ | ||
"ensemble_paths": ensemble_paths, | ||
"time_index": time_index, | ||
"column_keys": column_keys, | ||
} | ||
) | ||
|
||
with _cache_lock: | ||
if modelkey in _ensemble_set_model_cache: | ||
# Just return existing model from cache | ||
return _ensemble_set_model_cache[modelkey] | ||
|
||
# No matching model in cache -> create a new ensemble set model and insert in cache | ||
new_model = EnsembleSetModel( | ||
ensemble_paths=ensemble_paths, | ||
smry_time_index=time_index, | ||
smry_column_keys=column_keys, | ||
) | ||
_ensemble_set_model_cache[modelkey] = new_model | ||
|
||
return new_model |
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
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
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
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.