Skip to content

Conversation

asnyv
Copy link
Collaborator

@asnyv asnyv commented Feb 9, 2024

Quick attempt to resolve #260

A small question is how to handle the caching of decks in ResdataFiles. In this draft I cached only if requesting the full deck, and returned the cached even if only sections are requested. That means that the returned value if requesting sections might vary dependent on whether or not a full deck has previously been requested. Considering this is mainly implemented for speed increase I think it could be ok, but open to discuss that.

@asnyv asnyv requested a review from berland February 9, 2024 11:38
@codecov-commenter
Copy link

codecov-commenter commented Feb 9, 2024

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (eec0476) 95.18% compared to head (f7ca556) 95.21%.

❗ Current head f7ca556 differs from pull request most recent head da0fe9d. Consider uploading reports for the commit da0fe9d to get more accurate results

Files Patch % Lines
res2df/vfp/_vfp.py 20.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #487      +/-   ##
==========================================
+ Coverage   95.18%   95.21%   +0.03%     
==========================================
  Files          33       33              
  Lines        4463     4494      +31     
==========================================
+ Hits         4248     4279      +31     
  Misses        215      215              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

return Path(self._eclbase).absolute().parent

def get_deck(self) -> "opm.libopmcommon_python.Deck":
def get_deck(self, sections: list = []) -> "opm.libopmcommon_python.Deck":
Copy link
Collaborator

Choose a reason for hiding this comment

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

https://docs.python-guide.org/writing/gotchas/

use sections: list = None and then set it to the empty list later if None.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

considered to use None, but used an empty list as that is what is the default in opm.io.Parser.parse and tried to keep it more or less consistent. Open to change it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is a bug, you need to change it :)

There will be situations where you think you have an empty list, but then it isn't.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure if I understand you correctly.
The case here is:
If you give the opm parser an empty section list (which is the default), it returns the full deck.
If your opinion is that if you give an empty section list the expected returned value would be empty and that it might be confusing, I don't disagree with that. Also why I considered None in the first place. But I wouldn't call that a bug considering it was intended to keep the same format and behavior as opm.

So basically my question is: is what described above the "bug" or is it something else? I have no big issue with switching the default to None, but would like to know exactly what you mean as "the bug" to fix is 😉

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

It bit me hard once: equinor/fmu-ensemble@f109b6e

deck = resdatafiles.get_deck(
sections=[opm.io.eclSectionType.RUNSPEC, opm.io.eclSectionType.PROPS]
)
except (
Copy link
Collaborator

Choose a reason for hiding this comment

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

You may want to move this except to inside get_deck()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will take a look at it, probably a good idea.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

seems like an issue in this case will be that we cannot run it with opm < 2024.04 (which doesn't exist yet), as opm.io.eclSectionType.RUNSPEC isn't valid (without complicating the code outside get_deck).
An option is to instead have a list of strings as the get_deck() input and then map them to opm.io.eclSectionType inside get_deck(). Might also make it easier for most users.
E.g. a syntax like this get_deck(sections=["RUNSPEC", "PROPS"])

assert len(list(fd_dir.glob("*"))) == pre_fd_count
assert resdatafiles._rftfile is None

deck = resdatafiles.get_deck(sections=[opm.io.eclSectionType.PROPS])
Copy link
Collaborator

Choose a reason for hiding this comment

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

These new lines should probably be in a new test function, it is not related to testing of file descriptors.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will fix that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Explore speed increase in deck parsing

3 participants