Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Quickstart instruction #29

Open
iantei opened this issue Jan 17, 2025 · 1 comment
Open

Update Quickstart instruction #29

iantei opened this issue Jan 17, 2025 · 1 comment

Comments

@iantei
Copy link
Contributor

iantei commented Jan 17, 2025

Update the information to use pip3 incase pip command is not found

Issue 1:

  • Some system (like newer version of Mac OS) comes only with Python 3, correspondingly pip3 instead of pip. This leads to the following issue:
ashrest2-41625s:RouteE ashrest2$ pip install pip --upgrade
bash: pip: command not found
ashrest2-41625s:RouteE ashrest2$ pip install nrel.routee.powertrain
bash: pip: command not found

Solution 1:

Use pip3 instead of pip for the system which has Python 3.x instead of Python 2.

pip3 install pip --upgrade
pip3 install nrel.routee.powertrain

Result 1:

ashrest2-41625s:RouteE ashrest2$ pip3 install pip --upgrade
pip3 install nrel.routee.powertrainDefaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pip in /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/site-packages (21.2.4)
Collecting pip
  Downloading pip-24.3.1-py3-none-any.whl (1.8 MB)
     |████████████████████████████████| 1.8 MB 795 kB/s 
Installing collected packages: pip
  WARNING: The scripts pip, pip3 and pip3.9 are installed in '/Users/ashrest2/Library/Python/3.9/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-24.3.1
WARNING: You are using pip version 21.2.4; however, version 24.3.1 is available.
You should consider upgrading via the '/Library/Developer/CommandLineTools/usr/bin/python3 -m pip install --upgrade pip' command.
ashrest2-41625s:RouteE ashrest2$ pip3 install nrel.routee.powertrain

Update the quick start code - for pre-trained model from the RouteE model catalog

Issue 2:

