Skip to content

Combine context.plans and context.plan_functions into a single dictionary #180

Closed

Description

@DiamondJoseph

Making context.plans hold a dataclass e.g.

@dataclass
class PlanWithMetadata:
    plan_function: PlanGenerator
    params: 
    metadata:

prevents having to maintain two dictionaries but also means we can easily extract the serialisable parts of the plan to send.

Activity

  1. added
    enhancement
    on May 12, 2023
  2. callumforrester commented on May 12, 2023

    @callumforrester
    Contributor

    Also need to integrate the Plan and PlanModel classes

  3. callumforrester commented on Feb 7, 2024

    @callumforrester
    Contributor

    I think what's needed is something like

    @dataclass
    class Plan:
        model: PlanModel
        func: PlanGenerator
  4. self-assigned this
    on Mar 8, 2024
  5. stan-dot commented on Mar 14, 2024

    @stan-dot
    Contributor

    note: Plan is in core/bluesky_types.py with fields: name, description, model (Pydantic model)
    PlanModel is in service/model.py under with fields: name, description, parameter_schema (optional dictionary).
    The latter also has a classmethod 'from_plan', which serves as alternative constructor.

    Both classes extend BlueepiBaseModel

  6. stan-dot commented on Mar 14, 2024

    @stan-dot
    Contributor

    suggested plan of work:

    1. change the PlanModel fields to conform to @DiamondJoseph 's formulation above
    2. change all instances of Plan into the PlanGenerator (?)
    3. Do something about the two other classes in bluesky_types.py: DataEvent and WatchableStatus. Those could be moved into the Model class
  7. callumforrester commented on Mar 26, 2024

    @callumforrester
    Contributor

    Need to ensure that there is still a serialisable artefact (i.e. does not hold a function) that can be used as part of the API

  8. stan-dot commented on Mar 27, 2024

    @stan-dot
    Contributor

    explore avenue to add a field exempt from serialization to the pydantic model. also a pydantic model not a dataclass.

  9. stan-dot commented on Mar 28, 2024

    @stan-dot
    Contributor

    that's tightly connected with #407 , ideally it's 1 PR for both

  10. callumforrester commented on Apr 4, 2024

    @callumforrester
    Contributor
  11. stan-dot commented on Apr 4, 2024

    @stan-dot
    Contributor

    discussion output - serialize less, do not except fields, just do composition

  12. removed their assignment
    on Apr 22, 2024
  13. DiamondJoseph commented on Sep 6, 2024

    @DiamondJoseph
    ContributorAuthor

    May be able to make use of TypeAdapter instances to get the JSON schema from.

    class Plan(BlueapiBaseModel):
        """
        A plan that can be run
        """
    
        name: str = Field(description="Referenceable name of the plan")
        description: str | None = Field(
            description="Description/docstring of the plan", default=None
        )
        model: type[BaseModel] = Field(
            description="Validation model of the parameters for the plan"
        )

    becomes

    class Plan(BlueapiBaseModel):
        """
        A plan that can be run
        """
    
        name: str = Field(description="Referenceable name of the plan")
        description: str | None = Field(
            description="Description/docstring of the plan", default=None
        )
        type_adapter
        generator: PlanGenerator
    
        @property
        def schema(self) -> str:
            return self.type_adapter.json_schema()
  14. stan-dot commented on Sep 9, 2024

    @stan-dot
    Contributor

    @DiamondJoseph what if we just convert the plangenerator function to string?

  15. DiamondJoseph commented on Sep 9, 2024

    @DiamondJoseph
    ContributorAuthor

    @DiamondJoseph what if we just convert the plangenerator function to string?

    @stan-dot the plan generator was the actual code that was being executed by the RunEngine, but now that it's the opposite side of the _rpc call it's not completely unreasonable. Then

    class Plan(BlueapiBaseModel):
        ref: tuple[str, str]  # module and func name? Require module name if func name not unique?
        description: str  # from the docstring
        adapter or schema?
  16. callumforrester commented on Sep 9, 2024

    @callumforrester
    Contributor

    So the two dictionaries were originally made so separate the API object, that is passed in and out from external callers, and an internal object with non-serializable data in it to be passed around internally. As @DiamondJoseph says, now we have internal RPC between two processes that makes less sense.

    Another option is to try and keep the non-serializable data only in the worker process and never need to pass it around, if that's achievable. We are currently having this discussion because we're thinking about how to get plan information from BlueskyContext to TaskWorker, but I raised #616 to tidy up BlueskyContext anyway, so maybe there's a cleaner way to do all of this?

  17. stan-dot commented on Sep 9, 2024

    @stan-dot
    Contributor

    BlueskyContext is a god-object because it's too generic a name. TaskWorker will likely have its own context
    BlueapiServer will have its own context.

    shared state can be held in something like https://github.com/etcd-io/etcd

  18. added 2 commits that reference this issue on Nov 9, 2026
    601694f
    f0c530c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: contextenhancementpriority low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions