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

Add migration from BlockFs storage #4937

Merged
merged 1 commit into from
Jun 1, 2023
Merged

Conversation

pinkwah
Copy link
Contributor

@pinkwah pinkwah commented Feb 22, 2023

No description provided.

@codecov-commenter
Copy link

codecov-commenter commented Mar 13, 2023

Codecov Report

Merging #4937 (1aff5b5) into main (eddeded) will decrease coverage by 0.79%.
The diff coverage is 22.82%.

@@            Coverage Diff             @@
##             main    #4937      +/-   ##
==========================================
- Coverage   77.88%   77.09%   -0.79%     
==========================================
  Files         391      393       +2     
  Lines       25545    25926     +381     
  Branches     1675     1760      +85     
==========================================
+ Hits        19895    19987      +92     
- Misses       5064     5353     +289     
  Partials      586      586              
Impacted Files Coverage Δ
src/clib/lib/block_fs_native/module.cpp 0.00% <0.00%> (ø)
src/ert/_c_wrappers/enkf/ensemble_config.py 96.49% <ø> (ø)
src/ert/storage/migration/block_fs.py 22.29% <22.29%> (ø)
src/ert/storage/local_storage.py 89.94% <73.68%> (-8.31%) ⬇️
src/ert/_c_wrappers/enkf/config/surface_config.py 100.00% <100.00%> (ø)
src/ert/cli/main.py 91.30% <100.00%> (+0.19%) ⬆️
src/ert/gui/main.py 92.82% <100.00%> (+2.32%) ⬆️
src/ert/storage/__init__.py 91.30% <100.00%> (ø)
src/ert/storage/local_ensemble.py 96.27% <100.00%> (ø)

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Collaborator

@oyvindeide oyvindeide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! A minor question and nitpicky comment

size_t len;
size_t count;

bool is_compressed() const {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not seem to be used?

Comment on lines +164 to +166
self.path = Path(path)
if not ignore_migration_check and local_storage_needs_migration(self.path):
from ert.storage.migration.block_fs import migrate # pylint: disable=C0415

migrate(self.path)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used at the moment, perhaps turn this migration into an issue instead? I would suggest moving this to the main entry point instead, so we have more control of the migration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be used in production (if storage needs migration, migrate)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be optional though? So you get a prompt, saying would you like to delete or migrate?

ensemble = experiment.create_ensemble(name="default", ensemble_size=5)
bf._migrate_field(ensemble, parameter, ens_config)

for key, data in data["/REAL_0/FIELD"].groups.items():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to parameterize this instead? Cant immediately see how, but think it might be possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can metaprogram myself to a solution, ie:

@pytest.mark.parameterize("type", ["field", "surface"])
def test_stuff(type):
  getattr(bf, f"_migrate_{type}")(ensemble, parameter, ens_config)

  for key, data in data[f"/REAL_0/{type.upper()}"].groups.items():
      ...

Do we want to use getattr in this way?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, fine to leave it as is

@dafeda
Copy link
Contributor

dafeda commented May 26, 2023

What are the benefits of using C++ for this?

}
}

auto parse_name(const std::string &name, Kind kind)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does name refer to here?
Also, seems like parse_name is only tested for Kind::SUMMARY.
Is it worthwhile adding tests for other kinds as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I just forgot to do so.

@pinkwah pinkwah force-pushed the migration branch 3 times, most recently from 842c443 to 964018e Compare May 30, 2023 08:34
m_stream.read(name.data(), name.size());
skip<char>(m_stream); // NULL terminator

auto node_size = read_i32(m_stream, nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

annotate-cpp FTW :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

annotate-cpp complained that node_size was not used.

@pinkwah pinkwah force-pushed the migration branch 5 times, most recently from 51ae460 to 7a3952b Compare May 30, 2023 12:54
std::ifstream m_stream;
/** Stream mutex */
mutable std::mutex m_mutex;
/** List of SUMMARY blocks */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think comment is outdated as m_blocks holds other kinds of blocks as well.

return False

try:
with open("index.json", encoding="utf-8") as f:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it perhaps better to use _Index.parse_file here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might not be. We are only interested in the version key because the structure of index.json is unknown at this time. _Index.parse_file would imply that the structure of index.json is the same as it is currently, which may not be the case in the future.

return False
if version < _LOCAL_STORAGE_VERSION:
return True
raise NotImplementedError("Incompatible ERT Local Storage")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we be more explicit here and say that version > _LOCAL_STORAGE_VERSION or something like that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your wish is my command

@dafeda
Copy link
Contributor

dafeda commented May 31, 2023

Should these steps be a happy path?

  1. Install 4.5.6 which is what's in stable.
  2. Run ert ensemble_smoother poly.ert --target_case "es_update"
  3. Install this branch
  4. Run ert gui poly.ert
Exception ignored in: <function LocalStorageReader.__del__ at 0x16370a320>
Traceback (most recent call last):
  File "/Users/FCUR/git/ert/src/ert/storage/local_storage.py", line 142, in __del__
    self.close()
  File "/Users/FCUR/git/ert/src/ert/storage/local_storage.py", line 189, in close
    super().close()
  File "/Users/FCUR/git/ert/src/ert/storage/local_storage.py", line 70, in close
    for ensemble in self._ensembles.values():
AttributeError: 'LocalStorageAccessor' object has no attribute '_ensembles'
ERT crashed unexpectedly with "Use 'local_storage_set_ert_config' before retrieving the config".
See logfile(s) for details:
   /Users/FCUR/git/poly_example/logs/ert-log-2023-05-31T1455.txt

@dafeda
Copy link
Contributor

dafeda commented Jun 1, 2023

I redid the experiment previously defined and now get this:

Traceback (most recent call last):
  File "/Users/FCUR/envs/intel/.venvfmu/bin/ert", line 33, in <module>
    sys.exit(load_entry_point('ert', 'console_scripts', 'ert')())
  File "/Users/FCUR/envs/intel/.venvfmu/bin/ert", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/usr/local/Homebrew/Cellar/python@3.10/3.10.11/Frameworks/Python.framework/Versions/3.10/lib/python3.10/importlib/metadata/__init__.py", line 171, in load
    module = import_module(match.group('module'))
  File "/usr/local/Homebrew/Cellar/python@3.10/3.10.11/Frameworks/Python.framework/Versions/3.10/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/Users/FCUR/git/ert/src/ert/__main__.py", line 26, in <module>
    from ert.cli.main import ErtCliError, ErtTimeoutError, run_cli
  File "/Users/FCUR/git/ert/src/ert/cli/main.py", line 28, in <module>
    from ert.storage import StorageAccessor, local_storage_set_ert_config, open_storage
ImportError: cannot import name 'local_storage_set_ert_config' from 'ert.storage' (/Users/FCUR/git/ert/src/ert/storage/__init__.py)

@pinkwah pinkwah force-pushed the migration branch 2 times, most recently from dcd3db2 to bfc4590 Compare June 1, 2023 08:05
Copy link
Contributor

@dafeda dafeda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested also with running es-mda on snake_oil_field with ert version 4.5.6 and then with this branch.
Seems to work.

Stellar work and good to go I think 👍

@pinkwah pinkwah merged commit 9e65975 into equinor:main Jun 1, 2023
37 checks passed
@pinkwah pinkwah deleted the migration branch June 1, 2023 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

4 participants