This package provides modular function and class definitions for the Coral workflow system.
The definitions are organized into domain-specific modules:
- math_ops.py: Mathematical operations (
add,multiply,math.sqrt, etc.) and theCalculatorclass - string_ops.py: String processing utilities (
StringProcessorclass) - phiflow_defs.py: PhiFlow physics simulation wrappers
- primitives.py: Type mapping for primitive values
By default, all available modules are loaded:
from definitions import FUNCTION_MAP, CLASS_MAP, PRIMITIVES_MAP
# These contain all available definitions
print(len(FUNCTION_MAP)) # All registered functions
print(len(CLASS_MAP)) # All registered classesYou can customize which modules to load using the builder functions:
from definitions import build_function_map, build_class_map
# Load only PhiFlow definitions for physics simulations
FUNCTION_MAP = build_function_map(include=['phiflow'])
CLASS_MAP = build_class_map(include=['phiflow'])
# Load everything except PhiFlow
FUNCTION_MAP = build_function_map(exclude=['phiflow'])
CLASS_MAP = build_class_map(exclude=['phiflow'])
# Load only math and string operations
FUNCTION_MAP = build_function_map(include=['math', 'string'])
CLASS_MAP = build_class_map(include=['math', 'string'])'math'- Mathematical operations and Calculator class'string'- String processing utilities'phiflow'- PhiFlow physics simulation wrappers
To add a new domain-specific module:
- Create a new file in
definitions/(e.g.,mymodule.py) - Implement
get_functions()andget_classes()that return dictionaries - Import the module in
definitions/__init__.py - Add one entry to the
_MODULESdictionary indefinitions/__init__.py
# definitions/mymodule.py
from typing import Any, Dict
def my_function(x: float) -> float:
"""My custom function"""
return x * 2
class MyClass:
"""My custom class"""
def __init__(self, value: float):
self.value = value
def double(self) -> float:
return self.value * 2
def get_functions() -> Dict[str, Any]:
"""Return function definitions"""
return {
"my_function": my_function,
}
def get_classes() -> Dict[str, Any]:
"""Return class definitions"""
return {
"MyClass": MyClass,
}Then update definitions/__init__.py — add the import and a single _MODULES entry. AVAILABLE_MODULES
and both build_function_map() / build_class_map() read from _MODULES, so no other changes are needed:
from . import math_ops, string_ops, phiflow_defs, primitives, mymodule
_MODULES = {
'math': math_ops,
'string': string_ops,
'phiflow': phiflow_defs,
'mymodule': mymodule, # Add here
}- Library Independence: Each module handles its own import failures gracefully
- Selective Registration: Load only the definitions needed for your application
- Easier Maintenance: Domain-specific code stays together
- Reusability: Definition sets can be shared across projects
- Clear Dependencies: Import errors are isolated to specific modules