Skip to main content

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 results
  • experiment_types: Experiment campaigns, designs, runs
  • workflow_types: Workflow and step definitions
  • node_types: Node configurations and status
  • datapoint_types: Data storage and retrieval
  • event_types: Event logging and querying
  • resource_types: Resource management and tracking
  • auth_types: Ownership and authentication
  • base_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):

  1. Command line arguments
  2. Environment variables
  3. Subsystem-specific files (workcell.env, event.yaml)
  4. Generic files (.env, settings.yaml)
  5. Default values

Settings Precedence

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

madsci_common-0.4.5.tar.gz (44.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

madsci_common-0.4.5-py3-none-any.whl (56.6 kB view details)

Uploaded Python 3

File details

Details for the file madsci_common-0.4.5.tar.gz.

File metadata

  • Download URL: madsci_common-0.4.5.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

Hashes for madsci_common-0.4.5.tar.gz
Algorithm Hash digest
SHA256 68317fd8c6db38579aba3448039559d373c59013a7c262b8a86eb7e3f53108df
MD5 cf6d6f3a21aa2cd10bbaf1e4ba6376c0
BLAKE2b-256 9ffa364246da4ee39af942edacaf5964f00f7145177af309061343949037eb2e

See more details on using hashes here.

File details

Details for the file madsci_common-0.4.5-py3-none-any.whl.

File metadata

  • Download URL: madsci_common-0.4.5-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

Hashes for madsci_common-0.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 55286a93b505f52b55875a6a54a282f86c3506982d757d2c507591e2d2d5a7b8
MD5 67694057113a8fa0f17dbc924badd418
BLAKE2b-256 cca4a1ed09da3638999b355f7b3afbda7ce998d8f92661f8b14835e4f7ae0983

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page