Skip to content

Commit

Permalink
ENH: Improve file compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit9126 committed Nov 29, 2024
1 parent bd6445c commit 83d941e
Show file tree
Hide file tree
Showing 14 changed files with 251 additions and 21 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
target-branch: "develop"
schedule:
interval: "monthly"
80 changes: 80 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: CI

on:
push:
branches: [main, develop]
tags:
- "*"
paths-ignore:
- "doc/**"
- ".vscode/**"
pull_request:
branches: [main, develop]
paths-ignore:
- "doc/**"
- ".vscode/**"

env:
CI: true
UV_SYSTEM_PYTHON: 1

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4
with:
lfs: false

- name: Create LFS file list
run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id

- name: Cache git LFS
uses: actions/cache@v4
with:
path: .git/lfs
key: git-lfs-v1-${{ matrix.python-version }}-${{ hashFiles('.lfs-assets-id') }}
restore-keys: |
git-lfs-v1-${{ matrix.python-version }}
git-lfs-v1
git-lfs
- name: Git LFS
run: |
git lfs checkout
git lfs pull
git lfs prune --verify-remote
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
uv sync --frozen --all-extras
env:
GIT_LFS_SKIP_SMUDGE: 1

- name: Test with pytest
run: |
uv run pytest -vv -n=auto --durations=25 --cov-report html --cov-config pyproject.toml roseau
env:
ROSEAU_LOAD_FLOW_LICENSE_KEY: ${{ secrets.ROSEAU_LOAD_FLOW_LICENSE_KEY }}

- name: Archive code coverage results
uses: actions/upload-artifact@v4
if: ${{ always() }}
with:
name: code-coverage-report-${{ runner.os }}-python-${{ matrix.python-version }}
path: htmlcov/
27 changes: 27 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: pre-commit