ashrest2-41625s:RouteE ashrest2$ python3 route_first.py
['2016_TOYOTA_Camry_4cyl_2WD', '2017_CHEVROLET_Bolt', '2010_Mazda_3_i-Stop', '2012_Ford_Focus', '2012_Ford_Fusion', '2016_AUDI_A3_4cyl_2WD', '2016_BMW_328d_4cyl_2WD', '2016_BMW_i3_REx_PHEV_Charge_Depleting', '2016_BMW_i3_REx_PHEV_Charge_Sustaining', '2016_CHEVROLET_Malibu_4cyl_2WD', '2016_CHEVROLET_Spark_EV', '2016_CHEVROLET_Volt_Charge_Depleting', '2016_CHEVROLET_Volt_Charge_Sustaining', '2016_FORD_C-MAX_(PHEV)_Charge_Depleting', '2016_FORD_C-MAX_(PHEV)_Charge_Sustaining', '2016_FORD_C-MAX_HEV', '2016_FORD_Escape_4cyl_2WD', '2016_FORD_Explorer_4cyl_2WD', '2016_HYUNDAI_Elantra_4cyl_2WD', '2016_HYUNDAI_Sonata_PHEV_Charge_Depleting', '2016_HYUNDAI_Sonata_PHEV_Charge_Sustaining', '2016_Hyundai_Tucson_Fuel_Cell', '2016_KIA_Optima_Hybrid', '2016_Leaf_24_kWh', '2016_MITSUBISHI_i-MiEV', '2016_Nissan_Leaf_30_kWh', '2016_TESLA_Model_S60_2WD', '2016_TOYOTA_Camry_4cyl_2WD', '2016_TOYOTA_Corolla_4cyl_2WD', '2016_TOYOTA_Highlander_Hybrid', '2016_Toyota_Prius_Two_FWD', '2017_CHEVROLET_Bolt', '2017_Maruti_Dzire_VDI', '2017_Prius_Prime_Charge_Depleting', '2017_Prius_Prime_Charge_Sustaining', '2017_Toyota_Highlander_3', '2020_Chevrolet_Colorado_2WD_Diesel', '2020_VW_Golf_1', '2020_VW_Golf_2', '2021_BMW_iX_xDrive40', '2021_Cupra_Born', '2021_Fiat_Panda_Mild_Hybrid', '2021_Honda_N-Box_G', '2021_Peugot_3008', '2022_Ford_F-150_Lightning_4WD', '2022_MINI_Cooper_SE_Hardtop_2_door', '2022_Renault_Megane_E-Tech', '2022_Renault_Zoe_ZE50_R135', '2022_Tesla_Model_3_RWD', '2022_Tesla_Model_Y_RWD', '2022_Toyota_Avanza_E_J_MT', '2022_Toyota_RAV4_Hybrid_LE', '2022_Toyota_Yaris_Hybrid_Mid', '2022_Volvo_XC40_Recharge_twin', '2023_Mitsubishi_Pajero_Sport', '2023_Polestar_2_Long_range_Dual_motor', '2023_Volvo_C40_Recharge', '2024_BYD_Dolphin_Active', '2024_Toyota_Vios_1', '2024_VinFast_VF_e34', '2024_Volkswagen_Polo_1', 'BYD_ATTO_3', 'Daycab_new_300kW', 'Daycab_new_400kW', 'Daycab_old_300kW', 'Daycab_old_400kW', 'Maruti_Swift_4cyl_2WD', 'Nissan_Navara', 'Renault_Clio_IV_diesel', 'Renault_Megane_1', 'Sleeper_new_300kW', 'Sleeper_new_400kW', 'Sleeper_old_300kW', 'Sleeper_old_400kW', 'Toyota_Corolla_Cross_Hybrid', 'Toyota_Etios_Liva_diesel', 'Toyota_Hilux_Double_Cab_4WD', 'Toyota_Mirai']
========================================
Model Summary
--------------------
Vehicle description: 2016_TOYOTA_Camry_4cyl_2WD trained July 2024
Powertrain type: ICE
Number of estimators: 3
========================================
Estimator Summary
--------------------
Feature: speed_mph (mph)
Distance: distance (miles)
Target: gge (gallons gasoline)
Raw Predicted Consumption: 30.279 (miles/gallons gasoline)
Real World Predicted Consumption: 25.969 (miles/gallons gasoline)
Predict Method: RATE
========================================
Estimator Summary
--------------------
Feature: speed_mph (mph)
Feature: grade_percent (percent)
Distance: distance (miles)
Target: gge (gallons gasoline)
Raw Predicted Consumption: 30.289 (miles/gallons gasoline)
Real World Predicted Consumption: 25.977 (miles/gallons gasoline)
Predict Method: RATE
========================================
Estimator Summary
--------------------
Feature: speed_mph (mph)
Feature: grade_percent (percent)
Feature: turn_angle (degrees)
Distance: distance (miles)
Target: gge (gallons gasoline)
Raw Predicted Consumption: 30.364 (miles/gallons gasoline)
Real World Predicted Consumption: 26.041 (miles/gallons gasoline)
Predict Method: RATE
========================================
Traceback (most recent call last):
  File "/Users/ashrest2/RouteE/route_first.py", line 54, in <module>
    energy_result = model.predict(links_df)
  File "/Users/ashrest2/Library/Python/3.9/lib/python/site-packages/nrel/routee/powertrain/core/model.py", line 309, in predict
    raise ValueError(
ValueError: links_df must contain a distance column named: 'distance'

What has changed?

  • As suggested by @nreinicke we use distance as the data frame column over miles in our new model.

Executing with this gives the below changes

# Predict energy consumption for a set of road links
links_df = pd.DataFrame(
    {
        "distance": [0.1, 0.2, 0.3], # miles
        "speed_mph": [30, 40, 50], # mph
        "grade_dec": [-0.05, 0, 0.05], # decimal
    }
)

This yields in the following error:

Traceback (most recent call last):
  File "/Users/ashrest2/RouteE/route_first.py", line 54, in <module>
    energy_result = model.predict(links_df)
  File "/Users/ashrest2/Library/Python/3.9/lib/python/site-packages/nrel/routee/powertrain/core/model.py", line 330, in predict
    raise ValueError(
ValueError: This model has multiple feature sets and no features were explicitly provided. We attempted to just use the columns in the incoming dataframe but we couldn't find an estiamtor that matches the features: ['speed_mph', 'grade_dec']. Please provide an explicit list of feature names to the features paramter of the predict method or provide a dataframe that only contains the features you want to use. Here are the feature sets that can be used: [['speed_mph'], ['grade_percent', 'speed_mph'], ['grade_percent', 'speed_mph', 'turn_angle']]

I think the grade_dec has been updated to grade_percent.

So, executing with the following script -

Solution 2:

import pandas as pd
import nrel.routee.powertrain as pt
# Predict energy consumption for a set of road links
links_df = pd.DataFrame(
    {
        "distance": [0.1, 0.2, 0.3], # miles
        "speed_mph": [30, 40, 50], # mph
        "grade_percent": [-0.05, 0, 0.05], # decimal
    }
)

energy_result = model.predict(links_df)

Result 2:

ashrest2-41625s:RouteE ashrest2$ python3 route_first.py
['2016_TOYOTA_Camry_4cyl_2WD', '2017_CHEVROLET_Bolt', '2010_Mazda_3_i-Stop', '2012_Ford_Focus', '2012_Ford_Fusion', '2016_AUDI_A3_4cyl_2WD', '2016_BMW_328d_4cyl_2WD', '2016_BMW_i3_REx_PHEV_Charge_Depleting', '2016_BMW_i3_REx_PHEV_Charge_Sustaining', '2016_CHEVROLET_Malibu_4cyl_2WD', '2016_CHEVROLET_Spark_EV', '2016_CHEVROLET_Volt_Charge_Depleting', '2016_CHEVROLET_Volt_Charge_Sustaining', '2016_FORD_C-MAX_(PHEV)_Charge_Depleting', '2016_FORD_C-MAX_(PHEV)_Charge_Sustaining', '2016_FORD_C-MAX_HEV', '2016_FORD_Escape_4cyl_2WD', '2016_FORD_Explorer_4cyl_2WD', '2016_HYUNDAI_Elantra_4cyl_2WD', '2016_HYUNDAI_Sonata_PHEV_Charge_Depleting', '2016_HYUNDAI_Sonata_PHEV_Charge_Sustaining', '2016_Hyundai_Tucson_Fuel_Cell', '2016_KIA_Optima_Hybrid', '2016_Leaf_24_kWh', '2016_MITSUBISHI_i-MiEV', '2016_Nissan_Leaf_30_kWh', '2016_TESLA_Model_S60_2WD', '2016_TOYOTA_Camry_4cyl_2WD', '2016_TOYOTA_Corolla_4cyl_2WD', '2016_TOYOTA_Highlander_Hybrid', '2016_Toyota_Prius_Two_FWD', '2017_CHEVROLET_Bolt', '2017_Maruti_Dzire_VDI', '2017_Prius_Prime_Charge_Depleting', '2017_Prius_Prime_Charge_Sustaining', '2017_Toyota_Highlander_3', '2020_Chevrolet_Colorado_2WD_Diesel', '2020_VW_Golf_1', '2020_VW_Golf_2', '2021_BMW_iX_xDrive40', '2021_Cupra_Born', '2021_Fiat_Panda_Mild_Hybrid', '2021_Honda_N-Box_G', '2021_Peugot_3008', '2022_Ford_F-150_Lightning_4WD', '2022_MINI_Cooper_SE_Hardtop_2_door', '2022_Renault_Megane_E-Tech', '2022_Renault_Zoe_ZE50_R135', '2022_Tesla_Model_3_RWD', '2022_Tesla_Model_Y_RWD', '2022_Toyota_Avanza_E_J_MT', '2022_Toyota_RAV4_Hybrid_LE', '2022_Toyota_Yaris_Hybrid_Mid', '2022_Volvo_XC40_Recharge_twin', '2023_Mitsubishi_Pajero_Sport', '2023_Polestar_2_Long_range_Dual_motor', '2023_Volvo_C40_Recharge', '2024_BYD_Dolphin_Active', '2024_Toyota_Vios_1', '2024_VinFast_VF_e34', '2024_Volkswagen_Polo_1', 'BYD_ATTO_3', 'Daycab_new_300kW', 'Daycab_new_400kW', 'Daycab_old_300kW', 'Daycab_old_400kW', 'Maruti_Swift_4cyl_2WD', 'Nissan_Navara', 'Renault_Clio_IV_diesel', 'Renault_Megane_1', 'Sleeper_new_300kW', 'Sleeper_new_400kW', 'Sleeper_old_300kW', 'Sleeper_old_400kW', 'Toyota_Corolla_Cross_Hybrid', 'Toyota_Etios_Liva_diesel', 'Toyota_Hilux_Double_Cab_4WD', 'Toyota_Mirai']
========================================
Model Summary
--------------------
Vehicle description: 2016_TOYOTA_Camry_4cyl_2WD trained July 2024
Powertrain type: ICE
Number of estimators: 3
========================================
Estimator Summary
--------------------
Feature: speed_mph (mph)
Distance: distance (miles)
Target: gge (gallons gasoline)
Raw Predicted Consumption: 30.279 (miles/gallons gasoline)
Real World Predicted Consumption: 25.969 (miles/gallons gasoline)
Predict Method: RATE
========================================
Estimator Summary
--------------------
Feature: speed_mph (mph)
Feature: grade_percent (percent)
Distance: distance (miles)
Target: gge (gallons gasoline)
Raw Predicted Consumption: 30.289 (miles/gallons gasoline)
Real World Predicted Consumption: 25.977 (miles/gallons gasoline)
Predict Method: RATE
========================================
Estimator Summary
--------------------
Feature: speed_mph (mph)
Feature: grade_percent (percent)
Feature: turn_angle (degrees)
Distance: distance (miles)
Target: gge (gallons gasoline)
Raw Predicted Consumption: 30.364 (miles/gallons gasoline)
Real World Predicted Consumption: 26.041 (miles/gallons gasoline)
Predict Method: RATE
========================================

This works great!

@iantei
Copy link
Contributor Author

iantei commented Jan 17, 2025

In accordance to the documentation in installation for RouteE Powertrain Rust Smartcore.

Firstly, we need to install 'Anaconda' or 'Miniconda' to execute the first command -
conda install rust - though it's pretty intuitive for the necessity to install either of these to execute the command. It might be helpful to showcase the necessity of it.

ashrest2-41625s:rust ashrest2$ pip3 install maturin
Collecting maturin
  Using cached maturin-1.8.1-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.metadata (16 kB)
Using cached maturin-1.8.1-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (14.5 MB)
Installing collected packages: maturin
Successfully installed maturin-1.8.1
ashrest2-41625s:rust ashrest2$ maturin develop --release
💥 maturin failed
  Caused by: Couldn't find a virtualenv or conda environment, but you need one to use this command. For maturin to find your virtualenv you need to either set VIRTUAL_ENV (through activate), set CONDA_PREFIX (through conda activate) or have a virtualenv called .venv in the current or any parent folder. See https://virtualenv.pypa.io/en/latest/index.html on how to use virtualenv or use `maturin build` and `pip install <path/to/wheel>` instead.
ashrest2-41625s:rust ashrest2$ conda --version
conda 24.11.3
  • We cannot execute pip3 install maturin command outside the virtual environment. We need to create a virtual environment for the same.

I created the conda virtual environment via. the following:

conda create --name myenv python=3.12
conda init
conda activate myenv

Inside the myenv virtual environment, execute the following commands:

(myenv) ashrest2-41625s:rust ashrest2$ pip3 install maturin
Collecting maturin
  Using cached maturin-1.8.1-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.metadata (16 kB)
Using cached maturin-1.8.1-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (14.5 MB)
Installing collected packages: maturin
Successfully installed maturin-1.8.1
(myenv) ashrest2-41625s:rust ashrest2$ maturin develop --release
    Updating crates.io index
  Downloaded pyo3-macros v0.18.2
  Downloaded memoffset v0.8.0
  Downloaded windows-targets v0.42.2
  Downloaded rawpointer v0.2.1
  Downloaded num v0.4.0
  Downloaded autocfg v1.1.0
  Downloaded approx v0.5.1
  Downloaded itoa v1.0.6
  Downloaded num-integer v0.1.45
  Downloaded bitflags v1.3.2
  Downloaded inventory v0.3.5
  Downloaded indoc v1.0.9
  Downloaded target-lexicon v0.12.6
  Downloaded scopeguard v1.1.0
  Downloaded ghost v0.1.9
  Downloaded ctor v0.2.0
  Downloaded rand_core v0.6.4
  Downloaded unindent v0.1.11
  Downloaded typetag-impl v0.2.7
  Downloaded num-complex v0.4.3
  Downloaded erased-serde v0.3.25
  Downloaded lock_api v0.4.9
  Downloaded once_cell v1.17.1
  Downloaded num-iter v0.1.43
  Downloaded num-rational v0.4.1
  Downloaded pyo3-build-config v0.18.2
  Downloaded bincode v1.3.3
  Downloaded typetag v0.2.7
  Downloaded quote v1.0.26
  Downloaded parking_lot_core v0.9.7
  Downloaded parking_lot v0.12.1
  Downloaded anyhow v1.0.70
  Downloaded unicode-ident v1.0.8
  Downloaded serde_derive v1.0.160
  Downloaded smallvec v1.10.0
  Downloaded proc-macro2 v1.0.56
  Downloaded num-traits v0.2.15
  Downloaded ryu v1.0.13
  Downloaded pyo3-macros-backend v0.18.2
  Downloaded matrixmultiply v0.3.2
  Downloaded pyo3-ffi v0.18.2
  Downloaded rand v0.8.5
  Downloaded serde v1.0.160
  Downloaded cfg-if v1.0.0
  Downloaded num-bigint v0.4.3
  Downloaded redox_syscall v0.2.16
  Downloaded serde_json v1.0.96
  Downloaded syn v1.0.109
  Downloaded syn v2.0.15
  Downloaded ndarray v0.15.6
  Downloaded windows_aarch64_gnullvm v0.42.2
  Downloaded windows_x86_64_gnullvm v0.42.2
  Downloaded smartcore v0.3.1
  Downloaded pyo3 v0.18.2
  Downloaded libc v0.2.141
  Downloaded windows_x86_64_gnu v0.42.2
  Downloaded windows_x86_64_msvc v0.42.2
  Downloaded windows_aarch64_msvc v0.42.2
  Downloaded windows_i686_msvc v0.42.2
  Downloaded windows_i686_gnu v0.42.2
  Downloaded windows-sys v0.45.0
  Downloaded 61 crates (10.5 MB) in 5.05s (largest was `windows-sys` at 2.6 MB)
⚠️  Warning: `project.version` field is required in pyproject.toml unless it is present in the `project.dynamic` list
🔗 Found pyo3 bindings
🐍 Found CPython 3.12 at /Users/ashrest2/anaconda3/envs/myenv/bin/python
⚠️  Warning: `project.version` field is required in pyproject.toml unless it is present in the `project.dynamic` list
💥 maturin failed
  Caused by: Cannot build without valid version information. You need to specify either `project.version` or `project.dynamic = ["version"]` in pyproject.toml.
(myenv) ashrest2-41625s:rust ashrest2$

Issue: project.version is missing from pyproject.toml in routee-powertrain/rust/pyproject.toml

Solution:
Update routee-powertrain/rust/pyproject.toml with project.version or project.dynamic which is missing from routee-powertrain/pyproject.toml

...
[project]
name = "powertrain_rust"
version = "1.1.1"
...

Result:

(myenv) ashrest2-41625s:rust ashrest2$ maturin develop --release
🔗 Found pyo3 bindings
🐍 Found CPython 3.12 at /Users/ashrest2/anaconda3/envs/myenv/bin/python
   Compiling autocfg v1.1.0
   Compiling proc-macro2 v1.0.56
   Compiling quote v1.0.26
   Compiling unicode-ident v1.0.8
   Compiling target-lexicon v0.12.6
   Compiling serde_derive v1.0.160
   Compiling serde v1.0.160
   Compiling once_cell v1.17.1
   Compiling libc v0.2.141
   Compiling syn v1.0.109
   Compiling erased-serde v0.3.25
   Compiling cfg-if v1.0.0
   Compiling parking_lot_core v0.9.7
   Compiling scopeguard v1.1.0
   Compiling rawpointer v0.2.1
   Compiling anyhow v1.0.70
   Compiling smallvec v1.10.0
   Compiling num-traits v0.2.15
   Compiling num-integer v0.1.45
   Compiling num-bigint v0.4.3
   Compiling num-iter v0.1.43
   Compiling lock_api v0.4.9
   Compiling num-rational v0.4.1
   Compiling pyo3-build-config v0.18.2
   Compiling memoffset v0.8.0
   Compiling syn v2.0.15
   Compiling num-complex v0.4.3
   Compiling matrixmultiply v0.3.2
   Compiling rand_core v0.6.4
   Compiling serde_json v1.0.96
   Compiling rand v0.8.5
   Compiling approx v0.5.1
   Compiling unindent v0.1.11
   Compiling indoc v1.0.9
   Compiling itoa v1.0.6
   Compiling parking_lot v0.12.1
   Compiling ryu v1.0.13
   Compiling pyo3-ffi v0.18.2
   Compiling pyo3 v0.18.2
   Compiling num v0.4.0
   Compiling pyo3-macros-backend v0.18.2
   Compiling ctor v0.2.0
   Compiling ghost v0.1.9
   Compiling typetag-impl v0.2.7
   Compiling inventory v0.3.5
   Compiling pyo3-macros v0.18.2
   Compiling ndarray v0.15.6
   Compiling bincode v1.3.3
   Compiling typetag v0.2.7
   Compiling smartcore v0.3.1
   Compiling powertrain_rust v0.1.0 (/Users/ashrest2/RouteE/routee-powertrain/rust)
    Finished `release` profile [optimized] target(s) in 15.78s
📦 Built wheel for CPython 3.12 to /var/folders/qv/n6tmd7q17m9b_5sbd1y01fj0zfmv_j/T/.tmp5ccoB0/powertrain_rust-1.1.1-cp312-cp312-macosx_11_0_arm64.whl
✏️  Setting installed package as editable
🛠 Installed powertrain_rust-1.1.1
(myenv) ashrest2-41625s:rust ashrest2$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant