Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable collect for multiple detectors #1651

Merged
merged 36 commits into from
Mar 21, 2024
Merged

Conversation

abbiemery
Copy link
Contributor

Description

Changes the collect method in bundler to handle the collection of multiple detectors. Contains the logic to collect stream resources using the maximum common number of frames written, determined by the minimum index.

Asset has been altered to only address a resource and datum and a new StreamAsset has been created to address stream_resource and stream_datum.

Motivation and Context

This enables logic to be moved out of Ophyd-async, generalising the process
Fixes #1649.

How Has This Been Tested?

TBC.

@abbiemery abbiemery marked this pull request as ready for review March 1, 2024 09:45
@abbiemery abbiemery requested a review from coretl March 1, 2024 09:46
Copy link
Member

@danielballan danielballan left a comment

Choose a reason for hiding this comment

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

Looks great. The effort on these tests is hugely valuable. I am suggested additional docstrings and added one comment on DocHolder for consideration, but I'm happy for this to go ahead.

)


def read_Readable(self) -> Dict[str, Reading]:
return dict(det2=dict(value=1.2, timestamp=0.0))
class DocHolder(dict):
Copy link
Member

Choose a reason for hiding this comment

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

This is clever.

I'll mention that there is a utility in the test utils with a similar functionality, but I like the simplicity of this one.

It might be worth considering using collections.defaultdict(list) instead, which I think is a more "mainstream" / familiar way to achieve this, and refactoring assert_emitted into a function. On the other hand, I'm not sure that buys much over implementation here. Just a thought.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The choice between:

class DocHolder(dict):
    def append(self, name, doc):
        self.setdefault(name, []).append(doc)

    def assert_emitted(self, **numbers: int):
        assert list(self) == list(numbers)
        assert {name: len(d) for name, d in self.items()} == numbers

def test_plan():
    docs = DocHolder()
    RE(plan(), docs.append)
    docs.assert_emitted(start=1, descriptor=1, resource=1, datum=1, event=1, stop=1)

and

from collections import defaultdict

def assert_emitted(docs: Dict[str, list], **numbers: int):
    assert list(docs) == list(numbers)
    assert {name: len(d) for name, d in docs.items()} == numbers

def test_plan():
    docs = defaultdict(list)
    RE(plan(), lambda name, doc: docs[name].append(doc))
    assert_emitted(docs, start=1, descriptor=1, resource=1, datum=1, event=1, stop=1)

I think I marginally prefer the second, but not enough to change all the tests. @abbiemery I leave the choice up to you...

Copy link
Member

Choose a reason for hiding this comment

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

I am in complete agreement. Slight preference, but not sure it's worth the effort to change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Given the time pressure of these now, i'd rather make that a new issue to clean things up if it is preferred.

bluesky/tests/test_external_assets_and_paging.py Outdated Show resolved Hide resolved
Fix Test Cases for "Enable collect for multiple detectors" (1651)
@danielballan danielballan merged commit 82015a8 into main Mar 21, 2024
16 checks passed
@coretl coretl deleted the collect-multiple-detectors branch April 15, 2024 10:19
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.

Collect multiple detectors concurrently
3 participants