Skip to content
Leon edited this page Nov 10, 2024 · 1 revision

Project: LILY-QML
Version: 2.0.0 LLY-DML
Author: Leon Kaiser
Contact: info@lilyqml.de
Website: www.lilyqml.de
Contributors: Claudia Zendejas-Morales (@clausia)


Data Class Description

The Data class is designed to manage quantum circuit activation matrices within the LILY-QML project. It handles loading and converting data necessary for quantum computations, ensuring that matrices meet required dimensions and formats.

Constructor (__init__)

  • Purpose: Initializes the Data class by setting up the number of qubits, the circuit depth, activation matrices, and the working directory.
  • Parameters:
    • qubits (int): The number of qubits, corresponding to the number of rows in the matrices.
    • depth (int): The depth of the circuit, corresponding to the number of columns in the matrices.
    • activation_matrices (list, optional): Contains the three-dimensional activation matrices. Defaults to an empty list if not provided.
    • working_directory (str): The directory where data files and logs are managed. Defaults to 'var'.
  • Key Attributes:
    • self.qubits
    • self.depth
    • self.activation_matrices
    • self.working_directory
  • Returns: None.

get_data

  • Purpose: Loads values for qubits, depth, and activation matrices from data.json.
  • Operations:
    • Opens data.json in the working directory.
    • Loads qubits, depth, and activation_matrices from the file.
    • Converts activation matrices data into NumPy arrays.
  • Returns:
    • None if successful.
    • Error code "Error Code: 1028 - data.json not found" if data.json is missing.
    • Error code "Error Code: 1029 - train.json not found" if train.json is missing.

return_matrices

  • Purpose: Returns the stored activation matrices, ensuring that they have correct properties.
  • Operations:
    • Checks each matrix for the presence of the 'name' key.
    • Validates the shape of each matrix's data to ensure it matches the required dimensions (qubits x depth * 3 x 3).
  • Returns:
    • List of activation matrices if valid.
    • Error code "Error Code: 1030 - Activation matrix conversion unsuccessful" if validation fails.

convert_matrices

  • Purpose: Converts activation matrices to a specific format by combining values from 3 pages.
  • Operations:
    • Validates initial properties of each matrix before conversion.
      • Ensures each matrix has a 'name' key.
      • Checks that each matrix's data has 3 pages (third dimension).
      • Validates that the shape of each matrix matches (qubits, depth, 3).
    • Conversion process:
      • Creates a new matrix with dimensions qubits x (depth * 3).
      • Flattens the values from the 3 pages into the new matrix.
    • Validates the final matrices after conversion using check_final_matrix.
  • Returns:
    • None if successful.
    • Error code "Error Code: 1031 - Activation matrix invalid before conversion" if initial checks fail.
    • Error code "Error Code: 1008 - Activation matrix does not meet required dimensions" if final validation fails.

check_final_matrix

  • Purpose: Checks if a matrix meets the final required dimensions.
  • Parameters:
    • matrix (ndarray): The matrix to check.
  • Operations:
    • Verifies that the matrix has dimensions qubits x (depth * 3).
  • Returns:
    • True if valid.
    • False otherwise.

create_training_matrix

  • Purpose: Creates a training matrix with randomized values between -2π and .
  • Operations:
    • Generates a random matrix of shape (qubits, depth * 3) with values in the specified range.
    • Validates the dimensions of the training matrix.
      • Checks if the shape matches (qubits, depth * 3).
      • Uses check_final_matrix for additional validation.
    • Saves the training matrix to 'train.json' in the working directory.
  • Returns:
    • None if successful.
    • Error code "Error Code: 1007 - Training matrix does not meet required dimensions" if validation fails.

This class is essential for preparing and validating the data required for quantum computations in the LILY-QML project. It ensures that activation matrices and training matrices are correctly formatted and meet the necessary dimensional requirements for subsequent processing.