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

DM-33278: Improve storage class conversion #632

Merged
merged 13 commits into from Jan 19, 2022
Merged

DM-33278: Improve storage class conversion #632

merged 13 commits into from Jan 19, 2022

Conversation

timj
Copy link
Member

@timj timj commented Jan 14, 2022

  • Add a dataset type compatibility method.
  • Add support for specifying methods.

Checklist

  • ran Jenkins
  • added a release note for user-visible changes to doc/changes

@codecov
Copy link

codecov bot commented Jan 14, 2022

Codecov Report

Merging #632 (457729f) into main (90f5a21) will increase coverage by 0.01%.
The diff coverage is 93.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #632      +/-   ##
==========================================
+ Coverage   84.11%   84.12%   +0.01%     
==========================================
  Files         237      237              
  Lines       30143    30183      +40     
  Branches     5014     5018       +4     
==========================================
+ Hits        25354    25392      +38     
- Misses       3645     3646       +1     
- Partials     1144     1145       +1     
Impacted Files Coverage Δ
python/lsst/daf/butler/core/storageClass.py 93.92% <0.00%> (-0.61%) ⬇️
python/lsst/daf/butler/core/datasets/type.py 83.41% <94.73%> (+1.14%) ⬆️
...on/lsst/daf/butler/datastores/inMemoryDatastore.py 83.05% <100.00%> (+0.09%) ⬆️
tests/test_datasets.py 99.23% <100.00%> (+0.04%) ⬆️
tests/test_storageClass.py 98.88% <100.00%> (+0.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 90f5a21...457729f. Read the comment docs.

If a converter ends with () it is assumed to be a method
to run on the object to be converted and not a class method
or function.
Copy link
Contributor

@andy-slac andy-slac left a comment

Choose a reason for hiding this comment

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

Looks good, couple of minor comments/questions.

Comment on lines 162 to 168
In the first definition, the configuration says that if a ``PropertySet`` object is given then the ``toDict()`` method can be called on it and the returned value will be a `dict`.
In the second definition a ``PropertySet`` is again specified but this time the ``from_metadata`` class method will be called with the ``PropertySet`` as the first parameter and a ``TaskMetadata`` will be returned.
Copy link
Contributor

Choose a reason for hiding this comment

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

This difference between () and no () confused me a lot when I first saw it and it was not obvious what it means. I had to read everything more than once to figure it out. Now I think that toDict() is basically the same as lsst.daf.base.PropertySet.toDict (non-bound method). Would it be better to drop () and use non-bound method syntax for symmetry?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've been pondering this and the () syntax has the advantage that it doesn't lead to duplicating the full class name on both sides:

lsst.daf.butler.tests.MetricsExample: exportAsDict()

vs

lsst.daf.butler.tests.MetricsExample: lsst.daf.butler.tests.MetricsExample.exportAsDict

The latter does work and doesn't require any code changes to make it work without this ticket. Maybe that's a good enough argument for not trying to bother with the more succinct form.

if self._isCalibration != other._isCalibration:
return True

def is_compatible_with(self, other: "DatasetType") -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to quote DatasetType here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I'm confused between from __future__ import annotations being enabled and not being enabled. There was some other place where we did have to use strings if the type was used in the context of its own class but maybe that was to do with pydantic.

Copy link
Member

Choose a reason for hiding this comment

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

I believe we cannot use from __future__ import annotations with pydantic (which is really a shame, and I think it means we should mostly put pydantic classes in their own modules, so we can use it everywhere else). And without __future__.annotations, you do have to quote in places like this.

if self._isCalibration != other._isCalibration:
return True

def is_compatible_with(self, other: "DatasetType") -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

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

Does "compatible" mean compatible for both get and put? Is it symmetrical (X.is_compatible_with(Y) === Y.is_compatible_with(X))?

Copy link
Member Author

Choose a reason for hiding this comment

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

It really means self_sc.can_convert(other_sc) -- You have made me realize that ctrl_mpexec is going to have to try to distinguish inputs (so can convert on get to the required type for the Task) and outputs (so can convert the type used in the Task to the required type in the butler).

Sometimes a storage class can be defined with a different
name but is referring to the same python type.
@timj timj merged commit 8be9c34 into main Jan 19, 2022
@timj timj deleted the tickets/DM-33278 branch January 19, 2022 03:58
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.

None yet

3 participants