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

Feature: EventManager #4

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion .devcontainer/DevContainer.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ FROM mcr.microsoft.com/devcontainers/base:bullseye

# [Optional] Uncomment this section to install additional OS packages.
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends vim
&& apt-get -y install --no-install-recommends vim \
&& rm -rf /var/lib/apt/lists/*
3 changes: 3 additions & 0 deletions .devcontainer/devcontainer.compose.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
name: madsci_dev
services:
dev:
build:
Expand All @@ -14,6 +15,8 @@ services:
entrypoint: /usr/local/share/docker-init.sh
command: sleep infinity

network_mode: host

# Uncomment the next four lines if you will use a ptrace-based debuggers like C++, Go, and Rust.
# cap_add:
# - SYS_PTRACE
Expand Down
56 changes: 46 additions & 10 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

"customizations": {
"vscode": {
"settings": {
"python.defaultInterpreterPath": "/workspaces/MADSci/.venv/bin/python"
},
"extensions": [
"ms-python.python",
"donjayamanne.python-environment-manager",
Expand All @@ -26,21 +29,54 @@
"redhat.vscode-yaml",
"KevinRose.vsc-python-indent",
"ms-python.vscode-pylance",
"ms-toolsai.jupyter"
"ms-toolsai.jupyter",
"github.vscode-github-actions"
]
}
},

"features": {
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {},
"ghcr.io/devcontainers/features/python:1": {},
"ghcr.io/guiyomh/features/just:0": {},
"ghcr.io/devcontainers-extra/features/act:1": {},
"ghcr.io/devcontainers-extra/features/actionlint:1": {},
"ghcr.io/devcontainers-extra/features/pdm:2": {},
"ghcr.io/devcontainers-extra/features/vue-cli:2": {},
"ghcr.io/devcontainers-extra/features/pre-commit:2": {},
"ghcr.io/devcontainers-extra/features/ruff:1": {}
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
"moby": true,
"installDockerBuildx": true,
"installDockerComposeSwitch": true,
"version": "latest",
"dockerDashComposeVersion": "v2.32.3"
},
"ghcr.io/devcontainers/features/python:1": {
"installTools": true,
"installJupyterlab": true,
"version": "3.9"
},
"ghcr.io/guiyomh/features/just:0": {
"version": "latest"
},
"ghcr.io/devcontainers-extra/features/act:1": {
"version": "latest"
},
"ghcr.io/devcontainers-extra/features/actionlint:1": {
"version": "latest"
},
"ghcr.io/devcontainers-extra/features/pdm:2": {
"version": "latest"
},
"ghcr.io/devcontainers-extra/features/vue-cli:2": {
"version": "latest"
},
"ghcr.io/devcontainers-extra/features/pre-commit:2": {
"version": "latest"
},
"ghcr.io/devcontainers-extra/features/ruff:1": {
"version": "latest"
},
"ghcr.io/devcontainers-extra/features/mongosh-homebrew:1": {
"version": "latest"
},
"ghcr.io/devcontainers/features/nix:1": {
"multiUser": true,
"version": "latest",
"packages": "jless"
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [8000],
Expand Down
11 changes: 11 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## PR Info

_List any issues this PR closes or features it implements, and a concise description of the changes._

## Developer Checklists

I have:

- [ ] Run Pre-commit and Unit Tests, and ensured that they pass
- [ ] Created or updated documentation relevant to your change
- [ ] Created or updated unit tests relevant to your change
17 changes: 17 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Pre-Commit Checks

on:
push:

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
name: Checkout code
- uses: actions/setup-python@v4
name: Setup Python
with:
python-version: 3.9
- uses: pre-commit/[email protected]
name: Run Pre-Commit Checks
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ test_experiment/

# Output data
.wei/
.madsci/

#node modules
**/node_modules
3 changes: 3 additions & 0 deletions .justfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ default:
init: hooks
@which pdm || echo "pdm not found, you'll need to install it: https://github.com/pdm-project/pdm"
@pdm install
@cd madsci/madsci_common && pdm install && cd -
@pdm update
@#test -e .env || cp .env.example .env

# Install the pre-commit hooks
hooks:
@pre-commit install
@pre-commit autoupdate

# Run the pre-commit checks
checks:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repos:
- id: nbstripout
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.8.1
rev: v0.9.1
hooks:
# Run the linter.
- id: ruff
Expand Down
42 changes: 42 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
FROM python:3.12
LABEL org.opencontainers.image.source=https://github.com/AD-SDL/MADSci/
LABEL org.opencontainers.image.description="The Modular Autonomous Discovery for Science (MADSci) toolkit's base docker image."
LABEL org.opencontainers.image.licenses=MIT

RUN set -eux; \
apt-get update; \
apt-get install -y gosu; \
rm -rf /var/lib/apt/lists/*

# User configuration
ARG USER_ID=9999
ARG GROUP_ID=9999
ARG CONTAINER_USER=madsci

RUN groupadd -g ${GROUP_ID} ${CONTAINER_USER}
RUN useradd --create-home -u ${USER_ID} --shell /bin/bash -g ${CONTAINER_USER} ${CONTAINER_USER}

WORKDIR /home/${CONTAINER_USER}

# Create working directories
RUN mkdir -p /home/${CONTAINER_USER}/.madsci
RUN mkdir -p /home/${CONTAINER_USER}/MADSci

# install PDM
RUN pip install -U pdm
# disable update check
ENV PDM_CHECK_UPDATE=false
# copy files
COPY pyproject.toml pdm.lock README.md /home/${CONTAINER_USER}/MADSci/
COPY src/ /home/${CONTAINER_USER}/MADSci/src

WORKDIR /home/${CONTAINER_USER}/MADSci
RUN --mount=type=cache,target=/root/.cache \
pdm install -g -p . --check && \
pdm install -g -p src/madsci_common --check && \
pdm sync -g -p .

COPY madsci-entrypoint.sh /madsci-entrypoint.sh
RUN chmod +x /madsci-entrypoint.sh
ENTRYPOINT ["/madsci-entrypoint.sh"]
WORKDIR /home/${CONTAINER_USER}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 Argonne National Laboratory Rapid Prototyping Lab

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,3 @@
## Overview

MADSci is a modular, autonomous, and scalable framework for scientific discovery and experimentation.

## Components

- [Squid](./src/madsci.squid/README.md): The Workcell Management Engine.
- [Types](./src/madsci.types/README.md): The Type Definition Library for MADSci.
- [PyClient](./src/madsci.pyclient/README.md): The Python Client for MADSci.
- [Module](./src/madsci.module/README.md): The Module Library for integrating devices.
- [Server](./src/madsci.server/README.md): The REST API Server.
- [CLI](./src/madsci.cli/README.md): The Command Line Interface.
- [Dashboard](./src/madsci.dashboard/README.md): The web-based Dashboard and management interface.
- [Resources](./src/madsci.resources/README.md): The Resource Library for managing resources.
- [Events](./src/madsci.events/README.md): The Event Library for managing events.
41 changes: 41 additions & 0 deletions example_lab/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: madsci_example_lab
services:
mongodb:
container_name: mongodb
image: mongodb/mongodb-community-server:latest
ports:
- 27017:27017
event_manager:
container_name: event_manager
image: madsci:latest
build:
context: ..
dockerfile: Dockerfile
environment:
- USER_ID=1000
- GROUP_ID=1000
ports:
- 8001:8001
volumes:
- ${LOCAL_WORKSPACE_FOLDER:-../}/example_lab:/home/madsci/example_lab/
- ${LOCAL_WORKSPACE_FOLDER:-../}/.madsci:/home/madsci/.madsci/
command: python -m madsci.event_manager.event_server
depends_on:
- mongodb
liquidhandler:
container_name: liquidhandler
image: madsci:latest
build:
context: ..
dockerfile: Dockerfile
environment:
- USER_ID=1000
- GROUP_ID=1000
volumes:
- ${LOCAL_WORKSPACE_FOLDER:-../}/example_lab:/home/madsci/example_lab/
- ${LOCAL_WORKSPACE_FOLDER:-../}/.madsci:/home/madsci/.madsci/
command: python example_lab/example_modules/liquidhandler.py --definition example_lab/example_modules/nodes/default_liquidhandler.node.yaml
ports:
- 2001:2001
depends_on:
- event_manager
23 changes: 23 additions & 0 deletions example_lab/example_lab.lab.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: ExampleLab
lab_id: 01JFK5527MDKJ92RE7B8PX71ZM
description: An example of a lab powered by the MADSci framework
server_config:
host: 127.0.0.1
port: 8000
workcells: {}
commands:
start: docker compose up -d
logs: docker compose logs
stop: docker compose down
restart: docker compose restart
managers:
event_manager:
name: event_manager
manager_id: 01JHJVMM9KYMNHR8VQQGP4AYY3
description: An event manager for this example MADSci Lab
manager_type: event_manager
manager_config:
host: 0.0.0.0
port: 8001
db_url: mongodb://mongodb:27017
url: http://killingtime:8001/
53 changes: 53 additions & 0 deletions example_lab/example_modules/liquidhandler.module.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module_name: liquidhandler
module_type: device
module_description: null
capabilities:
get_info: false
get_state: false
get_status: false
send_action: false
get_action_result: false
get_action_history: false
action_files: false
send_admin_commands: false
set_config: false
get_resources: false
get_log: false
events: false
resources: false
admin_commands: []
config:
rest_node:
namespace: rest_node
description: Configuration related to the REST API of a REST node.
parameters:
host:
name: host
description: The host of the REST API.
default: 0.0.0.0
required: true
port:
name: port
description: The port of the REST API.
default: 2001
required: true
protocol:
name: protocol
description: The protocol of the REST API, either 'http' or 'https'.
default: http
required: true
madsci_events:
namespace: madsci_events
description: Configuration related to MADSci event logging.
parameters:
event_server:
name: event_server
description: The URL of the event manager.
default: http://event_manager:8001
required: false
log_level:
name: log_level
description: The default log level.
default: INFO
required: true
commands: {}
Loading
Loading