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

Initial VMXm FGS plan #942

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft

Initial VMXm FGS plan #942

wants to merge 8 commits into from

Conversation

Tom-Willemsen
Copy link
Contributor

@Tom-Willemsen Tom-Willemsen commented Oct 23, 2023

First pass at a FGS plan for VMXm - to test and refine on the beamline.

Based largely on existing FGS plan with references to the following devices removed:

  • ap_sg
  • flux
  • s4_slits
  • undulator
  • xbpm

Attenuator replaced with VmxmAttenuator

Nothing has been done about either shutter - understand that the fast shutter is being controlled by motion program, and that slow shutter can be controlled by GDA prior to calling into hyperion? This assumption might be wrong, check it on the beamline.

Needs DiamondLightSource/dodal#211

@codecov
Copy link

codecov bot commented Oct 24, 2023

Codecov Report

Attention: 91 lines in your changes are missing coverage. Please review.

Comparison is base (92b23da) 93.32% compared to head (a27463b) 90.38%.
Report is 86 commits behind head on main.

❗ Current head a27463b differs from pull request most recent head 35ee736. Consider uploading reports for the commit 35ee736 to get more accurate results

Files Patch % Lines
.../experiment_plans/vmxm_flyscan_xray_centre_plan.py 39.28% 68 Missing ⚠️
...nteraction/callbacks/xray_centre/nexus_callback.py 36.00% 16 Missing ⚠️
...ction/callbacks/xray_centre/callback_collection.py 66.66% 4 Missing ⚠️
...hyperion/external_interaction/nexus/nexus_utils.py 50.00% 2 Missing ⚠️
...hyperion/external_interaction/nexus/write_nexus.py 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     DiamondLightSource/hyperion#942      +/-   ##
==========================================
- Coverage   93.32%   90.38%   -2.94%     
==========================================
  Files          54       55       +1     
  Lines        2591     2747     +156     
==========================================
+ Hits         2418     2483      +65     
- Misses        173      264      +91     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -92,7 +92,7 @@ if [[ $START == 1 ]]; then
exit 1
fi

ISPYB_CONFIG_PATH="/dls_sw/dasc/mariadb/credentials/ispyb-artemis-${BEAMLINE}.cfg"
ISPYB_CONFIG_PATH="/dls_sw/dasc/mariadb/credentials/ispyb-artemis-i03.cfg"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need input from ispyb team to fix?

