Quantum Federated Learning with Qiskit

Resources:

What is Quantum Federated Learning?

Quantum Federated Learning (QFL) is a decentralized machine learning framework where multiple clients collaboratively train a global quantum model without sharing their private, local data. In this framework, clients perform local training on their own datasets and then share only their updated model weights with a central server for aggregation.

Code Outline and Explanation

The provided code implements QFL using the Iris dataset split across three simulated clients. Below is an outline of the technical steps:

1. Data Preparation

  • Loading and Filtering: The code loads the Iris dataset and filters it to include only two classes (binary classification).
  • Normalization: It uses MinMaxScaler to scale the four features into a range suitable for quantum encoding.
  • Decentralization: The dataset is shuffled and split into three separate parts, simulating three independent clients who keep their data local.

2. Quantum Model Design

  • Feature Map: The code uses a ZFeatureMap to translate classical data into quantum states.
  • Ansatz: A RealAmplitudes variational circuit serves as the trainable part of the model.
  • SamplerQNN: This Qiskit primitive integrates the circuit with a parity function to map quantum measurements to classical labels (0 or 1).

3. Federated Training Loop

The code executes 10 federated rounds. In each round, the following occurs:

  • Global Evaluation: The new global weights are used to test accuracy on a separate test set to track how the collective model is improving.
  • Local Training: Each client receives the current Global Weights, applies them to their local model, and trains on their local data for 5 iterations.
  • Weight Aggregation: After local training, the server collects the weights from all clients and calculates the average (FedAvg) to update the Global Weights.

Quantum_Federated_Learning (1)
graph LR
    subgraph Server [Central Server]
        Global[Global Model]
        Avg[FedAvg Aggregation]
    end

    subgraph Clients [Local Clients]
        C1[Client 1]
        C2[Client 2]
        C3[Client 3]
    end

    C1 -- Weights --> Avg
    C2 -- Weights --> Avg
    C3 -- Weights --> Avg
    Avg -- Updated Model --> Global
    Global -- Broadcast --> C1 & C2 & C3

Leave a Reply

Your email address will not be published. Required fields are marked *

error: