diff --git a/.github/workflows/flower.yml b/.github/workflows/flower.yml index 5b1c25f62c4..6a407107fc6 100644 --- a/.github/workflows/flower.yml +++ b/.github/workflows/flower.yml @@ -33,5 +33,7 @@ jobs: run: python -m poetry install --extras "simulation" - name: Check if protos need recompilation run: ./dev/check-protos.sh + - name: Check if example requirements.txt files need regeneration + run: ./dev/check-requirements-txt.sh - name: Lint + Test (isort/black/docformatter/mypy/pylint/flake8/pytest) run: ./dev/test.sh diff --git a/dev/check-requirements-txt.sh b/dev/check-requirements-txt.sh new file mode 100755 index 00000000000..e9e48a97867 --- /dev/null +++ b/dev/check-requirements-txt.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Copyright 2023 Flower Labs GmbH. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== + +set -e +cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"/../ + +# Regenerate requirements.txt files for examples in case they changed +echo "Regenerate requirements.txt files in case they changed" +./dev/generate-requirements-txt.sh 2> /dev/null + +# Fail if user forgot to sync requirements.txt and pyproject.toml +CHANGED=$(git diff --name-only HEAD examples) + +if [ -n "$CHANGED" ]; then + echo "Changes detected, requirements.txt and pyproject.toml is not synced. Please run the script dev/generate-requirements-txt." + exit 1 +fi + +echo "No changes detected" +exit 0 diff --git a/dev/generate-requirements-txt.sh b/dev/generate-requirements-txt.sh new file mode 100755 index 00000000000..f78e368e9cf --- /dev/null +++ b/dev/generate-requirements-txt.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# Copyright 2023 Flower Labs GmbH. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== + +set -e +cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"/../ + +# Purpose of this script is to regenerate requirements.txt +for path in $(find ./examples -type f -name 'pyproject.toml' | sed -E 's|/[^/]+$||' |sort -u) +do + echo -e "\nRunning pipreqs for example in ${path}" + pipreqs --mode 'compat' --force --ignore .venv,poetry.lock $path +done diff --git a/examples/advanced_pytorch/README.md b/examples/advanced_pytorch/README.md index 5124c5ec7dc..b4e61372600 100644 --- a/examples/advanced_pytorch/README.md +++ b/examples/advanced_pytorch/README.md @@ -21,13 +21,18 @@ This will create a new directory called `advanced_pytorch` containing the follow ```shell -- pyproject.toml +-- requirements.txt -- client.py -- server.py -- README.md -- run.sh ``` -Project dependencies (such as `pytorch` and `flwr`) are defined in `pyproject.toml`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. +### Installing Dependencies + +Project dependencies (such as `torch` and `flwr`) are defined in `pyproject.toml` and `requirements.txt`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)) or [pip](https://pip.pypa.io/en/latest/development/), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. + +#### Poetry ```shell poetry install @@ -42,6 +47,14 @@ poetry run python3 -c "import flwr" If you don't see any errors you're good to go! +#### pip + +Write the command below in your terminal to install the dependencies according to the configuration file requirements.txt. + +```shell +pip install -r requirements.txt +``` + # Run Federated Learning with PyTorch and Flower The included `run.sh` will start the Flower server (using `server.py`), @@ -55,4 +68,3 @@ poetry run ./run.sh The `run.sh` script starts processes in the background so that you don't have to open eleven terminal windows. If you experiment with the code example and something goes wrong, simply using `CTRL + C` on Linux (or `CMD + C` on macOS) wouldn't normally kill all these processes, which is why the script ends with `trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT` and `wait`. This simply allows you to stop the experiment using `CTRL + C` (or `CMD + C`). If you change the script and anything goes wrong you can still use `killall python` (or `killall python3`) to kill all background processes (or a more specific command if you have other Python processes running that you don't want to kill). You can also manually run `poetry run python3 server.py` and `poetry run python3 client.py` for as many clients as you want but you have to make sure that each command is ran in a different terminal window (or a different computer on the network). - diff --git a/examples/advanced_pytorch/requirements.txt b/examples/advanced_pytorch/requirements.txt new file mode 100644 index 00000000000..5a348e91470 --- /dev/null +++ b/examples/advanced_pytorch/requirements.txt @@ -0,0 +1,3 @@ +flwr~=1.4.0 +torch~=2.0.1 +torchvision~=0.15.2 diff --git a/examples/advanced_tensorflow/README.md b/examples/advanced_tensorflow/README.md index c7c6771f06c..152ca39dea7 100644 --- a/examples/advanced_tensorflow/README.md +++ b/examples/advanced_tensorflow/README.md @@ -21,13 +21,18 @@ This will create a new directory called `advanced_tensorflow` containing the fol ```shell -- pyproject.toml +-- requirements.txt -- client.py -- server.py -- README.md -- run.sh ``` -Project dependencies (such as `tensorflow` and `flwr`) are defined in `pyproject.toml`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. +### Installing Dependencies + +Project dependencies (such as `tensorflow` and `flwr`) are defined in `pyproject.toml` and `requirements.txt`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)) or [pip](https://pip.pypa.io/en/latest/development/), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. + +#### Poetry ```shell poetry install @@ -42,6 +47,14 @@ poetry run python3 -c "import flwr" If you don't see any errors you're good to go! +#### pip + +Write the command below in your terminal to install the dependencies according to the configuration file requirements.txt. + +```shell +pip install -r requirements.txt +``` + ## Run Federated Learning with TensorFlow/Keras and Flower The included `run.sh` will call a script to generate certificates (which will be used by server and clients), start the Flower server (using `server.py`), sleep for 2 seconds to ensure the the server is up, and then start 10 Flower clients (using `client.py`). You can simply start everything in a terminal as follows: diff --git a/examples/advanced_tensorflow/requirements.txt b/examples/advanced_tensorflow/requirements.txt new file mode 100644 index 00000000000..feccc7cc874 --- /dev/null +++ b/examples/advanced_tensorflow/requirements.txt @@ -0,0 +1,2 @@ +flwr~=1.4.0 +tensorflow~=2.12.0 diff --git a/examples/android/README.md b/examples/android/README.md index 7ef19c86862..9a8c54d43da 100644 --- a/examples/android/README.md +++ b/examples/android/README.md @@ -16,7 +16,11 @@ Start by cloning the example project. We prepared a single-line command that you git clone --depth=1 https://github.com/adap/flower.git && mv flower/examples/android . && rm -rf flower && cd android ``` -Project dependencies (such as `tensorflow` and `flwr`) are defined in `pyproject.toml`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. +### Installing Dependencies + +Project dependencies (such as `tensorflow` and `flwr`) are defined in `pyproject.toml` and `requirements.txt`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)) or [pip](https://pip.pypa.io/en/latest/development/), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. + +#### Poetry ```shell poetry install @@ -31,6 +35,14 @@ poetry run python3 -c "import flwr" If you don't see any errors you're good to go! +#### pip + +Write the command below in your terminal to install the dependencies according to the configuration file requirements.txt. + +```shell +pip install -r requirements.txt +``` + # Run Federated Learning on Android Devices The included `run.sh` will start the Flower server (using `server.py`). You can simply start it in a terminal as follows: diff --git a/examples/android/requirements.txt b/examples/android/requirements.txt new file mode 100644 index 00000000000..e75049b33f0 --- /dev/null +++ b/examples/android/requirements.txt @@ -0,0 +1 @@ +numpy~=1.21.1 diff --git a/examples/dp-sgd-mnist/README.md b/examples/dp-sgd-mnist/README.md index e6276e06ab1..2f1209dc979 100644 --- a/examples/dp-sgd-mnist/README.md +++ b/examples/dp-sgd-mnist/README.md @@ -18,13 +18,17 @@ This will create a new directory called `dp-sgd-mnist` containing the following ```shell -- pyproject.toml +-- requirements.txt -- client.py -- server.py -- common.py -- README.md ``` +### Installing Dependencies -Project dependencies (such as `tensorflow` and `tensorflow-privacy`) are defined in `pyproject.toml`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. +Project dependencies (such as `tensorflow` and `tensorflow-privacy`) are defined in `pyproject.toml` and `requirements.txt`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)) or [pip](https://pip.pypa.io/en/latest/development/), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. + +#### Poetry ```shell poetry install @@ -39,6 +43,14 @@ poetry run python3 -c "import flwr" If you don't see any errors you're good to go! +#### pip + +Write the command below in your terminal to install the dependencies according to the configuration file requirements.txt. + +```shell +pip install -r requirements.txt +``` + # Run Federated Learning with TensorFlow/Keras/Tensorflow-Privacy and Flower Afterwards you are ready to start the Flower server as well as the clients. You can simply start the server in a terminal as follows: @@ -47,6 +59,7 @@ Afterwards you are ready to start the Flower server as well as the clients. You # terminal 1 poetry run python3 server.py ``` + Now you are ready to start the Flower clients which will participate in the learning. To do so simply open two more terminals and run the following command in each: ```shell @@ -78,7 +91,6 @@ poetry run python3 client.py --num-clients 3 --partition 1 & poetry run python3 client.py --num-clients 3 --partition 2 --dpsgd True ``` - Additional training parameters for the client and server can be referenced by passing `--help` to either script. Other things to note is that when all clients are running `dpsgd`, either train for more rounds or increase the local epochs to achieve optimal performance. You shall need to carefully tune the hyperparameters to your specific setup. diff --git a/examples/dp-sgd-mnist/requirements.txt b/examples/dp-sgd-mnist/requirements.txt new file mode 100644 index 00000000000..fa51400e9e0 --- /dev/null +++ b/examples/dp-sgd-mnist/requirements.txt @@ -0,0 +1,4 @@ +flwr~=1.4.0 +numpy~=1.21.1 +tensorflow~=2.12.0 +tensorflow_privacy~=0.8.9 diff --git a/examples/embedded_devices/README.md b/examples/embedded_devices/README.md index 8010dcf4729..169f04edfb0 100644 --- a/examples/embedded_devices/README.md +++ b/examples/embedded_devices/README.md @@ -36,11 +36,13 @@ The only requirement for the server is to have flower installed. You can do so b 2. Extract the imgae (~14GB) and flash it onto the uSD card using Etcher (or equivalent). 3. Follow [the instructions](https://developer.nvidia.com/embedded/learn/get-started-jetson-xavier-nx-devkit) to setup the device. 4. Installing Docker: Docker comes pre-installed with the Ubuntu image provided by NVIDIA. But for convinience we will create a new user group and add our user to it (with the idea of not having to use `sudo` for every command involving docker (e.g. `docker run`, `docker ps`, etc)). More details about what this entails can be found in the [Docker documentation](https://docs.docker.com/engine/install/linux-postinstall/). You can achieve this by doing: + ``` bash $ sudo usermod -aG docker $USER # apply changes to current shell (or logout/reboot) $ newgrp docker ``` + 5. The minimal installation to run this example only requires an additional package, `git`, in order to clone this repo. Install `git` by: ```bash @@ -50,6 +52,7 @@ The only requirement for the server is to have flower installed. You can do so b 6. (optional) additional packages: * [jtop](https://github.com/rbonghi/jetson_stats), to monitor CPU/GPU utilization, power consumption and, many more. + ```bash # First we need to install pip3 $ sudo apt-get install python3-pip -y @@ -58,7 +61,9 @@ The only requirement for the server is to have flower installed. You can do so b # finally, install jtop $ sudo -H pip3 install -U jetson-stats ``` + * [TMUX](https://github.com/tmux/tmux/wiki), a terminal multiplexer. + ```bash # install tmux $ sudo apt-get install tmux -y @@ -67,6 +72,7 @@ The only requirement for the server is to have flower installed. You can do so b ``` 7. Power modes: The Jetson devices can operate at different power modes, each making use of more or less CPU cores clocked at different freqencies. The right power mode might very much depend on the application and scenario. When power consumption is not a limiting factor, we could use the highest 15W mode using all 6 CPU cores. On the other hand, if the devices are battery-powered we might want to make use of a low power mode using 10W and 2 CPU cores. All the details regarding the different power modes of a Jetson Xavier-NX can be found [here](https://docs.nvidia.com/jetson/l4t/index.html#page/Tegra%2520Linux%2520Driver%2520Package%2520Development%2520Guide%2Fpower_management_jetson_xavier.html%23wwpID0E0NO0HA). For this demo we'll be setting the device to the high performance mode: + ```bash $ sudo /usr/sbin/nvpmodel -m 2 # 15W with 6cpus @ 1.4GHz ``` @@ -76,6 +82,7 @@ The only requirement for the server is to have flower installed. You can do so b 1. Install Ubuntu server 20.04 LTS 64-bit for Rapsberry Pi. You can do this by using one of the images provided [by Ubuntu](https://ubuntu.com/download/raspberry-pi) and then use Etcher. Alternativelly, astep-by-step installation guide, showing how to download and flash the image onto a uSD card and, go throught the first boot process, can be found [here](https://ubuntu.com/tutorials/how-to-install-ubuntu-on-your-raspberry-pi#1-overview). Please note that the first time you boot your RPi it will automatically update the system (which will lock `sudo` and prevent running the commands below for a few minutes) 2. Install docker (+ post-installation steps as in [Docker Docs](https://docs.docker.com/engine/install/linux-postinstall/)): + ```bash # make sure your OS is up-to-date $ sudo apt-get update @@ -104,6 +111,7 @@ For this demo we'll be using [CIFAR-10](https://www.cs.toronto.edu/~kriz/cifar.h ## Server Launch the server and define the model you'd like to train. The current code (see `utils.py`) provides two models for CIFAR-10: a small CNN (more suitable for Raspberry Pi) and, a ResNet18, which will run well on the gpu. Each model can be specified using the `--model` flag with options `Net` or `ResNet18`. Launch a FL training setup with one client and doing three rounds as: + ```bash # launch your server. It will be waiting until one client connects $ python server.py --server_address --rounds 3 --min_num_clients 1 --min_sample_size 1 --model ResNet18 diff --git a/examples/ios/README.md b/examples/ios/README.md index 2b22d8bbca3..83908abd8ad 100644 --- a/examples/ios/README.md +++ b/examples/ios/README.md @@ -4,7 +4,11 @@ FLiOS is a sample application for testing and benchmarking the Swift implementat ## Project Setup -Project dependencies (`flwr`) are defined in `pyproject.toml`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. +### Installing Dependencies + +Project dependencies (`flwr`) are defined in `pyproject.toml` and `requirements.txt`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)) or [pip](https://pip.pypa.io/en/latest/development/), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. + +#### Poetry ```shell poetry install @@ -14,11 +18,19 @@ poetry shell Poetry will install all your dependencies in a newly created virtual environment. To verify that everything works correctly you can run the following command: ```shell -python3 -c "import flwr" +poetry run python3 -c "import flwr" ``` If you don't see any errors you're good to go! +#### pip + +Write the command below in your terminal to install the dependencies according to the configuration file requirements.txt. + +```shell +pip install -r requirements.txt +``` + # Run Federated Learning on iOS Clients To start the server, write the following command in the terminal in the ios folder (with the conda environment created above): @@ -27,7 +39,7 @@ To start the server, write the following command in the terminal in the ios fold python3 server.py ``` -Open the FlowerCoreML.xcodeproj with XCode, wait until the dependencies are fetched, then click build and run with iPhone 13 Pro Max as target, or you can deploy it in your own iOS device by connecting your Mac, where you run your XCode, and your iPhone. +Open the FLiOS.xcodeproj with XCode, wait until the dependencies are fetched, then click build and run with iPhone 13 Pro Max as target, or you can deploy it in your own iOS device by connecting your Mac, where you run your XCode, and your iPhone. When the iOS app runs, load both the training and test dataset first. Then enter the hostname and port of your server in the TextField provided. Finally press `Start` which will start the federated training. diff --git a/examples/ios/requirements.txt b/examples/ios/requirements.txt new file mode 100644 index 00000000000..9d6b364ee36 --- /dev/null +++ b/examples/ios/requirements.txt @@ -0,0 +1,2 @@ +flwr~=1.4.0 +numpy~=1.21.1 diff --git a/examples/mt-pytorch/requirements.txt b/examples/mt-pytorch/requirements.txt new file mode 100644 index 00000000000..49d95d299b3 --- /dev/null +++ b/examples/mt-pytorch/requirements.txt @@ -0,0 +1,4 @@ +flwr~=1.4.0 +torch~=2.0.1 +torchvision~=0.15.2 +tqdm~=4.65.0 diff --git a/examples/mxnet_from_centralized_to_federated/README.md b/examples/mxnet_from_centralized_to_federated/README.md index 0ab069d30b3..a0e29851a86 100644 --- a/examples/mxnet_from_centralized_to_federated/README.md +++ b/examples/mxnet_from_centralized_to_federated/README.md @@ -16,13 +16,18 @@ This will create a new directory called `mxnet_from_centralized_to_federated` co ```shell -- pyproject.toml +-- requirements.txt -- mxnet_mnist.py -- client.py -- server.py -- README.md ``` -Project dependencies (such as `mxnet` and `flwr`) are defined in `pyproject.toml`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. +### Installing Dependencies + +Project dependencies (such as `mxnet` and `flwr`) are defined in `pyproject.toml` and `requirements.txt`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)) or [pip](https://pip.pypa.io/en/latest/development/), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. + +#### Poetry ```shell poetry install @@ -32,11 +37,19 @@ poetry shell Poetry will install all your dependencies in a newly created virtual environment. To verify that everything works correctly you can run the following command: ```shell -python3 -c "import flwr" +poetry run python3 -c "import flwr" ``` If you don't see any errors you're good to go! +#### pip + +Write the command below in your terminal to install the dependencies according to the configuration file requirements.txt. + +```shell +pip install -r requirements.txt +``` + ## Run MXNet Federated This MXNet example is based on the [Handwritten Digit Recognition](https://mxnet.apache.org/versions/1.7.0/api/python/docs/tutorials/packages/gluon/image/mnist.html) tutorial and uses the MNIST dataset (hand-written digits with 28x28 pixels in greyscale with 10 classes). Feel free to consult the tutorial if you want to get a better understanding of MXNet. The file `mxnet_mnist.py` contains all the steps that are described in the tutorial. It loads the dataset and a sequential model, trains the model with the training set, and evaluates the trained model on the test set. diff --git a/examples/mxnet_from_centralized_to_federated/requirements.txt b/examples/mxnet_from_centralized_to_federated/requirements.txt new file mode 100644 index 00000000000..4865e949538 --- /dev/null +++ b/examples/mxnet_from_centralized_to_federated/requirements.txt @@ -0,0 +1,3 @@ +flwr~=1.4.0 +mxnet~=1.9.1 +numpy~=1.21.1 diff --git a/examples/opacus/README.md b/examples/opacus/README.md index a57c0ea5f58..7554d893c82 100644 --- a/examples/opacus/README.md +++ b/examples/opacus/README.md @@ -26,4 +26,3 @@ Run the server with `python server.py`. Then open two (or more) new terminals to Note: It is not possible to see the total privacy budget used with this example since the simulation creates clients from scratch every round. Run the simulation with `python dp_cifar_simulation.py`. - diff --git a/examples/opacus/requirements.txt b/examples/opacus/requirements.txt new file mode 100644 index 00000000000..e6e5dbb2fdf --- /dev/null +++ b/examples/opacus/requirements.txt @@ -0,0 +1,4 @@ +flwr~=1.4.0 +numpy~=1.21.1 +torch~=2.0.1 +torchvision~=0.15.2 diff --git a/examples/pytorch_federated_variational_autoencoder/README.md b/examples/pytorch_federated_variational_autoencoder/README.md index 2343b4d7082..4ba0ac4f059 100644 --- a/examples/pytorch_federated_variational_autoencoder/README.md +++ b/examples/pytorch_federated_variational_autoencoder/README.md @@ -13,16 +13,22 @@ This will create a new directory called `pytorch_federated_variational_autoencod ```shell -- pyproject.toml +-- requirements.txt -- client.py -- server.py -- README.md -- models.py ``` -Project dependencies (such as `torch` and `flwr`) are defined in `pyproject.toml`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. +### Installing Dependencies + +Project dependencies (such as `torch` and `flwr`) are defined in `pyproject.toml` and `requirements.txt`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)) or [pip](https://pip.pypa.io/en/latest/development/), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. + +#### Poetry ```shell poetry install +poetry shell ``` Poetry will install all your dependencies in a newly created virtual environment. To verify that everything works correctly you can run the following command: @@ -33,6 +39,14 @@ poetry run python3 -c "import flwr" If you don't see any errors you're good to go! +#### pip + +Write the command below in your terminal to install the dependencies according to the configuration file requirements.txt. + +```shell +pip install -r requirements.txt +``` + ## Federating the Variational Autoencoder Model Afterwards you are ready to start the Flower server as well as the clients. You can simply start the server in a terminal as follows: diff --git a/examples/pytorch_federated_variational_autoencoder/requirements.txt b/examples/pytorch_federated_variational_autoencoder/requirements.txt new file mode 100644 index 00000000000..5a348e91470 --- /dev/null +++ b/examples/pytorch_federated_variational_autoencoder/requirements.txt @@ -0,0 +1,3 @@ +flwr~=1.4.0 +torch~=2.0.1 +torchvision~=0.15.2 diff --git a/examples/pytorch_from_centralized_to_federated/README.md b/examples/pytorch_from_centralized_to_federated/README.md index 048d137d78d..1d29286c9b0 100644 --- a/examples/pytorch_from_centralized_to_federated/README.md +++ b/examples/pytorch_from_centralized_to_federated/README.md @@ -16,13 +16,18 @@ This will create a new directory called `pytorch_from_centralized_to_federated` ```shell -- pyproject.toml +-- requirements.txt -- cifar.py -- client.py -- server.py -- README.md ``` -Project dependencies (such as `torch` and `flwr`) are defined in `pyproject.toml`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. +### Installing Dependencies + +Project dependencies (such as `torch` and `flwr`) are defined in `pyproject.toml` and `requirements.txt`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)) or [pip](https://pip.pypa.io/en/latest/development/), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. + +#### Poetry ```shell poetry install @@ -32,11 +37,19 @@ poetry shell Poetry will install all your dependencies in a newly created virtual environment. To verify that everything works correctly you can run the following command: ```shell -python3 -c "import flwr" +poetry run python3 -c "import flwr" ``` If you don't see any errors you're good to go! +#### pip + +Write the command below in your terminal to install the dependencies according to the configuration file requirements.txt. + +```shell +pip install -r requirements.txt +``` + ## From Centralized To Federated This PyTorch example is based on the [Deep Learning with PyTorch](https://pytorch.org/tutorials/beginner/blitz/cifar10_tutorial.html) tutorial and uses the CIFAR-10 dataset (a RGB image classification task). Feel free to consult the tutorial if you want to get a better understanding of PyTorch. The file `cifar.py` contains all the steps that are described in the tutorial. It loads the dataset, trains a convolutional neural network (CNN) on the training set, and evaluates the trained model on the test set. diff --git a/examples/pytorch_from_centralized_to_federated/requirements.txt b/examples/pytorch_from_centralized_to_federated/requirements.txt new file mode 100644 index 00000000000..e6e5dbb2fdf --- /dev/null +++ b/examples/pytorch_from_centralized_to_federated/requirements.txt @@ -0,0 +1,4 @@ +flwr~=1.4.0 +numpy~=1.21.1 +torch~=2.0.1 +torchvision~=0.15.2 diff --git a/examples/quickstart_cpp/README.md b/examples/quickstart_cpp/README.md index ad7b6e22824..4525b2ff20b 100644 --- a/examples/quickstart_cpp/README.md +++ b/examples/quickstart_cpp/README.md @@ -3,17 +3,19 @@ In this example you will train a linear model on synthetic data using C++ clients. # Acknowledgements + Many thanks to the original contributors to this code: - Lekang Jiang (original author and main contributor) - Francisco José Solís (code re-organization) - Andreea Zaharia (training algorithm and data generation) # Install requirements + You'll need CMake and Python. ### Building the example -This example provides you with a `CMakeLists.txt` file to configure and build the client. Feel free to take a look inside it to see what is happening under the hood. +This example provides you with a `CMakeLists.txt` file to configure and build the client. Feel free to take a look inside it to see what is happening under the hood. ```bash cmake -S . -B build @@ -21,6 +23,7 @@ cmake --build build ``` # Run the server and two clients in separate terminals + ```bash python server.py ``` diff --git a/examples/quickstart_fastai/README.md b/examples/quickstart_fastai/README.md index 4021fba03ba..d2d65117131 100644 --- a/examples/quickstart_fastai/README.md +++ b/examples/quickstart_fastai/README.md @@ -15,27 +15,40 @@ This will create a new directory called `quickstart_fastai` containing the follo ```shell -- pyproject.toml +-- requirements.txt -- client.py -- server.py -- run.sh -- README.md ``` -Project dependencies (such as `fastai` and `flwr`) are defined in `pyproject.toml`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. +### Installing Dependencies + +Project dependencies (such as `fastai` and `flwr`) are defined in `pyproject.toml` and `requirements.txt`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)) or [pip](https://pip.pypa.io/en/latest/development/), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. + +#### Poetry ```shell poetry install poetry shell ``` -To verify that everything works correctly you can run the following command: +Poetry will install all your dependencies in a newly created virtual environment. To verify that everything works correctly you can run the following command: ```shell -python3 -c "import flwr" +poetry run python3 -c "import flwr" ``` If you don't see any errors you're good to go! +#### pip + +Write the command below in your terminal to install the dependencies according to the configuration file requirements.txt. + +```shell +pip install -r requirements.txt +``` + # Run Federated Learning with fastai and Flower Afterwards you are ready to start the Flower server as well as the clients. You can simply start the server in a terminal as follows: diff --git a/examples/quickstart_fastai/requirements.txt b/examples/quickstart_fastai/requirements.txt new file mode 100644 index 00000000000..0a7f315018a --- /dev/null +++ b/examples/quickstart_fastai/requirements.txt @@ -0,0 +1,3 @@ +fastai~=2.7.12 +flwr~=1.4.0 +torch~=2.0.1 diff --git a/examples/quickstart_huggingface/README.md b/examples/quickstart_huggingface/README.md index 518e2deaa1d..d999c2eb746 100644 --- a/examples/quickstart_huggingface/README.md +++ b/examples/quickstart_huggingface/README.md @@ -16,12 +16,17 @@ This will create a new directory called `quickstart_huggingface` containing the ```shell -- pyproject.toml +-- requirements.txt -- client.py -- server.py -- README.md ``` -Project dependencies (such as `torch` and `flwr`) are defined in `pyproject.toml`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. +### Installing Dependencies + +Project dependencies (such as `torch` and `flwr`) are defined in `pyproject.toml` and `requirements.txt`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)) or [pip](https://pip.pypa.io/en/latest/development/), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. + +#### Poetry ```shell poetry install @@ -31,11 +36,19 @@ poetry shell Poetry will install all your dependencies in a newly created virtual environment. To verify that everything works correctly you can run the following command: ```shell -python3 -c "import flwr" +poetry run python3 -c "import flwr" ``` If you don't see any errors you're good to go! +#### pip + +Write the command below in your terminal to install the dependencies according to the configuration file requirements.txt. + +```shell +pip install -r requirements.txt +``` + # Run Federated Learning with Flower Afterwards you are ready to start the Flower server as well as the clients. You can simply start the server in a terminal as follows: diff --git a/examples/quickstart_huggingface/requirements.txt b/examples/quickstart_huggingface/requirements.txt new file mode 100644 index 00000000000..697518c415b --- /dev/null +++ b/examples/quickstart_huggingface/requirements.txt @@ -0,0 +1,6 @@ +datasets~=2.12.0 +evaluate~=0.4.0 +flwr~=1.4.0 +numpy~=1.21.1 +torch~=2.0.1 +transformers~=4.29.2 diff --git a/examples/quickstart_jax/README.md b/examples/quickstart_jax/README.md index 07318c50e13..3b7c8008714 100644 --- a/examples/quickstart_jax/README.md +++ b/examples/quickstart_jax/README.md @@ -16,13 +16,18 @@ This will create a new directory called `quickstart_jax`, containing the followi ```shell -- pyproject.toml +-- requirements.txt -- jax_training.py -- client.py -- server.py -- README.md ``` -Project dependencies (such as `jax` and `flwr`) are defined in `pyproject.toml`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. +### Installing Dependencies + +Project dependencies (such as `jax` and `flwr`) are defined in `pyproject.toml` and `requirements.txt`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)) or [pip](https://pip.pypa.io/en/latest/development/), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. + +#### Poetry ```shell poetry install @@ -32,11 +37,19 @@ poetry shell Poetry will install all your dependencies in a newly created virtual environment. To verify that everything works correctly you can run the following command: ```shell -python3 -c "import flwr" +poetry run python3 -c "import flwr" ``` If you don't see any errors you're good to go! +#### pip + +Write the command below in your terminal to install the dependencies according to the configuration file requirements.txt. + +```shell +pip install -r requirements.txt +``` + ## Run JAX Federated This JAX example is based on the [Linear Regression with JAX](https://coax.readthedocs.io/en/latest/examples/linear_regression/jax.html) tutorial and uses a sklearn dataset (generating a random dataset for a regression pronlem). Feel free to consult the tutorial if you want to get a better understanding of JAX. If you play around with the dataset, please keep in mind that the data samples are generated randomly depending on the settings being done while calling the dataset function. Please checkout out the [scikit-learn tutorial for further information](https://scikit-learn.org/stable/modules/generated/sklearn.datasets.make_regression.html). The file `jax_training.py` contains all the steps that are described in the tutorial. It loads the train and test dataset and a linear regression model, trains the model with the training set, and evaluates the trained model on the test set. diff --git a/examples/quickstart_jax/requirements.txt b/examples/quickstart_jax/requirements.txt new file mode 100644 index 00000000000..bf7a9c64d66 --- /dev/null +++ b/examples/quickstart_jax/requirements.txt @@ -0,0 +1,4 @@ +flwr~=1.4.0 +jax~=0.4.10 +numpy~=1.21.1 +scikit_learn~=1.2.2 diff --git a/examples/quickstart_mlcube/requirements.txt b/examples/quickstart_mlcube/requirements.txt new file mode 100644 index 00000000000..feccc7cc874 --- /dev/null +++ b/examples/quickstart_mlcube/requirements.txt @@ -0,0 +1,2 @@ +flwr~=1.4.0 +tensorflow~=2.12.0 diff --git a/examples/quickstart_mxnet/README.md b/examples/quickstart_mxnet/README.md index 993e0d53ca7..605b2f9aef6 100644 --- a/examples/quickstart_mxnet/README.md +++ b/examples/quickstart_mxnet/README.md @@ -16,12 +16,17 @@ This will create a new directory called `quickstart_mxnet` containing the follow ```shell -- pyproject.toml +-- requirements.txt -- client.py -- server.py -- README.md ``` -Project dependencies (such as `mxnet` and `flwr`) are defined in `pyproject.toml`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. +### Installing Dependencies + +Project dependencies (such as `mxnet` and `flwr`) are defined in `pyproject.toml` and `requirements.txt`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)) or [pip](https://pip.pypa.io/en/latest/development/), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. + +#### Poetry ```shell poetry install @@ -31,11 +36,19 @@ poetry shell Poetry will install all your dependencies in a newly created virtual environment. To verify that everything works correctly you can run the following command: ```shell -python3 -c "import flwr" +poetry run python3 -c "import flwr" ``` If you don't see any errors you're good to go! +#### pip + +Write the command below in your terminal to install the dependencies according to the configuration file requirements.txt. + +```shell +pip install -r requirements.txt +``` + ## Run MXNet Federated This MXNet example is based on the [Handwritten Digit Recognition](https://mxnet.apache.org/versions/1.7.0/api/python/docs/tutorials/packages/gluon/image/mnist.html) tutorial and uses the MNIST dataset (hand-written digits with 28x28 pixels in greyscale with 10 classes). Feel free to consult the tutorial if you want to get a better understanding of MXNet. The file `client.py` contains all the steps that are described in the tutorial. It loads the dataset and a sequential model, trains the model with the training set, and evaluates the trained model on the test set. diff --git a/examples/quickstart_mxnet/requirements.txt b/examples/quickstart_mxnet/requirements.txt new file mode 100644 index 00000000000..4865e949538 --- /dev/null +++ b/examples/quickstart_mxnet/requirements.txt @@ -0,0 +1,3 @@ +flwr~=1.4.0 +mxnet~=1.9.1 +numpy~=1.21.1 diff --git a/examples/quickstart_pandas/README.md b/examples/quickstart_pandas/README.md index bde0652fb78..c6586848222 100644 --- a/examples/quickstart_pandas/README.md +++ b/examples/quickstart_pandas/README.md @@ -15,32 +15,45 @@ This will create a new directory called `quickstart_pandas` containing the follo ```shell -- pyproject.toml +-- requirements.txt -- client.py -- server.py -- start.sh -- README.md ``` -Project dependencies (such as `pandas` and `flwr`) are defined in `pyproject.toml`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. +If you don't plan on using the `run.sh` script that automates the run, you should first download the data and put it in a `data` folder, this can be done by executing: ```shell -$ poetry install -$ poetry shell +$ mkdir -p ./data +$ python -c "from sklearn.datasets import load_iris; load_iris(as_frame=True)['data'].to_csv('./data/client.csv')" +``` + +### Installing Dependencies + +Project dependencies (such as `pandas` and `flwr`) are defined in `pyproject.toml` and `requirements.txt`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)) or [pip](https://pip.pypa.io/en/latest/development/), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. + +#### Poetry + +```shell +poetry install +poetry shell ``` Poetry will install all your dependencies in a newly created virtual environment. To verify that everything works correctly you can run the following command: ```shell -$ python3 -c "import flwr" +poetry run python3 -c "import flwr" ``` If you don't see any errors you're good to go! -If you don't plan on using the `run.sh` script that automates the run, you should first download the data and put it in a `data` folder, this can be done by executing: +#### pip + +Write the command below in your terminal to install the dependencies according to the configuration file requirements.txt. ```shell -$ mkdir -p ./data -$ python -c "from sklearn.datasets import load_iris; load_iris(as_frame=True)['data'].to_csv('./data/client.csv')" +pip install -r requirements.txt ``` # Run Federated Analytics with Pandas and Flower diff --git a/examples/quickstart_pandas/requirements.txt b/examples/quickstart_pandas/requirements.txt new file mode 100644 index 00000000000..994eed4fac0 --- /dev/null +++ b/examples/quickstart_pandas/requirements.txt @@ -0,0 +1,3 @@ +flwr~=1.4.0 +numpy~=1.21.1 +pandas~=2.0.1 diff --git a/examples/quickstart_pytorch/README.md b/examples/quickstart_pytorch/README.md index b4633624614..0b8aa3c639b 100644 --- a/examples/quickstart_pytorch/README.md +++ b/examples/quickstart_pytorch/README.md @@ -15,12 +15,16 @@ This will create a new directory called `quickstart_pytorch` containing the foll ```shell -- pyproject.toml +-- requirements.txt -- client.py -- server.py -- README.md ``` +### Installing Dependencies -Project dependencies (such as `torch` and `flwr`) are defined in `pyproject.toml`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. +Project dependencies (such as `torch` and `flwr`) are defined in `pyproject.toml` and `requirements.txt`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)) or [pip](https://pip.pypa.io/en/latest/development/), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. + +#### Poetry ```shell poetry install @@ -30,11 +34,19 @@ poetry shell Poetry will install all your dependencies in a newly created virtual environment. To verify that everything works correctly you can run the following command: ```shell -python3 -c "import flwr" +poetry run python3 -c "import flwr" ``` If you don't see any errors you're good to go! +#### pip + +Write the command below in your terminal to install the dependencies according to the configuration file requirements.txt. + +```shell +pip install -r requirements.txt +``` + # Run Federated Learning with PyTorch and Flower Afterwards you are ready to start the Flower server as well as the clients. You can simply start the server in a terminal as follows: diff --git a/examples/quickstart_pytorch/requirements.txt b/examples/quickstart_pytorch/requirements.txt new file mode 100644 index 00000000000..49d95d299b3 --- /dev/null +++ b/examples/quickstart_pytorch/requirements.txt @@ -0,0 +1,4 @@ +flwr~=1.4.0 +torch~=2.0.1 +torchvision~=0.15.2 +tqdm~=4.65.0 diff --git a/examples/quickstart_pytorch_lightning/requirements.txt b/examples/quickstart_pytorch_lightning/requirements.txt new file mode 100644 index 00000000000..dfa386908d6 --- /dev/null +++ b/examples/quickstart_pytorch_lightning/requirements.txt @@ -0,0 +1,4 @@ +flwr~=1.4.0 +pytorch_lightning~=2.0.2 +torch~=2.0.1 +torchvision~=0.15.2 diff --git a/examples/quickstart_tabnet/README.md b/examples/quickstart_tabnet/README.md index 6e2771a0d79..06a4883e4d8 100644 --- a/examples/quickstart_tabnet/README.md +++ b/examples/quickstart_tabnet/README.md @@ -14,12 +14,17 @@ This will create a new directory called `quickstart_tabnet` containing the follo ```shell -- pyproject.toml +-- requirements.txt -- client.py -- server.py -- README.md ``` -Project dependencies (such as `tensorflow` and `flwr`) are defined in `pyproject.toml`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. +### Installing Dependencies + +Project dependencies (such as `tensorflow` and `flwr`) are defined in `pyproject.toml` and `requirements.txt`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)) or [pip](https://pip.pypa.io/en/latest/development/), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. + +#### Poetry ```shell poetry install @@ -29,11 +34,19 @@ poetry shell Poetry will install all your dependencies in a newly created virtual environment. To verify that everything works correctly you can run the following command: ```shell -poetry run python -c "import flwr" +poetry run python3 -c "import flwr" ``` If you don't see any errors you're good to go! +#### pip + +Write the command below in your terminal to install the dependencies according to the configuration file requirements.txt. + +```shell +pip install -r requirements.txt +``` + ## Run Federated Learning with TensorFlow/Keras and Flower Afterwards you are ready to start the Flower server as well as the clients. You can simply start the server in a terminal as follows: @@ -54,4 +67,4 @@ Alternatively you can run all of it in one shell as follows: poetry run python server.py & poetry run python client.py & poetry run python client.py -``` \ No newline at end of file +``` diff --git a/examples/quickstart_tabnet/requirements.txt b/examples/quickstart_tabnet/requirements.txt new file mode 100644 index 00000000000..4ebf6eafcbe --- /dev/null +++ b/examples/quickstart_tabnet/requirements.txt @@ -0,0 +1,4 @@ +flwr~=1.4.0 +tabnet~=0.1.6 +tensorflow~=2.12.0 +tensorflow_datasets~=4.9.2 diff --git a/examples/quickstart_tensorflow/README.md b/examples/quickstart_tensorflow/README.md index dd780c35073..d78a1ac7969 100644 --- a/examples/quickstart_tensorflow/README.md +++ b/examples/quickstart_tensorflow/README.md @@ -15,12 +15,17 @@ This will create a new directory called `quickstart_tensorflow` containing the f ```shell -- pyproject.toml +-- requirements.txt -- client.py -- server.py -- README.md ``` -Project dependencies (such as `tensorflow` and `flwr`) are defined in `pyproject.toml`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. +### Installing Dependencies + +Project dependencies (such as `tensorflow` and `flwr`) are defined in `pyproject.toml` and `requirements.txt`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)) or [pip](https://pip.pypa.io/en/latest/development/), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. + +#### Poetry ```shell poetry install @@ -35,6 +40,14 @@ poetry run python3 -c "import flwr" If you don't see any errors you're good to go! +#### pip + +Write the command below in your terminal to install the dependencies according to the configuration file requirements.txt. + +```shell +pip install -r requirements.txt +``` + ## Run Federated Learning with TensorFlow/Keras and Flower Afterwards you are ready to start the Flower server as well as the clients. You can simply start the server in a terminal as follows: diff --git a/examples/quickstart_tensorflow/requirements.txt b/examples/quickstart_tensorflow/requirements.txt new file mode 100644 index 00000000000..feccc7cc874 --- /dev/null +++ b/examples/quickstart_tensorflow/requirements.txt @@ -0,0 +1,2 @@ +flwr~=1.4.0 +tensorflow~=2.12.0 diff --git a/examples/simulation_pytorch/README.md b/examples/simulation_pytorch/README.md index 56241bb6f98..657d28c342d 100644 --- a/examples/simulation_pytorch/README.md +++ b/examples/simulation_pytorch/README.md @@ -9,6 +9,7 @@ This code splits CIFAR-10 dataset into `pool_size` partitions (user defined) and * A recent version of Ray. This example has been tested with Ray 1.4.1, 1.6 and 1.9.2. From a clean virtualenv or Conda environment with Python 3.7+, the following command will isntall all the dependencies needed: + ```bash $ pip install -r requirements.txt ``` diff --git a/examples/simulation_pytorch/requirements.txt b/examples/simulation_pytorch/requirements.txt index 8266375df5f..650b902c918 100644 --- a/examples/simulation_pytorch/requirements.txt +++ b/examples/simulation_pytorch/requirements.txt @@ -1,3 +1,6 @@ -flwr==1.0.0 -torch==1.13.1 -torchvision==0.13.0 +flwr~=1.4.0 +numpy~=1.21.1 +Pillow~=9.5.0 +ray~=2.4.0 +torch~=2.0.1 +torchvision~=0.15.2 diff --git a/examples/simulation_tensorflow/README.md b/examples/simulation_tensorflow/README.md index 170062fc4eb..86ab8aa9543 100644 --- a/examples/simulation_tensorflow/README.md +++ b/examples/simulation_tensorflow/README.md @@ -8,7 +8,7 @@ Run the example on Google Colab: [![Open in Colab](https://colab.research.google Alternatively, you can run `sim.ipynb` locally or in any other Jupyter environment. -## Running the example (via Poetry) +## Running the example Start by cloning the code example. We prepared a single-line command that you can copy into your shell which will checkout the example for you: @@ -22,13 +22,19 @@ This will create a new directory called `quickstart_simulation` containing the f -- README.md <- Your're reading this right now -- sim.ipynb <- Example notebook -- sim.py <- Example code --- pyproject.toml <- Example dependencies (for Poetry) +-- pyproject.toml <- Example dependencies +-- requirements.txt <- Example dependencies ``` -Project dependencies (such as `tensorflow` and `flwr`) are defined in `pyproject.toml` (the modern alternative to `requirements.txt`). We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. +### Installing Dependencies + +Project dependencies (such as `torch` and `flwr`) are defined in `pyproject.toml` and `requirements.txt`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)) or [pip](https://pip.pypa.io/en/latest/development/), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. + +#### Poetry ```shell poetry install +poetry shell ``` Poetry will install all your dependencies in a newly created virtual environment. To verify that everything works correctly you can run the following command: @@ -37,7 +43,17 @@ Poetry will install all your dependencies in a newly created virtual environment poetry run python3 -c "import flwr" ``` -If you don't see any errors you're good to go! +If you don't see any errors you're good to go! + +#### pip + +Write the command below in your terminal to install the dependencies according to the configuration file requirements.txt. + +```shell +pip install -r requirements.txt +``` + +### Run Federated Learning Example ```bash poetry run python3 sim.py diff --git a/examples/simulation_tensorflow/requirements.txt b/examples/simulation_tensorflow/requirements.txt new file mode 100644 index 00000000000..feccc7cc874 --- /dev/null +++ b/examples/simulation_tensorflow/requirements.txt @@ -0,0 +1,2 @@ +flwr~=1.4.0 +tensorflow~=2.12.0 diff --git a/examples/sklearn-logreg-mnist/README.md b/examples/sklearn-logreg-mnist/README.md index 6883a6760f0..555d101e6fc 100644 --- a/examples/sklearn-logreg-mnist/README.md +++ b/examples/sklearn-logreg-mnist/README.md @@ -15,13 +15,18 @@ This will create a new directory called `sklearn-logreg-mnist` containing the fo ```shell -- pyproject.toml +-- requirements.txt -- client.py -- server.py -- utils.py -- README.md ``` -Project dependencies (such as `scikit-learn` and `flwr`) are defined in `pyproject.toml`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. +### Installing Dependencies + +Project dependencies (such as `scikit-learn` and `flwr`) are defined in `pyproject.toml` and `requirements.txt`. We recommend [Poetry](https://python-poetry.org/docs/) to install those dependencies and manage your virtual environment ([Poetry installation](https://python-poetry.org/docs/#installation)) or [pip](https://pip.pypa.io/en/latest/development/), but feel free to use a different way of installing dependencies and managing virtual environments if you have other preferences. + +#### Poetry ```shell poetry install @@ -36,6 +41,14 @@ poetry run python3 -c "import flwr" If you don't see any errors you're good to go! +#### pip + +Write the command below in your terminal to install the dependencies according to the configuration file requirements.txt. + +```shell +pip install -r requirements.txt +``` + # Run Federated Learning with scikit-learn and Flower Afterwards you are ready to start the Flower server as well as the clients. You can simply start the server in a terminal as follows: diff --git a/examples/sklearn-logreg-mnist/requirements.txt b/examples/sklearn-logreg-mnist/requirements.txt new file mode 100644 index 00000000000..eec2e1a3c4b --- /dev/null +++ b/examples/sklearn-logreg-mnist/requirements.txt @@ -0,0 +1,4 @@ +flwr~=1.4.0 +numpy~=1.21.1 +openml~=0.13.1 +scikit_learn~=1.2.2 diff --git a/pyproject.toml b/pyproject.toml index 46dde63308f..82a07ed9cf2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -99,6 +99,7 @@ sphinx-reredirects = "==0.1.1" nbsphinx = "==0.8.12" nbstripout = "==0.6.1" sphinx-argparse = "==0.4.0" +pipreqs = "==0.4.13" [tool.isort] line_length = 88