Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Final tidy of the great ispyb refactor #1268

Merged
merged 10 commits into from
Apr 8, 2024

Conversation

rtuck99
Copy link
Contributor

@rtuck99 rtuck99 commented Mar 18, 2024

Fixes #1218

Link to dodal PR (if required): #XXX
(remember to update setup.cfg with the dodal commit tag if you need it for tests to pass!)

To test:

  1. do the tests pass

@@ -56,6 +68,8 @@ def __init__(
self.log = ISPYB_LOGGER

def activity_gated_start(self, doc: RunStart):
self._event_driven_data_collection_info = DataCollectionInfo()
self._sample_barcode = None
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This may be a bug because this will get called on every activity start while we are active not just the one where we are activated, thus we may end up erasing our data before we write it

@rtuck99 rtuck99 force-pushed the 1218_final_tidy_of_the_great_ispyb_refactor branch from 20d7c37 to 6a2a0a9 Compare March 22, 2024 16:20
@rtuck99 rtuck99 force-pushed the 1218_final_tidy_of_the_great_ispyb_refactor branch 2 times, most recently from 37e8849 to 266070d Compare April 2, 2024 13:48
@rtuck99 rtuck99 changed the base branch from main to 1252_fix_logging_unit_test_failures April 2, 2024 13:50
Base automatically changed from 1252_fix_logging_unit_test_failures to main April 3, 2024 11:30
Copy link
Collaborator

@DominicOram DominicOram left a comment

Choose a reason for hiding this comment

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

Half a review, can further discuss in person

@@ -178,6 +178,7 @@ def robot_load_then_centre(
yield from read_energy(cast(SetEnergyComposite, composite))
)

# XXX TODO 1173 remove this - left in to avoid breaking nexus files?
Copy link
Collaborator

@DominicOram DominicOram Apr 5, 2024

Choose a reason for hiding this comment

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

Created #1292 to remove this in a new PR

dcg_info = populate_data_collection_group(
self.ispyb.experiment_type,
params.hyperion_params.detector_params,
def populate_info_for_update(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should: Why are we putting the info from the start doc back into this object? Happy to discuss in person

Copy link
Collaborator

Choose a reason for hiding this comment

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

Discussed and fixed in #1279

@@ -178,6 +178,7 @@ def robot_load_then_centre(
yield from read_energy(cast(SetEnergyComposite, composite))
)

# XXX TODO 1173 remove this - left in to avoid breaking nexus files?
Copy link
Collaborator

@DominicOram DominicOram Apr 5, 2024

Choose a reason for hiding this comment

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

Created #1292 to remove this in a new PR

Copy link
Collaborator

@DominicOram DominicOram left a comment

Choose a reason for hiding this comment

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

Great, thank you! Made some comments but mostly quite minor in the end as I've pulled the bigger stuff into new issues

@@ -356,6 +356,7 @@ def flyscan_xray_centre(
@transmission_and_xbpm_feedback_for_collection_decorator(
composite.xbpm_feedback,
composite.attenuator,
# TODO 1033 don't use ispyb_params for this value, move it to experiment_params
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should: 1033 is now merged, I think this will be removed when you merge main into the PR?

dcg_info = populate_data_collection_group(
self.ispyb.experiment_type,
params.hyperion_params.detector_params,
def populate_info_for_update(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Discussed and fixed in #1279

@@ -220,6 +220,7 @@ def test_remote_callbacks_write_to_dev_ispyb_for_rotation(
test_rotation_params.hyperion_params.ispyb_params.beam_size_x = test_bs_x
test_rotation_params.hyperion_params.ispyb_params.beam_size_y = test_bs_y
test_rotation_params.hyperion_params.detector_params.exposure_time = test_exp_time
# TODO this should not be set here
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should: What does this comment mean? What's the path to fixing it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is part of the same set of changes as the other things which I have labelled #1173 but I think you've now labelled #1292 - basically the current_energy_ev shouldn't be in the ispyb_params but read out from events.

Comment on lines +403 to +404
# TODO Can't test barcode as need BLSample which needs Dewar, Shipping, Container entries for the
# upsert stored proc to use it.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should: The barcode is on the data collection group, I think we can test that. But also that will probably be removed soon anyway with #1293

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When you do an upsert_dc_group the sproc executes the following (or something similar):

     IF p_sampleId IS NULL AND p_sampleBarcode IS NOT NULL THEN
        SELECT max(bls.blSampleId) INTO p_sampleId
        FROM BLSample bls
          INNER JOIN Container c on c.containerId = bls.containerId
          INNER JOIN Dewar d on d.dewarId = c.dewarId
          INNER JOIN Shipping s on s.shippingId = d.shippingId
        WHERE bls.code = p_sampleBarcode AND s.proposalId = row_proposal_id;

Therefore the insert will not do anything unless you have all those things
The DCG upsert puts a barcode into a column called actualSampleBarcode, there isn't a column which is just called sampleBarcode, sampleBarcode is just used to lookup the sampleId

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is good to know. So basically setting sampleBarcode is just another way of setting the sampleId, which we are doing anyway.

@@ -805,3 +816,11 @@ def test_tidy_up_plans_disable_panda_and_zebra(
RE(tidy_up_plans(MagicMock()))
mock_panda_tidy.assert_called_once()
mock_zebra_tidy.assert_called_once()


def assert_event(mock_call, expected):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should: Can we just use the one in the conftest?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it seems I created both of them at pretty much the same time, so suspect I got distracted whilst moving it and just forgot

),
dummy_params.hyperion_params.detector_params,
dummy_params.hyperion_params.ispyb_params,
def scan_data_info_for_begin():
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could: I think it would be nicer if we could combine some of the common bits of these test helper functions that make ScanDataInfo and DataCollectionInfo as they're very verbose but I appreciate this makes it more explicit so up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thinking maybe I should remove this file if we don't support 2D gridscans!

@@ -289,6 +289,7 @@ def panda_flyscan_xray_centre(
@transmission_and_xbpm_feedback_for_collection_decorator(
composite.xbpm_feedback,
composite.attenuator,
# TODO 1033 don't use ispyb_params for this value, move it to experiment_params
parameters.hyperion_params.ispyb_params.transmission_fraction,
Copy link
Collaborator

Choose a reason for hiding this comment

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

As above

Comment on lines +117 to +120
# TODO 1173 Remove this once nexus_utils no longer needs it
self.params.hyperion_params.ispyb_params.transmission_fraction = doc[
"data"
]["attenuator_actual_transmission"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should: I think this disappears on merge?

Copy link
Contributor Author

@rtuck99 rtuck99 Apr 8, 2024

Choose a reason for hiding this comment

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

No it doesn't but I will remove them.
E: on reflection I will do that in a separate PR re new ticket #1295

convert_eV_to_angstrom(energy_ev)
)
# TODO 1173 Remove this once nexus_utils no longer needs wavelength_angstroms
self.params.hyperion_params.ispyb_params.current_energy_ev = energy_ev
Copy link
Collaborator

Choose a reason for hiding this comment

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

Created #1292 to remove this in a new PR

data_collection_group_id=data_collection_group_id,
data_collection_ids=(data_collection_id,),
ispyb_ids = IspybIds()
if scan_data_info.data_collection_info:
Copy link
Collaborator

Choose a reason for hiding this comment

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

The creating/updating of groups is very complicated, I've made #1293 to simplify

rtuck99 added 8 commits April 8, 2024 11:26
* Remove dependencies on populate_ methods
* Move some tests down to the callback mapping layer
* Populate test fixtures by direct parameter construction instead of duplicating caller logic
* Remove dependencies on dummy_params from unit tests
…emaining_data_collection_info()

Additional unit tests for callbacks
…due to nexus callback

* Correct references to current_energy_ev in various test.json files as it is now called expected_energy_ev
@rtuck99 rtuck99 force-pushed the 1218_final_tidy_of_the_great_ispyb_refactor branch from 266070d to 5b83260 Compare April 8, 2024 11:16
Copy link
Collaborator

@DominicOram DominicOram left a comment

Choose a reason for hiding this comment

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

Great, thank you!

@DominicOram
Copy link
Collaborator

Failing test is also failing on main so will merge this anyway and fix in a new PR

@DominicOram DominicOram merged commit 7075487 into main Apr 8, 2024
3 of 4 checks passed
@DominicOram DominicOram deleted the 1218_final_tidy_of_the_great_ispyb_refactor branch April 8, 2024 17:58
olliesilvester pushed a commit to olliesilvester/mx-bluesky that referenced this pull request Aug 23, 2024
…Source/1218_final_tidy_of_the_great_ispyb_refactor

Final tidy of the great ispyb refactor
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Final tidy of the great ispyb refactor
2 participants