-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(robot-server): show run time parameters in pending analysis (#15229
) Closes AUTH-282 # Overview Follow-up to #15217 This PR changes a *pending analysis'* `AnalysisSummary` to include the run time parameters (with overrides). In order to do this, we will now be parsing the RTPs before analysis response is created. This is a very quick process and shouldn't cause any perceptible delays in the response of neither `POST /protocols` nor `POST /runs/.../analyses` endpoints, as long as recommended python protocol guidelines are followed. # Test Plan - [ ] Upload a protocol with run time parameters, verify that the response contains run time parameter definitions along with the values specified in the request - [ ] Send a `POST` request on `/protocols/{protocolId}/analyses` endpoint with different RTP values, or by specifying the `forceReanalysis` flag, and verify that the newly pending analysis also contains (updated) RTPs - [ ] Verify that pending summaries in `GET` endpoints also contain RTPs - [ ] Verify that summaries of completed analyses don't expose RTPs, while RTPs are available in the full analyses. # Changelog - Main change is the introduction of `AnalysesManager`. The analyses manager is responsible for creating a protocol analyzer per analysis, extracting the run time parameters from the runner and starting the analysis. - To facilitate this extraction of run time parameters, the `ProtocolAnalyzer` has been divided into two functions- one that loads the runner and other that runs the runner. - Updated the router to use `AnalysesManager` for starting analyses instead of directly interacting with `ProtocolAnalyzer`. # Review requests - Does the new architecture of `AnalysesManager` & updated `ProtocolAnalyzer` makes sense. - This PR doesn't expose the run time parameters in analysis summaries of completed analyses because of two reasons- (1) as opposed to the RTPs of a pending analysis, the completed analysis isn't guaranteed to be cached in memory. So we would need to read the completed analysis from database, de-serialize it and then return it. This would be made easier when we start storing RTPs in their own database table, but we're not there yet. (2) I'm not sure if it is needed. A completed analysis already contains the RTPs. Would like to get others' opinions on this. - Usual code review # Risk assessment - Medium. It changes a core part of protocol analysis but the end effect is a small change to the API. As long as tests are passing, it shouldn't cause any problems. - Small risk of analysis behavior change for badly written protocols as mentioned in [this](#15229 (comment)) comment.
- Loading branch information
Showing
18 changed files
with
768 additions
and
354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
"""A collaborator for managing protocol analyses.""" | ||
from typing import Optional | ||
|
||
from opentrons.protocol_engine.types import RunTimeParamValuesType | ||
|
||
from robot_server.protocols.analysis_models import ( | ||
AnalysisStatus, | ||
AnalysisSummary, | ||
) | ||
from robot_server.protocols.analysis_store import AnalysisStore | ||
from robot_server.protocols import protocol_analyzer | ||
from robot_server.protocols.protocol_store import ProtocolResource | ||
from robot_server.service.task_runner import TaskRunner | ||
|
||
|
||
class AnalysesManager: | ||
"""A Collaborator that manages and provides an interface to Protocol Analyzers.""" | ||
|
||
def __init__(self, analysis_store: AnalysisStore, task_runner: TaskRunner) -> None: | ||
self._analysis_store = analysis_store | ||
self._task_runner = task_runner | ||
|
||
async def start_analysis( | ||
self, | ||
analysis_id: str, | ||
protocol_resource: ProtocolResource, | ||
run_time_param_values: Optional[RunTimeParamValuesType], | ||
) -> AnalysisSummary: | ||
"""Start an analysis of the given protocol resource with run time param values.""" | ||
analyzer = protocol_analyzer.create_protocol_analyzer( | ||
analysis_store=self._analysis_store, protocol_resource=protocol_resource | ||
) | ||
pending = self._analysis_store.add_pending( | ||
protocol_id=protocol_resource.protocol_id, | ||
analysis_id=analysis_id, | ||
) | ||
try: | ||
protocol_runner = await analyzer.load_runner( | ||
run_time_param_values=run_time_param_values | ||
) | ||
pending.runTimeParameters = protocol_runner.run_time_parameters | ||
except BaseException as error: | ||
await analyzer.update_to_failed_analysis( | ||
analysis_id=analysis_id, | ||
protocol_robot_type=protocol_resource.source.robot_type, | ||
error=error, | ||
run_time_parameters=[], | ||
) | ||
return AnalysisSummary( | ||
id=analysis_id, | ||
status=AnalysisStatus.COMPLETED, | ||
) | ||
|
||
self._task_runner.run( | ||
analyzer.analyze, | ||
runner=protocol_runner, | ||
analysis_id=analysis_id, | ||
run_time_parameters=protocol_runner.run_time_parameters, | ||
) | ||
return AnalysisSummary( | ||
id=analysis_id, | ||
status=AnalysisStatus.PENDING, | ||
runTimeParameters=pending.runTimeParameters, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.