diegojromerolopez / gelidum

Freeze your objects in python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there a way to unfreeze a frozen instance?

volkerjaenisch opened this issue · comments

Dear @diegojromerolopez

Thank you for this nice piece of software!
I need a frozen instance that I later can make a unfrozen (deep-)copy of. This is used for IMHO typical (scientific) data processing chains:

  1. Calculate a instance of an intermediate result A and store it frozen (e.g. load a dataset)
  2. Calculate a result B that depend on A but shares the same metadata (e.g. b = filter(A), or B= smooth(A))
  3. Store B frozen
    ...

In your documentation you stated that (deep-)copy of a frozen instance is not possible.

So I see two ways to achieve this goal:

  1. There may be a way to unfreeze a frozen instance?
  2. There may be a way to access the original instance below the frozen structural sharing?

Any help appreciated

Cheers,
Volker

Hello volkerjaenisch

Glad you find this project interesting and useful!

At the moment there is no way to unfreeze an instance, nor a way to get the original instance. I suppose you could have a side-effect in the on_freeze function, but that's not an elegant solution at all.

However, it's an interesting feature so I'm going to take a look and see if I can have a solution for this in a couple of days.

Best regards.

Hello @diegojromerolopez
Thank you very much for the fast response. I would be really happy if a solution could be found.
I am staying tuned.
Volker

@volkerjaenisch I have a possible solution for your problem in this PR: #22 please, check it out and see if it suits your needs.

Otherwise, could you give me a mock example of the pipeline you're trying to implement (for example using a toy dataset)? That way I could have a more clear idea of your use-case.

@diegojromerolopez
Perfect!
I will checkout your code tomorrow
Volker

Nice, keep me posted!

@diegojromerolopez
It seems to work.

But I learned that your code does not work inplace (build a readonly wrapper around the given instance) but returns a copy which is then made readonly. Sorry for not having understood that before I asked you. Since in that case of a not inplace operation we could use the original version of gelidum.

Also I noticed that you code does not support numpy arrays which I will open a separate issue for.

Sorry for the not so positive feedback. I really appreciate your effort

Volker

Exactly, the code of the PR does not work in-place, because now I have not a clear idea of how to unfreeze a frozen object. I'll need to think about this.

This package has some limitations, like not supporting classes with __slots__, maybe numpy arrays have that or for other reason gelidum does not support them.

No worries, any constructive feedback is positive feedback. Thank you!