Skip to main content

Extensible framework for building power system model translators with plugin architecture

Project description

r2x-core

Extensible framework for building power system model translators

image image image CI codecov Ruff Documentation

R2X Core provides the shared infrastructure for translating between power-system model formats. It gives translator authors a typed plugin lifecycle, a configuration-driven data loading layer, declarative rule mapping, unit-aware models, and versioned upgrade helpers.

Use it when you are building or extending translators for models such as ReEDS, PLEXOS, SWITCH, Sienna, or other infrasys-backed power-system workflows.

Install · Quickstart · Core concepts · Documentation · Development · Roadmap · Contributing · License

Install

pip install r2x-core

Or with uv:

uv add r2x-core

R2X Core supports Python 3.11, 3.12, and 3.13.

Quickstart

Load model input files

DataStore manages named DataFile definitions and reads them through the configured DataReader pipeline.

from r2x_core import DataFile, DataStore, TabularProcessing

store = DataStore(path="/path/to/data")
store.add_data([
    DataFile(
        name="generators",
        relative_fpath="gen.csv",
        proc_spec=TabularProcessing(
            column_mapping={"capacity_mw": "p_max_mw"},
            filter_by={"status": "active"},
        ),
    ),
    DataFile(name="loads", relative_fpath="load.parquet"),
])

generators = store.read_data("generators")
available = store.list_data()

Use relative_fpath for files under the store root, fpath for explicit paths, and ReaderConfig(kwargs=...) when the default reader needs format-specific options such as HDF5 dataset keys.

Build a class-based translator plugin

Class plugins implement only the lifecycle hooks they need. Hooks return Ok(...) or Err(...); Plugin.run() returns the final PluginContext and raises PluginError on the first hook failure.

from rust_ok import Ok

from r2x_core import Plugin, PluginConfig, PluginContext, System


class MyModelConfig(PluginConfig):
    input_folder: str
    model_year: int
    scenario: str = "base"


class MyModelTranslator(Plugin[MyModelConfig]):
    def on_build(self):
        system = System(name=f"{self.config.scenario}_{self.config.model_year}")
        return Ok(system)


config = MyModelConfig(input_folder="/path/to/data", model_year=2030)
context = PluginContext(config=config)
plugin = MyModelTranslator.from_context(context)
result = plugin.run()

print(result.system.name)

Create a function transform

For focused System -> System transformations, expose a plain function and register it through the r2x.transforms entry-point group.

from rust_ok import Ok, Result

from r2x_core import PluginConfig, System, expose_plugin


class ScaleConfig(PluginConfig):
    scale: float = 1.0


@expose_plugin
def scale_system(system: System, config: ScaleConfig) -> Result[System, str]:
    return Ok(system)
[project.entry-points."r2x.transforms"]
scale_system = "my_package.transforms:scale_system"

Core concepts

Concept What it does
Plugin / PluginContext Coordinates translator lifecycle hooks and shared pipeline state.
PluginConfig Provides typed Pydantic configuration for translators and transforms.
DataFile / DataStore Declares, reads, and processes model input files.
Rule / RuleFilter Maps source components to target components with declarative filters.
HasUnits / Unit Adds unit-aware field validation and display formatting.
UpgradeStep Applies versioned data or schema upgrade steps.

R2X Core builds on infrasys for System and Component primitives.

Documentation

Full documentation is available at natlabrockies.github.io/r2x-core, including tutorials, how-to guides, and the API reference.

Development

This repository uses uv and just for local automation.

just setup
just hooks
just test
just docs

Common tasks:

Command Purpose
just setup Install all dependency groups.
just format Format Python code with Ruff.
just lint Run Ruff checks.
just type Run ty type checks.
just test Run pytest.
just docs Build Sphinx docs.
just verify Run hooks, docstring coverage, and tests.

Roadmap

Contributing

We welcome contributions. See the contributing guide for local setup, development workflow, and review expectations.

License

R2X Core is released under the BSD 3-Clause License. See LICENSE.txt for details.

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

r2x_core-0.6.0.tar.gz (65.7 kB view details)

Uploaded Source

Built Distribution

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

r2x_core-0.6.0-py3-none-any.whl (80.4 kB view details)

Uploaded Python 3

File details

Details for the file r2x_core-0.6.0.tar.gz.

File metadata

  • Download URL: r2x_core-0.6.0.tar.gz
  • Upload date:
  • Size: 65.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for r2x_core-0.6.0.tar.gz
Algorithm Hash digest
SHA256 81e1c9d1fdc20ae87cda5afe4c61177607ad3528332ddc8db31ad7e4a37972c1
MD5 af735e2024c993718dd868b0fc76f3aa
BLAKE2b-256 a7a9a720b0fa47bf9aa49f09f0b322b437f69ee43dec45c75323af4b9534b310

See more details on using hashes here.

Provenance

The following attestation bundles were made for r2x_core-0.6.0.tar.gz:

Publisher: release.yaml on NatLabRockies/r2x-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file r2x_core-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: r2x_core-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 80.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for r2x_core-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bb89e321ce3c6ce94f39ce995b694a2564a856b76f11ca4b6ca3a5f651330b7a
MD5 3783aba535b5c42156773dd0dc019c9d
BLAKE2b-256 662906297166a90d094cfc64b8fcb5400b5efb4b87601a4583da465e03d26e49

See more details on using hashes here.

Provenance

The following attestation bundles were made for r2x_core-0.6.0-py3-none-any.whl:

Publisher: release.yaml on NatLabRockies/r2x-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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