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

Replace PlanModel using the __doc__ of a plan with using Annotated pydantic fields #644

Open
DiamondJoseph opened this issue Sep 17, 2024 · 1 comment
Labels
enhancement New feature or request rest api Potential REST API changes worker Relates to worker code

Comments

@DiamondJoseph
Copy link
Collaborator

DiamondJoseph commented Sep 17, 2024

blueapi controller plans returns a description of the plans that are available in the context. Currently this comes from the docstring of the plan function. This should get also/instead(?) the description of the Pydantic model that is constructed, including information about the fields of the plan: defaults, types, limits etc.

Using Annotated allows us to have this information presented as part of the json schema, and reduce the amount of information required in the docstring.

@DiamondJoseph
Copy link
Collaborator Author

e.g.

def stp_snapshot(
    detectors: list[Readable],
    temperature: Movable = inject("sample_temperature"),
    pressure: Movable = inject("sample_pressure"),
) -> MsgGenerator:
    """
    Moves devices for pressure and temperature (defaults fetched from the context)
    and captures a single frame from a collection of devices

    Args:
        detectors (List[Readable]): A list of devices to read while the sample is at STP
        temperature (Optional[Movable]): A device controlling temperature of the sample,
            defaults to fetching a device name "sample_temperature" from the context
        pressure (Optional[Movable]): A device controlling pressure on the sample,
            defaults to fetching a device name "sample_pressure" from the context
    Returns:
        MsgGenerator: Plan
    Yields:
        Iterator[MsgGenerator]: Bluesky messages
    """

then becomes

def stp_snapshot(
    detectors: set[Readable] = Annotated[
        Field(set[Readable], min_length=1), "Devices to read while the sample is at STP"
    ],
    temperature: Movable = Annotated[
        inject("sample_temperature"), "A device controlling temperature of the sample"
    ],
    pressure: Movable = Annotated[
        inject("sample_pressue"), "A device controlling pressure of the sample"
    ],
) -> MsgGenerator:
    """
    Moves devices for pressure and temperature (defaults fetched from the context)
    and captures a single frame from a collection of devices
    """

And the information about the detector minimum length (bad example) gets propagated through.

@callumforrester callumforrester added enhancement New feature or request rest api Potential REST API changes worker Relates to worker code labels Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request rest api Potential REST API changes worker Relates to worker code
Projects
None yet
Development

No branches or pull requests

2 participants