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

Improvements and hot fixes for version 3.0.0-alpha2 #88

Merged
merged 57 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
d227905
Added support for new definition of the connection
joan-pijpker Oct 22, 2024
ca1ed92
Added ChatGPT version of the script.
joan-pijpker Oct 22, 2024
566200d
Improved the script and renamed to build_runshfile
joan-pijpker Nov 5, 2024
17b6ddc
Corrected error message
joan-pijpker Nov 5, 2024
573bf4a
Adjusted the readme.md file
joan-pijpker Nov 5, 2024
c8364a8
Corrected the readme.md file
joan-pijpker Nov 5, 2024
33a0deb
Corrected the readme.md file
joan-pijpker Nov 5, 2024
4027fc7
Merge pull request #64 from Illuminator-team/remote-pi2
manuGil Nov 6, 2024
50e0e28
Update cluster setup documentation to clarify server/client roles and…
manuGil Nov 6, 2024
d2a7db0
add comments
manuGil Nov 6, 2024
469c881
remove user guide from documentation
manuGil Nov 6, 2024
6eb08ff
Refactor AdderModel step method to accept time parameter and print re…
manuGil Nov 6, 2024
e039184
Refactor builder_model_example.py to improve code readability and com…
manuGil Nov 6, 2024
2d68ac1
Update adder.yaml to change model type from AdderModel to Adder for c…
manuGil Nov 6, 2024
47a9de2
Merge branch 'dev' into refac/models
manuGil Nov 6, 2024
9a2a589
Update documentation structure: remove deprecated user guide, rename …
manuGil Nov 6, 2024
25652b8
Remove deprecated user guide references from documentation index
manuGil Nov 6, 2024
a2f6031
Add developer/set-up.md to documentation index
manuGil Nov 6, 2024
163806a
Update cluster-setup.md and set-up.md for clarity and accuracy in set…
manuGil Nov 6, 2024
12b07a5
create cluster package
manuGil Nov 6, 2024
5222741
Refactor CLI to use Typer for improved command handling and add scena…
manuGil Nov 6, 2024
9fa3a60
Enhance CLI help messages for scenario and cluster commands
manuGil Nov 6, 2024
e043349
Update pyproject.toml to add Typer dependency and modify entry point …
manuGil Nov 6, 2024
0504fc4
clean up test_engine.py
manuGil Nov 7, 2024
07f3084
Remove unused validate_config_data function and its YAML import
manuGil Nov 7, 2024
a3202ba
Add validate_config_data function for YAML configuration validation
manuGil Nov 7, 2024
54c81fe
Remove unused import of schema from illuminator.schemas.simulation in…
manuGil Nov 7, 2024
7ac78e6
Rename schemas directory to 'schema' and update validate_config_data …
manuGil Nov 7, 2024
1a316f2
Remove validate_yaml.py as it is no longer needed
manuGil Nov 7, 2024
94f7426
rename alidate_config_data() to load_config_file()
manuGil Nov 7, 2024
f0b102f
Update function to load config from file
manuGil Nov 7, 2024
3efa301
Fix typos and update terminology in cluster setup documentation
manuGil Nov 7, 2024
dd4cc0d
Refactor scenario_run and cluster_build commands to use load_config_f…
manuGil Nov 7, 2024
252b3da
add TODO
manuGil Nov 11, 2024
6af3162
fix error with depricated validate_config_file()
manuGil Nov 11, 2024
9b6d3c4
Merge pull request #81 from manuGil/refac/models
manuGil Nov 11, 2024
33c3329
Update cluster setup documentation for clarity and completeness
manuGil Nov 11, 2024
5801771
Add simulation configuration file documentation with YAML structure a…
manuGil Nov 14, 2024
d813a11
remove results from simulation schema
manuGil Nov 15, 2024
652c69f
update valid example for testing
manuGil Nov 15, 2024
32e0682
update unit tests for engine and simulation
manuGil Nov 15, 2024
205a32a
Update configuration file example with new scenario and model definit…
manuGil Nov 15, 2024
6597133
add build_runshfile.py to cluster package
manuGil Nov 15, 2024
5332479
Merge pull request #82 from manuGil/refac/models
manuGil Nov 15, 2024
f959d00
Refactor configuration keys in engine and simulation schema for clarity
manuGil Nov 15, 2024
e5aa4f3
Update results file path in scenario_run function to use monitor conf…
manuGil Nov 15, 2024
bb220a1
Replace load_yaml with load_config_file in build_runshfile.py for imp…
manuGil Nov 15, 2024
5254596
Update README to replace 'master' with 'server' for clarity in Raspbe…
manuGil Nov 15, 2024
2067287
Clarify monitor section in config-file.md by removing redundant infor…
manuGil Nov 15, 2024
0064688
Merge pull request #84 from manuGil/refac/models
manuGil Nov 15, 2024
2654899
Implement Simulation class to manage and run simulations with configu…
manuGil Nov 15, 2024
5d2d41d
Refactor scenario_run function to utilize Simulation class
manuGil Nov 15, 2024
28fa80b
Add simulations documentation and update index.rst for navigation
manuGil Nov 15, 2024
f2e94f5
Merge pull request #85 from manuGil/refac/models
manuGil Nov 15, 2024
2070e73
Current status: No longer has error on missing parameter
jgrguric96 Nov 15, 2024
67d6dfe
Creation stage has issues fixed. Currently on build_connections.
jgrguric96 Nov 18, 2024
643ab08
Merge pull request #86 from jgrguric96/hotfix/ModelConstructor
manuGil Nov 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions configuration/build_runshfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import yaml
import os
import sys

