-
Notifications
You must be signed in to change notification settings - Fork 3
Update data validation btp #21
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
Open
JunAishima
wants to merge
6
commits into
NSLS2:main
Choose a base branch
from
JunAishima:update-data-validation-btp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c66575e
replace data validation with bluesky-tiled-plugin validation
JunAishima c84a030
new validation requires using the migration catalog
JunAishima 1f5c8b3
update dependencies
JunAishima 242db8d
restore reading data streams
JunAishima a2eef40
turn tasks into concurrently running tasks
JunAishima e8e9450
run tasks concurrently
JunAishima File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,40 @@ | ||
| from prefect import task, flow, get_run_logger | ||
| from prefect.blocks.system import Secret | ||
| from bluesky_tiled_plugins.writing.validator import validate | ||
| import time as ttime | ||
| from tiled.client import from_profile | ||
|
|
||
|
|
||
| @task(retries=2, retry_delay_seconds=10) | ||
| def read_all_streams(uid, beamline_acronym): | ||
| @task | ||
| def check_stream(run): | ||
| logger = get_run_logger() | ||
| api_key = Secret.load("tiled-smi-api-key", _sync=True).get() | ||
| tiled_client = from_profile("nsls2", api_key=api_key) | ||
| run = tiled_client[beamline_acronym]["raw"][uid] | ||
| logger.info(f"Validating uid {uid}") | ||
| start_time = ttime.monotonic() | ||
| for stream in run: | ||
| logger.info(f"{stream}:") | ||
| stream_start_time = ttime.monotonic() | ||
| stream_data = run[stream].read() | ||
| stream_elapsed_time = ttime.monotonic() - stream_start_time | ||
| logger.info(f"{stream} elapsed_time = {stream_elapsed_time}") | ||
| logger.info(f"{stream} nbytes = {stream_data.nbytes:_}") | ||
| elapsed_time = ttime.monotonic() - start_time | ||
| logger.info(f"{elapsed_time = }") | ||
|
|
||
|
|
||
| @task(retries=2, retry_delay_seconds=10) | ||
| def validate_local(run_client): | ||
| logger = get_run_logger() | ||
| validate(run_client, fix_errors=True, try_reading=True, raise_on_error=True) | ||
|
|
||
| @flow | ||
| def data_validation(uid): | ||
| read_all_streams(uid, beamline_acronym="smi") | ||
| def data_validation(uid, beamline_acronym="smi"): | ||
| logger = get_run_logger() | ||
| api_key = Secret.load("tiled-smi-api-key", _sync=True).get() | ||
| tiled_client = from_profile("nsls2", api_key=api_key) | ||
| run_client = tiled_client[beamline_acronym]["migration"][uid] | ||
| run_client_raw = tiled_client[beamline_acronym]["raw"][uid] | ||
| logger.info(f"Launching tasks to check streams and validate uid {uid}") | ||
| start_time = ttime.monotonic() | ||
| check_stream_task = check_stream.submit(run_client_raw) | ||
| validate_task = validate_local.submit(run_client) | ||
| logger.info("Waiting for tasks to complete") | ||
| check_stream_task.result() | ||
| validate_task.result() | ||
| elapsed_time = ttime.monotonic() - start_time | ||
| logger.info(f"Finished checking and validating data; total {elapsed_time = }") | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may still need to keep the old validation task that uses the
/smi/rawcatalog while the data is still being written to Mongo (and add the new validation of the/smi/migrationcatalog). It doesn't cost us much (correctly me if I'm wrong), but for completeness I think it makes sense to keep it.We can the old function once Mongo is turned off and
/migrationis renamed/raw.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so you want to keep the task that reads all data as a check for
/smi/raw? we should talk about this more - this change would remove one of the major advantages of this PR, that we are not reading all of the data, which could be the main reason for prefect-worker2 CPU usage issues.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay, if improving the performance was the main reason -- maybe just remove it then. I don't know if anyone paid any attention to this reading failing.
Validating
/migration(what you've added) is important though; it fixes any inconsistencies in structures to make the data readable.