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

spec_scan lookup not working #782

Open
callumforrester opened this issue Jan 15, 2025 · 5 comments
Open

spec_scan lookup not working #782

callumforrester opened this issue Jan 15, 2025 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@callumforrester
Copy link
Contributor

callumforrester commented Jan 15, 2025

When running the spec_scan plan, blueapi's device reference deserialization mechanism cannot extract motors from a scanspec. The axes of the scan are still strings by the time the scanspec is passed to the plan, leading to an error message when blueapi tries to lookup the name of the "device":

2025-01-16 08:23:17,187 - 'str' object has no attribute 'name'
Traceback (most recent call last):
  File "/workspaces/blueapi/src/blueapi/worker/task_worker.py", line 340, in _cycle
    self._current.task.do_task(self._ctx)
  File "/workspaces/blueapi/src/blueapi/worker/task.py", line 33, in do_task
    ctx.run_engine(func(**prepared_params))
  File "/venv/lib/python3.11/site-packages/bluesky/run_engine.py", line 973, in __call__
    plan_return = self._resume_task(init_func=_build_task)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/bluesky/run_engine.py", line 1109, in _resume_task
    raise exc
  File "/venv/lib/python3.11/site-packages/bluesky/run_engine.py", line 1751, in _run
    raise err
  File "/venv/lib/python3.11/site-packages/bluesky/run_engine.py", line 1605, in _run
    msg = self._plan_stack[-1].send(resp)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/bluesky/utils/__init__.py", line 1260, in dec_inner
    return (yield from plan)
            ^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/dodal/plan_stubs/data_session.py", line 40, in attach_data_session_metadata_wrapper
    yield from bpp.inject_md_wrapper(plan, md={DATA_SESSION: data_session})
  File "/venv/lib/python3.11/site-packages/bluesky/preprocessors.py", line 755, in inject_md_wrapper
    return (yield from msg_mutator(plan, _inject_md))
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/bluesky/preprocessors.py", line 246, in msg_mutator
    msg = plan.send(None)
          ^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/dodal/plans/scanspec.py", line 47, in spec_scan
    yield from bp.scan_nd(tuple(detectors), _as_cycler(spec), md=_md)
  File "/venv/lib/python3.11/site-packages/bluesky/plans.py", line 1063, in scan_nd
    "motors": [motor.name for motor in cycler.keys],
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/bluesky/plans.py", line 1063, in <listcomp>
    "motors": [motor.name for motor in cycler.keys],
               ^^^^^^^^^^
AttributeError: 'str' object has no attribute 'name'

Steps To Reproduce

Run the failing spec_scan system test in #783

Acceptance Criteria

  • Running the plan (via, for example, `blueapi controller run spec_scan '{...}') performs a scan with no errors
@callumforrester callumforrester added the bug Something isn't working label Jan 15, 2025
@callumforrester
Copy link
Contributor Author

Tagging @huw-dls for awareness

@tpoliaw tpoliaw self-assigned this Jan 23, 2025
@tpoliaw
Copy link
Contributor

tpoliaw commented Jan 23, 2025

I think this is down to scanspec's discriminated_union_of_subclasses decorator not supporting generic types. For instance removing all references to ophyd types and models

uv tool run --with scanspec --with pydantic ptpython                                                                                                                                                   15:58:51
>>> import scanspec
... import pydantic
... from typing import Generic, Any, TypeVar
... T = TypeVar('T')
... @scanspec.core.discriminated_union_of_subclasses
... class Foo(Generic[T]):
...     pass
... @pydantic.dataclasses.dataclass
... class Bar(Foo[T]):
...     a: T
... print(pydantic.TypeAdapter(Foo[int]).validate_python({'a': '23', 'type': 'Bar'}))
... print(pydantic.TypeAdapter(Bar[int]).validate_python({'a': '23', 'type': 'Bar'}))
Bar(a='23')
Bar(a=23)

I'll keep looking but I think this might be better as a bug there instead of here.

@callumforrester
Copy link
Contributor Author

I think I am misunderstanding but I thought bluesky/scanspec#132 was supposed to cover this. Tagging @DiamondJoseph and @ZohebShaikh.

@tpoliaw
Copy link
Contributor

tpoliaw commented Jan 30, 2025

I have opened a new ticket in scanspec for this but will leave this open until it no longer affects blueapi.

@tpoliaw
Copy link
Contributor

tpoliaw commented Jan 31, 2025

Potential fix in scanspec: bluesky/scanspec#157

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

No branches or pull requests

2 participants