# Constants
DEFAULT_PORT = 5123
RUN_PATH = './Desktop/illuminatorclient/configuration/runshfile/'
RUN_MODEL = '/home/illuminator/Desktop/Final_illuminator'
RUN_FILE = 'run.sh'

def load_yaml(file_path):
"""Loads a YAML file and returns its content."""
try:
with open(file_path, 'r') as file:
return yaml.safe_load(file)
except FileNotFoundError:
print(f"Error: The file {file_path} was not found.")
return None
except yaml.YAMLError as exc:
print(f"Error while parsing YAML: {exc}")
return None

def build_run_command(model_type, connect_ip, connect_port):
"""Builds the SSH run command for a given model."""
return f"lxterminal -e ssh illuminator@{connect_ip} '{RUN_PATH}run{model_type}.sh {connect_ip} {connect_port} {RUN_MODEL}'&"

def process_models(data, output_file):
"""Processes each model in the YAML data and writes the commands to a file."""
if 'models' not in data:
print("Error: No 'models' key found in the YAML data.")
return

with open(output_file, 'w') as file:

file.write('#! /bin/bash\n')

for model in data['models']:
model_type = model.get('type', 'unknown')

# Extract connection details
connect = model.get('connect', {})
connect_ip = connect.get('ip')
connect_port = connect.get('port', DEFAULT_PORT)

# Ensure both IP and port are available
if connect_ip:
run_command = build_run_command(model_type, connect_ip, connect_port)
file.write(run_command + '\n')
else:
print(f"Warning: Model '{model_type}' has no IP address specified.")

def main():
if len(sys.argv) != 2:
print("Usage: python3 "+sys.argv[0]+" <path_to_yaml_file>")
sys.exit(1)

yaml_file = sys.argv[1]
output_file = RUN_FILE
data = load_yaml(yaml_file)

if data:
process_models(data, output_file)
print(f"Commands have been written to {output_file}")

if __name__ == "__main__":
main()

61 changes: 46 additions & 15 deletions configuration/modelling-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ models: # list of models for the energy network
- capacity
- soc_min
scenario_data: 'path/to/file' #path to the scenario data file for the model. This should be optional
method:
type: connect # can be python for local or connect for remote
location: null
connect_ip: 192.168.0.1
connect_port: 5123
connect:
ip: 192.168.0.1
port: 5000
- name: Battery2
type: Battery # models can reuse the same type
inputs:
Expand All @@ -38,11 +36,47 @@ models: # list of models for the energy network
charge_power_max: 100
states:
soc: 0.5 # initial value for the state, optional
method:
type: connect # can be python for local or connect for remote
location: null
connect_ip: 192.168.0.2
connect_port: 5123
connect:
ip: 192.168.0.2
port: 5000
- name: Battery3
type: Battery # models can reuse the same type
inputs:
input1: 0 # input-name: initial value, default value will be used if not defined
outputs:
output1: 0
output2: null
parameters:
charge_power_max: 100
states:
soc: 0.5 # initial value for the state, optional
connect:
port: 5000
- name: Battery4
type: Battery # models can reuse the same type
inputs:
input1: 0 # input-name: initial value, default value will be used if not defined
outputs:
output1: 0
output2: null
parameters:
charge_power_max: 100
states:
soc: 0.5 # initial value for the state, optional
connect:
ip:
port: 5000
- name: Battery5
type: Battery # models can reuse the same type
inputs:
input1: 0 # input-name: initial value, default value will be used if not defined
outputs:
output1: 0
output2: null
parameters:
charge_power_max: 100
states:
soc: 0.5 # initial value for the state, optional
- name: PV1
type: PV
inputs:
Expand All @@ -54,11 +88,8 @@ models: # list of models for the energy network
power_max: 100
states:
initial_soc: 0.5
method:
type: connect # can be python for local or connect for remote
location: null
connect_ip: 192.168.0.3
connect_port: 5123
connect:
ip: 192.168.0.3
connections:
- from: Battery1.output2 # start model, pattern: model_name.output_name/input_name
to: PV1.input1 # end model
Expand Down
22 changes: 0 additions & 22 deletions configuration/parse_yaml.py

