-
Notifications
You must be signed in to change notification settings - Fork 0
Testing #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Testing #34
Changes from all commits
f7d9d31
d53f5a1
f245217
138f55d
523efa3
cec9ce3
8ccc59c
3d82dbd
0aa996c
7f75f22
2e56b93
064bafa
a84bbad
0476eaa
fb41339
62135bc
973a0b2
cbbc28d
a8666f6
59b65f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Das sieht für mich eher nach einer Test-Konfiguration aus. Das sollte eher lokal bleiben und nicht Teil des Commits werden. |
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Auch das hier, gerne einfach löschen, da es nur eine lokale Konfiguration ist. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,7 @@ loggers: | |
| level: INFO | ||
|
|
||
| split_optimizer: | ||
| level: INFO | ||
| level: DEBUG | ||
|
|
||
| root: | ||
| handlers: [rich, info_file_handler] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. S.o. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| data_processing: | ||
| batch_size: 10 | ||
| batch_size: 100 | ||
| # batch_size_range: [1, 2, 4, 10, 100] | ||
| TRAINING_SIZE: ${TRAINING_SIZE} | ||
| TEST_SIZE: ${TEST_SIZE} | ||
|
|
||
| classes: ${classes} | ||
|
|
||
| torch_seed: ${torch_seed} |
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. S.o. |
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bin mir nicht ganz sicher, aber brauchen wir den Teil nicht? |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,5 @@ mlflow | |
| pennylane | ||
| torchmetrics | ||
| optuna | ||
| optuna_dashboard | ||
| optuna_dashboard | ||
| pytest | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| import torch | ||
| import pennylane as qml | ||
| import time | ||
| from .metric_tensor import metric_tensor | ||
|
|
||
| import logging | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| from pathlib import Path | ||
| import numpy as np | ||
| import torch | ||
| from kedro.framework.session import KedroSession | ||
| from kedro.framework.startup import bootstrap_project | ||
|
|
||
|
|
||
| def run_preprocessing(): | ||
| bootstrap_project(Path.cwd()) | ||
| with KedroSession.create() as session: | ||
| output = session.run(pipeline_name="preprocessing") | ||
|
|
||
| parameters = session.load_context().config_loader["parameters"]["data_processing"] | ||
| train_dataloader = output["train_dataloader"] | ||
| test_dataloader = output["test_dataloader"] | ||
|
|
||
| return parameters, train_dataloader, test_dataloader | ||
|
|
||
|
|
||
| class TestDataPreparation: | ||
| parameters, train_dataloader, test_dataloader = run_preprocessing() | ||
| _, second_train_dataloader, second_test_dataloader = run_preprocessing() | ||
|
|
||
| def test_data_shape(self): | ||
| train_data, _ = next(iter(self.train_dataloader)) | ||
| train_data_size = train_data.size() | ||
|
|
||
| test_data, _ = next(iter(self.test_dataloader)) | ||
| test_data_size = test_data.size() | ||
| test_size = self.test_dataloader.dataset.data.shape[0] | ||
|
|
||
| assert np.all( | ||
| np.array(test_data_size) == np.array([test_size, 1, 28, 28]) | ||
| ), f"test_data should have the shape[1, 1, 28, 28] but has the shape {np.array(test_data_size)}" | ||
| assert np.all( | ||
| np.array(train_data_size) == np.array([self.parameters["batch_size"], 1, 28, 28]) | ||
| ), f"train_data should have the shape[{self.parameters['batch_size']}, 1, 28, 28] but has the shape {np.array(train_data_size)}" | ||
|
|
||
|
|
||
| def test_data_size(self): | ||
| training_size = self.train_dataloader.dataset.data.shape[0] | ||
| test_size = self.test_dataloader.dataset.data.shape[0] | ||
|
|
||
| assert ( | ||
| training_size == self.parameters["TRAINING_SIZE"] | ||
| ), f"training_size is {training_size} but should be {self.parameters['TRAINING_SIZE']}" | ||
| assert ( | ||
| test_size == self.parameters["TEST_SIZE"] | ||
| ), f"test_size is {test_size} but should be {self.parameters['TEST_SIZE']}" | ||
|
|
||
| def test_normalization(self): | ||
| train_data, _ = next(iter(self.train_dataloader)) | ||
| test_data, _ = next(iter(self.test_dataloader)) | ||
|
|
||
| assert torch.max(train_data) <= 1, "train_data is not normalized" | ||
| assert torch.max(test_data) <= 1, "test_data is not normalized" | ||
|
|
||
| def test_data_reproducability(self): | ||
| train_data = self.train_dataloader.dataset.data | ||
| test_data = self.test_dataloader.dataset.data | ||
| second_train_data = self.second_train_dataloader.dataset.data | ||
| second_test_data = self.second_test_dataloader.dataset.data | ||
|
|
||
| assert torch.all(torch.eq(train_data, second_train_data)), "data preparation pipeline is not reproducable" | ||
| assert torch.all(torch.eq(test_data, second_test_data)), "data preparation pipeline is not reproducable" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import numpy as np | ||
| from kedro.framework.session import KedroSession | ||
| import json | ||
| from pathlib import Path | ||
| from kedro.framework.startup import bootstrap_project | ||
|
|
||
| def run_training(): | ||
| with KedroSession.create() as session: | ||
| output = session.run(pipeline_name="test_pipeline") | ||
| data_catalog = session.load_context().catalog | ||
|
|
||
| data_catalog = session.load_context().config_loader["catalog"] | ||
| metrics_fig = data_catalog["data_science.metrics_fig"]["data_set"] | ||
| filepath = metrics_fig["filepath"] | ||
|
|
||
| with open(filepath, "r") as file: | ||
| metrics = json.load(file) | ||
|
|
||
| train_loss = metrics["data"][0]["y"] | ||
| train_accuracy = metrics["data"][1]["y"] | ||
| val_accuracy = metrics["data"][3]["y"] | ||
| parameters = session.load_context().config_loader["parameters"][ | ||
| "data_processing" | ||
| ] | ||
|
|
||
| return train_loss, train_accuracy, val_accuracy, parameters | ||
|
|
||
|
|
||
| class TestTraining: | ||
| bootstrap_project(Path.cwd()) | ||
| train_loss, train_accuracy, val_accuracy, parameters = run_training() | ||
| second_train_loss, second_train_accuracy, second_val_accuracy, _ = run_training() | ||
|
|
||
| def test_training(self): | ||
| coincidence_accuracy = 1 / len(self.parameters["classes"]) | ||
| # check if accuracy is better than the minimum coincidence case | ||
| assert ( | ||
| self.train_accuracy[-1] > coincidence_accuracy | ||
| ), f"train accuracy should be higher than {coincidence_accuracy}" | ||
| assert ( | ||
| self.val_accuracy[-1] > coincidence_accuracy | ||
| ), f"validation accuracy should be higher than {coincidence_accuracy} " | ||
|
|
||
| def test_reproducability(self): | ||
| assert np.array_equal( | ||
| self.second_train_loss, self.train_loss | ||
| ), "training is not consistent" | ||
|
|
||
| def test_optimizer(): | ||
| bootstrap_project(Path.cwd()) | ||
| # iterate all optimizer, run a training | ||
| for i in ["SGD", "Adam"]: | ||
| for p in ["Adam", "SPSA", "SGD", "NGD", "QNG"]: | ||
| params = { | ||
| "data_science": { | ||
| "optimizer": { | ||
| "split": {"classical": {"name": i}, "quantum": {"name": p}} | ||
| } | ||
| } | ||
| } | ||
| # create kedroSession and change optimizer by passing extra_params | ||
| with KedroSession.create(extra_params=params) as session: | ||
| parameters = session.load_context().params["data_science"] | ||
| optimizer = parameters["optimizer"] | ||
| if "split" not in optimizer: | ||
| raise ValueError("Enable Split Optimizer in config") | ||
| output = session.run(pipeline_name="debug_pipeline") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Das können wir vermutlich löschen oder?