hive icon indicating copy to clipboard operation
hive copied to clipboard

[rust-refactor] meta issue

Open nreinicke opened this issue 2 years ago • 0 comments

summary

A meta issue to keep track of the experimental refactor of the core of hive into rust.

The current branch for all this work is explore-rust. All work should be branched off here and then merged back into it via a PR.

We should also periodically merge main back into this branch to keep it up to date.

setup

To build the rust backend, you can use maturin like this:

cd rust/
pip install maturin
maturin develop

Then, when running the main hive command, you can pass the USE_RUST environment variable to load the rust python objects:

USE_RUST=True hive denver_demo.yaml

testing

In addition to passing the unit tests, each PR should test running the hive base model hive denver_demo.yaml against the new rust additions: USE_RUST=True hive denver_demo.yaml to make sure the results are similar.

scope

The scope of this work is to move the core of hive into rust, exposed via python. At a high level this includes:

notes

In order to support our design choice of maintaining immutable copies of the simulation state, we need to use structural sharing whenever we modify state. In python, we've used the replace method for data classes:

https://github.com/NREL/hive/blob/96ec422b10a4c163e45b22eb6ac691bc4adac6b8/nrel/hive/model/base.py#L139-L149

In rust, we're using Arc to allow for shared references of state without deep copies:

https://github.com/NREL/hive/blob/96ec422b10a4c163e45b22eb6ac691bc4adac6b8/rust/src/base.rs#L165-L174

progress

Right now, we're just focusing on moving the model into rust:

  • [x] base
  • [ ] station
  • [ ] energy
  • [ ] request
  • [x] haversine road network
  • [ ] osm road network
  • [ ] vehicle
  • [ ] mechatronics
  • [ ] powertrain
  • [ ] powercurve
  • [x] entity position
  • [x] membership
  • [ ] passenger
  • [ ] sim time

nreinicke avatar Apr 23 '23 16:04 nreinicke