devito icon indicating copy to clipboard operation
devito copied to clipboard

pickling, singletons, and comparison

Open FabioLuporini opened this issue 5 years ago • 3 comments

We have several objects that should be instantiated as singletons (e.g., LEFT, RIGHT, ... FORWARD, BACKWARD, ...) but they are not. This causes a subtle issue upon unpickling when these objects are compared. For example:

  • upon unpickling, an IterationDirection is reconstructed along with a completely new Backward ...
  • ... but this Backward will be different from the Backward created in space.py

this causes is comparisons to fail. Which led to PR #813 .

With singletons we should be able to elegantly fix this

FabioLuporini avatar Apr 26 '19 06:04 FabioLuporini

we might be able to turn Tag into a singleton generator and then just have something along the lines of

LEFT = Tag('Left')(...)

FabioLuporini avatar Apr 26 '19 07:04 FabioLuporini

I think what we actually need to do is using python's Enum

FabioLuporini avatar Apr 27 '19 07:04 FabioLuporini

I've promoted this to a bug.

But I'm closing PR #813 for now because I prefer to introduce the concept of singletons so that is comparison works even after unpickling

FabioLuporini avatar Nov 29 '19 07:11 FabioLuporini