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

Ensure data read from enum signals is picklable #229

Closed
DominicOram opened this issue Apr 17, 2024 · 1 comment
Closed

Ensure data read from enum signals is picklable #229

DominicOram opened this issue Apr 17, 2024 · 1 comment

Comments

@DominicOram
Copy link
Contributor

For separation of RE and callbacks (e.g. using zmq) data from a read needs to be picklable. Currently if I do:

import pickle
from enum import Enum

import bluesky.plan_stubs as bps
from bluesky.run_engine import RunEngine
from ophyd_async.core import DeviceCollector, StandardReadable
from ophyd_async.epics.signal import epics_signal_r


class SynchrotronMode(str, Enum):
    SHUTDOWN = "Shutdown"
    INJECTION = "Injection"
    NOBEAM = "No Beam"
    DEV = "Mach. Dev."
    USER = "User"
    SPECIAL = "Special"
    STARTUP = "BL Startup"
    UNKNOWN = "Unknown"


class Device(StandardReadable):
    def __init__(
        self,
    ):
        self.mode = epics_signal_r(SynchrotronMode, "CS-CS-MSTAT-01:MODE")


RE = RunEngine()

with DeviceCollector():
    my_device = Device()


def my_plan():
    test = yield from bps.rd(my_device.mode)
    pickled_string = pickle.dumps(test)
    print(test, pickled_string)


RE(my_plan())

I get:

Traceback (most recent call last):
  File "/scratch/ffv81422/hyperion/dodal/scratch.py", line 40, in <module>
    RE(my_plan())
  File "/scratch/ffv81422/hyperion/dodal/.venv/lib/python3.10/site-packages/bluesky/run_engine.py", line 918, in __call__
    plan_return = self._resume_task(init_func=_build_task)
  File "/scratch/ffv81422/hyperion/dodal/.venv/lib/python3.10/site-packages/bluesky/run_engine.py", line 1057, in _resume_task
    raise exc
  File "/scratch/ffv81422/hyperion/dodal/.venv/lib/python3.10/site-packages/bluesky/run_engine.py", line 1687, in _run
    raise err
  File "/scratch/ffv81422/hyperion/dodal/.venv/lib/python3.10/site-packages/bluesky/run_engine.py", line 1547, in _run
    msg = self._plan_stack[-1].send(resp)
  File "/scratch/ffv81422/hyperion/dodal/scratch.py", line 36, in my_plan
    pickled_string = pickle.dumps(test)
_pickle.PicklingError: Can't pickle <enum 'GeneratedChoices'>: attribute lookup GeneratedChoices on ophyd_async.epics._backend.common failed

Acceptance Criteria

  • I can pickle the readback from an Enum signal
  • There are tests covering this
@coretl
Copy link
Collaborator

coretl commented Jun 18, 2024

Fixed by #237

@coretl coretl closed this as completed Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants