Skip to content
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

Small bugfixes #579

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source/install/installing_mala.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ itself is subject to ongoing development as well.

git clone https://github.com/mala-project/test-data ~/path/to/data/repo
cd ~/path/to/data/repo
git checkout v1.8.0
git checkout v1.8.1

* Export the path to that repo by ``export MALA_DATA_REPO=~/path/to/data/repo``

Expand Down
6 changes: 3 additions & 3 deletions mala/interfaces/ase_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def calculate_properties(self, atoms, properties):
"e_ewald"
]

def save_calculator(self, filename, save_path="./"):
def save_calculator(self, filename, path="./"):
"""
Save parameters used for this calculator.

Expand All @@ -210,10 +210,10 @@ def save_calculator(self, filename, save_path="./"):
filename : string
Name of the file in which to store the calculator.

save_path : string
path : string
Path where the calculator should be saved.

"""
self.predictor.save_run(
filename, save_path=save_path, additional_calculation_data=True
filename, path=save_path, additional_calculation_data=True
)
110 changes: 53 additions & 57 deletions mala/network/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ def _calculate_errors(
target_calculator, LDOS
) and not isinstance(target_calculator, Density):
raise Exception(
"Cannot calculate density from this "
"observable."
"Cannot calculate density from this " "observable."
)
target_calculator.read_additional_calculation_data(
self.data.get_snapshot_calculation_output(
Expand Down Expand Up @@ -145,8 +144,7 @@ def _calculate_errors(
target_calculator, LDOS
) and not isinstance(target_calculator, DOS):
raise Exception(
"Cannot calculate the DOS from this "
"observable."
"Cannot calculate the DOS from this " "observable."
)
target_calculator.read_additional_calculation_data(
self.data.get_snapshot_calculation_output(
Expand Down Expand Up @@ -299,10 +297,8 @@ def _calculate_energy_errors(
)
try:
target_calculator.read_from_array(predicted_outputs)
be_predicted_actual_fe = (
target_calculator.get_band_energy(
fermi_energy=fe_actual
)
be_predicted_actual_fe = target_calculator.get_band_energy(
fermi_energy=fe_actual
)
be_error_actual_fe = (
be_predicted_actual_fe - be_actual
Expand Down Expand Up @@ -386,9 +382,7 @@ def _calculate_energy_targets_and_predictions(
snapshot_number
)
if not output_file:
raise Exception(
"Output file needed for energy calculations."
)
raise Exception("Output file needed for energy calculations.")
target_calculator.read_additional_calculation_data(output_file)

targets = {}
Expand All @@ -400,12 +394,8 @@ def _calculate_energy_targets_and_predictions(
actual_outputs
)
except ValueError:
targets = {
energy_type: np.nan for energy_type in energy_types
}
predictions = {
energy_type: np.nan for energy_type in energy_types
}
targets = {energy_type: np.nan for energy_type in energy_types}
predictions = {energy_type: np.nan for energy_type in energy_types}
printout(
"CAUTION! LDOS ground truth is so wrong that the "
"estimation of the self consistent Fermi energy fails."
Expand All @@ -416,12 +406,8 @@ def _calculate_energy_targets_and_predictions(
predicted_outputs
)
except ValueError:
targets = {
energy_type: np.nan for energy_type in energy_types
}
predictions = {
energy_type: np.nan for energy_type in energy_types
}
targets = {energy_type: np.nan for energy_type in energy_types}
predictions = {energy_type: np.nan for energy_type in energy_types}
printout(
"CAUTION! LDOS prediction is so wrong that the "
"estimation of the self consistent Fermi energy fails."
Expand All @@ -447,8 +433,12 @@ def _calculate_energy_targets_and_predictions(
be_predicted = target_calculator.get_band_energy(
fermi_energy=fe_predicted
)
targets[energy_type] = be_actual * 1000 / len(target_calculator.atoms)
predictions[energy_type] = be_predicted * 1000 / len(target_calculator.atoms)
targets[energy_type] = (
be_actual * 1000 / len(target_calculator.atoms)
)
predictions[energy_type] = (
be_predicted * 1000 / len(target_calculator.atoms)
)
except ValueError:
targets[energy_type] = np.nan
predictions[energy_type] = np.nan
Expand All @@ -461,13 +451,17 @@ def _calculate_energy_targets_and_predictions(
)
try:
target_calculator.read_from_array(predicted_outputs)
be_predicted_actual_fe = (
target_calculator.get_band_energy(
fermi_energy=fe_actual
)
be_predicted_actual_fe = target_calculator.get_band_energy(
fermi_energy=fe_actual
)
targets[energy_type] = (
be_actual * 1000 / len(target_calculator.atoms)
)
predictions[energy_type] = (
be_predicted_actual_fe
* 1000
/ len(target_calculator.atoms)
)
targets[energy_type] = be_actual * 1000 / len(target_calculator.atoms)
predictions[energy_type] = be_predicted_actual_fe * 1000 / len(target_calculator.atoms)
except ValueError:
targets[energy_type] = np.nan
predictions[energy_type] = np.nan
Expand All @@ -491,8 +485,12 @@ def _calculate_energy_targets_and_predictions(
te_predicted = target_calculator.get_total_energy(
fermi_energy=fe_predicted
)
targets[energy_type] = te_actual * 1000 / len(target_calculator.atoms)
predictions[energy_type] = te_predicted * 1000 / len(target_calculator.atoms)
targets[energy_type] = (
te_actual * 1000 / len(target_calculator.atoms)
)
predictions[energy_type] = (
te_predicted * 1000 / len(target_calculator.atoms)
)
except ValueError:
targets[energy_type] = np.nan
predictions[energy_type] = np.nan
Expand All @@ -509,9 +507,15 @@ def _calculate_energy_targets_and_predictions(
fermi_energy=fe_actual
)
)

targets[energy_type] = te_actual * 1000 / len(target_calculator.atoms)
predictions[energy_type] = te_predicted_actual_fe * 1000 / len(target_calculator.atoms)

targets[energy_type] = (
te_actual * 1000 / len(target_calculator.atoms)
)
predictions[energy_type] = (
te_predicted_actual_fe
* 1000
/ len(target_calculator.atoms)
)
except ValueError:
targets[energy_type] = np.nan
predictions[energy_type] = np.nan
Expand All @@ -524,7 +528,7 @@ def _calculate_energy_targets_and_predictions(
def save_run(
self,
run_name,
save_path="./",
path="./",
zip_run=True,
save_runner=False,
additional_calculation_data=None,
Expand All @@ -537,7 +541,7 @@ def save_run(
run_name : str
Name under which the run should be saved.

save_path : str
path : str
Path where to which the run.

zip_run : bool
Expand Down Expand Up @@ -567,20 +571,16 @@ def save_run(
params_file = run_name + ".params.json"
if save_runner:
optimizer_file = run_name + ".optimizer.pth"
os.makedirs(save_path, exist_ok=True)
self.parameters_full.save(os.path.join(save_path, params_file))
os.makedirs(path, exist_ok=True)
self.parameters_full.save(os.path.join(path, params_file))
if self.parameters_full.use_ddp:
self.network.module.save_network(
os.path.join(save_path, model_file)
os.path.join(path, model_file)
)
else:
self.network.save_network(os.path.join(save_path, model_file))
self.data.input_data_scaler.save(
os.path.join(save_path, iscaler_file)
)
self.data.output_data_scaler.save(
os.path.join(save_path, oscaler_file)
)
self.network.save_network(os.path.join(path, model_file))
self.data.input_data_scaler.save(os.path.join(path, iscaler_file))
self.data.output_data_scaler.save(os.path.join(path, oscaler_file))

files = [model_file, iscaler_file, oscaler_file, params_file]
if save_runner:
Expand All @@ -593,27 +593,23 @@ def save_run(
additional_calculation_data
)
self.data.target_calculator.write_additional_calculation_data(
os.path.join(
save_path, additional_calculation_file
)
os.path.join(path, additional_calculation_file)
)
elif isinstance(additional_calculation_data, bool):
if additional_calculation_data:
self.data.target_calculator.write_additional_calculation_data(
os.path.join(
save_path, additional_calculation_file
)
os.path.join(path, additional_calculation_file)
)

files.append(additional_calculation_file)
with ZipFile(
os.path.join(save_path, run_name + ".zip"),
os.path.join(path, run_name + ".zip"),
"w",
compression=ZIP_STORED,
) as zip_obj:
for file in files:
zip_obj.write(os.path.join(save_path, file), file)
os.remove(os.path.join(save_path, file))
zip_obj.write(os.path.join(path, file), file)
os.remove(os.path.join(path, file))

@classmethod
def load_run(
Expand Down
2 changes: 1 addition & 1 deletion mala/network/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ def __create_training_checkpoint(self):
self.save_run(
self.parameters.checkpoint_name,
save_runner=True,
save_path=self.parameters.run_name,
path=self.parameters.run_name,
)
else:
self.save_run(self.parameters.checkpoint_name, save_runner=True)
Expand Down
12 changes: 6 additions & 6 deletions mala/targets/calculation_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def integrate_values_on_spacing(values, spacing, method, axis=0):
method : string
Integration method to be used. Currently supported:

- "trapz" for trapezoid method
- "simps" for Simpson method.
- "trapezoid" for trapezoid method
- "simpson" for Simpson method.
axis : int
Axis along which the integration is performed.

Expand All @@ -31,10 +31,10 @@ def integrate_values_on_spacing(values, spacing, method, axis=0):
integral_values : float
The value of the integral.
"""
if method == "trapz":
return integrate.trapz(values, dx=spacing, axis=axis)
elif method == "simps":
return integrate.simps(values, dx=spacing, axis=axis)
if method == "trapezoid":
return integrate.trapezoid(values, dx=spacing, axis=axis)
elif method == "simpson":
return integrate.simpson(values, dx=spacing, axis=axis)
else:
raise Exception("Unknown integration method.")

Expand Down
4 changes: 2 additions & 2 deletions mala/targets/density.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,8 @@ def get_number_of_electrons(
Integration method used to integrate density on the grid.
Currently supported:

- "trapz" for trapezoid method (only for cubic grids).
- "simps" for Simpson method (only for cubic grids).
- "trapezoid" for trapezoid method (only for cubic grids).
- "simpson" for Simpson method (only for cubic grids).
- "summation" for summation and scaling of the values (recommended)
"""
if density_data is None:
Expand Down
Loading