-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from AD-SDL/dev
Update to WEI v0.7.0
- Loading branch information
Showing
10 changed files
with
97 additions
and
121 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,37 +1,50 @@ | ||
#!/usr/bin/env python3 | ||
"""Example experiment application that uses the WEI client to run a workflow.""" | ||
|
||
import json | ||
from pathlib import Path | ||
|
||
from wei import ExperimentClient | ||
from wei.types.experiment_types import CampaignDesign, ExperimentDesign | ||
|
||
|
||
def main() -> None: | ||
"""Runs an example WEI workflow""" | ||
# This defines the Experiment object that will communicate with the WEI server | ||
exp = ExperimentClient("localhost", "8000", "Example_Program") | ||
|
||
# The path to the Workflow definition yaml file | ||
wf_path = Path(__file__).parent.parent / "workflows" / "example_workflow.yaml" | ||
|
||
# This runs the workflow | ||
run_info = exp.start_run( | ||
wf_path.resolve(), | ||
payload={ | ||
"wait_time": 5, | ||
"file_name": "experiment_output.jpg", | ||
}, | ||
# *This defines the ExperimentDesign object that will be used to register the experiment | ||
experiment_design = ExperimentDesign( | ||
experiment_name="Example_Experiment", | ||
experiment_description="This is an example experiment", | ||
) | ||
# *Optionally, you can also define a Campaign object to group multiple experiments together | ||
# *This is useful when you want to run multiple experiments together | ||
campaign = CampaignDesign( | ||
campaign_name="Example_Campaign", | ||
campaign_description="This is an example campaign", | ||
) | ||
experiment_client = ExperimentClient( | ||
server_host="localhost", | ||
server_port="8000", | ||
experiment=experiment_design, | ||
campaign=campaign, | ||
) | ||
print(json.dumps(run_info, indent=2)) | ||
|
||
# The below line can be used to fetch the result and save it in our local directory | ||
exp.get_wf_result_file( | ||
run_id=run_info["run_id"], | ||
filename=run_info["hist"]["Take Picture"]["action_msg"], | ||
output_filepath="experiment_output.jpg", | ||
# *The path to the Workflow definition yaml file | ||
workflow_dir = (Path(__file__).parent.parent / "workflows").resolve() | ||
workflow_path = workflow_dir / "example.workflow.yaml" | ||
|
||
# *This runs the workflow | ||
wf_run = experiment_client.start_run( | ||
workflow=workflow_path, | ||
payload={"wait_time": 5}, | ||
blocking=True, # *This will block the execution until the workflow is completed | ||
) | ||
|
||
# *You can use the below to get the image returned by the camera module | ||
datapoint_id = wf_run.get_datapoint_id_by_label("experiment_result") | ||
# experiment_client.get_datapoint_value(datapoint_id) # *This will return the image as a bytes object | ||
experiment_client.save_datapoint_value( | ||
datapoint_id, "experiment_output.jpg" | ||
) # *This will save the image to a file | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: Example_Workflow | ||
metadata: | ||
author: Tobias Ginsburg, Kyle Hippe, Ryan D. Lewis | ||
info: Example workflow for WEI | ||
version: 0.3 | ||
|
||
flowdef: | ||
- name: Sleep workcell for `payload.wait_time` seconds | ||
module: utilities | ||
action: delay | ||
args: | ||
seconds: "payload.wait_time" | ||
comment: Delay for `payload.wait_time` seconds before we take a picture | ||
|
||
- name: Take Picture | ||
module: webcam | ||
action: take_picture | ||
data_labels: | ||
image: experiment_result |
This file was deleted.
Oops, something went wrong.
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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