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

Ae sample quality #7

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions federation/plumbing/queue_server.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
from queue import Queue
from bluesky_adaptive.utils import extract_event_page
from bluesky_adaptive.recommendations import NoRecommendation


def index_reccomender_factory(
*,
adaptive_object,
sample_index_key,
sample_data_key,
*,
queue=None,
queue_server,
# TODO: Add more sensible defaults for these args.
mv_kwargs=None,
count_args=(),
count_kwargs=None,
):
if queue is None:
queue = Queue()
if mv_kwargs is None:
mv_kwargs = {}
if count_kwargs is None:
count_kwargs = {}

def callback(name, doc):
"""Assumes the start doc gives you the sample location,
and the event_page gives quality info. The current index is updated at the start
But the Agent quality matrix is only updated at tell."""
# TODO: Validate the assumptions on formats
# TODO: Update queue signatures from .put to ...?
print(f"callback received {name}")

if name == "start":
Expand All @@ -37,10 +41,21 @@ def callback(name, doc):
try:
next_point = adaptive_object.ask(1)
except NoRecommendation:
queue.put(None)
queue_server.queue_item_add(None)
Copy link

@jklynch jklynch Dec 6, 2021

Choose a reason for hiding this comment

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

Don't add None to the queueserver. If this is a case where you don't know which sample to measure and want to wait for a future recommendation just pass and tell the queueserver nothing. But maybe you do have a fallback you can do here when no recommendation is made.

else:
queue.put({sample_index_key: next_point})
queue_server.queue_item_add(
item_name="mv",
item_args=[next_point],
item_kwargs=mv_kwargs,
item_type="plan",
)
queue_server.queue_item_add(
item_name="count",
item_args=[*count_args],
item_kwargs=count_kwargs,
item_type="plan",
)
else:
print(f"Document {name} is not handled")

return callback, queue
return callback