Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ minimization, and generation curtailment minimization, where either generator re
```
pip install distopf
```

### Optional Extras

| Extra | Install command | Purpose |
|-------|----------------|---------|
| `cim` | `pip install distopf[cim]` | CIM XML file import support (requires pre-release packages `cim-graph` and `gridappsd-python`) |

> **Note:** The `cim` extra depends on pre-release packages. If you do not need CIM file support, a plain
> `pip install distopf` is sufficient. CIM functionality will raise an informative `ImportError` if those
> packages are not installed.

## Developer Installation
To install the latest version from github:

Expand All @@ -43,6 +54,10 @@ To install the latest version from github:

`pip install -e .`

To also install the optional CIM extra in editable mode:

`pip install -e ".[cim]"`

This installs your local DistOPF package the python environment you activated. The `-e` option enables editable
mode, which allows you to directly edit the package and see changes immediately reflected in your environment
without reinstalling.
Expand Down Expand Up @@ -342,6 +357,28 @@ case = opf.create_case(
)
```

# CIM XML Interface

To load a power system model from a CIM XML file, install the optional `cim` extra first:

```
pip install distopf[cim]
```

Then pass the path to your `.xml` file:

```python
import distopf as opf
case = opf.create_case(data_path="path/to/model.xml")
```

If the `cim` extra is not installed, calling `create_case` with a `.xml` file will raise:

```
ImportError: CIM file support requires optional dependencies.
Install them with: pip install distopf[cim]
```

# Citing this tool

Gray, Nathan T., Dubey, Anamika, Reiman, Andrew P., "DistOPF: Advanced Solutions for Distribution Optimal Power Flow Analysis - DistOPF v0.2 Documentation," (2025), https://doi.org/10.2172/2999990
Expand Down
8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ authors = [
]
requires-python = ">=3.10"
dependencies = [
"cim-graph==0.4.1a2",
"gridappsd-python==2025.3.2a13",
"cvxpy>=1.7.2",
"networkx>=3.4.2",
"numpy>=2.2.6",
Expand All @@ -25,6 +23,12 @@ dependencies = [
"highspy>=1.13.0",
]

[project.optional-dependencies]
cim = [
"cim-graph==0.4.1a2",
"gridappsd-python==2025.3.2a13",
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
Expand Down
6 changes: 6 additions & 0 deletions src/distopf/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1403,7 +1403,13 @@ def create_case_from_cim(
try:
# Lazy import to avoid loading cimgraph at module load time
from distopf.cim_importer import CIMToCSVConverter
except ImportError as e:
raise ImportError(
"CIM file support requires optional dependencies. "
"Install them with: pip install distopf[cim]"
) from e

try:
cim_parser = CIMToCSVConverter(data_path)
data = cim_parser.convert()

Expand Down
8 changes: 8 additions & 0 deletions tests/cim_converter/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import pytest

# Skip all CIM tests if the optional cim-graph dependency is not installed.
# Install it with: pip install distopf[cim]
pytest.importorskip(
"cimgraph",
reason="CIM tests require the 'cim' optional dependency: pip install distopf[cim]",
)
15 changes: 10 additions & 5 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading