The Modular Autonomous Discovery for Science (MADSci) Common Definitions and Utilities.
Project description
MADSci Common
Shared types, utilities, validators, base classes and other common code used across the MADSci toolkit.
Installation
See the main README for installation options. This package is available as:
- PyPI:
pip install madsci.common - Docker: Included in
ghcr.io/ad-sdl/madsci - Dependency: Required by all other MADSci packages
Core Components
Types System
Pydantic-based data models for the entire MADSci ecosystem:
# Import types organized by subsystem
from madsci.common.types.workflow_types import WorkflowDefinition
from madsci.common.types.node_types import NodeDefinition
from madsci.common.types.experiment_types import ExperimentDesign
from madsci.common.types.datapoint_types import ValueDataPoint
Available type modules:
action_types: Action definitions and resultsexperiment_types: Experiment campaigns, designs, runsworkflow_types: Workflow and step definitionsnode_types: Node configurations and statusdatapoint_types: Data storage and retrievalevent_types: Event logging and queryingresource_types: Resource management and trackingauth_types: Ownership and authenticationbase_types: Foundation classes and utilities
Utilities
Common helper functions and validators:
from madsci.common.utils import utcnow, new_ulid_str
from madsci.common.validators import ulid_validator
from madsci.common.serializers import serialize_to_yaml
# Generate unique IDs
experiment_id = new_ulid_str()
# UTC timestamps
timestamp = utcnow()
# YAML serialization
yaml_content = serialize_to_yaml(my_pydantic_model)
Settings Framework
Hierarchical configuration system using Pydantic Settings:
from madsci.common.types.base_types import MadsciBaseSettings
class MyManagerSettings(MadsciBaseSettings):
server_url: str = "http://localhost:8000"
database_url: str = "mongodb://localhost:27017"
# Supports env vars, CLI args, config files
settings = MyManagerSettings()
Configuration sources (in precedence order):
- Command line arguments
- Environment variables
- Subsystem-specific files (
workcell.env,event.yaml) - Generic files (
.env,settings.yaml) - Default values
Configuration options: See Configuration.md and example_lab/managers/ for examples.
Usage Patterns
Creating Custom Types
from madsci.common.types.base_types import MadsciBaseModel
from pydantic import Field
class MyCustomType(MadsciBaseModel):
name: str = Field(description="Object name")
value: float = Field(gt=0, description="Positive value")
metadata: dict = Field(default_factory=dict)
# Automatic validation, serialization to JSON/YAML
obj = MyCustomType(name="test", value=42.0)
json_str = obj.model_dump_json()
Extending Base Settings
from madsci.common.types.base_types import MadsciBaseSettings
class CustomSettings(MadsciBaseSettings, env_prefix="CUSTOM_"):
api_key: str = Field(description="API authentication key")
timeout: int = Field(default=30, description="Request timeout")
# Reads from CUSTOM_API_KEY, CUSTOM_TIMEOUT environment variables
settings = CustomSettings()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file madsci_common-0.4.6.tar.gz.
File metadata
- Download URL: madsci_common-0.4.6.tar.gz
- Upload date:
- Size: 44.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: pdm/2.25.6 CPython/3.9.23 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e6b8640f50340a19aa8a090dd17ee1f6d70c132d5646c281409d8313b3e5c6e
|
|
| MD5 |
2a2d7303873a8d6202fcb37d47d043ee
|
|
| BLAKE2b-256 |
ea210bbc43190a4a52de9dfb9a21b3f512e828a31a36d1f796ec8050f77ad6e5
|
File details
Details for the file madsci_common-0.4.6-py3-none-any.whl.
File metadata
- Download URL: madsci_common-0.4.6-py3-none-any.whl
- Upload date:
- Size: 56.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: pdm/2.25.6 CPython/3.9.23 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8fc36d6b0b9251d5f182c9bb5930e83817eba3d89858bf496bf26ee733be286b
|
|
| MD5 |
458d2dd842d78bbb3f878eb33d57d63d
|
|
| BLAKE2b-256 |
b761f0e56dadeae4783515e1ccec6f80c4b05b986dfd4243bca6088b61b3a005
|