Skip to content

Allow doing gridscans with generic number of grids#1623

Open
olliesilvester wants to merge 18 commits intomainfrom
364_make_nexus_callbacks_generic
Open

Allow doing gridscans with generic number of grids#1623
olliesilvester wants to merge 18 commits intomainfrom
364_make_nexus_callbacks_generic

Conversation

@olliesilvester
Copy link
Contributor

@olliesilvester olliesilvester commented Feb 11, 2026

Fixes #364 , #410

Changes nexus callbacks and the parameter model to allow for a generic number of grids done in the gridscan plan, rather than fixed fixed to doing 2 x 2D grids.

Note that this the ispyb integration with this will be done in a separate PR. Ispyb callback still expects 2 x 2D grids.

Also note that any plans using grid detection still only work for 2 X 2D grids

See issue for refactoring this here

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

Instructions to reviewer on how to test:

  1. Do thing x
  2. Confirm thing y happens

Checks for reviewer

  • Would the PR title make sense to a user on a set of release notes

if not self.omega_starts_deg
else self.omega_starts_deg[
0
], # This value is probably a lie after this PR... Could it be stored somewhere else? Should be an experiment param, not detector
Copy link
Contributor

Choose a reason for hiding this comment

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

It's metadata that we set on the detector but AFAIK it's not used downstream for gridscans. Would probably be fine to always set omega_start and omega_increment to 0, 0 for this tbh

x_steps: int = Field(gt=0)
y_steps: int = Field(gt=0)
omega_starts_deg: list[float] = Field(
default=[GridscanParamConstants.OMEGA_1, GridscanParamConstants.OMEGA_2]
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need defaults here? Why default to 2 grids at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only because this is the current "standard". But maybe it's better without a default

default=[GridscanParamConstants.BOX_WIDTH_UM] * 2
)
x_steps: PositiveInt # Currently this must be the same for each grid for panda scan
y_steps: list[PositiveInt]
Copy link
Contributor

Choose a reason for hiding this comment

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

It might make sense to hold a list of objects like _SingleGrid here and push the logic for building the grids into each single grid then SpecifiedGrids just holds the logic for concatenating them

Copy link
Contributor Author

@olliesilvester olliesilvester Feb 18, 2026

Choose a reason for hiding this comment

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

I think this probably will look nicer. The external parameters should still give all the grid info together, eg

omega_starts_deg: list[float] 
x_step_size_um: PositiveFloat 
y_step_sizes_um: list[PositiveFloat]
x_steps: PositiveInt  
y_steps: list[PositiveInt]

are all specified together. Then, internally we make SpecifiedGrids which contains: a list of SingleGrids (each of which has all the info needed to specify that one grid); as well as the concatenation bits: num_images, scan_spec, num_grids.

This will add another reasonable chunk onto the PR though. Better to accept this as technical debt and put into another issue or address now? I'd normally just do it, but I'm running out of time...

Copy link
Contributor

Choose a reason for hiding this comment

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

I think write up as another issue and address another time unless @rtuck99 disagrees.

The external parameters should still give all the grid info together

I actually think the external params should reflect what is possible. i.e. it's not clear that all those lists need to be the same length. IMO a better interface would be:

class SingleGrid:
    omega: float
    y_step_size: PositiveFloat # actually maybe should be outside this as there is no way of specifying differently for each grid
    y_steps: PositiveInt


x_step_size_um: PositiveFloat 
x_steps: PositiveInt  
grids: list[SingleGrid]

again, new issue though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I agree that i's better to be clear about what has to be the same length rather than relying on runtime validation. I was concerned that it would make the json blob look really ugly having to specify each grid like that. I think ugly json is preferable to unclear parameter rules though.

@codecov
Copy link

codecov bot commented Feb 16, 2026

Codecov Report

❌ Patch coverage is 94.11765% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.78%. Comparing base (6520e6e) to head (a31185d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1623      +/-   ##
==========================================
- Coverage   92.81%   92.78%   -0.04%     
==========================================
  Files         153      153              
  Lines        8642     8671      +29     
==========================================
+ Hits         8021     8045      +24     
- Misses        621      626       +5     
Components Coverage Δ
i24 SSX 78.60% <ø> (ø)
hyperion 98.22% <100.00%> (ø)
other 98.10% <93.85%> (-0.12%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@olliesilvester olliesilvester marked this pull request as ready for review February 18, 2026 14:52
@olliesilvester olliesilvester requested a review from a team as a code owner February 18, 2026 14:52
@olliesilvester olliesilvester changed the title make nexus callbacks generic (wip) Allow doing gridscans with generic number of grids Feb 18, 2026
@olliesilvester
Copy link
Contributor Author

FYI @rtuck99 this is a breaking change to hyperion - the external parameters have changed a bit. I'm happy to help Hyperion adjust for this

@olliesilvester olliesilvester mentioned this pull request Feb 18, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor nexus callbacks to be generic

2 participants

Comments