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

Store resources in provenance #996

Merged
merged 1 commit into from
Feb 11, 2025

Conversation

benjeffery
Copy link
Member

@benjeffery benjeffery commented Feb 8, 2025

Fixes #975

Note that this adds psutil as a dep.

@benjeffery benjeffery force-pushed the resources_provenance branch from 9ba826e to fadaa35 Compare February 8, 2025 02:19
Copy link

codecov bot commented Feb 8, 2025

Codecov Report

Attention: Patch coverage is 96.02273% with 7 lines in your changes missing coverage. Please review.

Project coverage is 93.16%. Comparing base (e3b2155) to head (329c814).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
tsinfer/provenance.py 83.72% 4 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #996      +/-   ##
==========================================
- Coverage   93.17%   93.16%   -0.02%     
==========================================
  Files          18       18              
  Lines        6374     6462      +88     
  Branches     1088     1097       +9     
==========================================
+ Hits         5939     6020      +81     
- Misses        296      300       +4     
- Partials      139      142       +3     
Flag Coverage Δ
C 93.16% <96.02%> (-0.02%) ⬇️
python 95.46% <96.02%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Copy link
Member

@jeromekelleher jeromekelleher left a comment

Choose a reason for hiding this comment

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

Looks great. I think we can make the changes less intrusive and build a little bit more helper infrastructure. Generally mucking about with dictionaries is something to be minimised.


def __exit__(self, exc_type, exc_val, exc_tb):
end_times = self.start_process.cpu_times()
self.metrics = {
Copy link
Member

Choose a reason for hiding this comment

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

Might as well make this a dataclass,

@dataclasses.dataclass
class ResourceMetrics:
     elapsed_time: float # etc

then, this can support aggregation, so you can sum over a bunch of them.

Can add the asdict() method for getting out the dict, as usual.

usage = resource.getrusage(resource.RUSAGE_SELF)
max_rss = usage.ru_maxrss

if sys.platform == "darwin":
Copy link
Member

Choose a reason for hiding this comment

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

Could avoid the missed coverage via

if sys.platform == "linux":
     max_rss *= 1024
return max_rss

if record_provenance:
tables = ts.dump_tables()
# We don't have a source here because tree sequence files don't have a UUID yet.
record = provenance.get_provenance_dict(
command="match_samples",
resources=timing.get_metrics(),
Copy link
Member

Choose a reason for hiding this comment

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

timing.metrics.asdict()

results=results,
**wd.common_params(),
)
# Rewrite the last provenance with the correct info
Copy link
Member

Choose a reason for hiding this comment

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

Should be able to rewrite this using the dataclass, creating them with fromdict(), summing them totether and taking asdict of the result. That'll be simpler and less fragile.

@benjeffery benjeffery force-pushed the resources_provenance branch 2 times, most recently from 66e0e2b to 4743033 Compare February 10, 2025 16:25
@benjeffery
Copy link
Member Author

@jeromekelleher Good call, 4743033 adds a dataclass and de-duplicates the combination logic.

@mergify mergify bot merged commit a826069 into tskit-dev:main Feb 11, 2025
12 checks passed
@benjeffery benjeffery deleted the resources_provenance branch February 11, 2025 14:46
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.

Include timing information in provenance
2 participants