Skip to content

Commit

Permalink
Merge pull request #3 from AD-SDL/dev
Browse files Browse the repository at this point in the history
Update to WEI v0.7.0
  • Loading branch information
LuckierDodge authored Oct 16, 2024
2 parents 9af8b0b + 4d46698 commit 00fbbd2
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 121 deletions.
1 change: 0 additions & 1 deletion HOW-TO.md

This file was deleted.

3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ checks: # Runs all the pre-commit checks
@pre-commit install
@pre-commit run --all-files || { echo "Checking fixes\n" ; pre-commit run --all-files; }

up: # Starts the workcell
@docker compose up --remove-orphans

clean:
@rm .env
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ As much as possible, this workcell is designed to be configured declaratively. T
- After creating the `.env`, check to make sure the values are complete and correct.
- The `compose.yaml` docker compose file, which defines a "stack" of containers that control your workcell
- Note: whenever you see `${SOME_VARIABLE_NAME}` in the compose file, this value is being taken from the `.env`
- The Workcell Config in `workcell_defs/example_workcell.yaml`, which allows you to define WEI specific configuration for your workcell
- The Workcell Config in `workcells/example.workcell.yaml`, which allows you to define WEI specific configuration for your workcell

## Building, Running, and Managing your Workcell

Expand Down
53 changes: 33 additions & 20 deletions applications/example_app/src/example_app.py
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()
19 changes: 19 additions & 0 deletions applications/example_app/workflows/example.workflow.yaml
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
39 changes: 0 additions & 39 deletions applications/example_app/workflows/example_workflow.yaml

This file was deleted.

48 changes: 36 additions & 12 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
name: example_workcell
include:
- path: 'docker/wei.compose.yaml'
project_directory: '.'
env_file: '.env'
services:
###########
# Modules #
###########
sleep_node:
image: ghcr.io/ad-sdl/sleep_module
container_name: sleep_node
command: python -m sleep_rest_node --port 2000
ports:
- 2000:2000
env_file:
- .env
camera_node:
image: ghcr.io/ad-sdl/camera_module
container_name: camera_node
Expand All @@ -24,3 +12,39 @@ services:
command: python -m camera_rest_node --port 2001
env_file:
- .env

#####################
# WEI Core Services #
#####################
wei_server:
image: ghcr.io/ad-sdl/wei
container_name: wei_server
ports:
- 8000:8000
volumes:
- ./workcells:/workcells
- ${WEI_DATA_DIR}:/home/app/.wei
environment:
- USER_ID=${USER_ID:-1000}
- GROUP_ID=${GROUP_ID:-1000}
command: python3 -m wei.server --workcell /workcells/${WORKCELL_FILENAME}
depends_on:
- wei_redis

utilities:
image: ghcr.io/ad-sdl/wei
container_name: utilities
ports:
- 8001:8001
command: 'python3 -m wei.modules.utility_module
--port 8001
--alias utilities'

wei_redis:
image: redis
container_name: wei_redis
ports:
- 6379:6379
volumes:
- ${REDIS_DIR}:/data
command: redis-server --save 60 1 --loglevel warning
42 changes: 0 additions & 42 deletions docker/wei.compose.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion example.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ USER_ID=
GROUP_ID=
WEI_DATA_DIR=~/.wei
REDIS_DIR=~/.wei/redis
WORKCELL_FILENAME=example_workcell.yaml
WORKCELL_FILENAME=example.workcell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ config:
update_interval: 1.0
use_diaspora: false
log_level: 20 # INFO level, see https://docs.python.org/3/library/logging.html#levels for a list of levels
autostart_engine: true

#List of all components accessible in this workcell
modules:
- name: sleeper
model: sleeper_test_node
interface: wei_rest_node
- name: utilities
model: WEI Utilities module
config:
rest_node_address: "http://sleep_node:2000"
rest_node_address: "http://utilities:8001"
- name: webcam
model: camera_test_node
interface: wei_rest_node
config:
rest_node_address: "http://camera_node:2001"

Expand Down

0 comments on commit 00fbbd2

Please sign in to comment.