Details
-
Type:
Story
-
Status: Invalid
-
Resolution: Done
-
Fix Version/s: None
-
Component/s: afw
-
Labels:
-
Epic Link:
-
Team:Data Release Production
-
Urgent?:No
Description
Erin Sheldon reports on slack that applying copy.deepcopy on an Exposure object fails to transfer even a reference to the PSF.
I think deepcopy will go through __reduce__ in this case, but we should check, and consider reimplementing __deepcopy__, to go through the C++ copy constructor instead, along with making sure __reduce__ doesn't miss anything.
Note that the desired behavior for deepcopy is that we actually perform a deep copy on any component that is mutable; immutable components such as the PSF or WCS may just be referenced (see this slack conversation if that seems surprising). I'd expect that to be the behavior of Storable.cloneStorable already for immutable objects already, so we could delegate to that, but I could easily imagine that it isn't, and maybe for good reason (Storable may not have a good way to obtain a shared_ptr to this, and if that's the limitation I'm not sure it's worth fixing on this ticket).
Krzysztof Findeisen, I've added you as a watcher just because you may already know some limitations or history that might block us from implementing what I've described as the desired behavior, or have a guess about where to look for what might be going wrong with components not being copied - I personally suspect that C++ copying is in good shape and the problem is somewhere in pybind11 or Python, but I'm not sure.
Attachments
Issue Links
- relates to
-
DM-32691 Add persistable class for constant PSFs
- To Do
Keep in mind that an ExposureInfo object can now contain arbitrary objects of almost-arbitrary type, and was in fact designed to move away from special treatment of PSF, WCS, etc. Delegating to a method on each object would work, however.
Since immutability is (literally) a foreign concept in C++, and anybody calling a method called clone presumably really does want a copy, I have made no attempt to do the kind of optimization you describe. I would recommend not doing so unless you can be sure the classes are truly immutable.
For example, Psf indeed lacks obvious mutators (including =
), but it also has a bunch of protected non-const methods for cache management... and why would an immutable class need a cache in the first place? I suspect that some subclasses of Psf, especially those implemented in Python, are actually mutable.