This file was deleted.

7 changes: 3 additions & 4 deletions configuration/run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#! /bin/bash
lxterminal -e ssh [email protected] './Desktop/illuminatorclient/configuration/runshfile/runWind.sh 192.168.0.1 5123 /home/illuminator/Desktop/Final_illuminator'&
lxterminal -e ssh [email protected] './Desktop/illuminatorclient/configuration/runshfile/runPV.sh 192.168.0.2 5123 /home/illuminator/Desktop/Final_illuminator'&
lxterminal -e ssh [email protected] './Desktop/illuminatorclient/configuration/runshfile/runLoad.sh 192.168.0.3 5123 /home/illuminator/Desktop/Final_illuminator'&
lxterminal -e ssh [email protected] './Desktop/illuminatorclient/configuration/runshfile/runBattery.sh 192.168.0.4 5123 /home/illuminator/Desktop/Final_illuminator'&
lxterminal -e ssh [email protected] './Desktop/illuminatorclient/configuration/runshfile/runBattery.sh 192.168.0.1 5000 /home/illuminator/Desktop/Final_illuminator'&
lxterminal -e ssh [email protected] './Desktop/illuminatorclient/configuration/runshfile/runBattery.sh 192.168.0.2 5000 /home/illuminator/Desktop/Final_illuminator'&
lxterminal -e ssh [email protected] './Desktop/illuminatorclient/configuration/runshfile/runPV.sh 192.168.0.3 5123 /home/illuminator/Desktop/Final_illuminator'&
118 changes: 79 additions & 39 deletions docs/cluster-setup.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,110 @@
# Cluster Pi Set Up
# Cluster Pi Setup


## Raspberry Pi Setup

The setup for the Illuminator requires one **master** Raspberry Pi and several **clients** Raspberry Pi's.
The Illuminator can be deployed to a cluster of Raspberry Pi's. It requires one Raspberry Pi acting as a **server** or 'master' and several **clients** Raspberry Pi's.
Raspberry Pi's must be connected and configured as a local network, and the
*master* must be configured to have permissions to access and control the *clients* through Secure Shell Protocol (SSH).
*server* must be configured to have permissions to access and control the *clients* through the Secure Shell Protocol (SSH).

During simulation, the *master* engage with the *clients* to run the simulations defined in the *simulation configuration*, and
During simulation, the *server* engage with the *clients* to run the simulations defined in the [simulation configuration file](user/config-file.md), and
information is exchanged between Rasberry Pi's using network sockets.
The **master** provides a Dashboard to viazulize the results, and saves them to a `.csv` files for later analysis.
The **server** provides a Dashboard to visualize the results, and saves them to a `.csv` files for later analysis.

<div align="center">
<img align="center" src="docs/_static/img/Structure.jpg" width="500">
<img align="center" src="_static/img/Structure.jpg" width="500">
</div>


### Set up a Raspberry Pi cluster
## Hardware Requirements
- A Raspberry Pi to use as a *server*.
- One or more Raspebrry Pi's to use as *clients*.
- A networkw switch to connect all Rasberry Pi's as a local network.

## Set up

Conduct the following steps on each Raspberry Pi to deploy the illuminator in the cluster.

