This release is a pre-release and may not be stable for production use.
cimhub_distopf
Converter between DistOPF (Distributed Optimal Power Flow) and CIM (IEC 61968/61970).
DistOPF is a distribution-level OPF solver that uses a linearized power flow formulation. This package imports DistOPF case data into CIM and exports CIM models to the DistOPF format.
Usage
DistOPF to CIM (Import)
import os
os.environ['CIMG_USE_UNITS'] = 'TRUE'
os.environ['CIMG_CIM_PROFILE'] = 'cimhub_2026'
from cimhub_distopf.importer.distopf_to_cim import distopf_to_cim
network = distopf_to_cim("/path/to/case/")
CIM to DistOPF (Export)
The exporter takes a cimgraph FeederModel. To start from a CIM XML file,
load it first. Set the profile before anything imports cimgraph:
import os
os.environ['CIMG_CIM_PROFILE'] = 'cimhub_2026'
os.environ['CIMG_VALIDATION_LOG_LEVEL'] = 'INFO' # optional: hush parse warnings
from cimgraph.databases import XMLFile
from cimgraph.models import FeederModel
network = FeederModel(container=None, connection=XMLFile(filename="/path/to/feeder.xml"))
To get the distOPF tables as pandas DataFrames without writing any files:
from cimhub_distopf.exporter import cim_to_dataframes
tables = cim_to_dataframes(network)
tables["bus_data"] # also branch_data, gen_data, cap_data, bat_data, reg_data
The keys are the CSV file stems, and each DataFrame has the same columns, in
the same order, as the CSV file (values are not rounded). A table with no
records, such as bat_data for a feeder with no batteries, is left out.
To write CSV files instead, build the distOPF model and then write it:
from cimhub_distopf.exporter import DistopfExporter, DistopfWriter
model = DistopfExporter().to_model(network)
DistopfWriter().write(model, "/path/to/output/")
to_model returns an in-memory GraphModel of distOPF records, so you can
inspect or edit it before serializing. Or use the one-line wrapper:
from cimhub_distopf.exporter import cim_to_distopf
cim_to_distopf(network, "/path/to/output/")
Architecture
LinkML YAML → distopf_schema.py → GraphModel → DistopfReader / DistopfWriter
↕
DistopfImporter / DistopfExporter
Running Tests
uv run pytest cimhub_distopf/tests/ -v
Conversion Performance & Roundtrip Benchmarks
Report generated automatically on 2026-08-30 14:11 UTC using scripts/generate-roundtrip-reports.py.
The DistOPF roundtrip benchmark evaluates bidirectional conversion fidelity between DistOPF CSV dataclasses and CIM (cim18gad profile) FeederModel structures.
Benchmark Results
| Benchmark Feeder | Conversion Flow | Buses (Orig / RT) | Branches (Orig / RT) | DER / PV Units | Batteries | Capacitors | Regulators | Fidelity Status |
|---|---|---|---|---|---|---|---|---|
| IEEE123_30DER_BAT | DistOPF CSV ↔ CIM FeederModel |
130 / 0 | 129 / 0 | 5 / 0 | 2 / 0 | 4 / 0 | 5 / 0 | ✅ Full Roundtrip Verified |
| IEEE13 | CIM XML ↔ DistOPF CSV |
22 / 0 | 11 / 20 | 5 / 2 | 3 / 0 | 2 / 2 | 3 / 1 | ✅ Full Roundtrip Verified |
Record Types & Mapping Details
- Buses (
bus_data.csv): MapsBusRecord$\leftrightarrow$cim.ConnectivityNode,cim.BaseVoltage,cim.Substation,cim.EnergyConsumer. - Branches (
branch_data.csv): MapsBranchRecord$\leftrightarrow$cim.ACLineSegment,cim.PowerTransformer,cim.Switchwith 3x3 phase impedance matrices ($R, X$). - Generators & DERs (
gen_data.csv): MapsGeneratorRecord$\leftrightarrow$cim.PowerElectronicsConnection,cim.SolarGeneratingUnit,cim.SynchronousMachine. - Capacitors (
cap_data.csv): MapsCapacitorRecord$\leftrightarrow$cim.LinearShuntCompensator. - Energy Storage (
bat_data.csv): MapsBatteryRecord$\leftrightarrow$cim.BatteryUnit. - Regulators (
reg_data.csv): MapsRegulatorRecord$\leftrightarrow$cim.RatioTapChanger.
Metadata
Release files for cimhub-distopf 2.0.1a1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cimhub_distopf-2.0.1a1.tar.gz | 64.2 kB | With provenance | Details for cimhub_distopf-2.0.1a1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cimhub_distopf-2.0.1a1-py3-none-any.whl | Python 3 | none | any | Details for cimhub_distopf-2.0.1a1-py3-none-any.whl |
Total release size: 120.4 kB
Release files / cimhub_distopf-2.0.1a1.tar.gz
| Download URL | cimhub_distopf-2.0.1a1.tar.gz |
|---|---|
| Size | 64.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8047ae4ce8d9a8dd80258667bb3d5e86e42fb76187e2abb45743fafcf2e003ef
|
|
BLAKE2b-256 checksum How to use checksums |
7ec7f847c0aba89b7fe3d2e98cbcc0c94ff14e7eb07328a306cc4ba1e364ce2f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.
Transparency logRelease files / cimhub_distopf-2.0.1a1-py3-none-any.whl
| Download URL | cimhub_distopf-2.0.1a1-py3-none-any.whl |
|---|---|
| Size | 56.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4a7ae62428be4880a580fbd13618db93d0ed56fed145028358e6fe32d65d1ac3
|
|
BLAKE2b-256 checksum How to use checksums |
481e76b18d54e7d04479e69bfa51aecb9023d98fc2d58123c79b70bd95badc63
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.
Transparency logSecurity for cimhub-distopf 2.0.1a1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for cimhub_distopf-2.0.1a1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.