LILY-QML / LLY-DML

LLY-DML is part of the LILY project and is a Quantum Machine Learning model. It uses so-called L-Gates. These gates are Machine Learning gates that modify their state based on an input to map to a desired state of an input.
https://www.lilyqml.de
2 stars 5 forks source link

Class Description: Circuit Test #21

Open xleonplayz opened 1 month ago

xleonplayz commented 1 month ago

Extension of the Test Class TestCircuit

The extended test class includes comprehensive tests for all methods of the Circuit class. Each test function is designed to validate the functionality of the respective method under various conditions, including the verification of success codes and error codes.

1. Test Function: read_data

Description:

Checks and Error Codes:

Additional Steps:


2. Test Function: convert_input_data

Description:

Checks and Error Codes:

Validations:


3. Test Case: _is_matrix_consistent

Description:

Test Cases:

  1. Consistent Matrix:
    • Pass a correctly formatted matrix.
    • Expected return: True.
  2. Inconsistent Matrix:
    • Pass a incorrectly formatted matrix (e.g., wrong number of rows, columns, or incorrect data types).
    • Expected return: False.

Checks and Error Messages:


4. Test Function: _is_empty_matrix

Description:

Test Cases:

  1. Matrix of All Zeros:
    • Pass a matrix containing only zeros.
    • Expected return: True.
  2. Matrix with Non-Zero Values:
    • Pass a matrix with at least one non-zero value.
    • Expected return: False.

Checks and Error Messages:


5. Test Function: check_input_data

Description:

Test Cases:

  1. Valid input_data:
    • Load correctly formatted input_data.
    • Expected return: True.
  2. Manipulated input_data:
    • Manipulate input_data (e.g., missing keys, incorrect types).
    • Expected return: False.

Checks and Error Messages:


6. Test Function: create_L_gate

Description:

Test Cases:

  1. Successful Creation of an L-Gate:
    • Pass a valid entry (entry).
    • Expected return of a circuit blueprint and success codes 2060 to 2065.
  2. Failed Creation of an L-Gate:
    • Pass an invalid entry (e.g., incorrect list lengths).
    • Expected return of an error code (1050 to 1055) and an error message.

Checks and Error Messages:


7. Test Function: create_initial_circuit

Description:

Test Cases:

  1. Successful Creation of the Initial Circuit:
    • Pass a valid matrix_name.
    • Expected return of success code 2066.
  2. Failed Creation of the Initial Circuit:
    • Pass an invalid matrix_name or faulty data.
    • Expected return of corresponding error codes (1066 to 1071).

Checks and Error Messages:


8. Test Function: check_circuit

Description:

Test Cases:

  1. Consistent Circuit:
    • A correctly created circuit.
    • Expected return: True.
  2. Inconsistent Circuit:
    • A circuit with an incorrect number of qubits, phases, or Hadamard gates.
    • Expected return: False and corresponding error codes (1072 to 1074).

Checks and Error Messages:


9. Test Function: measure

Description:

Test Cases:

  1. Successful Measurements:
    • Pass a valid shots value (positive integer).
    • Expected return of measurement results and success code 2067.
  2. Failed Measurements:
    • Pass an invalid shots value (e.g., negative number, non-integer).
    • Expected return of corresponding error codes (1075 to 1076).

Checks and Error Messages:


Summary of Test Functions and Codes

Method Overview

Method Description
__init__ Initializes a new instance of the Circuit class.
read_data Reads and extracts data from JSON files.
convert_input_data Converts raw input data into a structured format.
_is_matrix_consistent Checks the consistency of an activation matrix.
_is_empty_matrix Checks if a matrix consists solely of zeros.
check_input_data Verifies the structure and consistency of input_data.
create_L_gate Creates parameters for a single L-Gate.
create_initial_circuit Creates the initial circuit.
check_circuit Verifies the parameters of the entire circuit.
measure Performs measurements on the circuit.

Success and Error Codes

Success Codes

Code Description
2060 Entry successfully validated.
2061 Activation and training data list lengths are correct.
2062 Data successfully extracted.
2063 Circuit blueprint successfully created.
2064 Position successfully incremented.
2065 Line successfully incremented and moved to the next line.
2066 Initial circuit successfully created.
2067 Measurements successfully performed.

Error Codes

Code Description
1060 Invalid entry or missing keys.
1061 Invalid list lengths in activation_matrices or training_matrices.
1062 Error extracting data.
1063 Error merging data or creating the blueprint.
1064 Position exceeds the number of available triplets.
1065 No more lines in input_data (end of data structure).
1066 Error reading data.
1067 Inconsistent activation matrix.
1068 Error converting input data.
1069 Inconsistent input_data.
1070 Error creating the circuit.
1071 Error verifying the circuit.
1072 Number of qubits in the circuit does not match.
1073 Number of phases on a qubit does not match.
1074 Number of Hadamard gates on a qubit does not match.
1075 Invalid value for shots (must be positive).
1076 Error executing the circuit.
4111 No success message found.
4112 Qubit value is 0 or not present.
4113 Depth value is 0 or not present.
4114 Training matrix does not have the required dimensions.
4115 Activation matrix value is inconsistent or not present.
4116 Incorrect error code instead of 1060 or 1020.
4117 Consistent matrix should return True.
4118 Inconsistent matrix should return False.
4119 Matrix of all zeros should return True.
4120 Matrix with non-zero values should return False.
4121 Valid input_data should return True.
4122 Manipulated input_data should return False.
4123 Successful creation should return specific success codes.
4124 Failed creation should return specific error codes.
4125 Successful creation should return 2066.
4126 Failed creation should return specific error codes.
4127 Consistent circuit should return True.
4128 Inconsistent circuit should return specific error codes.
4129 Successful measurements should return 2067.
4130 Failed measurements should return specific error codes.

Additional Notes on Test Implementation