Initialize callbacks using params emitted in Bluesky documents#959
Conversation
and replace plan names with constants
DominicOram
left a comment
There was a problem hiding this comment.
Good start, thanks! I love pulling all the strings into constants. Some comments in code.
Maybe I'm being dumb but why can't we use a normal constructor instead of the setup method?
| self.params: GridscanInternalParameters | RotationInternalParameters | None = ( | ||
| None | ||
| ) | ||
| self.ispyb: StoreRotationInIspyb | Store3DGridscanInIspyb | Store2DGridscanInIspyb |
There was a problem hiding this comment.
Should: Don't we want this to be anything that inherits from StoreInIspyb?
There was a problem hiding this comment.
base StoreInIspyb doesn't have all the attributes, type checker will be mad
There was a problem hiding this comment.
Which attributes? The only errors I see when I set it to StoreInIspyb are the arguments/return types on begin_deposition, which is a legitimate issue in the StoreInIspyb class
There was a problem hiding this comment.
Ok, I fixed it properly :)
| assert isinstance(self.params, GridscanInternalParameters) or isinstance( | ||
| self.params, RotationInternalParameters | ||
| ), "ISPyB handler params set with wrong type" |
There was a problem hiding this comment.
Should: I don't think this is very pythonic, we should just try and use it. Also, mypy should pick it up hopefully
|
|
||
| def start(self, doc: dict): | ||
| if doc.get("subplan_name") == ROTATION_OUTER_PLAN: | ||
| self.run_uid = doc.get("uid") |
There was a problem hiding this comment.
Should: run_uid is never used, remove it?
| if self.params.experiment_params.is_3d_grid_scan | ||
| else Store2DGridscanInIspyb(self.ispyb_config, self.params) | ||
| ) | ||
| self.run_start_uid = doc.get("uid") |
There was a problem hiding this comment.
Should: run_start_uid is never used, can we remove it?
| self.ispyb: StoreRotationInIspyb = StoreRotationInIspyb( | ||
| self.ispyb_config, self.params | ||
| ) | ||
| self.ispyb_ids: tuple[int, int] | tuple[None, None] = (None, None) |
There was a problem hiding this comment.
Should: Do we want to reset the ids for every start document we get? Why does the grid ispyb callback do this on init rather than on start? Feels like they should have the same behaviour
There was a problem hiding this comment.
good point, but they will diverge soon, when the rotation scan one should check if it should be reset at all
| assert ( | ||
| self.ispyb.params is not None | ||
| ), "ISPyB handler attached to Zocalo handler did not recieve parameters" | ||
| zocalo_environment = self.ispyb.params.hyperion_params.zocalo_environment |
There was a problem hiding this comment.
Should: Can we just get this out of the metadata rather than the ispyb object?
| self.zocalo_interactor = ZocaloInteractor( | ||
| self.ispyb.params.hyperion_params.zocalo_environment | ||
| ) | ||
| self.grid_position_to_motor_position: Callable[ | ||
| [ndarray], ndarray | ||
| ] = self.ispyb.params.experiment_params.grid_position_to_motor_position |
There was a problem hiding this comment.
Should: I don't like that we have to go through the ispyb object to get these, it seems really tightly coupled. Can we have a chat about a better way?
There was a problem hiding this comment.
I didn't think it was a problem since we're pulling ispyb IDs from there anyway, but we can just get it from the parameters, that's fine
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #959 +/- ##
==========================================
+ Coverage 93.71% 93.79% +0.07%
==========================================
Files 56 57 +1
Lines 2673 2755 +82
==========================================
+ Hits 2505 2584 +79
- Misses 168 171 +3 ☔ View full report in Codecov by Sentry. |
DominicOram
left a comment
There was a problem hiding this comment.
Some missed comments from before. Mostly there now.
Maybe I'm being dumb but why can't we use a normal constructor instead of the setup method?
Question still stands.
| { | ||
| "subplan_name": GRIDSCAN_OUTER_PLAN, | ||
| "hyperion_internal_parameters": test_fgs_params.json(), | ||
| } |
There was a problem hiding this comment.
Nit: Pull this into a variable and use below.
| self.ispyb_ids: tuple = (None, None, None) | ||
|
|
||
| def start(self, doc: dict): | ||
| if doc.get("subplan_name") == "run_gridscan_move_and_tidy": |
There was a problem hiding this comment.
@dperl-dls still valid comment
| LOGGER.info( | ||
| "Nexus writer recieved start document with experiment parameters." | ||
| ) |
There was a problem hiding this comment.
@dperl-dls still valid comment
| ispyb_config: str, | ||
| experiment_type: str, | ||
| parameters: GridscanInternalParameters = None, | ||
| parameters: GridscanInternalParameters | None = None, |
There was a problem hiding this comment.
Should: When do we ever pass None into here in production? Do we need to allow it?
There was a problem hiding this comment.
good spot, I cleaned up a bunch of other ones in here too
The constructor of a dataclass requires values for the fields as arguments, but the zocalo callback needs to be instantiated with the ispyb handler as an argument; you can't set the fields of self anywhere (even in init) for a frozen dataclass; we need We will also shortly remove these callback collections completely |
DominicOram
left a comment
There was a problem hiding this comment.
Great, thank you! Sorry for such a long back and forth
Fixes #950
Fixes #372
Callback classes now all get their params from the
"hyperion_internal_params"emitted in the outer start document of each plan.Adds an
IspybIdsto clean up some type checking issues80% of line count is just tests being put into classes so I could mock stuff better
To test: