Skip to content

Commit

Permalink
Merge branch 'main' of github.com:NREL/altrios
Browse files Browse the repository at this point in the history
  • Loading branch information
calbaker committed Oct 24, 2023
2 parents 6f4e3f1 + b0940cf commit 6a7e1a6
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 18 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

![Altrios Logo](https://raw.githubusercontent.com/NREL/altrios/main/.github/images/ALTRIOS-logo-web.jpg)

[![Tests](https://github.com/NREL/altrios/actions/workflows/tests.yaml/badge.svg)](https://github.com/NREL/altrios/actions/workflows/tests.yaml) [![wheels](https://github.com/NREL/altrios/actions/workflows/wheels.yaml/badge.svg)](https://github.com/NREL/altrios/actions/workflows/wheels.yaml?event=release) ![Release](https://img.shields.io/badge/release-v0.1.0-blue) ![Python](https://img.shields.io/badge/python-3.9%20%7C%203.10-blue)
[![Tests](https://github.com/NREL/altrios/actions/workflows/tests.yaml/badge.svg)](https://github.com/NREL/altrios/actions/workflows/tests.yaml) [![wheels](https://github.com/NREL/altrios/actions/workflows/wheels.yaml/badge.svg)](https://github.com/NREL/altrios/actions/workflows/wheels.yaml?event=release) ![Release](https://img.shields.io/badge/release-v0.1.0-blue) ![Python](https://img.shields.io/badge/python-3.9%20%7C%203.10-blue) [![Documentation](https://img.shields.io/badge/documentation-custom-blue.svg)](https://nrel.github.io/altrios/) [![GitHub](https://img.shields.io/badge/GitHub-altrios-blue.svg)](https://github.com/NREL/altrios)



![Model Framework Schematic](https://raw.githubusercontent.com/NREL/altrios/main/.github/images/ALTRIOS_schematic_Alfred_Hicks.png)

Expand Down
8 changes: 6 additions & 2 deletions applications/demos/test_demos.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
import pytest


demo_paths = list(Path(__file__).parent.glob("*demo*.py"))
@pytest.mark.parametrize("demo_path", demo_paths, ids=[str(dp) for dp in demo_paths])
def demo_paths():
demo_paths = list(Path(__file__).parent.glob("*demo*.py"))
demo_paths.remove(Path(__file__).resolve())
return demo_paths

@pytest.mark.parametrize("demo_path", demo_paths(), ids=[str(dp) for dp in demo_paths()])
def test_demo(demo_path: Path):
os.environ['SHOW_PLOTS'] = "false"
rslt = subprocess.run(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "maturin"

[project]
name = "altrios"
version = "0.1.2"
version = "0.1.3"
authors = [
{ name = "ALTRIOS Team", email = "altrios@nrel.gov" },
{ name = "Chad Baker, Lead Developer" },
Expand Down
12 changes: 6 additions & 6 deletions python/altrios/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from pathlib import Path
from pkg_resources import get_distribution
__version__ = get_distribution("altrios").version

from pathlib import Path
import numpy as np
from altrios.loaders.powertrain_components import _res_from_excel

import logging

from altrios.loaders.powertrain_components import _res_from_excel
from altrios.utilities import set_param_from_path # noqa: F401
from altrios.utilities import download_demo_files # noqa: F401
from altrios import utilities as utils

import logging

# make everything in altrios_core_py available here
from altrios.altrios_core_py import *


# Set up logging
logging.basicConfig(
format="%(asctime)s.%(msecs)03d | %(filename)s#%(lineno)s | %(levelname)s: %(message)s",
Expand Down
23 changes: 20 additions & 3 deletions python/altrios/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import datetime
import requests
import os
from altrios import __version__


from altrios.altrios_core_py import (
Expand Down Expand Up @@ -268,12 +269,21 @@ def enable_logging():
set_log_level(logging.WARNING)


def download_demo_files():
def download_demo_files(demo_path: Path=Path("demos")):
"""
Downloads demo files from github repo into local directory.
# Arguments
demo_path: path (relative or absolute in )
# Warning
Running this function will overwrite existing files so make sure any files with
changes you'd like to keep are renamed.
"""

api_url = "https://api.github.com/repos/NREL/altrios/contents/applications/demos"
v = f"v{__version__}"

api_url = f"https://api.github.com/repos/NREL/altrios/contents/applications/demos?reg={v}"
response = requests.get(api_url)

if response.status_code == 200:
Expand All @@ -284,12 +294,19 @@ def download_demo_files():
file_url = item["download_url"]
file_name = item["name"]

demo_path = Path("demos")
demo_path.mkdir(exist_ok=True)

with open(demo_path / file_name, "wb") as file:
file_content = requests.get(file_url).content
file.write(file_content)

with open(demo_path / file_name, "r+") as file:
file_content = file.readlines()
prepend_str = f"# %% Downloaded from ALTRIOS version '{v}'. Guaranteed compatibility with this version only.\n"
prepend = [prepend_str]
file_content = prepend + file_content
file.seek(0)
file.writelines(file_content)

print(f"Saved {file_name} to {str(demo_path / file_name)}")
else:
Expand Down
4 changes: 2 additions & 2 deletions rust/Cargo.lock

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

4 changes: 2 additions & 2 deletions rust/altrios-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "altrios-core"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
license = "BSD-3-Clause"
authors = ["NREL/MTES/CIMS/MBAP Group"]
Expand All @@ -17,7 +17,7 @@ serde_json = "1.0"
uom = { workspace = true }
paste = "1.0.7"
easy-ext = "1.0.0"
altrios-proc-macros = { version = "0.1.1", path = "altrios-proc-macros" }
altrios-proc-macros = { version = "0.1.2", path = "altrios-proc-macros" }
argmin = "0.5.1"
enum_dispatch = "0.3.8"
rayon = "1.5.3"
Expand Down
5 changes: 5 additions & 0 deletions rust/altrios-core/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# altrios-core

![Altrios Logo](https://raw.githubusercontent.com/NREL/altrios/main/.github/images/ALTRIOS-logo-web.jpg)

[![Tests](https://github.com/NREL/altrios/actions/workflows/tests.yaml/badge.svg)](https://github.com/NREL/altrios/actions/workflows/tests.yaml) [![wheels](https://github.com/NREL/altrios/actions/workflows/wheels.yaml/badge.svg)](https://github.com/NREL/altrios/actions/workflows/wheels.yaml?event=release) ![Release](https://img.shields.io/badge/release-v0.1.0-blue) ![Python](https://img.shields.io/badge/python-3.9%20%7C%203.10-blue) [![Documentation](https://img.shields.io/badge/documentation-custom-blue.svg)](https://nrel.github.io/altrios/) [![GitHub](https://img.shields.io/badge/GitHub-altrios-blue.svg)](https://github.com/NREL/altrios)


This crate is primarily intended to be used as a backend for the [ALTRIOS PyPI package](https://pypi.org/project/altrios/), but it can also function as a dependency for other crates.

## Developers
Expand Down
2 changes: 1 addition & 1 deletion rust/altrios-core/altrios-proc-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "altrios-proc-macros"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
license = "BSD-3-Clause"
authors = ["NREL/MTES/CIMS/MBAP Group"]
Expand Down
5 changes: 5 additions & 0 deletions rust/altrios-core/altrios-proc-macros/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# altrios-proc-macros

![Altrios Logo](https://raw.githubusercontent.com/NREL/altrios/main/.github/images/ALTRIOS-logo-web.jpg)

[![Tests](https://github.com/NREL/altrios/actions/workflows/tests.yaml/badge.svg)](https://github.com/NREL/altrios/actions/workflows/tests.yaml) [![wheels](https://github.com/NREL/altrios/actions/workflows/wheels.yaml/badge.svg)](https://github.com/NREL/altrios/actions/workflows/wheels.yaml?event=release) ![Release](https://img.shields.io/badge/release-v0.1.0-blue) ![Python](https://img.shields.io/badge/python-3.9%20%7C%203.10-blue) [![Documentation](https://img.shields.io/badge/documentation-custom-blue.svg)](https://nrel.github.io/altrios/) [![GitHub](https://img.shields.io/badge/GitHub-altrios-blue.svg)](https://github.com/NREL/altrios)


This crate contains procedural macros used in [altrios-core](https://crates.io/crates/altrios-core).

## Developers
Expand Down
14 changes: 14 additions & 0 deletions tests/test_utilities.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import tempfile
import unittest
from pathlib import Path

from .mock_resources import *

from altrios.utilities import set_param_from_path
import altrios as alt


class TestUtilities(unittest.TestCase):
Expand All @@ -16,3 +19,14 @@ def test_set_param(self):
c = set_param_from_path(c, "state.pwr_fuel_watts", -100)

self.assertEqual(c.state.pwr_fuel_watts, -100)

def test_download_demo_files(self):
v = f"v{alt.__version__}"
prepend_str = f"# %% Downloaded from ALTRIOS version '{v}'. Guaranteed compatibility with this version only.\n"
with tempfile.TemporaryDirectory() as tmpdir:
tf_path = Path(tmpdir)
alt.download_demo_files(tf_path)
with open(next(tf_path.glob("*demo*.py")), 'r') as file:
lines = file.readlines()
assert prepend_str in lines[0]
assert len(lines) > 3

0 comments on commit 6a7e1a6

Please sign in to comment.