1. [Install Raspberry pi OS using Raspberry Pi imager.](https://www.raspberrypi.com/software/)
2. Set an static IP addresse for each Raspberry Pi. Use the following command on the terminal to open the `dhcpcd.conf` file:
```
2. Set an static IP address for the Raspberry Pi. Use the following command on the terminal to open the `dhcpcd.conf` file:

```shell
sudo nano /etc/dhcpcd.conf
```

In the `dhcpcd.conf` file, find the information to change the IP address as static as following:
In the `dhcpcd.conf` file, find the information to change the IP address to static as following:

```
```shell
interface etho
static ip_address=192.168.0.1/24 # change the IP address as you want
```
Finally, reboot the Raspberry Pi suing `sudo reboot` on the terminal.
3. [Configure SSH connections so that the *master* can connect to the *clients* without a password.](https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys-2)
4. Install the following Python packages.

Give all users execute permission to all the documents in `runshfile/` in order to make sure the *server* can access the *client* model.

```shell
chmod -R a+X *dir*
```
pandas
tk
python-csv
datetime
python-math
numpy
scipy
arrow
mosaik
mosaik_api
mosaik.util
wandb
matplotlib
itertools

Finally, reboot the Raspberry Pi using `sudo reboot` on the terminal.
3. [Configure SSH connections so that the *server* can connect to the *clients* without a password.](https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys-2)

4. Install the Illuminator Python package, and the addional dependencies:

```shell
# if connected to the internet
pip install illuminator

# or, if from source code
pip install Illuminator/
```
5. Send the Illuminator package [TODO: What is the illuminator package?] to all *clients*. Use the following command on the *master's* terminal to check the connection between *master* and the *clients*

```shell
ssh illuminator@ip #ip represent your follower IP address
# aditional dependencies
pip install tk python-csv python-math scipy wandb itertools
```
[TODO: This suggest that all Pi's need a user with the name 'illuminator']
5. Use the following command on the *server's* terminal to check the connections for each of the *clients:*

6. Run the `buildcilentremoterun.py` file on each *client* and give all users execute permission to all the documents in `runshfile/` in order
to make sure the leader can access the *client* model.
```shell
# notice that the followng assumes that each client has a
# user named 'illuminator'
ssh illuminator@ip #ip represent your follower IP address set in step 2
```
6. Run the `build_runshfile.py` file in the configuration directory on the *server*, this will generate a `run.sh` script. Give the appropiate `config.yaml` file containing the simulation scenario definition:

```shell
chmod -R a+X *dir*
python3 build_runshfile.py <config.yaml>
```

More detialed instructions are given in the [user guide document](docs/user/user-guide.md) and the [model build up document](Models.md).

The `runs.sh` file contains a list of commands that will start the models required by a simulation defined in the `config.yaml`, such as:

```shell
# add example
```

TODO: integrate this:

The lx terminal command does the following:

Lxterminal itself starts a terminal on a remote machine.

So ‘lxterminal -e ssh [email protected]’ would use SSH to login to machine 192.168.0.1 with the user illuminator which has no password (room for improvement 😉 ).

The second part:

'./Desktop/illuminatorclient/configuration/runshfile/runWind.sh 192.168.0.1 5123 /home/illuminator/Desktop/Final_illuminator'&

Is starting the script ./Desktop/illuminatorclient/configuration/runshfile/runWind.sh on the remote machine with the following parameters:

IP address 192.168.0.1
Port 5123
Path of mosaik /home/illuminator/Desktop/Final_illuminator

The & at the end starts the process in the background, so that the run.sh script does not wait for the command to finish but executes the next command immediately.

For example runWind.sh looks like this:

#! /bin/bash
cd $3/Wind
python wind_mosaik.py $1:$2 –remote

There you see the three parameters in action.


## Contact and Support
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
]

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'user/depricated-user-guide.md']



Expand Down
8 changes: 3 additions & 5 deletions docs/developer/start.md → docs/developer/set-up.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Set Up Environment
Follow these steps to set up a development environment.

**Requirements**
* Python >= 3.11
* Recent version of PIP


To set up a development environment:

1. Clone the repository:

```shell
Expand All @@ -22,14 +20,14 @@ cd Illuminator/
3. install the development dependencies in editable mode:

```shell
pip install -e .e
pip install -e .
```

## Running Unit Tests

We use `Pytest` to write and test the source code. To run all unit-tests, run the following command at the root of the repository:

```
```shell
pytest tests/
```

5 changes: 3 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ and the simulation engine is based on `Mosaik. <https://mosaik.offis.de/>`_
:maxdepth: 2
:caption: User's Documentation

user/start
user/user-guide
user/models
user/config-file.md
user/simulations.md

.. toctree::
:maxdepth: 2
Expand All @@ -39,6 +39,7 @@ and the simulation engine is based on `Mosaik. <https://mosaik.offis.de/>`_
:maxdepth: 2
:caption: Developer's Documentation

developer/set-up.md
developer/developer-docstrings.md
developer/testing-explained.md
developer/writing-tests.md
Expand Down
Loading