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.
The Start class is responsible for loading essential references and verifying that all necessary files and logs are correctly present at the start of the program. It coordinates the initialization process by conducting various checks and responds accordingly if any issues are detected. All important events and errors are documented in a log file.
Attributes
reader (Reader):
An instance of the Reader class, used for file and log management.
train_json_exists (bool):
A flag indicating whether the train.json file exists after the initial check. Set to False upon instantiation of the class.
Methods
1. __init__(self, reader)
Description:
Initializes the Start class and sets the train_json_exists flag to False.
Parameters:
reader (Reader): An instance of the Reader class used for file and log management.
Functionalities:
Assigns the reader instance to an attribute for use in other methods.
Initializes the train_json_exists flag to False.
2. run(self)
Description:
The run() method is the main execution method that coordinates the initialization process. It performs the following steps:
File Check:
Action: Calls the fileCheck() method from the Reader class to verify the presence of essential files and directories.
Log Message:"Initiating file check..."
Result Handling:
Error Code: 'var' Folder is Missing
Error Code: 1001 - 'var' folder is missing.
Log Message: "ERROR: 'var' folder is missing. Terminating program."
Action: Logs the error and terminates the program with the corresponding error code.
Error Code: 'data.json' Missing
Error Code: 1002 - 'data.json' file is missing in 'var' folder.
Log Message: "ERROR: 'data.json' file is missing. Terminating program."
Action: Logs the error and terminates the program with the corresponding error code.
Error Code: 'config.json' Missing
Error Code: 1003 - 'config.json' file is missing in 'var' folder.
Log Message: "ERROR: 'config.json' file is missing. Terminating program."
Action: Logs the error and terminates the program with the corresponding error code.
Success Code: All Files Present, 'train.json' Exists
Success Code: 2001 - All files are present. 'train.json' exists.
Log Message: "SUCCESS: All files are present. 'train.json' exists."
Action: Sets the train_json_exists flag to True and logs a corresponding message:
Log Message: "'train.json' found. Proceeding with initialization."
Success Code: All Files Present, 'train.json' Missing
Success Code: 2002 - All files are present. 'train.json' is missing.
Log Message: "SUCCESS: All files are present. 'train.json' is missing."
Action: Leaves the train_json_exists flag as False and logs a corresponding message. The program is not terminated if train.json is missing.
Log Message: "'train.json' missing. Proceeding without training file."
Unexpected Error Code:
Error Code: 100105 - Unexpected error during file check.
Log Message: "ERROR: Unexpected error during file check. Terminating program."
Action: Logs the error and terminates the program with the corresponding error code.
Logfile Check:
Action: Calls the checkLog() method from the Reader class to ensure an up-to-date log file exists.
Log Message:"Checking for an existing log file..."
Result Handling:
If the log file is valid and up-to-date:
Log Message: "Log file is valid and up-to-date."
If the log file cannot be created or accessed:
Error Code: 100106 - Failed to create or access log file.
Log Message: "ERROR: Failed to create or access log file. Terminating program."
Action: Logs the error and terminates the program with the corresponding error code.
Data Consistency Check:
Action: Calls the dataConsistency() method from the Reader class to ensure the data.json file is consistent.
Log Message:"Verifying data consistency for 'data.json'..."
Result Handling:
If data.json is inconsistent:
Error Code: 100104 - 'data.json' file is inconsistent.
Log Message: "ERROR: 'data.json' file is inconsistent. Terminating program."
Action: Logs the error and terminates the program with the corresponding error code.
If data.json is consistent:
Success Code: 200103 - 'data.json' is consistent. Proceeding with execution.
Log Message: "'data.json' is consistent. Proceeding with execution."
Action: Logs the successful consistency check and allows the program to continue.
Process Overview
Initialization:
A Reader instance is created.
A Start instance is created, which receives the Reader instance.
Execution (Start.run()):
File Check:
Calls fileCheck() to ensure all necessary files and directories are present.
Depending on the outcome, appropriate error or success codes are logged, and the program may be terminated.
Logfile Check:
Calls checkLog() to verify the existence and currency of the log file.
If there are issues, the program terminates with the corresponding error.
Data Consistency Check:
Calls dataConsistency() to check the consistency of the data.json file.
If inconsistent, the program terminates with the corresponding error.
If successful, the program continues.
Further Initialization:
After successfully running run(), the program can proceed with additional initialization, such as loading and processing data.
Class: Start
The Start class is responsible for loading essential references and verifying that all necessary files and logs are correctly present at the start of the program. It coordinates the initialization process by conducting various checks and responds accordingly if any issues are detected. All important events and errors are documented in a log file.
Attributes
reader
(Reader
):An instance of the
Reader
class, used for file and log management.train_json_exists
(bool
):A flag indicating whether the
train.json
file exists after the initial check. Set toFalse
upon instantiation of the class.Methods
1.
__init__(self, reader)
Description:
Initializes the
Start
class and sets thetrain_json_exists
flag toFalse
.Parameters:
reader
(Reader
): An instance of theReader
class used for file and log management.Functionalities:
reader
instance to an attribute for use in other methods.train_json_exists
flag toFalse
.2.
run(self)
Description:
The
run()
method is the main execution method that coordinates the initialization process. It performs the following steps:File Check:
fileCheck()
method from theReader
class to verify the presence of essential files and directories."Initiating file check..."
Result Handling:
Error Code:
'var' Folder is Missing
Error Code:
'data.json' Missing
Error Code:
'config.json' Missing
Success Code: All Files Present,
'train.json'
ExistsAction: Sets the
train_json_exists
flag toTrue
and logs a corresponding message:Success Code: All Files Present,
'train.json'
MissingAction: Leaves the
train_json_exists
flag asFalse
and logs a corresponding message. The program is not terminated iftrain.json
is missing.Unexpected Error Code:
Logfile Check:
checkLog()
method from theReader
class to ensure an up-to-date log file exists."Checking for an existing log file..."
Result Handling:
If the log file is valid and up-to-date:
If the log file cannot be created or accessed:
Data Consistency Check:
dataConsistency()
method from theReader
class to ensure thedata.json
file is consistent."Verifying data consistency for 'data.json'..."
Result Handling:
If
data.json
is inconsistent:If
data.json
is consistent:Process Overview
Initialization:
Reader
instance is created.Start
instance is created, which receives theReader
instance.Execution (
Start.run()
):File Check:
fileCheck()
to ensure all necessary files and directories are present.Logfile Check:
checkLog()
to verify the existence and currency of the log file.Data Consistency Check:
dataConsistency()
to check the consistency of thedata.json
file.Further Initialization:
run()
, the program can proceed with additional initialization, such as loading and processing data.