Skip to content

Commit

Permalink
Merge branch 'fastsim-2' into f2/numpy-arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecarow committed Dec 26, 2024
2 parents 6fc5587 + 6aed9c7 commit c07de89
Show file tree
Hide file tree
Showing 24 changed files with 380 additions and 154 deletions.
18 changes: 14 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:
- os: windows
ls: dir

env:
FASTSIM_DISABLE_NETWORK_TESTS: 1

runs-on: ${{ format('{0}-latest', matrix.os) }}
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -87,7 +90,8 @@ jobs:
pip install -U setuptools-rust &&
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=nightly --profile=minimal -y &&
rustup show
CIBW_BEFORE_BUILD_MACOS: >
rustup target add x86_64-apple-darwin
# - name: build windows 32bit binaries
# if: matrix.os == 'windows'
# run: cibuildwheel --output-dir dist
Expand All @@ -107,7 +111,7 @@ jobs:
- name: list dist files
run: ${{ matrix.ls || 'ls -lh' }} dist/

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
path: ./dist/*

Expand All @@ -117,7 +121,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: download files
uses: actions/download-artifact@v2.1.1
uses: actions/download-artifact@v4

- name: set up Python 3.10
uses: actions/setup-python@v4
Expand All @@ -128,7 +132,13 @@ jobs:

- run: twine check ./artifact/*

- name: upload files
- name: Publish distribution to Test PyPI
run: twine upload -r testpypi ./artifact/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.FASTSIM_TEST_PYPI_TOKEN }}

- name: Upload files to PyPI
run: twine upload ./artifact/*
env:
TWINE_USERNAME: __token__
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:

env:
PYTHON: ${{ matrix.python-version }}
FASTSIM_DISABLE_NETWORK_TESTS: 1

steps:
- uses: actions/checkout@v3

Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/wheels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ jobs:
pip install -U setuptools-rust &&
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=nightly --profile=minimal -y &&
rustup show
CIBW_BEFORE_BUILD_MACOS: >
rustup target add x86_64-apple-darwin
# - name: build windows 32bit binaries
# if: matrix.os == 'windows'
# run: cibuildwheel --output-dir dist
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# FASTSim

![FASTSim Logo](https://www.nrel.gov/transportation/assets/images/icon-fastsim.jpg)
<img src="https://raw.githubusercontent.com/NREL/fastsim/refs/heads/fastsim-2/docs/assets/fastsim-icon.svg" height="200">

[![homepage](https://img.shields.io/badge/homepage-fastsim-blue)](https://www.nrel.gov/transportation/fastsim.html) [![tests](https://github.com/NREL/fastsim/actions/workflows/tests.yaml/badge.svg)](https://github.com/NREL/fastsim/actions/workflows/tests.yaml) [![wheels](https://github.com/NREL/fastsim/actions/workflows/wheels.yaml/badge.svg)](https://github.com/NREL/fastsim/actions/workflows/wheels.yaml?event=release) [![python](https://img.shields.io/badge/python-3.8%20%7C%203.9%20%7C%203.10-blue)](https://pypi.org/project/fastsim/) [![documentation](https://img.shields.io/badge/documentation-book-blue.svg)](https://nrel.github.io/fastsim/) [![github](https://img.shields.io/badge/github-fastsim-blue.svg)](https://github.com/NREL/fastsim)

Expand Down
1 change: 1 addition & 0 deletions docs/assets/fastsim-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions python/fastsim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def package_root() -> Path:
"""Returns the package root directory."""
return Path(__file__).parent

def resources_root() -> Path:
"""Returns the resources root directory."""
return Path(__file__).parent / "resources"


DEFAULT_LOGGING_CONFIG = dict(
format = "%(asctime)s.%(msecs)03d | %(filename)s:%(lineno)s | %(levelname)s: %(message)s",
Expand Down
9 changes: 8 additions & 1 deletion python/fastsim/demos/test_demos.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import subprocess
import os
from pathlib import Path
Expand All @@ -22,8 +23,14 @@ def test_demo(demo_path: Path):
os.environ["SHOW_PLOTS"] = "false"
os.environ["TESTING"] = "true"

# NOTE: Try to set the python executable based on the current running python which
# MAY be running from a virtual environment.
python_exe = sys.executable
if python_exe == "" or python_exe is None:
python_exe = "python"

rslt = subprocess.run(
["python", demo_path],
[python_exe, demo_path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
Expand Down
8 changes: 1 addition & 7 deletions python/fastsim/tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ def test_list_resources_for_cycle(self):

def test_list_resources_for_vehicles(self):
"check if list_resources works for RustVehicle"
# NOTE: at the time of writing this test,
# there are no vehicle assets in resources.
# Therefore, we expect to get an empty vector.
# If resources are committed, this test should
# fail and we should use the following assert:
# self.assertTrue(len(resources) > 0)
rv = vehicle.Vehicle.from_vehdb(1).to_rust()
resources = rv.list_resources()
self.assertTrue(len(resources) == 0)
self.assertTrue(len(resources) == 1)
6 changes: 3 additions & 3 deletions rust/fastsim-cli/src/bin/fastsim-cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ pub fn calculate_mpgge_for_h2_diesel_ice(
dist_mi: f64,
max_fc_power_kw: f64,
kwh_per_gge: f64,
fc_kw_out_ach: &Vec<f64>,
fs_kwh_out_ach: &Vec<f64>,
fc_kw_out_ach: &[f64],
fs_kwh_out_ach: &[f64],
fc_pwr_out_perc: &Vec<f64>,
h2share: &Vec<f64>,
) -> anyhow::Result<H2AndDieselResults> {
Expand Down Expand Up @@ -168,7 +168,7 @@ pub fn calculate_mpgge_for_h2_diesel_ice(
})
}

pub fn integrate_power_to_kwh(dts_s: &Vec<f64>, ps_kw: &Vec<f64>) -> anyhow::Result<Vec<f64>> {
pub fn integrate_power_to_kwh(dts_s: &[f64], ps_kw: &[f64]) -> anyhow::Result<Vec<f64>> {
anyhow::ensure!(dts_s.len() == ps_kw.len());
let mut energy_kwh = Vec::<f64>::with_capacity(dts_s.len());
for idx in 0..dts_s.len() {
Expand Down
14 changes: 14 additions & 0 deletions rust/fastsim-core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@ fn main() {
return;
}

check_files_consistent(&prepath);
}

/// Checks if rust and python resource files are consistent
fn check_files_consistent(prepath: &String) {
let truth_files = [
format!(
"{}/{}/vehdb/2017_Toyota_Highlander_3.5_L.yaml",
env::current_dir().unwrap().as_os_str().to_str().unwrap(),
prepath
),
format!(
"{}/{}/longparams.json",
env::current_dir().unwrap().as_os_str().to_str().unwrap(),
Expand All @@ -42,6 +52,10 @@ fn main() {
];

let compare_files = [
format!(
"{}/resources/vehicles/2017_Toyota_Highlander_3.5_L.yaml",
env::current_dir().unwrap().as_os_str().to_str().unwrap()
),
format!(
"{}/resources/longparams.json",
env::current_dir().unwrap().as_os_str().to_str().unwrap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ pub fn add_pyo3_api(attr: TokenStream, item: TokenStream) -> TokenStream {
) -> anyhow::Result<()> {
bail!(PyNotImplementedError::new_err(
"Setting value at index is not implemented.
Run `tolist` method, modify value at index, and
then set entire vector.",
Run `tolist` method, modify value at index, and then set entire vector.",
))
}
pub fn tolist(&self) -> anyhow::Result<Vec<#contained_dtype>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ macro_rules! impl_get_body {
/// - impl_block: TokenStream2
/// - has_orphaned: bool, true if struct has `orphaned` field
/// - opts: FieldOptions struct instance
macro_rules! impl_set_body {
( // for generic
$type: ident, $field: ident, $impl_block: ident, $has_orphaned: expr, $opts: ident
Expand Down Expand Up @@ -146,13 +145,3 @@ macro_rules! impl_set_body {
}
};
}

#[derive(Debug, Default, Clone)]
pub struct FieldOptions {
/// if true, getters are not generated for a field
pub skip_get: bool,
/// if true, setters are not generated for a field
pub skip_set: bool,
/// if true, current field is itself a struct with `orphaned` field
pub field_has_orphaned: bool,
}
Loading

0 comments on commit c07de89

Please sign in to comment.