Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Ipyvolume viewer states are not JSON-serializable #471

Closed
Carifio24 opened this issue Oct 24, 2024 · 1 comment · Fixed by #474
Closed

Ipyvolume viewer states are not JSON-serializable #471

Carifio24 opened this issue Oct 24, 2024 · 1 comment · Fixed by #474
Labels
bug Something isn't working

Comments

@Carifio24
Copy link
Member

Carifio24 commented Oct 24, 2024

Describe the bug
The glue-jupyter 3D viewer states (used by the ipyvolume viewers) are not serializable due to limits_cache, which is a dictionary with component IDs as its keys.

To Reproduce

from glue_vispy_viewers.scatter.jupyter.scatter_viewer import JupyterVispyScatterViewer
from glue_jupyter.ipyvolume.scatter import IpyvolumeScatterView
from glue_jupyter import jglue
from glue.core import Data
from glue_jupyter.state_traitlets_helpers import GlueState

app = jglue()
data = Data(x=[0.0,1.0,2.0], y=[1.0,2.0,3.0], z=[8.0,9.0,10.0])
app.data_collection.append(data)

viewer = app.new_data_viewer(IpyvolumeScatterView, data=data)
gs = GlueState(viewer.state)
gs.convert_state_to_json(viewer.state, None)

Expected behavior
The viewer state should be JSON-serializable

Details:

  • Operating System: Ubuntu 22.04
  • Python version (python --version): Python 3.11.10

Additional context
This isn't a problem for the Jupyter VisPy volume viewers because the relevant property there is _limits_cache (note the underscore). "Private" properties are not serialized.

Thus, I think we could either:

@Carifio24 Carifio24 added the bug Something isn't working label Oct 24, 2024
@Carifio24
Copy link
Member Author

I should've mentioned this originally, but one use case where this becomes a problem is if you want to use the viewer state as a traitlet in a Vuetify template, e.g.:

import ipyvuetify as v
import traitlets

class TestTemplate(v.VuetifyTemplate):
    @traitlets.default('template')
    def _template(self):
        return """<div>
            <!-- Use the state somewhere here, like e.g. -->
            <p> {{ state }}</p>
        </div>
        """
    state = GlueState().tag(sync=True)

then the following will throw a TypeError: keys must be str, int, float, bool or None, not ComponentID

widget = TestTemplate(state=viewer.state)
widget

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant