Debugging module

This code implements a hybrid quantum-classical machine learning model for a binary classification task. The model processes input data from pressure sensors, likely for some sort of physical system. The quantum part of the model is a quantum neural network (QNN) that processes the input data using a quantum circuit. The classical part of the model is a feedforward neural network (FNN) with two hidden layers.

Here's a brief explanation of the code structure:

  1. Import necessary libraries and tools such as JAX, Haiku, Optax, PennyLane, etc.

  2. Load the training and testing data (commented out in the provided code).

  3. Define the quantum layer and the entire quantum circuit for the QNN model.

  4. Define the forward pass for the quantum model (qforward) and the classical model (cforward).

  5. Initialize the parameters and the optimizer.

  6. Define the loss_fn function to calculate the loss value between the predicted output and the ground truth.

  7. Define the update function to update the model parameters based on the gradients calculated.

  8. Implement the training loop that iterates through epochs, shuffles the training data, trains the model, and calculates the test accuracy (commented out in the provided code).

  9. Test the model and print the test accuracy (commented out in the provided code).

This hybrid quantum-classical model has the potential to leverage the advantages of quantum computing for certain problems while still utilizing classical computing resources for other parts of the model. The training loop, optimizer, and loss function are all handled by the JAX library, which simplifies gradient calculations and model updates. PennyLane is used to create the quantum circuit and integrate it with JAX.

qml_debugging.loss_fn(params, x, y)

Calculates the loss value between predicted output after a forward pass of the model and the ground truth

Parameters:
  • params (List[Float]) -- Parameters to be fed into the model

  • x (List[float]) -- The pressure sensor data to be fed into the model

  • y (List[int]) -- The ground truth class data

Returns:

Loss value between predicted output and the ground truth

Return type:

float

qml_debugging.quantum_circuit(x, circuit_weights)

Builds the entire Quantum circuit model

Parameters:
  • x (List[float]) -- The pressure sensor data to be fed into the model

  • circuit_weights (List[float]) -- Parameters to be fed into the model

Returns:

Returns the expected value of qubit measurement in PauliZ basis

Return type:

List[float]

qml_debugging.quantum_layer(weights)

Generates a layer in the QNN Model

Parameters:

weights (List[floats]) -- Parameters to be fed into the layer

qml_debugging.update(params, opt_state, x, y)

Updates the parameters based on the gradients calculated

Parameters:
  • params (List[float]) -- Parameters to be fed into the model

  • opt_state (List[float]) -- The optimizer state at the last epoch

  • x (List[float]) -- The pressure sensor data to be fed into the model

  • y (List[int]) -- The ground truth class data

Returns:

Returns the list of updated parameters, new state of the optimizer and loss value

Return type:

List[float], List[float], float