From 7502731f0b5074eeef71ec71829efab9c02a6d0c Mon Sep 17 00:00:00 2001 From: Lenz Fiedler Date: Wed, 17 Apr 2024 09:23:09 +0200 Subject: [PATCH] Blackified examples --- examples/advanced/ex01_checkpoint_training.py | 33 ++++++---- examples/advanced/ex02_shuffle_data.py | 15 +++-- examples/advanced/ex03_tensor_board.py | 26 +++++--- examples/advanced/ex04_acsd.py | 21 +++++-- ..._checkpoint_hyperparameter_optimization.py | 46 +++++++++----- ...distributed_hyperparameter_optimization.py | 45 ++++++++------ ...07_advanced_hyperparameter_optimization.py | 60 ++++++++++++------- .../advanced/ex08_visualize_observables.py | 23 +++---- examples/basic/ex01_train_network.py | 24 +++++--- examples/basic/ex02_test_network.py | 26 +++++--- examples/basic/ex03_preprocess_data.py | 30 ++++++---- .../basic/ex04_hyperparameter_optimization.py | 29 +++++---- examples/basic/ex05_run_predictions.py | 6 +- examples/basic/ex06_ase_calculator.py | 2 +- 14 files changed, 248 insertions(+), 138 deletions(-) diff --git a/examples/advanced/ex01_checkpoint_training.py b/examples/advanced/ex01_checkpoint_training.py index 857500d5e..341ff5c6f 100644 --- a/examples/advanced/ex01_checkpoint_training.py +++ b/examples/advanced/ex01_checkpoint_training.py @@ -4,6 +4,7 @@ from mala import printout from mala.datahandling.data_repo import data_repo_path + data_path = os.path.join(data_repo_path, "Be2") """ @@ -35,15 +36,27 @@ def initial_setup(): parameters.running.checkpoint_name = "ex01_checkpoint" data_handler = mala.DataHandler(parameters) - data_handler.add_snapshot("Be_snapshot0.in.npy", data_path, - "Be_snapshot0.out.npy", data_path, "tr") - data_handler.add_snapshot("Be_snapshot1.in.npy", data_path, - "Be_snapshot1.out.npy", data_path, "va") + data_handler.add_snapshot( + "Be_snapshot0.in.npy", + data_path, + "Be_snapshot0.out.npy", + data_path, + "tr", + ) + data_handler.add_snapshot( + "Be_snapshot1.in.npy", + data_path, + "Be_snapshot1.out.npy", + data_path, + "va", + ) data_handler.prepare_data() - parameters.network.layer_sizes = [data_handler.input_dimension, - 100, - data_handler.output_dimension] + parameters.network.layer_sizes = [ + data_handler.input_dimension, + 100, + data_handler.output_dimension, + ] test_network = mala.Network(parameters) test_trainer = mala.Trainer(parameters, test_network, data_handler) @@ -52,12 +65,12 @@ def initial_setup(): if mala.Trainer.run_exists("ex01_checkpoint"): - parameters, network, datahandler, trainer = \ - mala.Trainer.load_run("ex01_checkpoint") + parameters, network, datahandler, trainer = mala.Trainer.load_run( + "ex01_checkpoint" + ) printout("Starting resumed training.") else: parameters, network, datahandler, trainer = initial_setup() printout("Starting original training.") trainer.train_network() - diff --git a/examples/advanced/ex02_shuffle_data.py b/examples/advanced/ex02_shuffle_data.py index 7b93980fa..467da7922 100644 --- a/examples/advanced/ex02_shuffle_data.py +++ b/examples/advanced/ex02_shuffle_data.py @@ -19,9 +19,12 @@ parameters.data.shuffling_seed = 1234 data_shuffler = mala.DataShuffler(parameters) -data_shuffler.add_snapshot("Be_snapshot0.in.npy", data_path, - "Be_snapshot0.out.npy", data_path) -data_shuffler.add_snapshot("Be_snapshot1.in.npy", data_path, - "Be_snapshot1.out.npy", data_path) -data_shuffler.shuffle_snapshots(complete_save_path=".", - save_name="Be_shuffled*") +data_shuffler.add_snapshot( + "Be_snapshot0.in.npy", data_path, "Be_snapshot0.out.npy", data_path +) +data_shuffler.add_snapshot( + "Be_snapshot1.in.npy", data_path, "Be_snapshot1.out.npy", data_path +) +data_shuffler.shuffle_snapshots( + complete_save_path=".", save_name="Be_shuffled*" +) diff --git a/examples/advanced/ex03_tensor_board.py b/examples/advanced/ex03_tensor_board.py index b9d436a12..00728a560 100644 --- a/examples/advanced/ex03_tensor_board.py +++ b/examples/advanced/ex03_tensor_board.py @@ -4,6 +4,7 @@ from mala import printout from mala.datahandling.data_repo import data_repo_path + data_path = os.path.join(data_repo_path, "Be2") @@ -29,17 +30,24 @@ data_handler = mala.DataHandler(parameters) -data_handler.add_snapshot("Be_snapshot0.in.npy", data_path, - "Be_snapshot0.out.npy", data_path, "tr") -data_handler.add_snapshot("Be_snapshot1.in.npy", data_path, - "Be_snapshot1.out.npy", data_path, "va") +data_handler.add_snapshot( + "Be_snapshot0.in.npy", data_path, "Be_snapshot0.out.npy", data_path, "tr" +) +data_handler.add_snapshot( + "Be_snapshot1.in.npy", data_path, "Be_snapshot1.out.npy", data_path, "va" +) data_handler.prepare_data() -parameters.network.layer_sizes = [data_handler.input_dimension, - 100, - data_handler.output_dimension] +parameters.network.layer_sizes = [ + data_handler.input_dimension, + 100, + data_handler.output_dimension, +] network = mala.Network(parameters) trainer = mala.Trainer(parameters, network, data_handler) trainer.train_network() -printout("Run finished, launch tensorboard with \"tensorboard --logdir " + - trainer.full_visualization_path + "\"") +printout( + 'Run finished, launch tensorboard with "tensorboard --logdir ' + + trainer.full_visualization_path + + '"' +) diff --git a/examples/advanced/ex04_acsd.py b/examples/advanced/ex04_acsd.py index 434fb6d17..02f561a32 100644 --- a/examples/advanced/ex04_acsd.py +++ b/examples/advanced/ex04_acsd.py @@ -3,6 +3,7 @@ import mala import numpy as np from mala.datahandling.data_repo import data_repo_path + data_path = os.path.join(data_repo_path, "Be2") """ @@ -29,12 +30,20 @@ # When adding data for the ACSD analysis, add preprocessed LDOS data for # and a calculation output for the descriptor calculation. #################### -hyperoptimizer.add_snapshot("espresso-out", os.path.join(data_path, "Be_snapshot1.out"), - "numpy", os.path.join(data_path, "Be_snapshot1.out.npy"), - target_units="1/(Ry*Bohr^3)") -hyperoptimizer.add_snapshot("espresso-out", os.path.join(data_path, "Be_snapshot2.out"), - "numpy", os.path.join(data_path, "Be_snapshot2.out.npy"), - target_units="1/(Ry*Bohr^3)") +hyperoptimizer.add_snapshot( + "espresso-out", + os.path.join(data_path, "Be_snapshot1.out"), + "numpy", + os.path.join(data_path, "Be_snapshot1.out.npy"), + target_units="1/(Ry*Bohr^3)", +) +hyperoptimizer.add_snapshot( + "espresso-out", + os.path.join(data_path, "Be_snapshot2.out"), + "numpy", + os.path.join(data_path, "Be_snapshot2.out.npy"), + target_units="1/(Ry*Bohr^3)", +) # If you plan to plot the results (recommended for exploratory searches), # the optimizer can return the necessary quantities to plot. diff --git a/examples/advanced/ex05_checkpoint_hyperparameter_optimization.py b/examples/advanced/ex05_checkpoint_hyperparameter_optimization.py index 7bee9aec9..253b9e9e9 100644 --- a/examples/advanced/ex05_checkpoint_hyperparameter_optimization.py +++ b/examples/advanced/ex05_checkpoint_hyperparameter_optimization.py @@ -4,6 +4,7 @@ from mala import printout from mala.datahandling.data_repo import data_repo_path + data_path = os.path.join(data_repo_path, "Be2") """ @@ -29,34 +30,47 @@ def initial_setup(): parameters.hyperparameters.checkpoint_name = "ex05_checkpoint" data_handler = mala.DataHandler(parameters) - data_handler.add_snapshot("Be_snapshot0.in.npy", data_path, - "Be_snapshot0.out.npy", data_path, "tr") - data_handler.add_snapshot("Be_snapshot1.in.npy", data_path, - "Be_snapshot1.out.npy", data_path, "va") + data_handler.add_snapshot( + "Be_snapshot0.in.npy", + data_path, + "Be_snapshot0.out.npy", + data_path, + "tr", + ) + data_handler.add_snapshot( + "Be_snapshot1.in.npy", + data_path, + "Be_snapshot1.out.npy", + data_path, + "va", + ) data_handler.prepare_data() hyperoptimizer = mala.HyperOpt(parameters, data_handler) - hyperoptimizer.add_hyperparameter("float", "learning_rate", - 0.0000001, 0.01) + hyperoptimizer.add_hyperparameter( + "float", "learning_rate", 0.0000001, 0.01 + ) hyperoptimizer.add_hyperparameter("int", "ff_neurons_layer_00", 10, 100) hyperoptimizer.add_hyperparameter("int", "ff_neurons_layer_01", 10, 100) - hyperoptimizer.add_hyperparameter("categorical", "layer_activation_00", - choices=["ReLU", "Sigmoid"]) - hyperoptimizer.add_hyperparameter("categorical", "layer_activation_01", - choices=["ReLU", "Sigmoid"]) - hyperoptimizer.add_hyperparameter("categorical", "layer_activation_02", - choices=["ReLU", "Sigmoid"]) + hyperoptimizer.add_hyperparameter( + "categorical", "layer_activation_00", choices=["ReLU", "Sigmoid"] + ) + hyperoptimizer.add_hyperparameter( + "categorical", "layer_activation_01", choices=["ReLU", "Sigmoid"] + ) + hyperoptimizer.add_hyperparameter( + "categorical", "layer_activation_02", choices=["ReLU", "Sigmoid"] + ) return parameters, data_handler, hyperoptimizer if mala.HyperOptOptuna.checkpoint_exists("ex05_checkpoint"): - parameters, datahandler, hyperoptimizer = \ - mala.HyperOptOptuna.resume_checkpoint( - "ex05_checkpoint") + parameters, datahandler, hyperoptimizer = ( + mala.HyperOptOptuna.resume_checkpoint("ex05_checkpoint") + ) else: parameters, datahandler, hyperoptimizer = initial_setup() # Perform hyperparameter optimization. hyperoptimizer.perform_study() - diff --git a/examples/advanced/ex06_distributed_hyperparameter_optimization.py b/examples/advanced/ex06_distributed_hyperparameter_optimization.py index 336bddd87..8ccbc352e 100644 --- a/examples/advanced/ex06_distributed_hyperparameter_optimization.py +++ b/examples/advanced/ex06_distributed_hyperparameter_optimization.py @@ -4,6 +4,7 @@ from mala import printout from mala.datahandling.data_repo import data_repo_path + data_path = os.path.join(data_repo_path, "Be2") """ @@ -36,7 +37,7 @@ parameters.hyperparameters.checkpoint_name = "ex06" parameters.hyperparameters.hyper_opt_method = "optuna" parameters.hyperparameters.study_name = "ex06" -parameters.hyperparameters.rdb_storage = 'sqlite:///ex06.db' +parameters.hyperparameters.rdb_storage = "sqlite:///ex06.db" # Hyperparameter optimization can be further refined by using ensemble training # at each step and by using a different metric then the validation loss @@ -50,27 +51,37 @@ data_handler = mala.DataHandler(parameters) -data_handler.add_snapshot("Be_snapshot1.in.npy", data_path, - "Be_snapshot1.out.npy", data_path, "tr", - calculation_output_file= - os.path.join(data_path, "Be_snapshot1.out")) -data_handler.add_snapshot("Be_snapshot2.in.npy", data_path, - "Be_snapshot2.out.npy", data_path, "va", - calculation_output_file= - os.path.join(data_path, "Be_snapshot2.out")) +data_handler.add_snapshot( + "Be_snapshot1.in.npy", + data_path, + "Be_snapshot1.out.npy", + data_path, + "tr", + calculation_output_file=os.path.join(data_path, "Be_snapshot1.out"), +) +data_handler.add_snapshot( + "Be_snapshot2.in.npy", + data_path, + "Be_snapshot2.out.npy", + data_path, + "va", + calculation_output_file=os.path.join(data_path, "Be_snapshot2.out"), +) data_handler.prepare_data() hyperoptimizer = mala.HyperOpt(parameters, data_handler) -hyperoptimizer.add_hyperparameter("float", "learning_rate", - 0.0000001, 0.01) +hyperoptimizer.add_hyperparameter("float", "learning_rate", 0.0000001, 0.01) hyperoptimizer.add_hyperparameter("int", "ff_neurons_layer_00", 10, 100) hyperoptimizer.add_hyperparameter("int", "ff_neurons_layer_01", 10, 100) -hyperoptimizer.add_hyperparameter("categorical", "layer_activation_00", - choices=["ReLU", "Sigmoid"]) -hyperoptimizer.add_hyperparameter("categorical", "layer_activation_01", - choices=["ReLU", "Sigmoid"]) -hyperoptimizer.add_hyperparameter("categorical", "layer_activation_02", - choices=["ReLU", "Sigmoid"]) +hyperoptimizer.add_hyperparameter( + "categorical", "layer_activation_00", choices=["ReLU", "Sigmoid"] +) +hyperoptimizer.add_hyperparameter( + "categorical", "layer_activation_01", choices=["ReLU", "Sigmoid"] +) +hyperoptimizer.add_hyperparameter( + "categorical", "layer_activation_02", choices=["ReLU", "Sigmoid"] +) hyperoptimizer.perform_study() hyperoptimizer.set_optimal_parameters() diff --git a/examples/advanced/ex07_advanced_hyperparameter_optimization.py b/examples/advanced/ex07_advanced_hyperparameter_optimization.py index 48dc84850..629d47962 100644 --- a/examples/advanced/ex07_advanced_hyperparameter_optimization.py +++ b/examples/advanced/ex07_advanced_hyperparameter_optimization.py @@ -4,6 +4,7 @@ from mala import printout from mala.datahandling.data_repo import data_repo_path + data_path = os.path.join(data_repo_path, "Be2") """ @@ -33,30 +34,49 @@ def optimize_hyperparameters(hyper_optimizer): data_handler = mala.DataHandler(parameters) # Add all the snapshots we want to use in to the list. - data_handler.add_snapshot("Be_snapshot0.in.npy", data_path, - "Be_snapshot0.out.npy", data_path, "tr") - data_handler.add_snapshot("Be_snapshot1.in.npy", data_path, - "Be_snapshot1.out.npy", data_path, "va") - data_handler.add_snapshot("Be_snapshot2.in.npy", data_path, - "Be_snapshot2.out.npy", data_path, "te") + data_handler.add_snapshot( + "Be_snapshot0.in.npy", + data_path, + "Be_snapshot0.out.npy", + data_path, + "tr", + ) + data_handler.add_snapshot( + "Be_snapshot1.in.npy", + data_path, + "Be_snapshot1.out.npy", + data_path, + "va", + ) + data_handler.add_snapshot( + "Be_snapshot2.in.npy", + data_path, + "Be_snapshot2.out.npy", + data_path, + "te", + ) data_handler.prepare_data() printout("Read data: DONE.") hyperoptimizer = mala.HyperOpt(parameters, data_handler) - parameters.network.layer_sizes = [data_handler.input_dimension, - 100, 100, - data_handler.output_dimension] - hyperoptimizer.add_hyperparameter("categorical", "trainingtype", - choices=["Adam", "SGD"]) - hyperoptimizer.add_hyperparameter("categorical", - "layer_activation_00", - choices=["ReLU", "Sigmoid"]) - hyperoptimizer.add_hyperparameter("categorical", - "layer_activation_01", - choices=["ReLU", "Sigmoid"]) - hyperoptimizer.add_hyperparameter("categorical", - "layer_activation_02", - choices=["ReLU", "Sigmoid"]) + parameters.network.layer_sizes = [ + data_handler.input_dimension, + 100, + 100, + data_handler.output_dimension, + ] + hyperoptimizer.add_hyperparameter( + "categorical", "trainingtype", choices=["Adam", "SGD"] + ) + hyperoptimizer.add_hyperparameter( + "categorical", "layer_activation_00", choices=["ReLU", "Sigmoid"] + ) + hyperoptimizer.add_hyperparameter( + "categorical", "layer_activation_01", choices=["ReLU", "Sigmoid"] + ) + hyperoptimizer.add_hyperparameter( + "categorical", "layer_activation_02", choices=["ReLU", "Sigmoid"] + ) hyperoptimizer.perform_study() hyperoptimizer.set_optimal_parameters() diff --git a/examples/advanced/ex08_visualize_observables.py b/examples/advanced/ex08_visualize_observables.py index 1073f4ea1..e9834f3ba 100644 --- a/examples/advanced/ex08_visualize_observables.py +++ b/examples/advanced/ex08_visualize_observables.py @@ -5,10 +5,13 @@ import numpy as np from mala.datahandling.data_repo import data_repo_path -atoms_path = os.path.join(os.path.join(data_repo_path, "Be2"), - "Be_snapshot1.out") -ldos_path = os.path.join(os.path.join(data_repo_path, "Be2"), - "Be_snapshot1.out.npy") + +atoms_path = os.path.join( + os.path.join(data_repo_path, "Be2"), "Be_snapshot1.out" +) +ldos_path = os.path.join( + os.path.join(data_repo_path, "Be2"), "Be_snapshot1.out.npy" +) """ Shows how MALA can be used to visualize observables of interest. """ @@ -46,11 +49,11 @@ density_calculator.write_to_cube("Be_density.cube") # The radial distribution function can be visualized on discretized radii. -rdf, radii = ldos_calculator.\ - radial_distribution_function_from_atoms(ldos_calculator.atoms, - number_of_bins=500) +rdf, radii = ldos_calculator.radial_distribution_function_from_atoms( + ldos_calculator.atoms, number_of_bins=500 +) # The static structure factor can be visualized on a discretized k-grid. -static_structure, kpoints = ldos_calculator.\ - static_structure_factor_from_atoms(ldos_calculator.atoms, - number_of_bins=500, kMax=12) +static_structure, kpoints = ldos_calculator.static_structure_factor_from_atoms( + ldos_calculator.atoms, number_of_bins=500, kMax=12 +) diff --git a/examples/basic/ex01_train_network.py b/examples/basic/ex01_train_network.py index 93b771104..a5d14d890 100644 --- a/examples/basic/ex01_train_network.py +++ b/examples/basic/ex01_train_network.py @@ -3,6 +3,7 @@ import mala from mala.datahandling.data_repo import data_repo_path + data_path = os.path.join(data_repo_path, "Be2") """ @@ -54,10 +55,12 @@ data_handler = mala.DataHandler(parameters) # Add a snapshot we want to use in to the list. -data_handler.add_snapshot("Be_snapshot0.in.npy", data_path, - "Be_snapshot0.out.npy", data_path, "tr") -data_handler.add_snapshot("Be_snapshot1.in.npy", data_path, - "Be_snapshot1.out.npy", data_path, "va") +data_handler.add_snapshot( + "Be_snapshot0.in.npy", data_path, "Be_snapshot0.out.npy", data_path, "tr" +) +data_handler.add_snapshot( + "Be_snapshot1.in.npy", data_path, "Be_snapshot1.out.npy", data_path, "va" +) data_handler.prepare_data() #################### @@ -69,9 +72,11 @@ # class can be used to correctly define input and output layer of the NN. #################### -parameters.network.layer_sizes = [data_handler.input_dimension, - 100, - data_handler.output_dimension] +parameters.network.layer_sizes = [ + data_handler.input_dimension, + 100, + data_handler.output_dimension, +] test_network = mala.Network(parameters) #################### @@ -87,5 +92,6 @@ test_trainer = mala.Trainer(parameters, test_network, data_handler) test_trainer.train_network() additional_calculation_data = os.path.join(data_path, "Be_snapshot0.out") -test_trainer.save_run("be_model", - additional_calculation_data=additional_calculation_data) +test_trainer.save_run( + "be_model", additional_calculation_data=additional_calculation_data +) diff --git a/examples/basic/ex02_test_network.py b/examples/basic/ex02_test_network.py index 880b1bdc1..6ef81f880 100644 --- a/examples/basic/ex02_test_network.py +++ b/examples/basic/ex02_test_network.py @@ -4,6 +4,7 @@ from mala import printout from mala.datahandling.data_repo import data_repo_path + data_path = os.path.join(data_repo_path, "Be2") """ @@ -38,14 +39,22 @@ # When preparing the data, make sure to select "reparametrize_scalers=False", # since data scaling was initialized during model training. #################### -data_handler.add_snapshot("Be_snapshot2.in.npy", data_path, - "Be_snapshot2.out.npy", data_path, "te", - calculation_output_file= - os.path.join(data_path, "Be_snapshot2.out")) -data_handler.add_snapshot("Be_snapshot3.in.npy", data_path, - "Be_snapshot3.out.npy", data_path, "te", - calculation_output_file= - os.path.join(data_path, "Be_snapshot3.out")) +data_handler.add_snapshot( + "Be_snapshot2.in.npy", + data_path, + "Be_snapshot2.out.npy", + data_path, + "te", + calculation_output_file=os.path.join(data_path, "Be_snapshot2.out"), +) +data_handler.add_snapshot( + "Be_snapshot3.in.npy", + data_path, + "Be_snapshot3.out.npy", + data_path, + "te", + calculation_output_file=os.path.join(data_path, "Be_snapshot3.out"), +) data_handler.prepare_data(reparametrize_scaler=False) @@ -57,4 +66,3 @@ #################### results = tester.test_all_snapshots() printout(results) - diff --git a/examples/basic/ex03_preprocess_data.py b/examples/basic/ex03_preprocess_data.py index 58cb275ce..72ec9490a 100644 --- a/examples/basic/ex03_preprocess_data.py +++ b/examples/basic/ex03_preprocess_data.py @@ -3,6 +3,7 @@ import mala from mala.datahandling.data_repo import data_repo_path + data_path = os.path.join(data_repo_path, "Be2") """ @@ -61,13 +62,15 @@ outfile = os.path.join(data_path, "Be_snapshot0.out") ldosfile = os.path.join(data_path, "cubes/tmp.pp*Be_ldos.cube") -data_converter.add_snapshot(descriptor_input_type="espresso-out", - descriptor_input_path=outfile, - target_input_type=".cube", - target_input_path=ldosfile, - additional_info_input_type="espresso-out", - additional_info_input_path=outfile, - target_units="1/(Ry*Bohr^3)") +data_converter.add_snapshot( + descriptor_input_type="espresso-out", + descriptor_input_path=outfile, + target_input_type=".cube", + target_input_path=ldosfile, + additional_info_input_type="espresso-out", + additional_info_input_path=outfile, + target_units="1/(Ry*Bohr^3)", +) #################### # 3. Converting the data @@ -80,12 +83,13 @@ # complete_save_path keyword may be used. #################### -data_converter.convert_snapshots(descriptor_save_path="./", - target_save_path="./", - additional_info_save_path="./", - naming_scheme="Be_snapshot*.npy", - descriptor_calculation_kwargs= - {"working_directory": data_path}) +data_converter.convert_snapshots( + descriptor_save_path="./", + target_save_path="./", + additional_info_save_path="./", + naming_scheme="Be_snapshot*.npy", + descriptor_calculation_kwargs={"working_directory": data_path}, +) # data_converter.convert_snapshots(complete_save_path="./", # naming_scheme="Be_snapshot*.npy", # descriptor_calculation_kwargs= diff --git a/examples/basic/ex04_hyperparameter_optimization.py b/examples/basic/ex04_hyperparameter_optimization.py index 293f0251b..0b53805b6 100644 --- a/examples/basic/ex04_hyperparameter_optimization.py +++ b/examples/basic/ex04_hyperparameter_optimization.py @@ -4,6 +4,7 @@ from mala import printout from mala.datahandling.data_repo import data_repo_path + data_path = os.path.join(data_repo_path, "Be2") """ @@ -32,10 +33,12 @@ # Data is added in the same way it is done for training a model. #################### data_handler = mala.DataHandler(parameters) -data_handler.add_snapshot("Be_snapshot0.in.npy", data_path, - "Be_snapshot0.out.npy", data_path, "tr") -data_handler.add_snapshot("Be_snapshot1.in.npy", data_path, - "Be_snapshot1.out.npy", data_path, "va") +data_handler.add_snapshot( + "Be_snapshot0.in.npy", data_path, "Be_snapshot0.out.npy", data_path, "tr" +) +data_handler.add_snapshot( + "Be_snapshot1.in.npy", data_path, "Be_snapshot1.out.npy", data_path, "va" +) data_handler.prepare_data() #################### @@ -49,14 +52,20 @@ #################### hyperoptimizer = mala.HyperOpt(parameters, data_handler) -hyperoptimizer.add_hyperparameter("categorical", "learning_rate", - choices=[0.005, 0.01, 0.015]) hyperoptimizer.add_hyperparameter( - "categorical", "ff_neurons_layer_00", choices=[32, 64, 96]) + "categorical", "learning_rate", choices=[0.005, 0.01, 0.015] +) +hyperoptimizer.add_hyperparameter( + "categorical", "ff_neurons_layer_00", choices=[32, 64, 96] +) +hyperoptimizer.add_hyperparameter( + "categorical", "ff_neurons_layer_01", choices=[32, 64, 96] +) hyperoptimizer.add_hyperparameter( - "categorical", "ff_neurons_layer_01", choices=[32, 64, 96]) -hyperoptimizer.add_hyperparameter("categorical", "layer_activation_00", - choices=["ReLU", "Sigmoid", "LeakyReLU"]) + "categorical", + "layer_activation_00", + choices=["ReLU", "Sigmoid", "LeakyReLU"], +) #################### # 4. PERFORMING THE HYPERPARAMETER STUDY. diff --git a/examples/basic/ex05_run_predictions.py b/examples/basic/ex05_run_predictions.py index 9c1e118d1..4e0d72e3b 100644 --- a/examples/basic/ex05_run_predictions.py +++ b/examples/basic/ex05_run_predictions.py @@ -5,6 +5,7 @@ from mala import printout from mala.datahandling.data_repo import data_repo_path + data_path = os.path.join(data_repo_path, "Be2") assert os.path.exists("be_model.zip"), "Be model missing, run ex01 first." @@ -22,8 +23,9 @@ # To use the predictor class to test an ML-DFT model, simply load it via the # Tester class interface. Afterwards, set the necessary parameters. #################### -parameters, network, data_handler, predictor = mala.Predictor.\ - load_run("be_model") +parameters, network, data_handler, predictor = mala.Predictor.load_run( + "be_model" +) #################### diff --git a/examples/basic/ex06_ase_calculator.py b/examples/basic/ex06_ase_calculator.py index 1759c9939..0ea62a342 100644 --- a/examples/basic/ex06_ase_calculator.py +++ b/examples/basic/ex06_ase_calculator.py @@ -5,6 +5,7 @@ from ase.io import read from mala.datahandling.data_repo import data_repo_path + data_path = os.path.join(data_repo_path, "Be2") assert os.path.exists("be_model.zip"), "Be model missing, run ex01 first." @@ -35,4 +36,3 @@ atoms = read(os.path.join(data_path, "Be_snapshot1.out")) atoms.set_calculator(calculator) print(atoms.get_potential_energy()) -