API for controlling a hydrogen production factory, enabling configuration of electrolyzers and storage, and optimizing production schedules using linear programming.
The HydrogenFactory API allows users to:
- Configure electrolyzers (PEM or Alkaline) with specified power capacity and efficiency.
- Configure storage with maximum hydrogen capacity.
- Optimize a 24-hour production schedule to minimize electricity costs, using random or user-provided electricity prices and hydrogen demand, with configurations stored in
config.json.
The API uses FastAPI for a robust, asynchronous interface and PuLP for linear optimization, ensuring efficient hydrogen production planning.
-
Install Poetry: Ensure Poetry is installed:
pip install poetry
-
Install Dependencies: Install project dependencies using Poetry:
poetry install
-
Run the API: Start the FastAPI application with Uvicorn:
poetry run uvicorn hydrogen_factory.main:app --host 0.0.0.0 --port 8000 --reload
--reloadenables auto-restart on code changes (development mode).- The API will be available at
http://localhost:8000.
-
Access the API:
- Root Endpoint: Visit
http://localhost:8000/to see the welcome message. - Interactive Docs: Open
http://localhost:8000/docsfor a Swagger UI to explore and test endpoints.
- Root Endpoint: Visit
The API includes three main endpoints, which can be tested using the Swagger UI (http://localhost:8000/docs) or curl.
-
POST /api/electrolyzer/configure
- Configures an electrolyzer.
- Example:
curl -X POST "http://localhost:8000/api/electrolyzer/configure" -H "Content-Type: application/json" -d '{"electrolyzer_id": "E1", "type": "PEM", "capacity": 1000.0, "efficiency": 0.02}'
-
POST /api/storage/configure
- Configures storage.
- Example:
curl -X POST "http://localhost:8000/api/storage/configure" -H "Content-Type: application/json" -d '{"storage_id": "S1", "max_capacity": 100.0}'
-
POST /api/schedule/optimize
- Optimizes the production schedule for 24 hours.
- Example:
curl -X POST "http://localhost:8000/api/schedule/optimize" -H "Content-Type: application/json" -d '{"electrolyzer_id": "E1", "storage_id": "S1"}'
The project includes unit and integration tests in tests/.
- Run all tests:
poetry run pytest tests/ -v
- Run API tests specifically:
poetry run pytest tests/test_api/ -v