Skip to content

Conversation

@rjgildea
Copy link

@rjgildea rjgildea commented Dec 13, 2021

Use an entry points mechanism to allow enable a more flexible and extensible approach to handling scenarios in mimas.

The simplest mechanism is to register one (or more) functions that take a scenario and return a list of MimasRecipeInvocations or MimasISPyBJobInvocations:

def handle_scenarios(scenario: MimasScenario) -> List[Invocation]:
    return [
        MimasRecipeInvocation(...),
        MimasISPyBJobInvocation(...),
        ...
    ]

This function will handle every scenario passed to the mimas service. Alternatively, a more modular approach can be used, using the @match_specification decorator to filter scenarios that match a given specification before passing them to the function:

from dlstbx.mimas.specification import BeamlineSpecification, DCClassSpecification

is_i99 = BeamlineSpecification("i99")
is_rotation = DCClassSpecification(MimasDCClass.ROTATION)

@match_specification(is_i99 & is_rotation)
def handle_i99_rotation(scenario: MimasScenario) -> List[Invocation]:
    return [
        MimasRecipeInvocation(...),
        MimasISPyBJobInvocation(...),
        ...
    ]

Various commonly used specifications are provided, such as BeamlineSpecification, DCClassSpecification, DetectorClassSpecification, EventSpecification andVisitSpecification. More complex custom specifications may be built by inheriting from ScenarioSpecification. Specifications can be combined using bitwise operators (&, |, ~).

Once this is merged, I would suggest moving the non-DLS-specific components to the python-zocalo repository (see also DiamondLightSource/python-zocalo#129).

Copy link
Contributor

@Anthchirp Anthchirp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty cool. Love it.

@rjgildea rjgildea merged commit 68d8550 into master Dec 17, 2021
@rjgildea rjgildea deleted the mimas-specification branch December 17, 2021 09:22
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 this pull request may close these issues.

3 participants