on:
push:
branches: [main, develop]
paths-ignore:
- ".vscode/**"
- ".idea/**"
tags:
- "*"
pull_request:
branches: [main, develop]
paths-ignore:
- ".vscode/**"
- ".idea/**"

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
lfs: false
- uses: actions/setup-python@v5
with:
python-version: "3.13"
- uses: pre-commit/[email protected]
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ authors = [
{ name = "Sébastien Vallet", email = "[email protected]" },
{ name = "Benoît Vinot", email = "[email protected]" },
{ name = "Florent Cadoux", email = "[email protected]" },
{ name = "Louise Muller", email = "[email protected]" },
{ name = "Victor Gouin" },
]
maintainers = [
{ name = "Ali Hamdan", email = "[email protected]" },
]
readme = "README.md"
license = { file = "LICENSE.md" }
classifiers = [
"Development Status :: 3 - Alpha",
# "License :: OSI Approved :: The 3-Clause BSD License (BSD-3-Clause)", # https://github.com/pypa/trove-classifiers/issues/70
Expand Down Expand Up @@ -64,7 +63,7 @@ dev = [
managed = true

[tool.uv.sources]
roseau-load-flow = { git = "ssh://git@github.com/RoseauTechnologies/Roseau_Load_Flow.git" , branch="develop"}
roseau-load-flow = { git = "https://github.com/RoseauTechnologies/Roseau_Load_Flow.git", branch = "develop" }

[build-system]
requires = ["hatchling"]
Expand Down
15 changes: 15 additions & 0 deletions roseau/load_flow_single/__about__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
__authors__ = ", ".join(
(
"Ali Hamdan <[email protected]>",
"Sébastien Vallet <[email protected]>",
"Benoît Vinot <[email protected]>",
"Florent Cadoux <[email protected]>",
)
)
__copyright__ = "Roseau Technologies 2018"
__credits__ = "Roseau Technologies"
__license__ = "BSD-3-Clause"
__maintainer__ = "Ali Hamdan"
__email__ = "[email protected]"
__status__ = "In development"
__url__ = "https://github.com/RoseauTechnologies/Roseau_Load_Flow_Single/"
54 changes: 54 additions & 0 deletions roseau/load_flow_single/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
import importlib.metadata

from roseau.load_flow import exceptions, license, show_versions, testing, typing, units, utils
from roseau.load_flow.exceptions import RoseauLoadFlowException, RoseauLoadFlowExceptionCode
from roseau.load_flow.license import License, activate_license, deactivate_license, get_license
from roseau.load_flow.units import Q_, ureg
from roseau.load_flow.utils import Insulator, LineType, Material, constants
from roseau.load_flow_single.__about__ import (
__authors__,
__copyright__,
__credits__,
__email__,
__license__,
__maintainer__,
__status__,
__url__,
)
from roseau.load_flow_single.models.branches import AbstractBranch
from roseau.load_flow_single.models.buses import Bus
from roseau.load_flow_single.models.core import Element
Expand All @@ -16,7 +33,19 @@
from roseau.load_flow_single.models.transformers import Transformer, TransformerParameters
from roseau.load_flow_single.network import ElectricalNetwork

__version__ = importlib.metadata.version("roseau-load-flow-single")

__all__ = [
# RLFS elements
"__authors__",
"__copyright__",
"__credits__",
"__email__",
"__license__",
"__maintainer__",
"__status__",
"__url__",
"__version__",
"Element",
"Line",
"LineParameters",
Expand All @@ -34,4 +63,29 @@
"Projection",
"Control",
"AbstractBranch",
# Other imports from RLF to have the same interface
# utils
"Insulator",
"LineType",
"Material",
"utils",
"constants",
# License
"License",
"activate_license",
"deactivate_license",
"get_license",
"license",
# Units
"Q_",
"units",
"ureg",
# Exceptions
"RoseauLoadFlowException",
"RoseauLoadFlowExceptionCode",
"exceptions",
# Other
"show_versions",
"testing",
"typing",
]
27 changes: 22 additions & 5 deletions roseau/load_flow_single/io/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from typing import TYPE_CHECKING, TypeVar

from roseau.load_flow.exceptions import RoseauLoadFlowException, RoseauLoadFlowExceptionCode
from roseau.load_flow.io.dict import NETWORK_JSON_VERSION
from roseau.load_flow.typing import Id, JsonDict
from roseau.load_flow_single.models import (
AbstractBranch,
Expand All @@ -29,8 +30,6 @@

logger = logging.getLogger(__name__)

NETWORK_JSON_VERSION = 2
"""The current version of the network JSON file format."""

_T = TypeVar("_T", bound=AbstractBranch)

Expand Down Expand Up @@ -87,13 +86,31 @@ def network_from_dict(
"""
data = copy.deepcopy(data) # Make a copy to avoid modifying the original

# version = data.get("version", 0)
# TODO version check

# Check that the network is single phase
is_multiphase = data.get("is_multiphase", True)
assert not is_multiphase, f"Unsupported phase selection {is_multiphase=}."

# Check on the version
# 3 was the first version to support RLFS
version = data.get("version", 3)
if version <= 2:
msg = (
f"The version {version} of the network file can not be single-phased. This featured appeared in the "
f"version 3..."
)
logger.error(msg)
raise AssertionError(msg)
# elif version <= NETWORK_JSON_VERSION:
# logger.warning(
# f"Got an outdated network file (version {version}), trying to update to the current format "
# f"(version {NETWORK_JSON_VERSION}). Please save the network again."
# )
# if version == 3:
# data = v3_to_v4_converter(data)
else:
# If we arrive here, we dealt with all legacy versions, it must be the current one
assert version == NETWORK_JSON_VERSION, f"Unsupported network file version {version}."

# Track if ALL results are included in the network
has_results = include_results

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": 2,
"version": 3,
"is_multiphase": false,
"buses": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": 2,
"version": 3,
"is_multiphase": false,
"buses": [
{
Expand Down
7 changes: 3 additions & 4 deletions roseau/load_flow_single/models/tests/test_buses.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def test_voltage_limits():
assert bus.max_voltage == Q_(434.6, "V")

# Can be reset to None
bus.nominal_voltage = None
bus.min_voltage_level = None
bus.max_voltage_level = None
bus.nominal_voltage = None
assert bus.min_voltage_level is None
assert bus.max_voltage_level is None
assert bus.min_voltage is None
Expand All @@ -60,19 +60,19 @@ def test_voltage_limits():

# NaNs are converted to None
for na in (np.nan, float("nan"), pd.NA):
bus.nominal_voltage = na
bus.min_voltage_level = na
bus.max_voltage_level = na
bus.nominal_voltage = na
assert bus.nominal_voltage is None
assert bus.min_voltage_level is None
assert bus.max_voltage_level is None
assert bus.min_voltage is None
assert bus.max_voltage is None

# Min/Max voltage values defined without nominal voltage are useless
bus.nominal_voltage = None
bus.min_voltage_level = None
bus.max_voltage_level = None
bus.nominal_voltage = None
with pytest.warns(
UserWarning,
match=r"The min voltage level of the bus 'bus' is useless without a nominal voltage. Please define a nominal "
Expand Down Expand Up @@ -102,7 +102,6 @@ def test_voltage_limits():
bus.nominal_voltage = Q_(400, "V")
bus.min_voltage_level = None
bus.max_voltage_level = None
bus.nominal_voltage = None

# Bad values
bus.min_voltage_level = 0.95
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": 2,
"version": 3,
"is_multiphase": false,
"buses": [
{
Expand Down Expand Up @@ -315,15 +315,15 @@
"id": "lp0",
"z_line": [0.2430129333, 0.0962375209],
"y_shunt": [0.0, 3.40441e-5],
"ampacity": 323,
"ampacity": 323.0,
"line_type": "UNDERGROUND",
"material": "AM",
"section": 148
"section": 148.0
},
{
"id": "lp1",
"z_line": [0.4184, 0.1066400577],
"ampacity": 195,
"ampacity": 195.0,
"line_type": "TWISTED",
"material": "AL",
"section": 75.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": 2,
"version": 3,
"is_multiphase": false,
"buses": [
{
Expand Down
Loading

0 comments on commit 83d941e

Please sign in to comment.