Extensible framework for building power system model translators with plugin architecture
Project description
r2x-core
Extensible framework for power system model translation
R2X Core is a model-agnostic framework for building power system model translators. It provides the core infrastructure, data models, plugin architecture, and APIs that enable translation between different power system modeling platforms.
About R2X Core
R2X Core serves as the foundation for building translators between power system models like ReEDS, PLEXOS, SWITCH, Sienna, and more. It provides a plugin-based architecture where you can register parsers, exporters, and transformations to create custom translation workflows.
Features
- Capability-based plugin architecture - Plugins implement only the hooks they need (validate, prepare, build, transform, translate, export, cleanup)
- Declarative rule system - Define model translations through configuration, not code
- Rule filters for selective translation - Composable filters to control which components rules process
- Standardized component models - Power system components via infrasys
- Multiple file format support - Native support for CSV, HDF5, Parquet, JSON, and XML
- Configurable HDF5 reader - Flexible configuration-driven approach for any HDF5 structure
- Type-safe configuration - Pydantic-based
PluginConfigwith automatic validation - Per-unit system - Automatic unit handling with device-base, natural units, and system-base display modes
- Flexible data store - Automatic format detection, intelligent caching, and component tracking
- Entry point discovery - External packages can register plugins via setuptools/pyproject.toml entry points
Installation
pip install r2x-core
Or with uv:
uv add r2x-core
Python version support: 3.11, 3.12, 3.13
Quick Start
Using the DataStore
The DataStore provides a high-level interface for managing and loading data files:
from r2x_core import DataStore, DataFile
# Create a DataStore pointing to your data directory
store = DataStore(path="/path/to/data")
# Add files to the store
data_file = DataFile(name="generators", fpath="gen.csv")
store.add_data(data_file)
# Or add multiple files at once
files = [
DataFile(name="generators", fpath="gen.csv"),
DataFile(name="loads", fpath="load.csv"),
DataFile(name="buses", fpath="buses.h5")
]
store.add_data(*files)
# Read data from the store
gen_data = store.read_data("generators")
# List all available data files
available_files = store.list_data()
# Remove a data file
store.remove_data("generators")
Building a Model Translator with Plugins
Create a plugin to translate power system models:
from r2x_core import Plugin, PluginConfig, PluginContext, Rule, System, DataStore
from rust_ok import Ok
# Define type-safe configuration
class MyModelConfig(PluginConfig):
input_folder: str
model_year: int
scenario: str = "base"
# Implement your translator plugin
class MyModelTranslator(Plugin[MyModelConfig]):
def on_prepare(self):
# Load data and setup resources
return Ok(None)
def on_build(self):
# Create system from input data
system = System(name=f"{self.config.scenario}_{self.config.model_year}")
return Ok(system)
def on_translate(self):
# Define translation rules
rules = [
Rule(
name="translate_generators",
source_type="SourceGenerator",
target_type="Generator",
version=1,
field_map={
"name": "name",
"capacity": "p_max_mw",
"location": "zone",
}
),
]
# Apply rules to create target system
return Ok(self.system)
# Execute the translation
config = MyModelConfig(input_folder="/path/to/data", model_year=2030)
context = PluginContext(config=config)
plugin = MyModelTranslator.from_context(context)
result = plugin.run()
print(f"Translated system: {result.system.name}")
Plugin Registration and Discovery
Register plugins via pyproject.toml entry points for automatic discovery:
[project.entry-points.r2x_plugin]
my_model_translator = "my_package.plugins:MyModelTranslator"
my_model_builder = "my_package.plugins:MyModelBuilder"
The plugin system automatically discovers and introspects plugins to extract their capabilities:
from r2x_core import Plugin
# Get plugin metadata programmatically
config_type = MyModelTranslator.get_config_type()
print(f"Config type: {config_type.__name__}")
# Discover which hooks are implemented
hooks = MyModelTranslator.get_implemented_hooks()
print(f"Implemented hooks: {hooks}")
# Output: ['on_prepare', 'on_build', 'on_translate']
# Introspect config fields
import inspect
fields = config_type.model_fields
for field_name, field_info in fields.items():
print(f" {field_name}: {field_info.annotation}")
Plugins are discovered, instantiated, and executed through a shared registry that handles dependency injection and lifecycle management.
Documentation
Comprehensive documentation is available at nrel.github.io/r2x-core:
- Getting Started Tutorial - Step-by-step guide to building your first translator
- Installation Guide - Detailed installation instructions and options
- How-To Guides - Task-oriented guides for common workflows:
- Explanations - Deep dives into key concepts:
- Tutorials - In-depth walkthroughs:
- API Reference - Complete API documentation
Roadmap
Curious about what we're working on? Check out the roadmap:
- Active issues - Issues that we are actively working on
- Prioritized backlog - Issues we'll be working on next
- Nice-to-have - Features or fixes anyone can start working on (please let us know before you do)
- Ideas - Future work or ideas for R2X Core
Contributing
We welcome contributions! Please see our Contributing Guide for guidelines on how to contribute to R2X Core.
License
R2X Core is released under the BSD 3-Clause License. See LICENSE.txt for details.
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 r2x_core-0.4.2.tar.gz.
File metadata
- Download URL: r2x_core-0.4.2.tar.gz
- Upload date:
- Size: 65.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4bbb1029e1e14cddc2099bf87459042c15a6b97cc47ac7b1ff6518fdc2634f0c
|
|
| MD5 |
5adac9b318181300db8e066110de94e6
|
|
| BLAKE2b-256 |
bad994d0a790f674b048023a5fdea8ee60b8a33fe46f6999a36e98c0e01a59a7
|
Provenance
The following attestation bundles were made for r2x_core-0.4.2.tar.gz:
Publisher:
release.yaml on NatLabRockies/r2x-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
r2x_core-0.4.2.tar.gz -
Subject digest:
4bbb1029e1e14cddc2099bf87459042c15a6b97cc47ac7b1ff6518fdc2634f0c - Sigstore transparency entry: 941670816
- Sigstore integration time:
-
Permalink:
NatLabRockies/r2x-core@c0f2f16e975e4eefc9f71eb9b1d465763c3b2daf -
Branch / Tag:
refs/heads/main - Owner: https://github.com/NatLabRockies
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@c0f2f16e975e4eefc9f71eb9b1d465763c3b2daf -
Trigger Event:
push
-
Statement type:
File details
Details for the file r2x_core-0.4.2-py3-none-any.whl.
File metadata
- Download URL: r2x_core-0.4.2-py3-none-any.whl
- Upload date:
- Size: 80.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
415a9855c2b0729eec3b735fdb1f3f52c47cd4e9230dbdfdc888b0f979f4f4b9
|
|
| MD5 |
425400af6799bccc10d0ddd1afbe232b
|
|
| BLAKE2b-256 |
c976fefffd3743e863a305029d025799c67e62e9960dd1b6cf6083f4ddaa5cad
|
Provenance
The following attestation bundles were made for r2x_core-0.4.2-py3-none-any.whl:
Publisher:
release.yaml on NatLabRockies/r2x-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
r2x_core-0.4.2-py3-none-any.whl -
Subject digest:
415a9855c2b0729eec3b735fdb1f3f52c47cd4e9230dbdfdc888b0f979f4f4b9 - Sigstore transparency entry: 941670830
- Sigstore integration time:
-
Permalink:
NatLabRockies/r2x-core@c0f2f16e975e4eefc9f71eb9b1d465763c3b2daf -
Branch / Tag:
refs/heads/main - Owner: https://github.com/NatLabRockies
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@c0f2f16e975e4eefc9f71eb9b1d465763c3b2daf -
Trigger Event:
push
-
Statement type: