Repository navigation
Galactocentric frame defaults registry - #10624
Conversation
|
Hello @nstarman 👋! It looks like you've made some changes in your pull request, so I've checked the code again for style. There are no PEP8 style issues with this pull request - thanks! 🎉 Comment last updated at 2020-09-16 20:03:53 UTC |
|
If this PR aligns with Astropy's goals for ScienceState, I think there's room to push further. In particular, the This currently does not work as the context would have |
|
Cool, thanks for this @nstarman! I'll review this sometime over the next week or so. |
mhvk
left a comment
There was a problem hiding this comment.
I like the new registry very much! There are some in-line comments, mostly to help clarify.
My main suggestion would be to not add the StateMixinMeta metaclass, at least not in this PR. The ScienceState class is used in quite a few other places, and I think we should first make sure it provides greatest benefit to all (and that it doesn't make expanding them more difficult). I also think the benefit here is small at best - I don't really see why the ScienceState classes should have dict-like behaviour. My overall sense would be just to keep things minimal, but I could see instead adding a few @classproperty to help get more information on the current state (or perhaps expand what .get() can return).
|
The question is which to do first? Based upon the comments, particularly the implementation details to make a
I do have a fix for all this, but I think should be the subject of a different PR since it is a more substantial change to ScienceState. The changes to As a preview for a ScienceState PR. It is a drop-in replacement for all the current ScienceState classes. It should allow the galactocentric.py.txt (Unfortunately these had to be attached as .txt) |
|
@nstarman - looks like we agree - let's just split this into a first part that adds the registration and a follow-up PR that improves |
|
With the exception of moving |
|
Mainly minor comments from me, but otherwise this is looking great! |
adrn
left a comment
There was a problem hiding this comment.
I'm happy with this, apart from a few remaining minor comments!
adrn
left a comment
There was a problem hiding this comment.
Sorry for the delay (just back from vacation). This is looking great! I have a few minor suggested changes, otherwise I think this is ready.
|
Thanks for the comments @adrn . I think I have addressed / committed them all.
And same with travis. Unrelated failures. |
58e6c7e to
c3b0924
Compare
|
Tried to make it squash to 1, but there was a conflict on force push, so the minimum appears to be 2. RTD failure still unrelated. |
mhvk
left a comment
There was a problem hiding this comment.
Always seem to see yet more when I look at code again. So sorry!
Anyway, it allows me to note that the way to get one commit (and avoid a merge commit in your branch, which we try to avoid [if mostly for backporting which is not relevant here]) is to do a rebase on master before git push -f.
| return copy.deepcopy(self) | ||
|
|
||
|
|
||
| def _reduce_stateproxy(sp: _StateProxy): |
There was a problem hiding this comment.
I think the advantage of the class above is that it can now define __getstate__ instead of registering this override. Or am I missing something? I am actually slightly confused why this needed - why not adjust the .copy method itself?
There was a problem hiding this comment.
Unfortunately, a __getstate__ method doesn't work in this case. I could create a custom __deepcopy__ method, but the copyreg method also allows the object to be pickled.
There was a problem hiding this comment.
https://docs.python.org/3/library/copy.html
ultimate and penultimate paragraphs
There was a problem hiding this comment.
But with this code, doesn't it mean that if you unpickle the pickled instance, you get a dict rather than a _StateProxy?
I'm actually not quite sure whether it is possible to pickle and unpickle the class itself, but it would not seem good that if I pickled the registry for use in another process, all the registries would become dict... Especially if the goal is to ensure to avoid a place being made to propagate back.
Overall, I do wonder if we're not over-engineering this. Might it not make more sense to just create a new dict (i.e., do the deep copy) inside the get_registry method? (I vaguely fear this is returning to a previous design -- if so, sorry!).
There was a problem hiding this comment.
If I switch from copyreg to implementing __deepcopy__ in _StateProxy, then the deep copy will happen inside the get_from_registry method and it will have identical behavior to MappinProxy (ie read-only), but also implement getitem. It will not be able to be pickled, so should not have any unexpected behavior.
|
Out of the code thread, maybe good to explicitly discuss (cc @adrn): the idea of the I can see the benefit, but am wondering whether it is worth the complexity and performance, given the extra copies any time the state is queried. I also worry about giving a false sense of security, if not for this code, then for the rest of astropy! p.s. Don't want to make a big deal of this, though! Just thinking the extra code now introduced to make the |
4f33c95 to
f07fbeb
Compare
Thanks for the tip. |
I think the new implementation is a lot cleaner. Instead of direct |
f6a7cdc to
133667d
Compare
mhvk
left a comment
There was a problem hiding this comment.
two lines that are no longer needed left...
Otherwise, looks great!
133667d to
9b9d46c
Compare
@mhvk astropy#10624 (comment) Signed-off-by: Nathaniel Starkman <[email protected]>
@mhvk astropy#10624 (comment) Signed-off-by: Nathaniel Starkman <[email protected]>
4db4100 to
1fd3d76
Compare
|
Darn, was just looking at this to merge it and now it has a conflict... Could you rebase/sqash one more time, @nstarman? Thanks! |
Signed-off-by: Nathaniel Starkman <[email protected]>
1fd3d76 to
d54a9a3
Compare
@mhvk, done. As far as I can tell, the failures are unrelated. |
|
Thanks, @nstarman! |
|
🎉 A huge thanks to you @nstarman for this! (CI failures were indeed unrelated.) |
|
Thanks for all the comments and suggestions! This was a great learning experience. |
Description
galactocentric_frame_defaultsallows for a user-defined set of parameters to be manually set. This PR extends that capability to a registry system such that parameter sets may be named and get/set just like the built-in option (pre-v4.0, v4.0).Additional metadata, such as the value standard deviations, is supported by the
_statedictionary attribute, whose items are also exposed to the user by key access on the main class.If metadata is added to one parameter set, for consistency it should be added to all. Though the built-in options are read-only for "value" and "references", they permit additional fields, such as the standard deviation.