src/hyperion/experiment_plans/experiment_registry.py Outdated Show resolved Hide resolved
src/hyperion/external_interaction/nexus/nexus_utils.py Outdated Show resolved Hide resolved
src/hyperion/unit_tests/test_lookup_table.txt Outdated Show resolved Hide resolved
test_parameters.json Outdated Show resolved Hide resolved
eiger_params = EigerDetector(
"Eiger 16M", (detector_pixels.height, detector_pixels.width), "Si", 46051, 0
"Eiger 9M", (detector_pixels.height, detector_pixels.width), "CdTe", 2418770, 0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Definitely needs fixing before merge - this would break i03 if merged as-is

Comment on lines +56 to +60
# FIXME - HACK - plans commented out here because VMXm complains about no
# aperture_scatterguard which is needed for some plans.
# Need a way to either mark plans as being relevant only on some beamlines, or
# generally allow hyperion to *start* even if some plans reference nonexistent
# devices (and then fail at runtime if that plan is actually used).
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As per code comment - definitely needs fixing before merge.

@@ -32,7 +32,7 @@ def deploy(self, url):
deploy_repo.git.checkout(self.latest_version_str)

print("Setting permissions")
groups_to_give_permission = ["i03_staff", "gda2", "dls_dasc"]
groups_to_give_permission = ["i02-1_staff", "gda2", "dls_dasc"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fix this before merge. But don't just add vmxm/i03 to the list as that would give i03 permissions on vmxm and vice-versa.

Probably f"{beamline}_staff" would work, check that group exists for all supported beamlines.

Comment on lines +70 to +73
elif args.beamline == "i03":
return f"/dls_sw/{args.beamline}/software/bluesky"
elif args.beamline == "i02-1":
return f"/dls_sw/{args.beamline}/software/bluesky"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Remove this, it doesn't do anything, it's obsolete.

@@ -0,0 +1,225 @@
from __future__ import annotations
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For this whole file: there's obviously a lot of duplication, but also a lot of instrument-specific functionality.

Probably spin out an issue to come up with the right set of abstractions.

Also probably shouldn't be called _xray_centre_plan on VMXm, as it doesn't actually do xray centring at all - it does real data collections! So just vmxm_fast_grid_scan maybe. Will also need updating in GDA if changed.

Comment on lines +60 to +71
self.params.hyperion_params.ispyb_params.undulator_gap = doc["data"].get(
"undulator_gap", 0.0
)
self.params.hyperion_params.ispyb_params.synchrotron_mode = doc["data"].get(
"synchrotron_machine_status_synchrotron_mode", None
)
self.params.hyperion_params.ispyb_params.slit_gap_size_x = doc["data"].get(
"s4_slit_gaps_xgap", 0.0
)
self.params.hyperion_params.ispyb_params.slit_gap_size_y = doc["data"].get(
"s4_slit_gaps_ygap", 0.0
)
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 write an issue in hyperion to think harder about this.

Conceptually, I don't think the ispyb_callback class should "know" about instrument-specific things like s4_slits, which either don't exist or don't make sense for other beamlines. I think it should be getting this list of parameters from some beamline-specific configuration or parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But in the short term, I think this will work for both i03 and VMXm - even if it will end up putting nonsense values into VMXm's ispyb entries.

Cast to a list to pass it to Bluesky.preprocessors.subs_decorator()."""
Cast to a list to pass it to Bluesky.preprocessors.subs_decorator().

Note: specific to i03."""
Copy link
Contributor Author

@Tom-Willemsen Tom-Willemsen Nov 24, 2023

Choose a reason for hiding this comment

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

It would be nice to have this kind of comment (or an equivalent naming standard) throughout hyperion so that we can easily tell what is beamline specific, and what is being kept generic.

Maybe create an issue to come up with this standard and then retroactively apply it where we know there is instrument-specific code.


nexus_handler: GridscanNexusFileCallback
ispyb_handler: GridscanISPyBCallback
zocalo_handler: XrayCentreZocaloCallback

@classmethod
def from_params(cls, parameters: InternalParameters):
nexus_handler = GridscanNexusFileCallback()
nexus_handler = GridscanNexusFileCallback(create_i03_goniometer_axes)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Still feels like we should be passing this from "higher up" the call chain. But probably fine for now. Possibly create an issue to think about where this comes from.



class Gridscan2DNexusFileCallback(CallbackBase):
"""Similar to above, but for a 2D gridscan"""
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 the duplication with the class above shouldn't block merging in the short term, but let's write an issue to improve this in the longer term.

chi: float = 0,
phi: float = 0,
) -> Goniometer:
"""Returns a Nexgen 'Goniometer' object with the dependency chain of I03's Smargon
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
"""Returns a Nexgen 'Goniometer' object with the dependency chain of I03's Smargon
"""Returns a Nexgen 'Goniometer' object with the dependency chain of VMXm's axes

Comment is obviously wrong!

LOGGER.info("Creating ispyb entry.")
self.ispyb_ids = self.ispyb.begin_deposition()
LOGGER.info(f"Recieved ISPYB IDs: {self.ispyb_ids}")
LOGGER.info("Creating ispyb entry.")
Copy link
Contributor

Choose a reason for hiding this comment

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

How come this part is no longer within the if statement?

Copy link
Contributor Author

@Tom-Willemsen Tom-Willemsen Dec 4, 2023

Choose a reason for hiding this comment

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

If I recall correctly, VMXm only uses the READ_HARDWARE plan so they need to create the ispyb entry on that event - otherwise they won't get an entry at all. For i03, we need to check whether this is right.

It feels like a bit of a hack anyway to have this ispyb stuff listening on a specific type of message - but I think David or Dom have been doing some work to pull the ispyb interactions into an ophyd device? If that's the case then this may go away.



@dataclass(frozen=True, order=True)
class VmxmFastGridScanCallbackCollection(AbstractPlanCallbackCollection):
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think this would be nicer if it was called something like FastGridScanNoZocaloCallBackCollection, and then has the goniometer axes creation as a parameter? Then it isn't specific to VMXm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See my comment of the equivalent bit of code for i03:

Still feels like we should be passing this from "higher up" the call chain. But probably fine for now. Possibly create an issue to think about where this comes from.

So yes I agree with 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.

Don't put too much effort into this though, because I think David (or Dom?) is looking at pulling all or most of these callbacks into ophyd devices which would then make this obsolete anyway.

@olliesilvester
Copy link
Contributor

olliesilvester commented Dec 4, 2023

Things we need to change before we merge: (You wrote all this stuff in the comments anyway, this is mainly for me)

Other things which aren't as urgent but we should still do at some point:

  • Find the right set of abstractions between vmxm_flyscan_xray_centre_plan and the regular flyscan_xray_centre_plan. Also rename this for VMXm since it isn't actually doing any xray centring - instead the grid scan is the actual data collection. An issue for this should be made once this code is merged.
  • The ispyb callback class should use a beamline-specific config, since otherwise we have to put default values into ispyb entries for other beamlines - values for devices which don't exist for that beamline.
  • Make it clear throughout hyperion as to which parts are generic and which parts are beamline specific
  • Think of a nicer way to create the nexus file handler with beamline specific goniometer axes. Right now the callback collection classes are beamline specific, but only because the goniometer axes are beamline specific
  • Create abstractions for the GridscanNexusFilecallback, since there's currently a lot of duplication.
    Since callbacks are being reworked right now anyway, I won't make an issue for some of these yet

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.

2 participants