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

Add procedure completed actions and undo #228

Merged
merged 17 commits into from
Dec 17, 2024

Conversation

imaitland
Copy link
Collaborator

@imaitland imaitland commented Dec 10, 2024

  • The front end must display the current progress of the procedure. This PR adds a "completed_actions" property.
  • The front end must support undoing actions. This PR adds an "undo" endpoint".

@imaitland imaitland requested a review from amitschang December 10, 2024 21:23
Copy link

codecov bot commented Dec 10, 2024

Codecov Report

Attention: Patch coverage is 96.15385% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
evolver/app/routers/hardware.py 91.66% 1 Missing ⚠️
evolver/hardware/standard/pump.py 50.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@imaitland imaitland marked this pull request as ready for review December 11, 2024 17:30
@imaitland imaitland requested a review from a team as a code owner December 11, 2024 17:30
@imaitland imaitland force-pushed the iainland/add-procedure-completed-actions-and-undo branch from b7c60a1 to acac5bb Compare December 11, 2024 18:54
Copy link
Member

@amitschang amitschang left a comment

Choose a reason for hiding this comment

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

overall looks good. Some inline commentsI think can help make it easier to work with if I'm understanding correctly!

calibrator = hardware_instance.calibrator
if not calibrator:
raise CalibratorNotFoundError
Copy link
Member

Choose a reason for hiding this comment

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

[minor] Would be a good place for walrus!

    if not (calibrator := hardware_instance.calibrator):
        raise CalibratorNotFoundError

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nice, will fix.

Comment on lines +161 to +164
dispatch_action(client, "test", "measure_vial_0_temperature", {"temperature": 25.0})
dispatch_action(client, "test", "read_vial_0_raw_output")
dispatch_action(client, "test", "calculate_vial_0_fit")
Copy link
Member

Choose a reason for hiding this comment

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

I think this is fine for now, but we might want to make a note to create a mock procedure for the tests which cover action kinds (e.g. ones that need input, ones that don't, etc.), iso using the temperature one - just because this looks more generic

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah i agree, created an issue.#231

@@ -193,5 +193,5 @@ class Config(Calibrator.Config):
input_transformer: dict[int, ConfigDescriptor | Transformer | None] | None = None
output_transformer: dict[int, ConfigDescriptor | Transformer | None] | None = None

def create_calibration_procedure(self, selected_hardware, *args, **kwargs):
def create_calibration_procedure(self, selected_hardware, resume, *args, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

I know this is not added in this PR, but I don't think we even need this method here. It is abstract in the base and we can leave it out to have consistent error (TypeError from the ABC) - plus satisfying to remove code!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, cool will fix.

@@ -19,14 +19,26 @@ class TemperatureCalibrator(IndependentVialBasedCalibrator):

class CalibrationData(Transformer.Config):
measured: Dict[int, Dict[str, List[float]]] = {} # {vial_index: {"reference": [], "raw": []}}
completed_actions: List[str] = []
Copy link
Member

Choose a reason for hiding this comment

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

Since completed_actions looks like something we want to support at the interface, perhaps this should actually go in Transformer.Config (or actually I think better yet: this class should be based off Calibrator.CalibrationData and that should have completed_actions)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

makes sense, will fix.

This can be done by defining a SaveProcedureState action in the procedure and dispatching it.
"""
super().__init__(*args, **kwargs)
self.actions = []
self.state = {}
self.state = CalibrationStateModel(**(state or {})).model_dump()
Copy link
Member

Choose a reason for hiding this comment

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

looking at this and the setdefaults done below, I wonder if we rather could benefit from state being CalibrationStateModel iso Dict and make the model allow extra fields.

class CalibrationStateModel(BaseModel):
    model_config = ConfigDict(extra='allow')
    completed_actions: List[str] = Field(default_factory=list)

This way instantiating will always make the default empty list if not supplied, and user doesn't have to state explicitly deal with that. Also, I think without the extra being "allow"ed, this part might drop the things in **state that are not completed_actions

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will fix.

@imaitland imaitland force-pushed the iainland/add-procedure-completed-actions-and-undo branch from acac5bb to 40b7e50 Compare December 16, 2024 20:09
@imaitland imaitland requested a review from amitschang December 16, 2024 21:04
Copy link
Member

@amitschang amitschang left a comment

Choose a reason for hiding this comment

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

Thanks for the updates!

@imaitland imaitland merged commit 508f7c9 into main Dec 17, 2024
8 checks passed
@imaitland imaitland deleted the iainland/add-procedure-completed-actions-and-undo branch December 17, 2024 18:45
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.

2 participants