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

Pickling object does not preserve opts #6286

Closed
ahuang11 opened this issue Jun 15, 2024 · 2 comments
Closed

Pickling object does not preserve opts #6286

ahuang11 opened this issue Jun 15, 2024 · 2 comments
Labels
type: bug Something isn't correct or isn't working

Comments

@ahuang11
Copy link
Collaborator

import pickle
import holoviews as hv
hv.extension("bokeh")

curve = hv.Curve([0, 1, 2], kdims=["XAXIS"]).opts(color="red")
pickle.loads(pickle.dumps(curve))

Expected:
image

Actual:
image

@ahuang11 ahuang11 added TRIAGE Needs triaging type: bug Something isn't correct or isn't working and removed TRIAGE Needs triaging labels Jun 15, 2024
@ahuang11
Copy link
Collaborator Author

ahuang11 commented Jun 15, 2024

There's some differences in operations:
__getstate__ obj_dict

{
    '_in_method': False,
    'interface': <class 'holoviews.core.data.dictionary.DictInterface'>,
    'data': OrderedDict([
        ('XAXIS', array([0, 1, 2])),
        ('y', array([0, 1, 2]))
    ]),
    '_id': None,
    '_plot_id': 4362542608,
    '_param__private': <param.parameterized._InstancePrivate object at 0x1342eaec0>,
    'ndims': 1,
    '_cached_constants': {},
    '_settings': None,
    '_pipeline': chain(
        dynamic='default', 
        group='', 
        input_ranges={}, 
        link_inputs=False, 
        name='chain00873', 
        operations=[
            factory(
                args=[], 
                dynamic='default', 
                group='Operation', 
                input_ranges={}, 
                kwargs={'kdims': [Dimension('XAXIS')], 'vdims': [Dimension('y')]}, 
                link_inputs=False, 
                name='factory00860', 
                output_type=<class 'holoviews.element.chart.Curve'>, 
                streams=[]
            ), 
            factory(
                args=[], 
                dynamic='default', 
                group='Operation', 
                input_ranges={}, 
                kwargs={'mode': None}, 
                link_inputs=False, 
                name='factory00871', 
                output_type=<class 'holoviews.core.accessors.Opts'>, 
                streams=[]
            ), 
            method(
                args=[], 
                dynamic='default', 
                group='Operation', 
                input_ranges={}, 
                input_type=<class 'holoviews.core.accessors.Opts'>, 
                kwargs={'color': 'red'}, 
                link_inputs=False, 
                method_name='call', 
                name='method00872', 
                output_type=None, 
                streams=[]
            )
        ], 
        output_type=<class 'holoviews.element.chart.Curve'>, 
        streams=[]
    ),
    '_transforms': [],
    '_cached': None,
    '_dataset': None,
    '_index_skip': False
}

__setstate__ d

{
    '_in_method': False,
    'interface': <class 'holoviews.core.data.dictionary.DictInterface'>,
    'data': OrderedDict([
        ('XAXIS', array([0, 1, 2])),
        ('y', array([0, 1, 2]))
    ]),
    '_id': None,
    '_plot_id': 4426047952,
    '_param__private': <param.parameterized._InstancePrivate object at 0x13d5f34c0>,
    'ndims': 1,
    '_cached_constants': {},
    '_settings': None,
    '_pipeline': chain(
        dynamic='default',
        group='',
        input_ranges={},
        link_inputs=False,
        name='chain00874',
        operations=[
            factory(
                args=[],
                dynamic='default',
                group='Operation',
                input_ranges={},
                kwargs={'kdims': [Dimension('XAXIS')], 'vdims': [Dimension('y')]},
                link_inputs=False,
                name='factory00860',
                output_type=<class 'holoviews.element.chart.Curve'>,
                streams=[]
            )
        ],
        output_type=<class 'holoviews.element.chart.Curve'>,
        streams=[]
    ),
    '_transforms': [],
    '_cached': None,
    '_dataset': None,
    '_index_skip': False
}

From ChatGPT:

Plot ID:

First dictionary: _plot_id: 4362542608
Second dictionary: _plot_id: 4426047952
Pipeline Name:

First dictionary: name='chain00873'
Second dictionary: name='chain00874'
Operations within Pipeline:

First dictionary has three operations (one factory with kwargs={'kdims': [Dimension('XAXIS')], 'vdims': [Dimension('y')]}, another factory with kwargs={'mode': None}, and a method with kwargs={'color': 'red'}).
Second dictionary has only one operation (a factory with kwargs={'kdims': [Dimension('XAXIS')], 'vdims': [Dimension('y')]}).
_param__private Memory Address:

First dictionary: _param__private: <param.parameterized._InstancePrivate object at 0x1342eaec0>
Second dictionary: _param__private: <param.parameterized._InstancePrivate object at 0x13d5f34c0>

@ahuang11
Copy link
Collaborator Author

User issue

Needed to set hv.Store.save_option_state = True

import pickle
import holoviews as hv
hv.Store.save_option_state = True
hv.extension("bokeh")

curve = hv.Curve([0, 1, 2], kdims=["XAXIS"]).opts(color="red")
pickle.loads(pickle.dumps(curve))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

No branches or pull requests

1 participant