diff --git a/impsy/dataset.py b/impsy/dataset.py index b40bf28..0879291 100755 --- a/impsy/dataset.py +++ b/impsy/dataset.py @@ -22,7 +22,9 @@ def transform_log_to_sequence_example(logfile: str, dimension: int): return np.array(perf_df[["t"] + data_names]) -def generate_dataset(dimension: int, source: str = "logs", destination: str = "datasets"): +def generate_dataset( + dimension: int, source: str = "logs", destination: str = "datasets" +): """Generate a dataset from .log files in the log directory.""" # Load up the performances log_location = f"{source}/" @@ -61,7 +63,7 @@ def generate_dataset(dimension: int, source: str = "logs", destination: str = "d raw_perfs.append(raw) if acc == 0: - click.secho("Zero values to add to dataset! aborting.", fg='red') + click.secho("Zero values to add to dataset! aborting.", fg="red") return click.secho(f"total number of values: {acc}", fg="blue") diff --git a/impsy/tests/test_commands.py b/impsy/tests/test_commands.py index 8c073b1..1da5e3b 100644 --- a/impsy/tests/test_commands.py +++ b/impsy/tests/test_commands.py @@ -3,11 +3,12 @@ def test_main_command(): - runner = CliRunner() - result = runner.invoke(cli) - assert result.exit_code == 0 + runner = CliRunner() + result = runner.invoke(cli) + assert result.exit_code == 0 + def test_model_test_command(): - runner = CliRunner() - result = runner.invoke(cli, ['test-mdrnn']) - # assert result.exit_code == 0 + runner = CliRunner() + result = runner.invoke(cli, ["test-mdrnn"]) + # assert result.exit_code == 0 diff --git a/impsy/tests/test_data.py b/impsy/tests/test_data.py index 44e5eaf..77f62f4 100644 --- a/impsy/tests/test_data.py +++ b/impsy/tests/test_data.py @@ -4,45 +4,49 @@ import random -def create_test_log_files(location = "tests/logs", dimension = 4, number = 10, events = 50): - """Creates some test log files for dataset testing.""" - assert dimension > 1, "minimum dimension is 2" - os.makedirs(location, exist_ok=True) - log_files = [] - for i in range(number): - test_log_file = f"{location}/2024-06-{i:02d}T12-00-00-4d-mdrnn.log" - with open(test_log_file, "w") as file: - for j in range(events): - nums = [random.random() for _ in range(dimension-1)] - num_string = ",".join(map(str, nums)) - test_line = f"2024-06-01T12:00:{j:02d},interface,{num_string}\n" - file.write(test_line) - log_files.append(test_log_file) - return log_files +def create_test_log_files(location="tests/logs", dimension=4, number=10, events=50): + """Creates some test log files for dataset testing.""" + assert dimension > 1, "minimum dimension is 2" + os.makedirs(location, exist_ok=True) + log_files = [] + for i in range(number): + test_log_file = f"{location}/2024-06-{i:02d}T12-00-00-4d-mdrnn.log" + with open(test_log_file, "w") as file: + for j in range(events): + nums = [random.random() for _ in range(dimension - 1)] + num_string = ",".join(map(str, nums)) + test_line = f"2024-06-01T12:00:{j:02d},interface,{num_string}\n" + file.write(test_line) + log_files.append(test_log_file) + return log_files def remove_test_log_files(log_files): - """Deletes test log files""" - for f in log_files: - os.remove(f) + """Deletes test log files""" + for f in log_files: + os.remove(f) def test_log_to_examples(): - """Tests transform_log_to_sequence_example with a single example""" - dimension = 8 - log_files = create_test_log_files(number = 1, dimension = dimension) - log = dataset.transform_log_to_sequence_example(log_files[0], dimension) - remove_test_log_files(log_files) - assert(isinstance(log, np.ndarray)) - assert(len(log[0]) == dimension) + """Tests transform_log_to_sequence_example with a single example""" + dimension = 8 + log_files = create_test_log_files(number=1, dimension=dimension) + log = dataset.transform_log_to_sequence_example(log_files[0], dimension) + remove_test_log_files(log_files) + assert isinstance(log, np.ndarray) + assert len(log[0]) == dimension def test_dataset_command(): - """Test the dataset command runs""" - test_log_area = "tests/logs" - test_dataset_area = "tests/datasets" - os.makedirs(test_dataset_area, exist_ok=True) - dimension = 4 - log_files = create_test_log_files(location = test_log_area, dimension = dimension, number = 10) - dataset.generate_dataset(dimension=dimension, source="tests/logs", destination=test_dataset_area) - remove_test_log_files(log_files) + """Test the dataset command runs""" + test_log_area = "tests/logs" + test_dataset_area = "tests/datasets" + os.makedirs(test_dataset_area, exist_ok=True) + dimension = 4 + log_files = create_test_log_files( + location=test_log_area, dimension=dimension, number=10 + ) + dataset.generate_dataset( + dimension=dimension, source="tests/logs", destination=test_dataset_area + ) + remove_test_log_files(log_files) diff --git a/impsy/tests/test_interaction.py b/impsy/tests/test_interaction.py index 2ac2182..6fe8334 100644 --- a/impsy/tests/test_interaction.py +++ b/impsy/tests/test_interaction.py @@ -1,10 +1,11 @@ from impsy import interaction + def test_interaction_server(): - """Just tests creation of an interaction server object""" - interaction_server = interaction.InteractionServer() + """Just tests creation of an interaction server object""" + interaction_server = interaction.InteractionServer() -def test_logging(): - """Just sets up logging""" - interaction.setup_logging(2) +def test_logging(): + """Just sets up logging""" + interaction.setup_logging(2) diff --git a/impsy/tflite_converter.py b/impsy/tflite_converter.py index 05ce58a..2ca1425 100644 --- a/impsy/tflite_converter.py +++ b/impsy/tflite_converter.py @@ -38,7 +38,10 @@ def convert_tflite(): # setup converter click.secho("Setup converter.") converter = tf.lite.TFLiteConverter.from_keras_model(net.model) - converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS] + converter.target_spec.supported_ops = [ + tf.lite.OpsSet.TFLITE_BUILTINS, + tf.lite.OpsSet.SELECT_TF_OPS, + ] converter._experimental_lower_tensor_list_ops = False click.secho("Do the conversion.") @@ -46,5 +49,5 @@ def convert_tflite(): click.secho("Saving..") tflite_model_name = f'{config["model"]["file"]}-lite.tflite' - with open(tflite_model_name, 'wb') as f: - f.write(tflite_model) + with open(tflite_model_name, "wb") as f: + f.write(tflite_model) diff --git a/impsy/utils.py b/impsy/utils.py index 91e67b7..0bf43ae 100644 --- a/impsy/utils.py +++ b/impsy/utils.py @@ -3,7 +3,7 @@ import random -# MDRNN config +# MDRNN config SIZE_TO_PARAMETERS = { @@ -45,7 +45,9 @@ def generate_data(samples: int = 50000, dimension: int = 2): print("Generating", str(NSAMPLE), "toy data samples.") t_data = np.float32(np.array(range(NSAMPLE)) / 10.0) t_interval = t_data[1] - t_data[0] - t_r_data = np.random.normal(0, t_interval / 20.0, size=NSAMPLE) ## fuzz up the time sampling + t_r_data = np.random.normal( + 0, t_interval / 20.0, size=NSAMPLE + ) ## fuzz up the time sampling t_data = t_data + t_r_data r_data = np.random.normal(size=NSAMPLE) # x_data = np.sin(t_data) * 1.0 + (r_data * 0.05)