Skip to content

Commit 96ec422

Browse files
committed
Merge branch 'main' into explore-rust
2 parents af4bdfd + 2220709 commit 96ec422

73 files changed

Lines changed: 416 additions & 2941 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
cache/
2+
build/
3+
14
py-notebooks/
25
*.ipynb
36

README.md

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,34 @@ HIVE supports researchers who explore **Electric Vehicle (EV) fleet control**, *
1111
Out-of-the-box, it provides a baseline set of algorithms for fleet dispatch, but provides a testbed for exploring alternatives from leading research in model-predictive control (MPC) and deep reinforcement learning.
1212
HIVE is designed to integrate with vehicle power and energy grid power models in real-time for accurate, high-fidelity energy estimation over arbitrary road networks and demand scenarios.
1313

14-
## Installation
14+
For more information about HIVE, please visit the [HIVE website](https://www.nrel.gov/hive).
1515

16-
HIVE depends on a Python installation [3.7, 3.8, 3.9, 3.10] and the pip package manager ( [python.org](https://www.python.org/downloads/).
17-
In our installation example we use [conda](https://www.anaconda.com/products/distribution) | [miniconda](https://docs.conda.io/en/latest/miniconda.html) for managing a HIVE Python environment.
16+
For technical details about the HIVE platform, please see the [Technical Report](https://www.nrel.gov/docs/fy21osti/80682.pdf).
1817

19-
### via pip
18+
For more documentation on how to use HIVE, please see the [HIVE documentation](https://nrelhive.readthedocs.io/en/latest/).
2019

21-
> pip install nrel.hive
20+
## Installation
2221

23-
### build from source
22+
HIVE depends on a Python installation [3.7, 3.8, 3.9, 3.10] and the pip package manager ( [python.org](https://www.python.org/downloads/).
23+
In our installation example we use [conda](https://www.anaconda.com/products/distribution) | for managing a HIVE Python environment.
2424

25-
Via conda, create a dedicated 'hive' Python environment:
25+
### (optional) set up a virtual environment using conda
2626

27-
> conda create -n hive python=3.8
28-
> conda activate hive
27+
We recommend setting up a virtual environment to install HIVE.
28+
One way to do this is to use Anaconda:
29+
1. Install [Anaconda](https://www.anaconda.com/products/distribution) or [Miniconda](https://docs.conda.io/en/latest/miniconda.html)
30+
1. Open a terminal or Anaconda Prompt.
31+
1. Create a new virtual environment: `conda create --name hive python=3.10`
32+
1. Activate the virtual environment `conda activate hive`
2933

30-
to run tests, also install `pytest`:
34+
### via pip
3135

32-
> pip install pytest
36+
> pip install nrel.hive
3337

34-
to load hive as a command line application along with all dependencies into your conda environment:
38+
### build from source
3539

36-
> git clone https://github.com/NREL/hive.git
40+
Clone the repository and install the code via pip:
41+
> git clone <https://github.com/NREL/hive.git>
3742
> cd hive
3843
> pip install -e .
3944

@@ -59,30 +64,7 @@ denver_demo_constrained_charging.yaml | default scenario with limited charging s
5964
denver_demo_fleets.yaml | default scenario with two competing TNC fleets
6065
manhattan.yaml | larger test scenario with 200 vehicles and 20k requests sampled from the NY Taxi Dataset
6166

62-
## Scenario configuration
63-
64-
Scenarios are run by reading a YAML file describing the parameters of the simulation. The files list all scenario-specific parameters but can fall back to defaults set [here](https://github.com/NREL/hive/blob/main/nrel/hive/resources/defaults/hive_config.yaml).
65-
66-
Scenario YAML files organize a list of resource files to use as input. If a file resource is listed which doesn't resolve to a local file path, HIVE will search for a default resource [here](nrel/hive/resources). By default, HIVE expects file resources stored in a directory matching their resource type. For example, using the [default Denver scenario](nrel/hive/resources/scenarios/denver_downtown/denver_demo.yaml):
67-
68-
```yaml
69-
...
70-
input:
71-
vehicles_file: denver_demo_vehicles.csv # vehicles/denver_demo_vehicles.csv
72-
requests_file: denver_demo_requests.csv # requests/denver_demo_requests.csv
73-
bases_file: denver_demo_bases.csv # bases/denver_demo_bases.csv
74-
...
75-
```
76-
77-
For a description of file contents and schemas, please read our [technical report](https://www.nrel.gov/docs/fy21osti/80682.pdf). Example scenario and resource data can be found [here](nrel/hive/resources).
78-
79-
## Global configuration
80-
81-
Some values are set by a global configuration file with filename `.hive.yaml`.
82-
The defaults are set in the repo [here](nrel/hive/resources/defaults/.hive.yaml).
83-
If you want to override any entries in this file, you can create a new one by the same name `.hive.yaml` and place it in your working directory or a parent directory.
84-
Hive will also check your base user directory for this file (aka `~/.hive.yaml`).
85-
This can be useful if you would like to reduce the output files or change the default output base directory (for example, to something like `~/hive/output`).
67+
For more information on how to build your own scenario, please see the [HIVE documentation](https://nrelhive.readthedocs.io/en/latest/inputs.html).
8668

8769
## Dependencies
8870

@@ -103,7 +85,7 @@ Beyond these, HIVE uses Uber H3, a geospatial index which HIVE uses for position
10385

10486
## Developer documentation
10587

106-
Documentation can be found [here](https://readthedocs.org/nrel-hive).
88+
Documentation can be found [here](https://nrelhive.readthedocs.io/en/latest/developer/index.html).
10789

10890
## Why HIVE?
10991

@@ -303,6 +285,19 @@ If you have found HIVE useful for your research, please cite our [technical repo
303285
}
304286
```
305287

288+
## Contributors
289+
290+
HIVE is currently maintained by Nick Reinicke ([@nreinicke](https://github.com/nreinicke)) and Rob Fitzgerald ([@robfitzgerald](https://github.com/robfitzgerald)). It would not be what it is today without the support of:
291+
292+
- Brennan Borlaug
293+
- Thomas Grushka
294+
- Jacob Holden
295+
- Joshua Hoshiko
296+
- Eleftheria Kontou
297+
- Matthew Moniot
298+
- Eric Wood
299+
- Clement Raimes
300+
306301
## Notice
307302

308303
Copyright © 2022 Alliance for Sustainable Energy, LLC, Inc. All Rights Reserved

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
author = "NREL"
2424

2525
# The full version, including alpha/beta/rc tags
26-
release = "v1.0.0"
26+
release = "v1.2.2"
2727

2828
# -- General configuration ---------------------------------------------------
2929

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Contributing to HIVE
2+
3+
This simple guide will walk you through the process of contributing to HIVE.
4+
5+
## Table of Contents
6+
7+
- Identifying an Issue
8+
- Letting Others Know You're Working on the Issue
9+
- Forking the Repository
10+
- Opening a Pull Request
11+
12+
## Identifying an Issue
13+
14+
1. Go to the "Issues" tab in the repository.
15+
1. Look for issues with labels such as "good first issue" if you're new to the project.
16+
1. Read the issue description and any associated comments to make sure you understand the problem and its requirements.
17+
1. Choose an issue that aligns with your skills and interests.
18+
19+
## Letting Others Know You're Working on the Issue
20+
21+
1. Leave a comment on the issue, stating that you'd like to work on it. This helps prevent duplication of effort and lets us know someone is addressing the problem.
22+
1. Wait for a response from the maintainers or the issue creator. They may provide additional information or guidance, or assign the issue to you.
23+
24+
## Forking the Repository
25+
26+
1. Navigate to the main HIVE page on GitHub.
27+
1. Click on the "Fork" button in the upper right corner. This creates a copy of the repository under your GitHub account.
28+
1. Clone your forked repository to your local machine by clicking the "Code" button and copying the URL. Then, open your terminal or command prompt and run git clone [URL], replacing [URL] with the copied URL.
29+
30+
## Opening a Pull Request
31+
32+
1. Create a new branch in your local repository by running git checkout -b [branch-name], replacing [branch-name] with a descriptive name for your changes.
33+
1. Make changes to the code, addressing the issue you've chosen to work on.
34+
1. Commit your changes with a meaningful commit message. Use git add [file] to stage changes, and git commit -m "[commit-message]" to commit them.
35+
1. Push your changes to your forked repository using git push origin [branch-name].
36+
1. Go to your forked repository on GitHub and click on the "Pull requests" tab.
37+
1. Click on the "New Pull Request" button, and select your branch in the "compare" dropdown menu.
38+
1. Review your changes and click "Create Pull Request". Add a descriptive title and a detailed explanation of the changes you made.
39+
1. Submit your pull request. The project maintainers will review your changes and provide feedback or merge your changes into the main repository.
40+
41+
Thanks for taking the time to contribute to HIVE!

docs/source/developer/release.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
- `docs/source/conf.py`
66
- `pyproject.toml`
77

8+
1. Create a new branch and open a PR on GitHub which will run all actions
9+
10+
1. Apply any fixes to make the actions pass
11+
812
1. Build the wheel and source distributions:
913

1014
```bash
@@ -29,3 +33,5 @@
2933
git tag -a v<major>.<minor>.<patch> -m "version <major>.<minor>.<patch>"
3034
git push origin <tagname>
3135
```
36+
37+
1. Merge PR

docs/source/inputs.md

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
## Scenario Config
44

5-
The main simulation input is a yaml file that contains a bunch of parameters for running a scenario.
6-
On example of a scenario file can be found at `nrel.hive.resources.scenarios.denver_demo.yaml`:
5+
Scenarios are run by reading a YAML file describing the parameters of the simulation. The files list all scenario-specific parameters but can fall back to defaults set [here](https://github.com/NREL/hive/blob/main/nrel/hive/resources/defaults/hive_config.yaml).
6+
7+
Scenario YAML files organize a list of resource files to use as input. If a file resource is listed which doesn't resolve to a local file path, HIVE will search for a default resource [here](nrel/hive/resources). By default, HIVE expects file resources stored in a directory matching their resource type.
78

89
```{note}
910
some inputs in hive are optional and will fall back to defaults if not specified; here we will denote whether the
@@ -33,49 +34,44 @@ In addition to the scenario config yaml file, each scenario has several other fi
3334
```{include} ../../nrel/hive/resources/scenarios/denver_downtown/charging_prices/README.md
3435
```
3536

36-
### Fleets
37+
### Fleets
3738

3839
```{include} ../../nrel/hive/resources/scenarios/denver_downtown/fleets/README.md
3940
```
4041

41-
### Geofence
42-
43-
```{include} ../../nrel/hive/resources/scenarios/denver_downtown/geofence/README.md
44-
```
45-
46-
### Mechatronics
42+
### Mechatronics
4743

4844
```{include} ../../nrel/hive/resources/scenarios/denver_downtown/mechatronics/README.md
4945
```
5046

51-
### Requests
47+
### Requests
5248

5349
```{include} ../../nrel/hive/resources/scenarios/denver_downtown/requests/README.md
5450
```
5551

56-
### Road Network
52+
### Road Network
5753

5854
```{include} ../../nrel/hive/resources/scenarios/denver_downtown/road_network/README.md
5955
```
6056

61-
### Service Prices
57+
### Service Prices
6258

6359
```{include} ../../nrel/hive/resources/scenarios/denver_downtown/service_prices/README.md
6460
```
6561

66-
### Stations
62+
### Stations
6763

6864
```{include} ../../nrel/hive/resources/scenarios/denver_downtown/stations/README.md
6965
```
7066

71-
### Stations
67+
### Stations
7268

7369
```{include} ../../nrel/hive/resources/scenarios/denver_downtown/stations/README.md
7470
```
7571

76-
### Vehicles
72+
### Vehicles
7773

78-
```{include} ../../nrel/hive/resources/scenarios/denver_downtown/stations/README.md
74+
```{include} ../../nrel/hive/resources/scenarios/denver_downtown/vehicles/README.md
7975
```
8076

8177
## Global Config

examples/download_road_network.py

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,47 @@
11
from pathlib import Path
2-
32
import geopandas as gpd
4-
3+
import argparse
54
from nrel.hive.model.roadnetwork.osm.osm_roadnetwork import OSMRoadNetwork
65

7-
GEOJSON_PATH = Path(
8-
"../nrel/hive/resources/scenarios/denver_downtown/geofence/downtown_denver.json"
6+
# this example script builds a HIVE road network using OSMNx and GeoPandas
7+
# and can be called from the command line via
8+
# `$ python download_road_network.py some_boundary.geojson`
9+
# under the hood, HIVE will call OSMNx and build the road network with some
10+
# simple rules for downloading and reading the OSM data. for more complex
11+
# network parsing rules you will need to build your own process.
12+
13+
parser = argparse.ArgumentParser(description="network builder")
14+
parser.add_argument(
15+
"boundary",
16+
type=Path,
17+
help="GeoJSON boundary file describing the extent of the network to load",
18+
)
19+
parser.add_argument(
20+
"--outfile",
21+
type=Path,
22+
default="network.json",
23+
help="file path to use when writing the HIVE network",
924
)
10-
OUTFILE = Path("denver_demo_road_network.json")
11-
1225

13-
def build_road_network(geojson_file: Path, outfile: Path):
14-
df = gpd.read_file(geojson_file)
1526

16-
polygon = df.iloc[0].geometry
27+
def import_network(geojson_file: Path, outfile: Path):
28+
"""builds a road network for HIVE from the provided source GeoJSON.
29+
a simple wrapper around reading the GeoJSON via GeoPandas and then
30+
calling HIVE's OSM network reader.
31+
depends on OSMNx: https://github.com/gboeing/osmnx
1732
33+
:param geojson_file: file containing network boundary
34+
:type geojson_file: Path
35+
:param outfile: _description_
36+
:type outfile: Path
37+
"""
38+
df = gpd.read_file(geojson_file)
39+
polygon = df.geometry.unary_union
1840
rn = OSMRoadNetwork.from_polygon(polygon)
1941

20-
rn.to_file(OUTFILE)
42+
rn.to_file(outfile)
2143

2244

2345
if __name__ == "__main__":
24-
build_road_network(GEOJSON_PATH, OUTFILE)
46+
args = parser.parse_args()
47+
import_network(args.boundary, args.outfile)

nrel/hive/app/hive_cosim.py

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ def load_scenario(
2121
scenario_file: Path,
2222
custom_instruction_generators: Optional[Tuple[T, ...]] = None,
2323
custom_init_functions: Optional[Iterable[InitFunction]] = None,
24+
output_suffix: Optional[str] = None,
2425
) -> RunnerPayload:
2526
"""
2627
load a HIVE scenario from file and return the initial simulation state
2728
:param scenario_file: the HIVE scenario file to read
2829
:return: the initial simulation state payload
2930
:raises: Error when issues with files
3031
"""
31-
config = load_config(scenario_file)
32+
config = load_config(scenario_file, output_suffix)
3233
initial_payload = load_simulation(config, custom_instruction_generators, custom_init_functions)
3334

3435
# add a specialized Reporter handler that catches vehicle charge events
@@ -40,7 +41,6 @@ def load_scenario(
4041
class CrankResult(NamedTuple):
4142
runner_payload: RunnerPayload
4243
sim_time: SimTime
43-
charge_events: DataFrame
4444

4545

4646
def crank(
@@ -55,38 +55,23 @@ def crank(
5555
:param time_steps: the number of steps to take, using the timestep size set in the HiveConfig
5656
:param progress_bar: show a progress bar in the console
5757
:param flush_events: write all requested event logs to their file destinations
58+
5859
:return: the updated simulation state and all charge events that occurred
5960
"""
6061

6162
steps = tqdm(range(time_steps), position=0) if progress_bar else range(time_steps)
6263

63-
def run_step(acc: Tuple[RunnerPayload, Tuple[DataFrame, ...]], i: int):
64-
rp0, events = acc
64+
def run_step(rp0: RunnerPayload, i: int):
6565
# regular step
6666
rp1 = rp0.u.apply_update(rp0)
6767
if flush_events:
6868
rp1.e.reporter.flush(rp1)
6969

70-
# output events
71-
new_events = None
72-
for handler in rp1.e.reporter.handlers:
73-
if isinstance(handler, VehicleChargeEventsHandler):
74-
new_events = handler.get_events()
75-
handler.clear()
76-
77-
if new_events is None:
78-
raise SimulationStateError(
79-
f"VehicleChargeEventsHandler missing from reporter in env {rp1.e}"
80-
)
81-
82-
updated_events = events + (new_events,)
83-
84-
return rp1, updated_events
70+
return rp1
8571

86-
initial = (runner_payload, ())
87-
next_state, unmerged_events = ft.reduce(run_step, steps, initial)
88-
events = pd.concat(unmerged_events)
89-
result = CrankResult(next_state, next_state.s.sim_time, events)
72+
initial = runner_payload
73+
next_state = ft.reduce(run_step, steps, initial)
74+
result = CrankResult(next_state, next_state.s.sim_time)
9075
return result
9176

9277

nrel/hive/config/config_builder.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55

66
class ConfigBuilder:
7-
87
T = TypeVar("T")
98

109
@classmethod

0 commit comments

Comments
 (0)