Skip to content

Add background scans to i15-1 converter - #73

Open
jacob-williamson wants to merge 24 commits into
mainfrom
95_calibration_sets
Open

Add background scans to i15-1 converter#73
jacob-williamson wants to merge 24 commits into
mainfrom
95_calibration_sets

Conversation

@jacob-williamson

Copy link
Copy Markdown
Collaborator

@jacob-williamson
jacob-williamson marked this pull request as draft July 10, 2026 11:15
@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.76%. Comparing base (e06458a) to head (29f8bbc).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #73      +/-   ##
==========================================
+ Coverage   98.74%   98.76%   +0.01%     
==========================================
  Files          17       18       +1     
  Lines         876      889      +13     
==========================================
+ Hits          865      878      +13     
  Misses         11       11              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jacob-williamson
jacob-williamson marked this pull request as ready for review July 13, 2026 15:09
@jacob-williamson
jacob-williamson marked this pull request as draft August 3, 2026 16:43
@jacob-williamson
jacob-williamson marked this pull request as ready for review August 4, 2026 16:12

@DominicOram DominicOram left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, looks like something we can definitely start testing. Some comments in code.

Additionally, could we put some more info logging in so that we can work out what the queue is doing in terms of finding existing backgrounds, adding new ones and removing duplicates?


from pydantic import BaseModel

BACKGROUND = Literal["air", "capillary_1", "capillary_2"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should: I think the capillaries are the same as those at https://github.com/DiamondLightSource/ulims-json-schemas/blob/9c156ced3504787f98b102747b28e4afba152292/schemas/samples/i15-1/powder/0.0.1.json#L38, which we can pull out of the graph. Happy to put this in another issue. We should also check with the beamline as this is a weirdly long list. It may be that we just need bs, fq, pi.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

#78

return new_tasks

def _get_required_backgrounds(self, experiment: Experiment) -> list[BackgroundInfo]:
return [BackgroundInfo(bg_type="air", cobra=False, blower=False)]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should: This is fine as a start but can you add tickets for adding the rest of the logic? i.e. add a background with that capillary type and ones at the correct temperature.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

#79

name="Background",
instrument_session=instrument_session,
# Need to get sample info for test samples (air, empty capillary etc)
sample=Sample(name="air_1_1", id="", data={}),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So the current expected behaviour is that we will run a collection on puck 1, sample 1? I think this is ok but:

  1. We need to make sure we put something in this position on the beamline
  2. For the air collection we will actually need to run a data collection with no sample loaded - this is proabbly a new issue

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

#83

self, background: BackgroundInfo, instrument_session: str
) -> Experiment:
return Experiment(
name="Background",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should: Can we pull this into a constant?

Comment thread src/daq_queuing_service/api/errors.py Outdated

@app.exception_handler(ConverterError)
async def converter_error_handler(request: Request, exception: ConverterError):
LOGGER.exception("Queue error occurred")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should: Was this accidentally added? If not, we should add the exception details.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

By some magic, this gives you the whole stack trace. However, I should add the same for all the exception handlers as it makes the queue logs much more useful.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh, I remember the exception magic now...

new_tasks.append(task)
return self._remove_repeated_backgrounds(new_tasks)

def _remove_repeated_backgrounds(self, tasks: list[Task]) -> list[Task]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Adding all the backgrounds then removing the repeats is probably not going to work indefinitely. There is a usecase for the different temperature collections to do something more clever e.g. if there is an experiment that takes data between 0-10 deg and another between 5-10 degrees then we can cover it with just one background between 0-10 degrees. There's also quite a bit of inefficiency here where we're looping through the list multiple times. I think it's ok for now to just think about air and empty capillaries at room temp though, which this does cover, so we can think about that another day.

@jacob-williamson jacob-williamson Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I think the logic here needs to be more complex, especially since background tasks persist between _syncs. I think this diagram sums it up
backgrounds logic drawio
Not covered there though is the need to remove background experiments from the queue if they are no longer required, for example if the experiment that required it has been removed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yh, I think spin it into a new issue though. For now just getting something where we can show it adds some backgrounds would be good

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

#80

),
]

def _add_required_background_scans(self, tasks: list[Task]) -> list[Task]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could: Can you add a docstring here?

TaskWithPosition,
)

SCAN_PLANS = Literal["centre_sample", "static_collection"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should: What is this literal for?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Have deleted it

def get_background_tiled_id(
required_background: BackgroundInfo, instrument_session: str
) -> str | None:
client = from_uri("https://tiled.diamond.ac.uk/api/v1")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should: I think this only works if you're logged in already right? I'm not sure how we make sure the queue is logged in?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This seems to work when running the queue locally without having logged in.. which does seem weird

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Have we tested in prod? Let's merge it and see

from tiled.queries import Eq

from daq_queuing_service.plugins.i15_1.backgrounds import BackgroundInfo

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should: I think just add an ignore for the linter on this whole file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

i15-1: Create calibration data sets if needed

2 participants