Skip to content

Commit

Permalink
now test poetry caching
Browse files Browse the repository at this point in the history
  • Loading branch information
amandamalk0601 committed Jan 22, 2024
1 parent 74a190f commit ad3adb8
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 50 deletions.
21 changes: 10 additions & 11 deletions .github/workflows/building-and-installation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: Build
on:
pull_request:
branches:
- main
- pipeline_adjustments #main

jobs:
integration-tests:
Expand All @@ -17,26 +17,25 @@ jobs:
steps:
# downloads the repository code to the runner's file system for workflow access
- uses: actions/checkout@v4
with:
ref: 'pipeline_adjustments'

# sets up python environment with specified versions
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}


# installs poetry without automatic creation of a virtual environment
- name: Install poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: false

# sets up python environment with specified versions
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'

- name: Build package out of local poject
run: poetry build

- name: Install package
run: pip install dist/*.tar.gz
run: pip install dist/*.tar.gz

- name: Run example scenario and compare result
run: |
Expand Down
28 changes: 15 additions & 13 deletions .github/workflows/linting-and-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,38 @@ jobs:
steps:
# downloads the repository code to the runner's file system for workflow access
- uses: actions/checkout@v4

# installs poetry without automatic creation of a virtual environment
- name: Install poetry
uses: snok/install-poetry@v1
with:
ref: 'pipeline_adjustments'
virtualenvs-create: false

# sets up python environment with specified versions
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
id: cp312
with:
python-version: ${{ matrix.python-version }}
python-version: ${{ matrix.python-version }}
cache: 'poetry'

- run: echo '${{ steps.cp312.outputs.cache-hit }}' # true if cache-hit occurred on the primary key

# get rid of DeprecationWarning related to Jupyter paths when running pytest
- name: Set JUPYTER_PLATFORM_DIRS environment variable
env:
JUPYTER_PLATFORM_DIRS: 1
run: |
echo "JUPYTER_PLATFORM_DIRS=${JUPYTER_PLATFORM_DIRS}" >> $GITHUB_ENV
# installs poetry without automatic creation of a virtual environment
- name: Install poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: false

- name: Install dependencies
run: poetry install --extras "dev"
run: poetry install --extras "sil dev analysis"

- name: Run type checker
run: mypy vessim
run: poetry run mypy vessim

- name: Run linter
run: ruff vessim
#- name: Run linter
# run: poetry run ruff vessim

#- name: Run tests
# run: python -m pytest
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ build:
- pip install poetry
- poetry config virtualenvs.create false
post_install:
- poetry install --extras "sil analysis docs"
- poetry install --extras "dev sil analysis docs"

sphinx:
configuration: docs/conf.py
2 changes: 1 addition & 1 deletion examples/basic_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from examples._data import load_carbon_data, load_solar_data
from _data import load_carbon_data, load_solar_data
from vessim import HistoricalSignal
from vessim.cosim import Microgrid, Environment, ComputingSystem, Generator, Monitor, \
MockPowerMeter, SimpleBattery
Expand Down
4 changes: 2 additions & 2 deletions examples/controller_example.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Dict, List

from examples._data import load_carbon_data, load_solar_data
from examples.basic_example import SIM_START, DURATION
from _data import load_carbon_data, load_solar_data
from basic_example import SIM_START, DURATION
from vessim import HistoricalSignal
from vessim.cosim import ComputingSystem, Generator, Monitor, Controller, Microgrid, \
Environment, DefaultStoragePolicy, MockPowerMeter, SimpleBattery
Expand Down
2 changes: 1 addition & 1 deletion examples/util/example_node/node_api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, host: str = "0.0.0.0", port: int = 8000):
self.setup_routes()

def setup_routes(self) -> None:
"""Setup the routes for the FastAPI application. """
"""Setup the routes for the FastAPI application."""

class PowerModeModel(BaseModel):
power_mode: str
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sys
from typing import Union
sys.path.append("../")
from linear_power_model import LinearPowerModel
from node_api_server import FastApiServer
Expand Down
17 changes: 10 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,18 @@ pandas = "*"
mosaik = "*"
mosaik-api = "*"
loguru = "*"
matplotlib = "*"
requests = "*"
docker = "*"
redis = "*"
uvicorn = "*"
fastapi = "*"

# Optional dependencies (software-in-the-loop)
requests = {version = "*", optional = true}
fastapi = {version = "*", optional = true}
docker = {version = "*", optional = true}
redis = {version = "*", optional = true}
uvicorn = {version = "*", optional = true}

# Optional dependencies (analysis)
jupyterlab = {version = "*", optional = true}
seaborn = {version = "0.12.2", optional = true}
matplotlib = {version = "*", optional = true}

# Optional dependencies (development)
pytest = {version = "*", optional = true}
Expand All @@ -69,7 +71,8 @@ furo = {version = "*", optional = true}
sphinx-copybutton = {version = "*", optional = true}

[tool.poetry.extras]
analysis = ["jupyterlab", "seaborn"]
sil = ["requests", "fastapi", "docker", "redis", "uvicorn"]
analysis = ["jupyterlab", "matplotlib", "seaborn"]
dev = ["pytest", "mypy", "types-psutil", "pandas-stubs", "types-requests", "black", "ruff"]
docs = ["furo", "sphinx-copybutton"]

Expand Down
11 changes: 6 additions & 5 deletions vessim/_signal.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import ABC, abstractmethod
from datetime import timedelta, datetime
from pathlib import Path
from typing import Union, Optional, Literal, Dict, Hashable, List
from typing import Any, Union, Optional, Literal, Dict, List

import pandas as pd

Expand All @@ -25,9 +25,9 @@ def __init__(
fill_method: Literal["ffill", "bfill"] = "ffill",
):
actual = convert_to_datetime(actual)
self._actual: Dict[Hashable, pd.Series]
self._actual: Dict[str, pd.Series]
if isinstance(actual, pd.Series):
self._actual = {actual.name: actual.dropna()}
self._actual = {str(actual.name): actual.dropna()}
elif isinstance(actual, pd.DataFrame):
self._actual = {col: actual[col].dropna() for col in actual.columns}
else:
Expand Down Expand Up @@ -55,7 +55,7 @@ def from_dataset(
cls,
dataset: str,
data_dir: Optional[Union[str, Path]] = None,
params: Dict = None,
params: Optional[Dict[Any, Any]] = None,
):
if params is None:
params = {}
Expand All @@ -65,7 +65,7 @@ def columns(self) -> List:
"""Returns a list of all columns where actual data is available."""
return list(self._actual.keys())

def at(self, dt: DatetimeLike, column: str = None, **kwargs):
def at(self, dt: DatetimeLike, column: Optional[str] = None, **kwargs):
dt = pd.to_datetime(dt)
column_data = _get_column_data(self._actual, column)

Expand All @@ -88,6 +88,7 @@ def at(self, dt: DatetimeLike, column: str = None, **kwargs):
f"'{dt}' is too late to get data in column '{column}'."
)


def forecast(
self,
start_time: DatetimeLike,
Expand Down
8 changes: 4 additions & 4 deletions vessim/cosim/controller.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import ABC, abstractmethod
from collections import defaultdict
from datetime import datetime
from typing import Dict, Callable, Any, Tuple, TYPE_CHECKING, MutableMapping, Optional
from typing import DefaultDict, Dict, List, Callable, Any, Tuple, TYPE_CHECKING, MutableMapping, Optional

import mosaik_api # type: ignore
import pandas as pd
Expand All @@ -13,7 +13,7 @@


class Controller(ABC):
def __init__(self, step_size: int):
def __init__(self, step_size: Optional[int] = None):
self.step_size = step_size
self.microgrid: Optional["Microgrid"] = None
self.clock: Optional[Clock] = None
Expand Down Expand Up @@ -82,7 +82,7 @@ def to_csv(self, out_path: str):


def flatten_dict(d: MutableMapping, parent_key: str = "") -> MutableMapping:
items = []
items: List[Tuple[str, Any]] = []
for k, v in d.items():
new_key = parent_key + "." + k if parent_key else k
if isinstance(v, MutableMapping):
Expand All @@ -109,7 +109,7 @@ def __init__(self):
super().__init__(self.META)
self.eid = "Controller"
self.step_size = None
self.controller: Optional[Controller] = None
self.controller = None

def init(self, sid, time_resolution=1.0, **sim_params):
self.step_size = sim_params["step_size"]
Expand Down
6 changes: 3 additions & 3 deletions vessim/cosim/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
class Microgrid:
def __init__(
self,
actors: List[Actor] = None,
controllers: List[Controller] = None,
actors: Optional[List[Actor]] = None,
controllers: Optional[List[Controller]] = None,
storage: Optional[Storage] = None,
storage_policy: Optional[StoragePolicy] = None,
zone: Optional[str] = None,
Expand Down Expand Up @@ -102,7 +102,7 @@ def run(
for microgrid in self.microgrids:
microgrid.initialize(self.world, self.clock, self.grid_signals)
if until is None:
until = float("inf")
until = int("inf")
self.world.run(until=until, rt_factor=rt_factor, print_progress=print_progress)
except Exception as e:
if str(e).startswith("Simulation too slow for real-time factor"):
Expand Down
2 changes: 1 addition & 1 deletion vessim/sil.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from time import sleep
from typing import Dict, Callable, Optional, List, Any

import docker
import docker # type: ignore
import pandas as pd
import redis
import requests
Expand Down

0 comments on commit ad3adb8

Please sign in to comment.